my dsound/winealsa hacks

James Courtier-Dutton James at
Sun Sep 24 09:28:04 CDT 2006

Tomas Carnecky wrote:
> James Courtier-Dutton wrote:
>> I have place some documentation on the ALSA wiki site:
>> It tries to explain the constraints that the current ALSA resampler 
>> works under.
>> You might like to read it as I think it will have impact on your plans.
> Thanks. One question though, if the app in in blocking mode and requests 
> the said two periods, will alsa wait until the hardware has processed 
> three 48000Hz-periods and then copy the two 44100Hz-periods to the 
> application (because: 3 periods at 48000Hz > 2*1024 frames at 44100Hz)?
> DirectSound doesn't know anything about periods, the windows application 
> operates on bytes rather than frames or periods. So whether I'd have to 
> wait for two or three periods wouldn't matter. The important thing is 
> that I get X bytes in the right format to pass that back to the 
> application.
> tom

Maybe the ALSA terminology needs to be clarified.
A frame is equivalent of one sample being played, irrespective of the 
number of channels or the about of bits.
1 frame of a Stereo 48khz 16bit PCM stream is 4 bytes.
1 frame of a 5.1 48khz 16bit PCM stream is 12 bytes.

A period is the amount of frames in between each hardware interrupt. The 
poll() will return once a period.

The buffer is a ring buffer. The buffer size always has to be greater 
than one period size. Commonly this is 2*period size, but some hardware 
can do 8 periods per buffer. It is also possible for the buffer size to 
not be an integer multiple of the period size.

Now, if the hardware has been set to 48000Hz , 2 periods, of 1024 frames 
each, making a buffer size of 2048 frames. The hardware will interrupt 2 
times per buffer. The application 44100Hz will also have 2 periods of 
940 frames.
ALSA will endeavor to keep the buffer as full as possible. Once the 
first period has been played, the third is transfered into the space the 
first one occupied while the second period is being played. (normal ring 
buffer behaviour).

So, once a period has been transfered to the sound card hardware, it 
cannot be modified, even though the sound card has not yet played it 
from the DACs.

As Direct Sound does not know anything about periods, I don't really 
know how you will be able to get it to work well with ALSA. I expect 
that some sort of double buffer will be required.
Does Direct Sound have a concept of position of the ADC, and also a 
concept of where in the buffer it is sensible to fill with new samples?


More information about the wine-devel mailing list