[Openal-devel] Get part of a source / buffer

Chris Robinson chris.kcat at gmail.com
Sun May 24 06:53:48 PDT 2009


On Sunday 24 May 2009 6:15:37 am Niall09 wrote:
> Hi,
>
> Is there any way to get a part of a buffer that im playing, as i want to
> take a tiny part of the currently playing buffer, convert it to a short and
> put it through pitch detection. So i can detect the pitch dynamically as a
> sound plays.

Hi.

You can't get the current buffer data OpenAL is playing, but you can get the 
current position in the buffer. With the position, you can reference your own 
copy of the data for pitch detection. As an example:

ALshort *data;
ALuint frames;
ALuint channels;
ALuint freq;
...

alBufferData(buffer, ((channels==1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16),
             data, frames*channels*2, freq);
alSourcei(source, AL_BUFFER, buffer);
...

ALfloat pos;
alGetSourcef(source, AL_SEC_OFFSET, &pos);

detect_pitch(&data[(ALuint)(pos*freq) * channels]);


That is, of course, assuming 16-bit data. Easy enough to modify for 8- or 32-
bit, though.


More information about the Openal-devel mailing list