Community Forums Archive

Go Back

Subject:Average pan of a .wav file
Posted by: bejj
Date:10/9/2013 9:55:28 AM

Hello,
I'd like to compute the average pan (from 100% LEFT to 100% RIGHT) of lots of .wav files. How would you do this ?

Compute a ratio RMS_dB_level_right / RMS_dB_level_left ?
Ratio = 1 => average pan is centre
Ratio near 0 => average pan is left
Ratio near infinity => average pan is right

Would you see a better way for doing this ?
(It would be better with 0=Full LEFT, 50=Centre, 100=FULL RIGHT)

How would you code such a thing ?

Thanks in advance for your ideas!

Subject:RE: Average pan of a .wav file
Reply by: roblesinge
Date:10/9/2013 11:24:28 AM

If I'm understanding you correctly, you'd want to get the statistics on each channel, add it to a variable and then compute the average for each channel.

First create a SfAudioStatistics object, then you'll want to loop through each file and pull the statistics for each channel using the GetStatistics() method of ISfFileHost (the object holding your file). You'd then want to add the RMSlevel field to a summing variable. Then just calculate your average for right and left.

Rob.

Subject:RE: Average pan of a .wav file
Reply by: bejj
Date:10/10/2013 4:12:49 AM

Hi roblesinge,

Do you know how to get the RMS level of the right channel, and the RMS level of the left channel ?

Something like :

leftRMS=RMS(f.leftchannel);
rightRMS=RMS(f.rightchannel);
ratio = rightRMS / leftRMS ;

Thank you !

Message last edited on10/10/2013 4:13:08 AM bybejj.
Subject:RE: Average pan of a .wav file
Reply by: roblesinge
Date:10/10/2013 7:59:15 AM

The GetStatistics method takes a uint parameter which determines which channel the statistics come from. I might be wrong here, but I believe you would want to use 0 for both channels, 1 for left and 2 for right. You would basically call GetStatistics twice, once for each channel. I don't have time today to code this for you, but an outline of your script would look like this:

-You'll need two summing integer variables (left and right), a variable to hold your averages, an SfAudioStatistics object to hold your statistics and an ISfFileHost object to hold each file.
-Get list of files to be averaged
-loop through the list
-open each file
-file.GetStatistics(1) for left and add the RMSLevel to a summing variable like SumLeft
-Do the same for the right channel
-Calculate your ratio

Rob.

Subject:RE: Average pan of a .wav file
Reply by: bejj
Date:10/11/2013 5:13:49 AM

Thank you I will try this.

Subject:RE: Average pan of a .wav file
Reply by: bejj
Date:10/12/2013 12:57:16 AM

Hi, Here is the solution.
I finally use a Subtraction of left and right dB RMS levels instead of a ratio in order to compute the average pan :
For example 0 is "mostly centre"
For example 20/-20 are "mostly left" or "mostly right"


string path = @"D:\temp";
string[] fileHolder = Directory.GetFiles(path, "*.wav");
for (int x = 0; x < fileHolder.Length ; x++)
{
ISfFileHost file = app.OpenFile(fileHolder[x], false, true);
SfAudioStatistics[] stat = new SfAudioStatistics[file.Channels];
file.UpdateStatistics(SfAudioSelection.All);
stat[0] = file.GetStatistics(0);stat[1] = file.GetStatistics(1);
DPF("Average Pan {0:N} ; {1}", SfHelpers.RatioTodB(stat[1].RMSLevel) - SfHelpers.RatioTodB(stat[0].RMSLevel), fileHolder[x]);
file.Close(CloseOptions.DiscardChanges);
}

Go Back