[xiph-commits] r3104 - in liboggplay/trunk/plugin: . audio
laser13 at svn.annodex.net
laser13 at svn.annodex.net
Wed Jun 27 21:21:00 PDT 2007
Author: laser13
Date: 2007-06-27 21:20:59 -0700 (Wed, 27 Jun 2007)
New Revision: 3104
Modified:
liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c
liboggplay/trunk/plugin/plugin_gui_win32.c
Log:
Win32 system volume setting support.
Modified: liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c
===================================================================
--- liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c 2007-06-28 02:08:06 UTC (rev 3103)
+++ liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c 2007-06-28 04:20:59 UTC (rev 3104)
@@ -49,6 +49,8 @@
#define DEFAULT_DEVICE_NAME "Default WAVE Device"
#define DEFAULT_DEVICE WAVE_MAPPER
+#define HAS_OGGPLAY 1
+
#define VERBOSE_OUTPUT 0
// INFO: if you get weird compile errors make sure there is no extra chars pass '\'
@@ -212,7 +214,10 @@
return status;
}
-/** volume in hundreths of dB*/
+/**
+ * retrieved volume as an int in a scale from 0x0000 to 0xFFFF
+ * only one value for all channels
+ */
int sa_stream_get_write_volume(sa_stream_t *s, int32_t vol[], unsigned int *n) {
int status;
DWORD volume;
@@ -220,20 +225,20 @@
WORD right;
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;
- //printf("Volume level is on the left channel %d, on the right %d\n", left, right);
- vol[0] = (int32_t)(left + right /2);
+ //printf("Volume level is on the left channel %d, on the right %d\n", left, right);
+ vol[0] = (int32_t)(left + right /2);
return SA_SUCCESS;
}
-/** volume in hundreths of dB*/
+/** changes volume as an int in a scale from 0x0000 to 0xFFFF*/
int sa_stream_change_write_volume(sa_stream_t *s, const int32_t vol[], unsigned int n) {
int status;
DWORD volume;
@@ -242,12 +247,9 @@
ERROR_IF_NO_INIT(s);
- volume = vol[0] * 65535;
- //printf("Volume %d\n", volume);
- left = volume & LEFT_CHANNEL_MASK;
- //printf("Volume low bits %d\n", left);
- right = left << 16;
- //printf("Volume high bits %d\n", right);
+ volume = (DWORD)vol[0];
+ left = volume & LEFT_CHANNEL_MASK;
+ right = left << 16;
volume = right | left;
status = waveOutSetVolume(s->hWaveOut, volume);
@@ -368,8 +370,13 @@
int status;
WAVEFORMATEX wfx;
UINT supported = FALSE;
-
+
+ // some random estimations of the correct block count
+ // could be to allocate enough for 250 ms audio offset
+ // plus extra 2 spare blocks on to of initial burst of audio samples, e.g:
+ // int blockCount = (((250 * s->rate * s->channels * sizeof(short)) / (1000 * BLOCK_SIZE)) + 2);
status = allocateBlocks(BLOCK_SIZE, BLOCK_COUNT, &(s->waveBlocks));
+
HANDLE_WAVE_ERROR(status, "allocating audio buffer blocks");
s->waveFreeBlockCount = BLOCK_COUNT;
Modified: liboggplay/trunk/plugin/plugin_gui_win32.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_win32.c 2007-06-28 02:08:06 UTC (rev 3103)
+++ liboggplay/trunk/plugin/plugin_gui_win32.c 2007-06-28 04:20:59 UTC (rev 3104)
@@ -71,7 +71,9 @@
sa_stream_t * audio_handle;
BOOL audio_ok;
BOOL audio_opened;
-#endif
+#endif
+ BOOL set_to_pause;
+ BOOL finished;
nsPluginInstance * plugin_instance;
} PluginWindowInfo;
@@ -90,7 +92,8 @@
info->audio_opened = FALSE;
info->audio_handle = NULL;
return;
- }
+ }
+
if (sa_stream_open(info->audio_handle) != SA_SUCCESS) {
info->audio_opened = FALSE;
info->audio_handle = NULL;
@@ -220,6 +223,8 @@
(info->playback_target >> 16), ref_time, offset);*/
offset = (offset > 0) ? offset : OGGPLAY_MIN_OFFSET;
+ // !!! check if we should skip frames here
+
/* try switching oggplays */
if (switch_oggplays(info) == TRUE) {
offset = 10;
@@ -270,27 +275,29 @@
HWND hWnd = (HWND)np_window->window;
/* allocate structure */
- info = (PluginWindowInfo*)malloc(sizeof(PluginWindowInfo));
- info->width = np_window->width;
- info->height = np_window->height;
- info->oggplay_handle = oggplay_handle;
- info->frame_data = (PluginOggFrame*)malloc(sizeof(PluginOggFrame));
- info->frame_data->frame = NULL;
+ info = (PluginWindowInfo*)malloc(sizeof(PluginWindowInfo));
+ info->width = np_window->width;
+ info->height = np_window->height;
+ info->oggplay_handle = oggplay_handle;
+ info->frame_data = (PluginOggFrame*)malloc(sizeof(PluginOggFrame));
+ info->frame_data->frame = NULL;
info->frame_data->samples = NULL;
info->frame_data->cmml_strings = NULL;
- info->frame_data->size = 0;
- info->shutdown_gui = 1;
- info->window = hWnd;
- info->new_oggplay_handle = NULL;
- info->playback_state = PLAYING;
+ info->frame_data->size = 0;
+ info->shutdown_gui = 1;
+ info->window = hWnd;
+ info->new_oggplay_handle = NULL;
+ info->playback_state = PLAYING;
/* initialisation of callback related variables */
- info->plugin_instance = instance;
+ info->plugin_instance = instance;
/* audio and synchronisation related variables */
- info->playback_target = 0;
+ info->playback_target = 0;
+ info->set_to_pause = FALSE;
+ info->finished = FALSE;
#ifdef USE_AUDIO
- info->audio_opened = FALSE;
- info->audio_handle = NULL;
- info->audio_ok = FALSE;
+ info->audio_opened = FALSE;
+ info->audio_handle = NULL;
+ info->audio_ok = FALSE;
#endif
/*
@@ -568,13 +575,36 @@
void
gui_set_volume(void *handle, float volume) {
-//!todo
+ PluginWindowInfo * info;
+ int vol[1];
+
+#if USE_AUDIO
+ info = (PluginWindowInfo *)handle;
+ 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);
+#endif
+ return;
}
float
gui_get_volume(void *handle) {
-//!todo
- return 0.0f;
+
+ PluginWindowInfo * info;
+ float volume;
+ int vol[1];
+
+ volume = 0.0f;
+#if USE_AUDIO
+ info = (PluginWindowInfo *)handle;
+ 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;
+ }
+#endif
+ return volume;
}
long
More information about the commits
mailing list