[Vm-dev] [PATCH 2/3] ALSA: Don't pass uninitialized variable
Daniel Drake
dsd at laptop.org
Wed Mar 27 18:14:33 UTC 2013
The documentation on snd_pcm_hw_params_set_rate_near() and similar is not
very complete, but simple experimentation shows that the dir parameter is
treated as both an input and an output.
This variable was uninitialized; this was causing the device open to fail
on OLPC XO-4 the first time (the variable had positive contents).
Given that I don't fully understand this API, I have looked towards
other ALSA API users for how to fix this. Almost all users that I have
found simply pass a NULL value here. A couple of others pass a variable
initialized to 0. Both of those work in this case and avoid the device
open failure seen on XO-4.
Index: Squeak-4.10.2.2614-src-no-mp3/unix/vm-sound-ALSA/sqUnixSoundALSA.c
===================================================================
--- Squeak-4.10.2.2614-src-no-mp3.orig/unix/vm-sound-ALSA/sqUnixSoundALSA.c
+++ Squeak-4.10.2.2614-src-no-mp3/unix/vm-sound-ALSA/sqUnixSoundALSA.c
@@ -100,7 +100,6 @@ static sqInt sound_Start(sqInt frameCoun
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
unsigned int uval;
- int dir;
if (output_handle) sound_Stop();
@@ -114,9 +113,9 @@ static sqInt sound_Start(sqInt frameCoun
snd_pcm_hw_params_set_format(output_handle, hwparams, SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_channels(output_handle, hwparams, output_channels);
uval= samplesPerSec;
- snd_pcm_hw_params_set_rate_near(output_handle, hwparams, &uval, &dir);
+ snd_pcm_hw_params_set_rate_near(output_handle, hwparams, &uval, NULL);
output_buffer_period_size= frameCount;
- snd_pcm_hw_params_set_period_size_near(output_handle, hwparams, &output_buffer_period_size, &dir);
+ snd_pcm_hw_params_set_period_size_near(output_handle, hwparams, &output_buffer_period_size, NULL);
snd(pcm_hw_params(output_handle, hwparams), "sound_Start: snd_pcm_hw_params");
snd_pcm_sw_params_alloca(&swparams);
@@ -278,7 +277,6 @@ static sqInt sound_StartRecording(sqInt
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
snd_pcm_uframes_t frames;
- int dir;
if (input_handle) sound_StopRecording();
@@ -292,9 +290,9 @@ static sqInt sound_StartRecording(sqInt
snd_pcm_hw_params_set_format(input_handle, hwparams, SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_channels(input_handle, hwparams, input_channels);
input_rate= desiredSamplesPerSec;
- snd_pcm_hw_params_set_rate_near(input_handle, hwparams, &input_rate, &dir);
+ snd_pcm_hw_params_set_rate_near(input_handle, hwparams, &input_rate, NULL);
frames= 4096;
- snd_pcm_hw_params_set_period_size_near(input_handle, hwparams, &frames, &dir);
+ snd_pcm_hw_params_set_period_size_near(input_handle, hwparams, &frames, NULL);
snd(pcm_hw_params(input_handle, hwparams), "sound_StartRecording: snd_pcm_hw_params");
snd_pcm_sw_params_alloca(&swparams);
More information about the Vm-dev
mailing list