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

Niall09 niallb.08 at gmail.com
Mon May 25 06:53:41 PDT 2009


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 at opensource.creative.com
> http://opensource.creative.com/mailman/listinfo/openal-devel
> 
> 

-- 
View this message in context: http://www.nabble.com/Get-part-of-a-source---buffer-tp23693533p23707376.html
Sent from the OpenAL - Dev mailing list archive at Nabble.com.



More information about the Openal-devel mailing list