Community Forums Archive

Go Back

Subject:watermarking---please help
Posted by: papisound
Date:4/17/2007 12:21:00 PM

Hello to all,

I am wondering if any one has a script that will do a batch watermarking and would be so gracious to share the script.?

I just need to take a bunch of music files in a directory and and mix it with another short clip (watermark) and output the results to a different directory. I would like the watermark to repeat with about 10 seconds in between each repeat.

If anyone one could assist I would be greatly appreciative!!!

Subject:RE: watermarking---please help
Reply by: _TJ
Date:4/18/2007 4:07:29 PM

Look in the scripting SDK for a sample script called Mix Tone Every 4 Seconds.cs

tj

Subject:RE: watermarking---please help
Reply by: papisound
Date:4/19/2007 8:34:06 AM

Thanks for the tip, but still more quesitons.
First off I had to find it in SDK sound forge 9. I have soundforge 8...will it still run the script?

Then I looked at the script and is this were I change the script to my appropiate file locations>:
ISfFileHost file = app.CurrentFile;
ISfFileHost filePop = app.OpenFile(@"e:\media\pop48k.wav", true, true);

I assume the pop48k.wav is the watermark...but how do I make the target file be all the files within a particular directory?

Thanks!!
Hector

Subject:RE: watermarking---please help
Reply by: _TJ
Date:4/19/2007 6:04:01 PM

I have soundforge 8, will it still run the script?
That script was originally written with Sound Forge 8. So it should work,
the only way to know for sure is to try it.

Then I looked at the script and is this were I change the script to my appropiate file locations
Yes.

but how do I make the target file be all the files within a particular directory?
See the sample GenericMultiOpenAndProcess.cs, or GenericProcessAFolder.cs for examples of how to loop and process multiple files in a single script.

tj



Subject:RE: watermarking---please help
Reply by: papisound
Date:4/24/2007 2:28:34 PM

I greatly appreciate you showing me around, but i would have to say i am not a programmer. But i did get this far and tried to combine the two scripts you pointed to. The end result is this:
***************************************************************
System.ApplicationException: 22 compiler errors.
at SoundForge.CodeDomScriptManager.Compile(String szFile, String szSourceText)
at SoundForge.ScriptHost.RunScript(String szFile, String szSourceText, EngineType eType, Boolean fCompileOnly, Boolean fDebug)
*****************************************************************

The code i combined is listed below. Could you please assist in correcting this code. Thank you very much for your time.

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

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

string strWildcard = GETARG("Wild","*.wav");
string strOutputType = GETARG("Filetype",".mp3");

// pick a folder to process
string strSourceDir = SfHelpers.ChooseDirectory("Choose a folder to process all files from.", @"e:\Media");
if (null == strSourceDir)
return "no source directory - quitting";

// pick an output folder
string strOutDir = SfHelpers.ChooseDirectory("Choose a folder for the output files.", @"e:\Renders");
if (null == strOutDir)
return "no destination directory - quitting";

// choose an output format
/* ISfRenderer rend = app.FindRenderer(null, strOutputType);
if (null == rend)
return "no renderer - quitting";
ISfGenericPreset tpl = rend.ChooseTemplate(IntPtr.Zero, 0);
if (null == tpl)
return "no render template - quitting"; */

// now process them until we are done or the user hits cancel
//
foreach (string strFilename in Directory.GetFiles(strSourceDir, strWildcard))
{
// make an output filename using the input filename and the output folder name with a new extension based on the render format.
string strBase = Path.GetFileNameWithoutExtension(strFilename);
string strOutfile = Path.Combine(strOutDir, strBase + "." + rend.Extension);

SfStatus result = ProcessAFile(app, strFilename, strOutfile, tpl);

DPF("{0} : {1}", strFilename, result.ToString());
if (result == SfStatus.Cancel)
break;
}

return null; // return null for success, an error string otherwise
}

