]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/waveout.c
FSF address change.
[vlc] / modules / audio_output / waveout.c
index d742c28fc82c46fa41b8483611fb5271c966a001..fbee1c0ab161c6a4326f17ac621d617cbc86ad74 100644 (file)
@@ -1,16 +1,16 @@
 /*****************************************************************************
  * waveout.c : Windows waveOut plugin for vlc
  *****************************************************************************
- * Copyright (C) 2001 VideoLAN
+ * Copyright (C) 2001 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
- *      
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -34,7 +34,7 @@
 #include <windows.h>
 #include <mmsystem.h>
 
-#define FRAME_SIZE 1024              /* The size is in samples, not in bytes */
+#define FRAME_SIZE 4096              /* The size is in samples, not in bytes */
 #define FRAMES_NUM 8
 
 /*****************************************************************************
  *****************************************************************************/
 #ifdef UNDER_CE
 #   define DWORD_PTR DWORD
+#   ifdef waveOutGetDevCaps
+#       undef waveOutGetDevCaps
+        MMRESULT WINAPI waveOutGetDevCaps(UINT, LPWAVEOUTCAPS, UINT);
+#   endif
 #endif
 
 #ifndef WAVE_FORMAT_IEEE_FLOAT
@@ -123,6 +127,10 @@ static int PlayWaveOut   ( aout_instance_t *, HWAVEOUT, WAVEHDR *,
 static void CALLBACK WaveOutCallback ( HWAVEOUT, UINT, DWORD, DWORD, DWORD );
 static void WaveOutThread( notification_thread_t * );
 
+static int VolumeInfos( aout_instance_t *, audio_volume_t * );
+static int VolumeGet( aout_instance_t *, audio_volume_t * );
+static int VolumeSet( aout_instance_t *, audio_volume_t );
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -132,6 +140,7 @@ static void WaveOutThread( notification_thread_t * );
     "audio output mode (which is not well supported by some soundcards)." )
 
 vlc_module_begin();
+    set_shortname( "WaveOut" );
     set_description( _("Win32 waveOut extension output") );
     set_capability( "audio output", 50 );
     set_category( CAT_AUDIO );
@@ -245,6 +254,8 @@ static int Open( vlc_object_t *p_this )
     }
     else
     {
+        WAVEOUTCAPS wocaps;
+
         if( val.i_int == AOUT_VAR_5_1 )
         {
             p_aout->output.output.i_physical_channels
@@ -286,6 +297,21 @@ static int Open( vlc_object_t *p_this )
             p_aout->output.output.i_bytes_per_frame;
 
         aout_VolumeSoftInit( p_aout );
+
+        /* Check for hardware volume support */
+        if( waveOutGetDevCaps( (UINT_PTR)p_aout->output.p_sys->h_waveout,
+                               &wocaps, sizeof(wocaps) ) == MMSYSERR_NOERROR &&
+            wocaps.dwSupport & WAVECAPS_VOLUME )
+        {
+            DWORD i_dummy;
+            if( waveOutGetVolume( p_aout->output.p_sys->h_waveout, &i_dummy )
+                == MMSYSERR_NOERROR )
+            {
+                p_aout->output.pf_volume_infos = VolumeInfos;
+                p_aout->output.pf_volume_get = VolumeGet;
+                p_aout->output.pf_volume_set = VolumeSet;
+            }
+        }
     }
 
 
@@ -689,7 +715,7 @@ static void CALLBACK WaveOutCallback( HWAVEOUT h_waveout, UINT uMsg,
 }
 
 /*****************************************************************************
- * WaveOutThread: this thread will capture play notification events. 
+ * WaveOutThread: this thread will capture play notification events.
  *****************************************************************************
  * We use this thread to feed new audio samples to the sound card because
  * we are not authorized to use waveOutWrite() directly in the waveout
@@ -773,3 +799,40 @@ static void WaveOutThread( notification_thread_t *p_notif )
         }
     }
 }
+
+static int VolumeInfos( aout_instance_t * p_aout, audio_volume_t * pi_soft )
+{
+    *pi_soft = AOUT_VOLUME_MAX / 2;
+    return 0;
+}
+
+static int VolumeGet( aout_instance_t * p_aout, audio_volume_t * pi_volume )
+{
+    DWORD i_waveout_vol;
+
+#ifdef UNDER_CE
+    waveOutGetVolume( 0, &i_waveout_vol );
+#else
+    waveOutGetVolume( p_aout->output.p_sys->h_waveout, &i_waveout_vol );
+#endif
+
+    i_waveout_vol &= 0xFFFF;
+    *pi_volume = p_aout->output.i_volume =
+        (i_waveout_vol * AOUT_VOLUME_MAX + 0xFFFF /*rounding*/) / 2 / 0xFFFF;
+    return 0;
+}
+
+static int VolumeSet( aout_instance_t * p_aout, audio_volume_t i_volume )
+{
+    unsigned long i_waveout_vol = i_volume * 0xFFFF * 2 / AOUT_VOLUME_MAX;
+    i_waveout_vol |= (i_waveout_vol << 16);
+
+#ifdef UNDER_CE
+    waveOutSetVolume( 0, i_waveout_vol );
+#else
+    waveOutSetVolume( p_aout->output.p_sys->h_waveout, i_waveout_vol );
+#endif
+
+    p_aout->output.i_volume = i_volume;
+    return 0;
+}