Community Forums Archive

Go Back

Subject:Creating effect presets using Fields_
Posted by: ciaranw
Date:10/28/2008 5:20:00 AM

I have been trying to script some effect preset creation (Resample / Bit-Depth Converter / Channel Converter) for file format conversion.

Looking at the samples and documentation I thought I could use Fields_Resample etc to set fields, then ToPreset() to apply them to a preset, finally applying that preset with DoEffect(effect, preset, etc).

I can create and set fields (and verify that they have been set) but when I use ToPreset and run the preset I don't get the correct result.

I then tried using FromPreset() to test my fields and didn't get back the values I had set.

How can I be sure to write my fields correctly to a preset?

I guess I'm doing something wrong here but I'm out of ideas...

.....

//Create a custom Channel Converter preset

//Select CC effect
ISfGenericEffect effectC = app.FindEffect("Channel Converter");

//Create a CC "Fields" object
Fields_ChannelConverter fieldsC = new Fields_ChannelConverter();

//Set fields
fieldsC.OutputChannels = format.Channels;
DPF("fieldsC output channels = {0}", fieldsC.OutputChannels);
//fieldsC.LeftVolumeFromLeft = 100.0;
//fieldsC.LeftVolumeFromRight = 0.0;
//fieldsC.RightVolumeFromLeft = 0.0;
//fieldsC.RightVolumeFromRight = 100.0;

//Get any old CC preset and overwrite its fields
ISfGenericPreset presetC = effectC.GetPreset("");
fieldsC.ToPreset(presetC);


Fields_ChannelConverter fieldsTest = new Fields_ChannelConverter();
fieldsTest = Fields_ChannelConverter.FromPreset(presetC);
DPF("presetC output channels = {0}", fieldsTest.OutputChannels);

//Apply preset
file.DoEffect("Channel Converter", presetC, new SfAudioSelection(file), EffectOptions.EffectOnly);
if (app.WaitForDoneOrCancel() != SfStatus.Success)
{
DPF("Channel conversion failed");
return SfStatus.Fail;
}
else DPF("Converted to {0} channel(s)", format.Channels);

Subject:RE: Creating effect presets using Fields_
Reply by: _TJ
Date:11/4/2008 11:20:10 AM

I think the problem is here


effectC.GetPreset("")


Getting the "" preset is code for getting the 'default preset'.

The default preset is a special-case preset that doesn't have any fields,
it's just a signal to the plugin that it should use the last-used settings that
the user chose.

When you use ToFields() in this preset, it doesn't end up overwriting that signal.

You need to GetPreset() using a real preset name, then you should be able to overwrite the fields.

Incidently, for Resample, Bit-Depth Converter & Channel Converter, in Sound Forge 9.0 you can now invoke these plugins directly by calling methods on ISfFileHost, there is no longer any need to build a preset and call DoEffect().

Here's the method prototypes

// these are methods on ISfFileHost

// resample
SfStatus DoResample(
uint cSamplesPerSec,
int nFilterAccuracy,
EffectOptions opt);

// resample
SfStatus DoResample(
uint cSamplesPerSec,
int nAccuracy,
bool fAntiAlias,
bool fSetRateOnly,
EffectOptions opt);

// bit depth converter
SfStatus DoConvertSampleType(
SfSampleType eSampleType,
DitherType eDitherType,
NoiseShapeType eNoiseShape,
EffectOptions opt);

// channel converter
SfStatus DoConvertChannels(
uint cChannels,
uint fuInvertMask,
double[] aGainMap,
EffectOptions opt);


tj




Message last edited on11/4/2008 11:21:11 AM by_TJ.
Subject:RE: Creating effect presets using Fields_
Reply by: ciaranw
Date:11/14/2008 9:43:23 AM

Thanks TJ, both approaches are very useful!

Go Back