public SfStatus ProcessAFile(IScriptableApp app, string strFilename, string strOutfile, ISfGenericPreset tpl)
{
SfStatus result = SfStatus.Success;

// open the file
ISfFileHost file = app.OpenFile(strFilename, false, true);


/* add code here to process the file */

ISfFileHost file = app.CurrentFile;
ISfFileHost filePop = app.OpenFile(@"c:\royaltyfreemusic.wav", true, true);

Int64 ccLength = file.Length;
Int64 ccMix = filePop.Length;
Int64 ccStep = file.SecondsToPosition(10.0);
Int64 ccStart = 0;

if (filePop.SampleRate != file.SampleRate)
{
DPF("rate doesnt match - quitting");
}

ISfFileHost filePops = app.NewFile(file.DataFormat, false);
if (ccStart > 0)
filePops.InsertSilence(0, ccStart);

app.DoEvents(app.Win32Window.Handle);

SfAudioSelection aselPop = new SfAudioSelection(filePop);
for (Int64 ccPos = ccStart; ccPos + ccMix < ccLength; ccPos += ccStep)
{
filePops.OverwriteAudio(ccPos, 0, filePop, aselPop);
if (ccMix < ccStep)
{
filePops.InsertSilence(ccPos + ccMix, ccStep - ccMix);
}
}

filePop.Close(CloseOptions.DiscardChanges);

file.MixAudio(new SfAudioSelection(file), 1.0, 1.0, filePops, new SfAudioSelection(filePops));
}

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)); }
public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; }
public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); }
public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); }



// wait for processing to finish
result = file.WaitForDoneOrCancel();
if (result != SfStatus.Success)
return result;

// save the file under the new name and given format
file.RenderAs(strOutfile, null, tpl, null, RenderOptions.RenderOnly);
result = file.WaitForDoneOrCancel();

file.Close(CloseOptions.DiscardChanges);

return result;
}

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


Subject:RE: watermarking---please help
Reply by: _TJ
Date:4/24/2007 5:47:32 PM

You should put [code] [/code] tags around you code so that the formatting doesn't get lost.

It's really hard to read with all of the formatting lost.

thanks,
tj

Message last edited on4/25/2007 3:13:57 PM by_TJ.
Subject:RE: watermarking---please help
Reply by: jetdv
Date:4/25/2007 6:26:18 AM

SonyTJ, they're now [ code ] and [ /code ] tags.

Subject:RE: watermarking---please help
Reply by: papisound
Date:4/25/2007 1:03:47 PM

As requested:


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

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

string strWildcard = GETARG("Wild","*.wav");
string strOutputType = GETARG("Filetype",".mp3");

// pick a folder to process
string strSourceDir = SfHelpers.ChooseDirectory("Choose a folder to process all files from.", @"e:\Media");
if (null == strSourceDir)
return "no source directory - quitting";

// pick an output folder
string strOutDir = SfHelpers.ChooseDirectory("Choose a folder for the output files.", @"e:\Renders");
if (null == strOutDir)
return "no destination directory - quitting";

// choose an output format
/* ISfRenderer rend = app.FindRenderer(null, strOutputType);
if (null == rend)
return "no renderer - quitting";
ISfGenericPreset tpl = rend.ChooseTemplate(IntPtr.Zero, 0);
if (null == tpl)
return "no render template - quitting"; */

// now process them until we are done or the user hits cancel
//
foreach (string strFilename in Directory.GetFiles(strSourceDir, strWildcard))
{
// make an output filename using the input filename and the output folder name with a new extension based on the render format.
string strBase = Path.GetFileNameWithoutExtension(strFilename);
string strOutfile = Path.Combine(strOutDir, strBase + "." + rend.Extension);

SfStatus result = ProcessAFile(app, strFilename, strOutfile, tpl);

DPF("{0} : {1}", strFilename, result.ToString());
if (result == SfStatus.Cancel)
break;
}

