Community Forums Archive

Go Back

Subject:File Statistics
Posted by: spoken
Date:1/27/2006 7:46:57 AM

I know that the file statistics of individual files are now available on the clipboard.

Is it possible to create a printed report of statistics for a batch of files? I would like to create a report of RMS values for a group of files. Are there any other solutions out there?

Subject:RE: File Statistics
Reply by: _TJ
Date:1/27/2006 12:52:13 PM

There are no existing tools that I'm aware of, but Statistics is scriptable, so a pretty simple script could do this.

have a Look a the script StatisticsTest.cs. It's in the Unit Tests subfolder of the C# samples of the Sound Forge Scripting SDK.

Message last edited on1/27/2006 1:45:26 PM by_TJ.
Subject:RE: File Statistics
Reply by: _TJ
Date:1/27/2006 4:30:07 PM

Here's a script that get's statistics for the current file in Sound Forge and prints them out in the Script Editor's output pane.


using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;

public class EntryPoint {
public void Begin(IScriptableApp app) {

ISfFileHost file = app.CurrentFile;

file.UpdateStatistics(null);
file.WaitForDoneOrCancel();

if (file.StatisticsAreUpToDate)
{
DPF("Statistics for file '{0}' {1}", file.Filename, file.DataFormat.ToString());
SfAudioStatistics[] stat = new SfAudioStatistics[file.Channels];
for (uint ii = 0; ii < file.Channels; ++ii)
{
stat[ii] = file.GetStatistics(ii);
}

ISfPositionFormatter pos = file.Formatter;

if (file.Channels == 1)
{
Int64 ccPeak = stat[0].MaxValueLocation;
double dPeak = stat[0].MaxValue;
if (Math.Abs(stat[0].MinValue) > dPeak)
{
dPeak = Math.Abs(stat[0].MinValue);
ccPeak = stat[0].MinValueLocation;
}
DPF("Start {0,20} ", pos.Format(stat[0].Start));
DPF("Length {0,20} ", pos.Format(stat[0].Length));
DPF("Average {0,20} ", stat[0].Average);
DPF("RMSLevel {0,20} dB", SfHelpers.RatioTodB(stat[0].RMSLevel));
DPF("PeakValue {0,20} dB", SfHelpers.RatioTodB(dPeak));
DPF("PeakValueLocation {0,20} ", pos.Format(ccPeak));
DPF("MinValue {0,20} % of full scale", stat[0].MinValue * 100);
DPF("MinValueLocation {0,20} ", pos.Format(stat[0].MinValueLocation));
DPF("MaxValue {0,20} % of full scale", stat[0].MaxValue * 100);
DPF("MaxValueLocation {0,20} ", pos.Format(stat[0].MaxValueLocation));
DPF("ZeroCrossingFrequency {0,20} Hz", SfHelpers.RatioTodB(stat[0].ZeroCrossingFrequency));
}
else if (file.Channels == 2)
{
Int64 ccPeak0 = stat[0].MaxValueLocation;
double dPeak0 = stat[0].MaxValue;
if (Math.Abs(stat[0].MinValue) > dPeak0)
{
dPeak0 = Math.Abs(stat[0].MinValue);
ccPeak0 = stat[0].MinValueLocation;
}

Int64 ccPeak1 = stat[1].MaxValueLocation;
double dPeak1 = stat[1].MaxValue;
if (Math.Abs(stat[1].MinValue) > dPeak1)
{
dPeak1 = Math.Abs(stat[1].MinValue);
ccPeak1 = stat[1].MinValueLocation;
}

DPF("-----Parameter------ {0,20} {1,20} ", "----Left----", "----Right----");
// DPF("Start {0,20} {1,20} ", pos.Format(stat[0].Start) , pos.Format(stat[1].Start) );
DPF("Length {0,20} {1,20} ", pos.Format(stat[0].Length) , pos.Format(stat[1].Length) );
DPF("Average {0,20} {1,20} ", stat[0].Average, stat[1].Average);
DPF("RMSLevel {0,20} dB {1,20} dB", SfHelpers.RatioTodB(stat[0].RMSLevel), SfHelpers.RatioTodB(stat[1].RMSLevel));
DPF("PeakValue {0,20} dB {1,20} dB", SfHelpers.RatioTodB(dPeak0), SfHelpers.RatioTodB(dPeak1));
DPF("PeakValueLocation {0,20} {1,20} ", pos.Format(ccPeak0), pos.Format(ccPeak1));
DPF("MinValue {0,20} % {1,20} %", stat[0].MinValue * 100, stat[1].MinValue * 100);
DPF("MinValueLocation {0,20} {1,20} ", pos.Format(stat[0].MinValueLocation), pos.Format(stat[1].MinValueLocation));
DPF("MaxValue {0,20} % {1,20} %", stat[0].MaxValue * 100, stat[1].MaxValue * 100);
DPF("MaxValueLocation {0,20} {1,20} ", pos.Format(stat[0].MaxValueLocation), pos.Format(stat[1].MaxValueLocation));
DPF("ZeroCrossingFrequency {0,20} Hz {1,20} Hz", stat[0].ZeroCrossingFrequency, stat[1].ZeroCrossingFrequency );
}
}
else
{
DPF("Statistics are NOT up to date");
}


}

public void FromSoundForge(IScriptableApp app) {
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, object o) { ForgeApp.OutputText(String.Format(fmt,o)); }
public static void DPF(string fmt, object o, object o2) { ForgeApp.OutputText(String.Format(fmt,o,o2)); }
public static void DPF(string fmt, object o, object o2, object o3) { ForgeApp.OutputText(String.Format(fmt,o,o2,o3)); }
} //EntryPoint


Go Back