[xiph-commits] r3127 - in liboggplay/trunk/plugin: . audio

laser13 at svn.annodex.net laser13 at svn.annodex.net
Thu Jun 28 08:02:19 PDT 2007


Author: laser13
Date: 2007-06-28 08:02:19 -0700 (Thu, 28 Jun 2007)
New Revision: 3127

Modified:
   liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c
   liboggplay/trunk/plugin/plugin_gui_win32.c
Log:
1) Added finished state reporting. 
2) Software emulated volume control (a al shans).
3) Some random cleanup.

Modified: liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c
===================================================================
--- liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c	2007-06-28 14:49:44 UTC (rev 3126)
+++ liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c	2007-06-28 15:02:19 UTC (rev 3127)
@@ -209,16 +209,20 @@
   return status;
 }
 
-#define LEFT_CHANNEL_MASK  0x0000FFFF
+#define LEFT_CHANNEL_MASK 0x0000FFFF
 #define RIGHT_CHANNEL_MASK 0xFFFF0000
 
 /** volume in hundreths of dB*/
 int sa_stream_get_write_volume(sa_stream_t *s, int32_t vol[], unsigned int *n) {
-  WORD left;
-  WORD right;
-  DWORD volume;
+  int status;
+	DWORD volume;
+	WORD left;
+	WORD right;
+
+	ERROR_IF_NO_INIT(s);
   
-  ERROR_IF_NO_INIT(s);
+	status = waveOutGetVolume(s->hWaveOut, &volume);
+	HANDLE_WAVE_ERROR(status, "reading audio volume level");
 
 	left = volume & LEFT_CHANNEL_MASK;
 	right = (volume & RIGHT_CHANNEL_MASK) >> 16;
@@ -230,13 +234,13 @@
 
 /** volume in hundreths of dB*/
 int sa_stream_change_write_volume(sa_stream_t *s, const int32_t vol[], unsigned int n) {
-  WORD left;
-  WORD right;
-  DWORD volume;
-  int   status;
-
-  ERROR_IF_NO_INIT(s);
+  int status;
+	DWORD volume;
+	WORD left;
+	WORD right;
 	
+	ERROR_IF_NO_INIT(s);
+	
   volume = (DWORD)vol[0];
 	left = volume & LEFT_CHANNEL_MASK;	  
 	right = left;	  
@@ -247,6 +251,7 @@
 
 	return SA_SUCCESS;
 
+
 }
 
 /** sync/timing */

Modified: liboggplay/trunk/plugin/plugin_gui_win32.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_win32.c	2007-06-28 14:49:44 UTC (rev 3126)
+++ liboggplay/trunk/plugin/plugin_gui_win32.c	2007-06-28 15:02:19 UTC (rev 3127)
@@ -50,6 +50,8 @@
 #define OGGPLAY_FRAME_SKIP_OFFSET -30
 #define OGGPLAY_MIN_OFFSET        3
 
+#define SOFT_VOLUME 1
+
 typedef struct {
   // window related data
   int                 width;
@@ -70,12 +72,12 @@
 #ifdef USE_AUDIO
   sa_stream_t     *   audio_handle;  
   BOOL        	      audio_opened;  
+  float               volume;
 #endif
   BOOL                set_to_pause;
   BOOL                finished;
   BOOL                valid_frame;
-  nsPluginInstance *  plugin_instance;  
-  
+  nsPluginInstance *  plugin_instance;    
 } PluginWindowInfo;
 
 #ifdef USE_AUDIO
@@ -160,7 +162,6 @@
 initialise_gui(nsPluginInstance *instance, NPWindow *np_window, 
                 void *oggplay_handle) {
   
-  DWORD                 disp_id;
   PluginWindowInfo    * info;
   HWND                  hWnd      = (HWND)np_window->window;  
 
@@ -186,7 +187,8 @@
   info->set_to_pause        = FALSE;
 #ifdef USE_AUDIO  
   info->audio_opened        = FALSE;    
-  info->audio_handle        = NULL;  
+  info->audio_handle        = NULL;
+  info->volume              = 1.0;
 #endif
 
   /*
@@ -347,14 +349,14 @@
   RECT          r;
   __int64       bytes, ref_time, offset;
 
+  hWnd = (HWND)(info->window);
+
   if ((info->playback_state == PAUSED) && (info->set_to_pause == FALSE)) {    
       SetTimer(hWnd, IDT_DISPLAY_TIMER, OGGPLAY_MIN_OFFSET, NULL);
       printf("Setting short timeout\n");
       return;    
-  } 
+  }   
 
-  hWnd = (HWND)(info->window);
-
   /* check if we need to change oggplay objects */
   switch_oggplays(info); 
   
@@ -367,8 +369,9 @@
 
     case OGGPLAY_STREAM_LAST_DATA:
       info->finished = TRUE;
+      info->playback_state = FINISHED;
       onEndOfMovie(info->plugin_instance);
-      return TRUE;
+      return;
 
     default:
       break;
@@ -409,7 +412,17 @@
       open_audio(info);
     }
     /* if audio device is opened try writing data */
-    if (info->audio_opened == TRUE) {                 
+    if (info->audio_opened == TRUE) {
+#ifdef SOFT_VOLUME      
+      /* apply per-application volume */
+      if (info->volume < 1.0) {
+        short * samples = (short *)(info->frame_data->samples);
+        UINT     i;
+        for (i = 0; i < info->frame_data->size/sizeof(short); i ++) {
+          samples[i] *= info->volume;
+        }
+      }
+#endif
       if (sa_stream_write(info->audio_handle, 
             info->frame_data->samples, 
             info->frame_data->size) != SA_SUCCESS) {
@@ -557,15 +570,19 @@
 void
 gui_set_volume(void *handle, float volume) {
   PluginWindowInfo * info;    
-  int vol[1];
 
 #if USE_AUDIO
+  int vol[1];
   info = (PluginWindowInfo *)handle;
+#ifndef SOFT_VOLUME      
   vol[0] = (int)(volume * 65535);
   vol[0] = (vol[0] > 65535) ? 65535 : vol[0];
   vol[0] = (vol[0] < 0) ? 0 : vol[0];
   sa_stream_change_write_volume(info->audio_handle, vol, 1);  
+#else
+  info->volume = volume;
 #endif
+#endif
   return;
 }
 
@@ -574,17 +591,23 @@
 
   PluginWindowInfo * info;
   float volume;
+#if USE_AUDIO  
   int vol[1];
-  
+#endif
+
   volume = 0.0f;
 #if USE_AUDIO
   info = (PluginWindowInfo *)handle;
+#ifndef SOFT_VOLUME        
   if (sa_stream_get_write_volume(info->audio_handle, vol, 1) == SA_SUCCESS) {
     volume = (vol[0] * 1.0 / 65535); //2 << (sizeof(WORD) * 8) - 1
     volume = (volume > 1.0) ? 1.0 : volume;
     volume = (volume < 0.0) ? 1.0 : volume;
   }
+#else
+  volume = info->volume;
 #endif
+#endif
   return volume;
 }
 



More information about the commits mailing list