return null; // return null for success, an error string otherwise
}

public SfStatus ProcessAFile(IScriptableApp app, string strFilename, string strOutfile, ISfGenericPreset tpl)
{
SfStatus result = SfStatus.Success;

// open the file
ISfFileHost file = app.OpenFile(strFilename, false, true);


/* add code here to process the file */

ISfFileHost file = app.CurrentFile;
ISfFileHost filePop = app.OpenFile(@"c:\royaltyfreemusic.wav", true, true);

Int64 ccLength = file.Length;
Int64 ccMix = filePop.Length;
Int64 ccStep = file.SecondsToPosition(10.0);
Int64 ccStart = 0;

if (filePop.SampleRate != file.SampleRate)
{
DPF("rate doesnt match - quitting");
}

ISfFileHost filePops = app.NewFile(file.DataFormat, false);
if (ccStart > 0)
filePops.InsertSilence(0, ccStart);

app.DoEvents(app.Win32Window.Handle);

SfAudioSelection aselPop = new SfAudioSelection(filePop);
for (Int64 ccPos = ccStart; ccPos + ccMix < ccLength; ccPos += ccStep)
{
filePops.OverwriteAudio(ccPos, 0, filePop, aselPop);
if (ccMix < ccStep)
{
filePops.InsertSilence(ccPos + ccMix, ccStep - ccMix);
}
}

filePop.Close(CloseOptions.DiscardChanges);

file.MixAudio(new SfAudioSelection(file), 1.0, 1.0, filePops, new SfAudioSelection(filePops));
}

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)); }
public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; }
public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); }
public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); }



// wait for processing to finish
result = file.WaitForDoneOrCancel();
if (result != SfStatus.Success)
return result;

// save the file under the new name and given format
file.RenderAs(strOutfile, null, tpl, null, RenderOptions.RenderOnly);
result = file.WaitForDoneOrCancel();

file.Close(CloseOptions.DiscardChanges);

return result;
}

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

Subject:RE: watermarking---please help
Reply by: _TJ
Date:4/25/2007 3:23:00 PM

Looks like just got some extra duplicate code left over from trying to merge the two scripts. just delete this line


ISfFileHost file = app.CurrentFile;

and this block

}

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)); }
public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; }
public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); }
public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); }

Message last edited on4/25/2007 3:25:12 PM by_TJ.
Subject:RE: watermarking---please help
Reply by: papisound
Date:4/26/2007 10:12:18 AM

I removed the first peace, and the second peace of code i added to the bottom of the script. and i produced these errors

*****
System.ApplicationException: 31 compiler errors.
at SoundForge.CodeDomScriptManager.Compile(String szFile, String szSourceText)
at SoundForge.ScriptHost.RunScript(String szFile, String szSourceText, EngineType eType, Boolean fCompileOnly, Boolean fDebug)
******


Here is the current script:


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

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

string strWildcard = GETARG("Wild","*.wav");
string strOutputType = GETARG("Filetype",".mp3");

// pick a folder to process
string strSourceDir = SfHelpers.ChooseDirectory("Choose a folder to process all files from.", @"e:\Media");
if (null == strSourceDir)
return "no source directory - quitting";

// pick an output folder
string strOutDir = SfHelpers.ChooseDirectory("Choose a folder for the output files.", @"e:\Renders");
if (null == strOutDir)
return "no destination directory - quitting";

// choose an output format
/* ISfRenderer rend = app.FindRenderer(null, strOutputType);
if (null == rend)
return "no renderer - quitting";
ISfGenericPreset tpl = rend.ChooseTemplate(IntPtr.Zero, 0);
if (null == tpl)
return "no render template - quitting"; */

