« Return to Thread: Get part of a source / buffer

Re: Get part of a source / buffer

by Niall09 :: Rate this Message:

Reply to Author | View in Thread

Hi,

I keep trying your example, but &data[(ALuint)(pos*freq) * channels] keeps returning 0.

Chris Robinson-5 wrote:
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.
_______________________________________________
Openal-devel mailing list
Openal-devel@opensource.creative.com
http://opensource.creative.com/mailman/listinfo/openal-devel

 « Return to Thread: Get part of a source / buffer