Community Forums Archive

Go Back

Subject:Time Stretch Increments
Date:5/2/2005 1:18:17 PM

I would like to create a script that performs incremental time stretches on a .WAV file. The increments would be every 2% from 80% to 120% of original speed. I cannot figure out how to tweak the example script files to do so. Any guidance would be most appreciated.

Mark

Subject:RE: Time Stretch Increments
Reply by: _TJ
Date:5/2/2005 6:00:56 PM

To do this, you would have to go into the Time Stretch plugin and create (and save off) a preset for each of your desired time stretch intervals. It would be wise to give them each a similar name.

Lets say you call these presets "Marks preset N" where N is the percentage
value. So you would have 20 presets called "Marks preset 80", "Marks preset 82", etc.

Once you have done this, you can then write a script that would use each of the presets in turn.


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

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

SfStatus status;
string szFilename = "testfile.wav";

for (int ii = 80; ii <= 120; ii+=2)
{
ISfFileHost file = app.OpenFile(szFilename, false, false);
if (null == file)
break;

string szPreset = String.Format("Marks preset {0}", ii);
file.DoEffect("Time Stretch", szPreset, new SfAudioSelection(0,-1), EffectOptions.EffectOnly);
status = file.WaitForDoneOrCancel();
if (status != SfStatus.Success)
break;

// assuming that you want to save the file...
string szBase = Path.GetFileNameWithoutExtension(file.Filename);
string szDir = Path.GetDirectoryName(file.Filename);
string szExt = Path.GetExtension(file.Filename);
string szNewBase = String.Format("{0} ({1})", szBase, szPreset);
string szNewFilename = Path.Combine(szDir, szNewBase + szExt);
file.SaveAs(szNewFilename, file.SaveFormat.Guid, "Default Template",
RenderOptions.RenderOnly | RenderOptions.FailIfExisting | RenderOptions.AndClose);
status = file.WaitForDoneOrCancel();
if (SfStatus.Success != status)
break;
}

}

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


Subject:RE: Time Stretch Increments
Date:5/3/2005 12:07:17 PM

Thank you so much. I will try that technique. I previously had named everything from about 80 to about 120 but with very simple names, such as "80" and "92."

Subject:RE: Time Stretch Increments
Date:5/3/2005 8:14:40 PM

I have been receiving the following error message when trying to run the script:

Sound Forge Error 0x8004E00A The item was not found.
while calling SoundForge.ISfFileHost OpenFile(System.String, Boolean, Boolean)
--------message----------
Exception from HRESULT: 0x8004E00A.
--------Stack Trace----------
at SoundForge.IScriptableApp.OpenFile(String pszFileName, Boolean fReadOnly, Boolean fNoWindow)
at EntryPoint.Begin(IScriptableApp app)
at EntryPoint.FromSoundForge(IScriptableApp app)

I don't know whether the reason has to do with testfile.wav sitting in my v:\ directory. The current default directory IS v:\. I changed your example by putting in "preset" instead of "marks preset". All of the presets are named preset 80, preset 82, etc.

Here is the current file. I also clicked the compile button:

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

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

SfStatus status;
string szFilename = "testfile.wav";

for (int ii = 80; ii <= 120; ii+=2)
{
ISfFileHost file = app.OpenFile(szFilename, false, false);
if (null == file)
break;

string szPreset = String.Format("Preset {0}", ii);
file.DoEffect("Time Stretch", szPreset, new SfAudioSelection(0,-1), EffectOptions.EffectOnly);
status = file.WaitForDoneOrCancel();
if (status != SfStatus.Success)
break;

// assuming that you want to save the file...
string szBase = Path.GetFileNameWithoutExtension(file.Filename);
string szDir = Path.GetDirectoryName(file.Filename);
string szExt = Path.GetExtension(file.Filename);
string szNewBase = String.Format("{0} ({1})", szBase, szPreset);
string szNewFilename = Path.Combine(szDir, szNewBase + szExt);
file.SaveAs(szNewFilename, file.SaveFormat.Guid, "Default Template",
RenderOptions.RenderOnly | RenderOptions.FailIfExisting | RenderOptions.AndClose);
status = file.WaitForDoneOrCancel();
if (SfStatus.Success != status)
break;
}

}

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


Subject:RE: Time Stretch Increments
Reply by: jetdv
Date:5/4/2005 7:00:44 AM

string szFilename = "testfile.wav";

Do you have a file named "testfile.wav"?

You might want to change this line to read the proper path and filename for the file you want to modify.

Subject:RE: Time Stretch Increments
Date:5/4/2005 7:26:08 AM

Yes, I have a file named "testfile.wav". My previous version of the script had "v:\testfile.wav" in place of just "testfile.wav" . This made no difference. Is it case sensitive? Can you think of any other solutions?

Subject:RE: Time Stretch Increments
Date:5/4/2005 8:31:56 AM

By putting "testfile.wav" in c:\program files\Sony\Sound Forge 8.0 I was able to get the script to at least load the File.

However, it does not run the rest of the script and provides this error message:

Sound Forge Error 0x8004E00A The item was not found.
while calling SoundForge.ISfGenericPreset DoEffect(System.String, System.Object, SoundForge.SfAudioSelection, SoundForge.EffectOptions)
--------message----------
Exception from HRESULT: 0x8004E00A.
--------Stack Trace----------
at SoundForge.ISfFileHost.DoEffect(String strEffectNameOrGUID, Object vPresetNameOrData, SfAudioSelection asel, EffectOptions opt)
at EntryPoint.Begin(IScriptableApp app)
at EntryPoint.FromSoundForge(IScriptableApp app)

Subject:RE: Time Stretch Increments
Reply by: ForumAdmin
Date:5/4/2005 1:03:00 PM

These two adjustments should get you up and running:
1) If you want to use a full path for your filename, prefix it with an @
Example: string szFilename = @"f:\testfile.wav";

2) Rename your effect. Replace "Time Stretch", with "Sony Time Stretch"

Let us know if that works.

Subject:RE: Time Stretch Increments
Date:5/4/2005 3:11:57 PM

Bingo! That move to "Sony Time Stretch" made all the difference. It works well now. It took about 5 minutes to run the whole course of 20 stretches and saves. This will save me a LOT of time over the next year or two. I really appreciate the specific direct help that I got in the forum.

Go Back