[Openal] Capture audio, send to output source

Chris Robinson chris.kcat at gmail.com
Tue Jul 29 18:42:13 PDT 2008


On Tuesday 29 July 2008 06:15:39 pm Darren Rook wrote:
> Here is my psuedo code (4 buffers):
>
> if (New incoming samples)
> {
>    get them, process them, save them to an internal buffer.
> }
> if ((AL_SOURCE_STATE == AL_PLAYING) && (samples in internal buffer) &&
> (AL_BUFFERS_PROCESSED>1))
> {
>   buffer internal buffer to AL_BUFFERS_PROCESSED (divided evenly among
> processed buffers)
> }
> else if ((AL_SOURCE_STATE != AL_PLAYING) && (>= 100ms of samples in
> internal buffer))
> {
>   buffer internal buffer to all 4 buffers (divided evenly)
>   play buffers
> }

You need to make sure you have enough in the internal buffer before putting it 
into the AL buffer, otherwise you could get small buffer like one buffer with 
128 bytes, another with 192, another with 512, and another with 256.. 
totalling around 1KB, which is smaller than the typical update size (so one 
sound card update will exhaust all the buffered data).

Making sure you have 4 to 8KB per buffer should work fine. Something like:

if (New incoming samples)
{
   get them, process them, save them to an internal buffer.
}

while ((internal buffer bytes >= 4096) && (AL_BUFFERS_PROCESSED>1))
{
  buffer 4096 bytes from internal buffer to 1 buffer

  if ((AL_SOURCE_STATE != AL_PLAYING))
  {
    play buffers
  }
}


More information about the Openal mailing list