1

Warning: Complete audio beginner

Background: I have audio recordings that were recorded through a mobile device using an app. I need to write a program that takes the audio and finds periods of increasing volume (don't know if that's the correct term) followed by a sudden drop in volume.

Want: Ideally I'd want to take the audio file and convert it to text containing numeric values that represent the loudness (volume) every one second interval. So if the audio is one hour long, I'd have 3600 data points.

What I've Tried: I opened the audio file using audacity. In the menu bar, I clicked analyze --> sample data export and it gave me values between -1 to +1.

Problem: I don't know if each data point refers to one second of the audio recording. I don't want negative values. There are also options in audacity in which I'm not sure what to put. Such as project rate (Hz), sample format (16-bit PCM, 24-bit PCM, and 32-bit float), and how many samples I want.

Thank you for your help!

  • Are you looking for the A) instantaneous value at a sample point every second or B) the peak value during the previous second, or C) the average or integrated value over the previous second or D) something else? – Jim Mack Aug 21 '15 at 17:08
  • Hi @JimMack, I'd be looking for the instantaneous value at a sample point for every second. – itsSLO Aug 21 '15 at 20:32
  • Everyone here seems to be talking about level metering rather than loudness metering - that's a different thing, and much more difficult to calculate. We should change the title if that's what is actually intended. – Mark Durham Aug 22 '15 at 19:55
  • @MarkDurham What's the difference? – itsSLO Aug 24 '15 at 22:06
  • Because loudness is something we perceive, so it is difficult to measure. Have a look at the Wikipedia page for loudness: en.wikipedia.org/wiki/Loudness and this: en.wikipedia.org/wiki/Equal-loudness_contour. Essentially frequency content and duration heavily affect how loud something appears, so your numeric values will not represent how loud the sound is, just what level it is. That could be what you want - it depends on the application which you don't explain. – Mark Durham Aug 25 '15 at 15:57
1

You would rather turn to a program like Matlab or its open source equivalent Octave.

Open your mono-channel audio data as a vector (using wavread for instance), and turn each sample value to its square value. Then compute the mean every N samples, N depending on the smoothness/time-precision you need.

  • Thank you for your response, what's the advantage to squaring it vs. taking the absolute value? – itsSLO Aug 24 '15 at 21:28
  • It is because you wanted to represent "how low the audio is" and unless I am mistaken, perceived loudness is proportional to the square of the amplitude (you should be able to find more precise definitions and terminology in acoustics and psycho-acoustics literature, especially about intensity, loundness, logarithmic scale, sound pressure level, etc.). – maxime.bochon Aug 25 '15 at 6:59
0

Seeing that typically there are 16k-48k samples per second, picking one at random wouldn't tell you anything about the trend in level. You'd have a 1 in 16000 chance of getting a representative value. In order for the value for "one second" to mean anything you'd have to integrate over the duration.

You're looking for an envelope of the signal. Probably the most useful measurement would be the running average of one (or more) second's worth of samples. You might think of that as a trend line (as in stock prices etc). Sampling the trend line every second would give you what you need.

Since you have values of -1 to +1, you'd take the absolute value or magnitude, since -1 has the same 'volume' as +1 for your purposes.

  • The running average of samples within a second is always more or less exactly zero (unless there's some DC bias problem). You probably mean the running average of the squared samples's square root. – leftaroundabout Aug 21 '15 at 22:02
  • How will I know how many samples are in one second? In audacity, I currently have my project rate at 41khz and 41k samples. – itsSLO Aug 21 '15 at 23:05
  • @leftaroundabout - That's why I said he had to deal with magnitude (absolute value). Squaring each sample accomplishes that too but is more costly. Taking the sqrt of the average of the squared values (not exactly what you said) is a good technique but for his purposes is probably overkill. – Jim Mack Aug 22 '15 at 1:05
  • @itsSLO The file metadata will tell you what the sample rate is. If you load the file into Audacity it will read and display that, or you can use a tool like MediaInfo to discover it. – Jim Mack Aug 22 '15 at 1:10
  • @JimMack: well, you may want to rephrase that a bit, it's not evident what you mean there. — Squaring each sample is not significantly more expensive than taking the absolute value: both are a single cycle on any modern processor. Indeed taking the square root is a bit costly (though bit-fiddling tricks can help), but since you don't need to do that for every sample it doesn't really matter. – leftaroundabout Aug 22 '15 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.