[alsa-devel] Long-standing SDL ALSA bug

Sam Lantinga slouken at libsdl.org
Tue Oct 13 12:05:23 CEST 2009


Thanks for the feedback!  I think that improved our ALSA driver
significantly (attached!)

On Tue, Oct 13, 2009 at 12:03 AM, Clemens Ladisch <clemens at ladisch.de> wrote:
> Sam Lantinga wrote:
>> I'm attaching the latest versions of the SDL audio files, and I'd
>> really appreciate it if you take a look and sanity check our code.
>
>>       device = SDL_getenv("AUDIODEV");        /* Is there a standard variable name? */
>
> ALSA's devices look at certain environment variables; you are supposed
> to use names like "default" or "surround51" to get that default
> configuration.
>
>>       if (channels == 6) device = "surround51";
>>       else if (channels == 4) device = "surround40";
>
> The devices do not have automatic sample format/rate conversion; you
> might want to use "plug:surround.." instead.
>
>> /* This function waits until it is possible to write a full sound buffer */
>> static void ALSA_WaitAudio(_THIS)
>
> This function doesn't actually wait ...
>
>>       if ( status == -EAGAIN ) {
>>               SDL_Delay(1);
>>               continue;
>>       }
>
> Not necessary in blocking mode.
>
>>       rate = spec->freq;
>>       status = SDL_NAME(snd_pcm_hw_params_set_rate_near)(pcm_handle, hwparams, &rate, NULL);
>>       spec->freq = rate;
>
> The returned rate could be wildly different, but I guess SDL correctly
> handles the new value in spec->freq.
>
>>       /* Set the buffer size, in samples */
>>       frames = spec->samples;
>>       status = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, &frames, NULL);
>
> This does _not_ set the buffer size.
>
>>       periods = 2;
>>       SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, &periods, NULL);
>
> A bigger number of periods would make the writing of audio data less
> bursty.
>
>>       status = SDL_NAME(snd_pcm_sw_params_set_start_threshold)(pcm_handle, swparams, 0);
>
> Zero doesn't really make sense; the default value 1 would be OK.
>
>>       status = SDL_NAME(snd_pcm_sw_params_set_avail_min)(pcm_handle, swparams, frames);
>
> The default value is the period size anyway, so you can remove this.
> (If you change the buffer size code above to use _set_buffer_size_near,
> this call would be wrong.)
>
>
> Best regards,
> Clemens
>



-- 
	-Sam Lantinga, Founder and President, Galaxy Gameworks LLC
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SDL_alsa_audio.c
Type: application/octet-stream
Size: 18374 bytes
Desc: not available
Url : http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20091013/53c7e56c/attachment.dll 


More information about the Alsa-devel mailing list