Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Change the frequency of a sample instance in real-time?

This thread is locked; no one can reply to it. rss feed Print
Change the frequency of a sample instance in real-time?
xsquid
Member #16,498
July 2016

I'm trying to change the frequency of an ALLEGRO_SAMPLE_INSTANCE in real-time (to simulate the Doppler effect).

Scanning through the docs, the only way I can see to do this is to create a mixer with the frequency I want, and create a new voice with the same frequency (since they need to match). To do this in real-time, I need to repeatedly create mixer/voice pairs every time I want to update the frequency of the sound. Is there a better way to do this?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Obviously, that would be bad. You can't re-create your master voice and mixer on every frame. Luckily you don't need to change the frequency of the mixer to change the frequency of the sound. Use al_set_sample_instance_speed to change the frequency of the sample instance in real time.

Go to: