Community Forums Archive

Go Back

Subject:programmatically set parameters
Posted by: JimEE
Date:8/29/2013 3:03:38 PM

I am trying to create a C# script to generate a sine wave.

I have used one of the example scripts to create the framework using the "Simple Synthesis" effect. The example however, displays a dialog box for the user to select the parameters for creating the sine wave or allows the user to select preset.

How do I programmatically, in C#, set the parameters such as Start Frequency, End Frequency, Length, etc?

Thanks,
Jim

Subject:RE: programmatically set parameters
Reply by: roblesinge
Date:8/29/2013 4:22:32 PM

Can you post your code in some code tags?

You may have to create a preset and then pass that preset into the Synthesis effect using DoEffect or something like that.

Rob.

Subject:RE: programmatically set parameters
Reply by: JimEE
Date:8/30/2013 8:33:49 AM


public void Begin(IScriptableApp app) {

//start MODIFY HERE -----------------------------------
int uiSampleRate = GETARG("SampleRate", 8000);
string szFileName = GETARG("FileName", "output");

// GETARG is a function that defines the default script settings. You can use the Script Args field to over-ride
// the values within GETARG().
// Example: To over-ride GETARG(Key, valueA), type Key=valueB in the Script Args field.
// Use an ampersand (&) to separate different Script Args: KeyOne=valueB&KeyTwo=valueC

//Example Script Args: Files=1&fx=FM Synthesis

//end MODIFY HERE -----------------------------------

// specify 8 bit, 1 channel, at the user specified sample rate
SfWaveFormat format = new SfWaveFormat(SfSampleType.Wav8, (uint)uiSampleRate, 1);

// create a new audio file (no user interaction required)
ISfFileHost file = app.NewFile(format, false);

// obtain a pointer to the "Simple Synthesis" effect
ISfGenericEffect effect = app.FindEffect("Simple Synthesis");

// if an error occurred finding the effect
if (null == effect) {
DPF("ERROR: unable to find the \"Simple Synthesis\" effect");
return;
}

// Waveform shape: Sine
// Length: 1.667 seconds
// Start Frequency: 1,295 Hz
// End Frequency: 545 Hz
// Amplitude: 0 dB
// Log Sweep: No
// Insert new waveform at: End of file

// TODO: setting for the effect

// generate the sine wave
file.DoEffect(effect.Name, preset, null, EffectOptions.EffectOnly);

// if an error occurred creating the sine wave
if (SfStatus.Success != file.WaitForDoneOrCancel()) {
DPF("ERROR: unable to create the sine wave");
return;
}

// TODO: save to file

return;
}

Subject:RE: programmatically set parameters
Reply by: JimEE
Date:8/30/2013 8:40:21 AM

I am really hoping to not use a preconfigured (vs created on the fly by the script) preset for two reasons. I really want the C# function to be fully self contained and not have any dependencies. I also don’t want to manage converting the presets to newer SF versions as they become available.

There are quite a few wave forms I am trying to create, so I’d rather not have a huge library of presets to manage.

Jim

Subject:RE: programmatically set parameters
Reply by: roblesinge
Date:8/30/2013 9:36:53 AM

Jim,

Unfortunately, I don't think you can access the fields in the Simple Synthesis dialog to create a preset on the fly. I'd recommend you investigate creating Sine waves on your own. Check out the "Generate a tone.cs" or "Generate a constantly falling tone.cs" in the SDK sample scripts. Or just Google how to do it and implement the algorithm in a SF script.

Rob.

Subject:RE: programmatically set parameters
Reply by: JimEE
Date:9/3/2013 9:25:15 AM

Thanks!

Go Back