Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro 5 dynamically created samples

This thread is locked; no one can reply to it. rss feed Print
Allegro 5 dynamically created samples
Don Freeman
Member #5,110
October 2004
avatar

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,
D

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Chris Katko
Member #1,881
January 2002
avatar

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:

https://medium.com/programming-for-music/generating-raw-audio-samples-f08f3adf73af

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

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Mark Oates
Member #1,146
March 2001
avatar

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: https://liballeg.org/a5docs/trunk/audio.html#allegro_audio_depth

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

https://github.com/allegroflare/allegro_flare/blob/master/include/allegro_flare/sample_renderer.h
https://github.com/allegroflare/allegro_flare/blob/master/src/allegro_flare/sample_renderer.cpp

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Chris Katko
Member #1,881
January 2002
avatar

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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).

Go to: