[Openal] Square wave with different frequencies

Peter Mulholland darkmatter at blueyonder.co.uk
Thu Sep 6 06:58:31 PDT 2007


Hello etxmato,

Thursday, September 6, 2007, 2:38:24 PM, you wrote:

> Hello,

> I'm new to openAL and fairly new to sound programming as well, so please
> forgive me if this is going to be a silly or simple question. 

> I need to be able to generate square wave sounds of different frequencies
> ranging from 43 Hz to ~700KHz. My initial plan was to use openAL, create a
> simple buffer with a square wave and change the frequency as needed. When
> started I realized that changing the frequency of a buffer is not really
> possible after it has been created with alBufferData and linked to a source.
> So I opted for changing the pitch as needed by setting the pitch to (needed
> frequency)/(buffer frequency). Got some results but after some searching on
> the net I found out that I can't really do this either as the pitch should
> not be less than 0.5 and/or more than 2 in most implementations.

> So now my question is, does anyone have any recommendation on how to
> generate wave sounds (in my case a simple square wave is needed) with
> different frequencies. i.e:
> - Do I need to have 1 buffer for every frequency I might need? 
> - If so how many buffers can I create? would it be ok to create around 1000
> (small) buffers?
> - Are there any other ways of changing the frequency of a specific sound
> buffer or source+buffer?
> - Maybe I should use another sound library?

I would not recommend OpenAL for this. It sounds like your needs would
be better served by PortAudio. This doesn't do any mixing or anything,
but will let you generate your squarewave directly using a stream
callback.

-- 
Best regards,
 Peter                            mailto:darkmatter at blueyonder.co.uk



More information about the Openal mailing list