Allegro 5 dynamically created samples
Don Freeman

Sorry if this has been asked and answered before, but my google foo has not been great with this.

So basically I am wanting to create real time audio effects with Allegro 5, but am kind of at a loss as to how to go about that. What I found seems to suggest creating an ALLEGRO_SAMPLE using al_create_sample with my own data but I'm confused as to what that data actually represents. Is it the amplitude of the sound at certain intervals of time? Any help clarifying this would be extremely grateful.

Thanks in advance,

Chris Katko

I looked into this MANY YEARS ago. But IIRC, it is raw waveform data as in, positions of the speaker. say, 0 = full retracted, 255 = full extended.

Allegro should be using the same as any other API, so other API tutorials should be applicable:

Also, IIRC, there should be at least one raw audio generate example in Allegro 5's example folder.

Mark Oates

It depends on the sample format, but you can imagine a waveform graphic having a center line, the wave is sampled as many points progressing forward in time (towards the right) as sample values at the minimum (-1.0f), to values at the maximum (1.0f) and everything in between, (0.0 in the center). In this case, the samples represent the amplitude.

Again, depending on the sample format, those values could be floating 0.0 to 1.0, with 0.5 being the center; or 0 to 255, with 128 being the center, 0 to 65536, or -1.0...1.0 being the top.

That's called the "DEPTH". Some sample depths include ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_AUDIO_DEPTH_INT8, etc. Here are the depth types:

Also, here's some code that renders an ALLEGRO_SAMPLE, which might be helpful:

Chris Katko
Edgar Reynaldo

Basically, you need a waveform, an amplitude form, and a pitch form to create a sound wave. You combine the three to make your sound.

Waveform goes from -1.0 to 1.0, amplitude goes from 0.0 to 1.0 and pitch goes from something like 20Hz to 20000Hz (waves per second).

Thread #618575. Printed from