Subject:Peak level of .wav file
Posted by: bejj
Date:10/21/2012 1:29:16 PM
Hi, Do you know a function that computes the peak level (ex: -3dB) of a wav file ? (in a script ) Thanks a lot in advance, |
Subject:RE: Peak level of .wav file
Reply by: bejj
Date:10/21/2012 1:36:01 PM
I've found the function "ISfFileHost.FindAudioPeak", but it returns the position of peak, and not the value. Any idea for the dB value of peak ? |
Subject:RE: Peak level of .wav file
Reply by: bejj
Date:10/21/2012 4:15:48 PM
I've found a solution. This scripts prints the dB peak level of all .wav in each subfolder of "D:\TEMP". using System; using System.IO; using System.Windows.Forms; using SoundForge; public class EntryPoint { public string Begin(IScriptableApp app) { string[] dirHolder = Directory.GetDirectories(@"D:\TEMP"); for (int d = 0; d < dirHolder.Length ; d++) { string[] fileHolder = Directory.GetFiles(dirHolder[d], "*.wav"); double maxpeak = -1000; for (int x = 0; x < fileHolder.Length ; x++) { ISfFileHost file = app.OpenFile(fileHolder[x], false, true); Int64 peakpos = file.FindAudioPeak(new SfAudioSelection(0, file.Length)); double peak = Math.Max(Math.Abs(file.GetSample(peakpos,0)),Math.Abs(file.GetSample(peakpos,1))); maxpeak=Math.Max(maxpeak, 20 * Math.Log(peak,10)); file.Close(CloseOptions.DiscardChanges); } DPF("PeakValue {0,20} dB : {1}", maxpeak,dirHolder[d]); } return null; } public void FromSoundForge(IScriptableApp app) { ForgeApp = app; //execution begins here app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name)); string msg = Begin(app); app.SetStatusText(msg != null ? msg : 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, params object[] args) { ForgeApp.OutputText(String.Format(fmt, args)); } public static string GETARG(string key, string str) { string val = Script.Args.ValueOf(key); if (val == null) val = str; return val; } } //EntryPoint |