Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » working directly with SAMPLE structure

Credits go to Bruce Perry for helping out!
This thread is locked; no one can reply to it. rss feed Print
working directly with SAMPLE structure
Kikaru
Member #7,616
August 2006
avatar

In my ever-living attempt to create a game maker utility, I decided to look at the Allegro SAMPLE structure. Well, it doesn't make a lot of sense. What I really want to know is: what is contained in the void *data;? Or better yet, what is the name of the allegro source file that contains that function?

Thanks in advance! :D

Richard Phipps
Member #1,632
November 2001
avatar

data is a pointer to the raw sample data held in memory. What exactly do you want to know? :)

Kikaru
Member #7,616
August 2006
avatar

What does it do? What is the arrangement, of the data?

Jonatan Hedborg
Member #4,886
July 2004
avatar

Unsigned char/short/long depending on the bits per sampling. first left then right (if stereo). Or the other way around :)

Kikaru
Member #7,616
August 2006
avatar

Is that frequency or amplitude?

Jonatan Hedborg
Member #4,886
July 2004
avatar

It's the amplitude of that specific sampling (time).

Thomas Fjellstrom
Member #476
June 2000
avatar

Its standard raw PCM data. Something you can shove into a soundcard with little to no effort.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Bruce Perry
Member #270
April 2000

Description of PCM, the format used by samples in Allegro.

Sound is vibrations in the air. The analogue signal being sampled is the movements of the air particles as the wave passes through them, or the movements of the diaphragm in a microphone, or the movements of the cone in a speaker.

The 'data' pointer points to an array of either unsigned chars or unsigned shorts (not longs in Allegro). The value 0x80 or 0x8000 corresponds to equilibrium. A long line of 0x80 or 0x8000 represents silence. Any other data should oscillate around this value, although it often doesn't if the microphone used to record it was cheap.

If you are processing these data, make sure the values don't overflow. That will sound ghastly. If there is a risk of overflow, you should clamp the values to the maximum/minimum, which sounds a bit bad but still OK.

Have fun ;D

Note: the values are not the amplitude, they are the elongation. The amplitude is the maximum elongation that a wave reaches, and thus describes the strength of the wave as a whole.

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Kikaru
Member #7,616
August 2006
avatar

Ok. Thanks for the link! I am trying to work out how to make an all-in-one file packing format that I can save and load to for my stuff. :)

Jonatan Hedborg
Member #4,886
July 2004
avatar

uhm... you mean something like datafiles?

Kikaru
Member #7,616
August 2006
avatar

No, custom. I am going to work on my own compression format (half-done already), and the file can contain images, sounds, and maybe some extra data, for use with my own app only (I want to make a game creator).

Jonatan Hedborg
Member #4,886
July 2004
avatar

Alright. Any special reason why you want to re-invent the wheel? If you don't like this particular wheel there are other wheels that you might like better :)

Kikaru
Member #7,616
August 2006
avatar

I have 2 reasons: 1) I like working with files, and this seems fun. 2) It is also known as "practice." :)

Go to: