jccorner Posted July 24, 2007 Posted July 24, 2007 Howdy folks. I've been searching and searching but have not found a suitable solution yet. My issue is that I have an array of bytes that is holding the data of a audio signal. What I want to do is simply measure the volume. Does anyone have a direction to point me in?? I would greatly appreciate the assist. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
techmanbd Posted July 24, 2007 Posted July 24, 2007 http://music.arts.uci.edu/dobrian/digitalaudio.htm I found this article, hopefully it will help. And for google, you may want to try putting this in the search Digital Audio byte to dB or Digital Audio byte to analog volume Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
jccorner Posted July 26, 2007 Author Posted July 26, 2007 Thanks but I didn't see anything regarding a .net implementation. I understand that decibels can be calculated from power or even voltage, but how do I gather this information when looking at an array of bytes?? Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
MrPaul Posted July 26, 2007 Posted July 26, 2007 Amplitude and decibels Amplitude is a measure of the magnitude of oscillation, which generally means the maximum absolute value of the wave: maxVal = 0; for (int i = 0; i < audioData.Length; i++) { if (Math.Abs(audioData[i]) > maxVal) maxVal = Math.Abs(audioData[i]); } //maxVal now contains the maximum amplitude of the sample Decibels can be used to express amplitude, but decibels express a ratio, not an absolute value. This means that amplitudes expressed in decibels are relative to some reference amplitude. For the calculation, amplitude ratio is calculated in the same way as voltage ratio: [size=5]X[size=1]dB[/size] = 20log[size=1]10[/size](X / X[size=1]0[/size])[/size] The value of X can be determined using the code above, but as for the reference value X0, you need to decide what value to use - typically a very small value if you are measuring the amplitude with respect to silence. Good luck :cool: Quote Never trouble another for what you can do for yourself.
jccorner Posted August 10, 2007 Author Posted August 10, 2007 MrPaul, thank you very much. I actually didn't know I got another resopnse since I found something that gave me some estimate using a very complicated algorithm (FFT) but I will definitey look to implement when I get a chance. One question though, should I be looking in a range, because when I look at the data I see a lot of zero and 255 values (255 being the highest)?? Thanks again. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
MrPaul Posted August 10, 2007 Posted August 10, 2007 Audio data format? The Fast Fourier Transform (FFT) will turn a time domain signal into its frequency domain representation, which will give you the relative amplitudes of the various frequencies in the signal, but I can't see how it would help you calculate an overall amplitude for the entire signal. The problem is that the term volume doesn't have much meaning unless you are comparing two signals for differences in amplitudes - as I said, decibels express a ratio. Your query about zeros and 255 values raises another good point - do you know the format of the audio data? Standard PCM audio, as you'd find in a WAV file, is encoded into 16 bit samples, so to obtain useful values you have to treat it as such, using the short/Short data type. Quote Never trouble another for what you can do for yourself.
jccorner Posted August 10, 2007 Author Posted August 10, 2007 Re: Audio data format? Your query about zeros and 255 values raises another good point - do you know the format of the audio data? Standard PCM audio, as you'd find in a WAV file, is encoded into 16 bit samples, so to obtain useful values you have to treat it as such, using the short/Short data type. I'm using 32 bit samples and you are correct, I'm using the sbyte data type. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
MrPaul Posted August 10, 2007 Posted August 10, 2007 BitConverter You can use the BitConverter class to convert each four byte sequence into more the more usable Int32: value = BitConverter.ToInt32(byteArray, index); index += 4; :) Quote Never trouble another for what you can do for yourself.
ZeroEffect Posted April 14, 2008 Posted April 14, 2008 I found this while looking for ahow to return the dB value of a captured buffer. i found the formula that is shown above and built a function to return the value. Private function GetSample(ByVal sample As Byte()) as integer Dim dBValue As Double Dim range As Int16 = 32767.0 ' highest value as a double buffShort = CType(Convert.ToInt16(sample(2)), Short) 'sample(2) is a random value from the 'buffer not Peak Value. dBValue = (20 * Log10(buffShort / range)) + 100 tbData.AppendText(vbCrLf & buffShort & vbCrLf & dBValue) ' this is for monitoring If dBValue < 0 Then ' I was getting infinity errors dBValue = 0 End If return dBValue End Sub I am having two issues. 1 how do I get the peak value in the buffer? 2. the values I am returning are not the dB value of the audio. could someone please help me? Thanks ZeroEffect Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
techmanbd Posted April 14, 2008 Posted April 14, 2008 Zero, I think this is what you are looking for with getting the peak value of the sample byte Array.Sort(sample) Dim intPeakValue as Integer = sample(sample.GetUpperBound(0)) This will sort the data in the sample array, then you get the upperbound value as an integer. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.