// now process them until we are done or the user hits cancel
//
foreach (string strFilename in Directory.GetFiles(strSourceDir, strWildcard))
{
// make an output filename using the input filename and the output folder name with a new extension based on the render format.
string strBase = Path.GetFileNameWithoutExtension(strFilename);
string strOutfile = Path.Combine(strOutDir, strBase + "." + rend.Extension);

SfStatus result = ProcessAFile(app, strFilename, strOutfile, tpl);

DPF("{0} : {1}", strFilename, result.ToString());
if (result == SfStatus.Cancel)
break;
}

return null; // return null for success, an error string otherwise
}

public SfStatus ProcessAFile(IScriptableApp app, string strFilename, string strOutfile, ISfGenericPreset tpl)
{
SfStatus result = SfStatus.Success;

// open the file
ISfFileHost file = app.OpenFile(strFilename, false, true);


/* add code here to process the file */

ISfFileHost filePop = app.OpenFile(@"c:\royaltyfreemusic.wav", true, true);

Int64 ccLength = file.Length;
Int64 ccMix = filePop.Length;
Int64 ccStep = file.SecondsToPosition(10.0);
Int64 ccStart = 0;

if (filePop.SampleRate != file.SampleRate)
{
DPF("rate doesnt match - quitting");
}

ISfFileHost filePops = app.NewFile(file.DataFormat, false);
if (ccStart > 0)
filePops.InsertSilence(0, ccStart);

app.DoEvents(app.Win32Window.Handle);

SfAudioSelection aselPop = new SfAudioSelection(filePop);
for (Int64 ccPos = ccStart; ccPos + ccMix < ccLength; ccPos += ccStep)
{
filePops.OverwriteAudio(ccPos, 0, filePop, aselPop);
if (ccMix < ccStep)
{
filePops.InsertSilence(ccPos + ccMix, ccStep - ccMix);
}
}

filePop.Close(CloseOptions.DiscardChanges);

file.MixAudio(new SfAudioSelection(file), 1.0, 1.0, filePops, new SfAudioSelection(filePops));
}

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)); }
public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; }
public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); }
public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); }



// wait for processing to finish
result = file.WaitForDoneOrCancel();
if (result != SfStatus.Success)
return result;

// save the file under the new name and given format
file.RenderAs(strOutfile, null, tpl, null, RenderOptions.RenderOnly);
result = file.WaitForDoneOrCancel();

file.Close(CloseOptions.DiscardChanges);

return result;
}

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; }


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)); }
public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; }
public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); }
public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); }
} //EntryPoint

Subject:RE: watermarking---please help
Reply by: _TJ
Date:4/26/2007 5:23:26 PM

Sorry. I guess I wasn't clear. Delete the single line I showed,
and ALSO DELETE the block of code that I showed. Both are
extra.

And make sure to notice that the block of code to delete begins
with a {

tj

Subject:RE: watermarking---please help
Reply by: papisound
Date:4/27/2007 9:54:59 AM

My apologies for not thinking about deleting both blocks.

But, I did as you said this time and only generated two errors. :)

Any thoughts on this:
*********************************
System.ApplicationException: 2 compiler errors.
at SoundForge.CodeDomScriptManager.Compile(String szFile, String szSourceText)
at SoundForge.ScriptHost.RunScript(String szFile, String szSourceText, EngineType eType, Boolean fCompileOnly, Boolean fDebug)
***********************************

Thank you for your help!!
Look forward to hearing back from you.

Subject:RE: watermarking---please help
Reply by: papisound
Date:4/30/2007 10:01:14 AM

Would it help if i copied the current code?


Subject:RE: watermarking---please help
Reply by: _TJ
Date:5/1/2007 12:47:37 PM

Ah yes. I see the problem. for some reason the code to choose an output format is commented out.

you need to change this line
    /* ISfRenderer rend = app.FindRenderer(null, strOutputType);

to this
   ISfRenderer rend = app.FindRenderer(null, strOutputType);


and this line
      return "no render template - quitting"; */

to this
      return "no render template - quitting";


Or, in other words, remove the comment markers /* */ that surround the code
that chooses an output format.

tj

Go Back