Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Limits of freq increase when playing sample?

This thread is locked; no one can reply to it. rss feed Print
Limits of freq increase when playing sample?
Chris Baume
Member #8,273
January 2007

When continuously increasing the freq of a sample using adjust_sample, the program crashes when the freq property exceeds 11888.

Why is this the limit, and is there any way of increasing it?

Thanks for your help,

Chris

Milan Mimica
Member #3,877
September 2003
avatar

No crash here.

#include <allegro.h>

int main() {
        int x;
        allegro_init();
        install_timer();

        install_sound(MIDI_ALSA, MIDI_NONE, NULL);
        SAMPLE *s = load_sample("blah.wav");
        play_sample(s, 255, 127, 1000, 0);
        for (x = 0; x < 12000; x++)
                adjust_sample(s, 255, 127, x, 0);
        rest(2000);
        return 0;
}
END_OF_MAIN()

Chris Baume
Member #8,273
January 2007

Managed to work it out!

My problem was when the loop parameter of the adjust_sample function was set to 1, and the sample rate of the wave file is 44100Hz. The above code crashes under those conditions.

However, by decreasing the sample rate of the wave file to 22050Hz, the maximum value for freq becomes 23776 (double 11888).

So, when adjusting the playback rate of a looping sample, the maximum value for freq is:

(max freq) = 35664 - 0.5392 * (sample rate in Hz)

I'm guessing the limit has something to do with refreshing buffers, I can't be sure. But hopefully this will help someone if they get stuck.

Go to: