Audio meters

Audio software developers forum.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
eb9109
Posts: 2
Joined: Tue Jan 17, 2012 10:28 pm
Operating System: Please select

Audio meters

Post by eb9109 » Tue Jan 17, 2012 10:34 pm

How does Audacity access the data to make the audio meters say for a named ogg file?

Can anyone point me to code for this?

Thx

DVDdoug
Forum Crew
Posts: 9419
Joined: Fri Sep 10, 2010 11:30 pm
Operating System: Windows 10

Re: Audio meters

Post by DVDdoug » Wed Jan 18, 2012 12:18 am

I haven't looked at the source code for Audacity, but you can! :P

The "hard part" is decoding the OGG file. (uncompressed WAV files are much simpler.) Once the OGG file is decoded, you get a series of samples (values or numbers) and each value represents the "height" of the wave at one moment in time. i.e. CDs are sampled at 44.1kHz, so there are 44,100 samples for every second of audio (for each channel). If you plot those values and "connect the dots", you'll see the waveform. If you zoom-in with Audacity, you can see the individual samples. Normally, when you are looking at a few minutes (or several seconds) of audio, there are not enough pixels to show all of the samples.

You can take the peak values (or calculate a moving average) to get the data for your meters.

With audacity (and most audio editors) the sample values are stored in floating-point with a value of 1.0 (or -1.0) representing 0dB. So, the decoded file is an array of floating-point numbers, usually between +1.0 and -1.0. (Silence is a series of zeros.) In a stereo WAV file, the left & right samples alternate, but the audio editor might use separate arrays for left & right.

Note that the audio file may hold samples in a different format. i.e. 16-bit WAV files holds integer values between
-32,768 and +32,767. But, the data is usually normalized to +/-1 (floating point) for editing, analysis, or DSP. The data has to be converted back to integers before being fed into the digital-to-analog converter for playback. A compressed file (OGG, MP3, etc.) doesn't hold the individual sample values, so it has to be decoded before it can be analyzed or played-back.

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Audio meters

Post by steve » Wed Jan 18, 2012 12:34 am

Audacity does not operate directly on compressed audio files. The audio data is decoded to uncompressed PCM data when the file is imported.
The C++ Source code for the VU meters is in /src/widgets/Meter.cpp
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

eb9109
Posts: 2
Joined: Tue Jan 17, 2012 10:28 pm
Operating System: Please select

Re: Audio meters

Post by eb9109 » Wed Jan 18, 2012 3:20 am

Thx for the posts and the code, guess I need to be able to get the ogg to uncompress into memory to be able to access its bytes sequentially. Am working in darkBasic which can call and use dlls and indeed play ogg files(created with Audacity). Was thinking of how to make a dll to read sound values of my ogg as I play it. Perhaps I could invoke the lame enc to uncompress them to PCM wav data somehow.

DVDdoug
Forum Crew
Posts: 9419
Joined: Fri Sep 10, 2010 11:30 pm
Operating System: Windows 10

Re: Audio meters

Post by DVDdoug » Thu Jan 19, 2012 12:13 am

Perhaps I could invoke the lame enc to uncompress them to PCM wav data somehow.
LAME does not encode/decode OGG files. It's only for MP3s. (I don't know how Audacity encodes/decodes OGG, but it's easy to find a CODEC.)

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Audio meters

Post by steve » Thu Jan 19, 2012 7:05 pm

Have a look at libsndfile and libvorbis.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply