Community Forums Archive

Go Back

Subject:How to specify effect parameters
Posted by: Phil-H
Date:10/12/2007 5:15:09 PM

I have created a script which I am using to adjust the speed of analogue recordings by resampling them. Basically the user marks out regions within a file which correspond to a predetermined duration. The script calculates the average duration of the regions and then calculates what the new sample rate should be. I want to be able to pass this calculated value to the resample process. I’ve searched in the SDK manual, this forum and the example scripts and from what I’ve found it seems that it is only possible to use preset when applying effects or processes. Is there any way to use variables as parameter values for effects?

Thanks in advance.

Phil

Subject:RE: How to specify effect parameters
Reply by: ForumAdmin
Date:10/15/2007 10:36:15 AM

In this case, Resample is exposed independently on ISfFileHost:

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

A few other built-in effects are exposed similarly. For the general case (e.g. DirectX or VST plug-ins), you have to use or generate presets because plug-ins do not expose their (entire) parameter set to the host. They are "black boxes" in that sense.

J.

Message last edited on10/15/2007 10:44:09 AM byForumAdmin.
Subject:RE: How to specify effect parameters
Reply by: Phil-H
Date:10/15/2007 5:07:02 PM

J

Thanks a lot for that. I've managed to get that working specifying the sample rate and filter accuracy but I'm not sure how to specify the effect options. When I first use resample in my script I need to select 'Set the sample rate only (do not resample)'. How do I do this?

At the moment this part of the code looks like:

src.DoResample(newRate, nFilterAccuracy, EffectOptions.EffectOnly);

where newRate is a uint and nFilterAccuracy is an int.

Thanks

Phil

Subject:RE: How to specify effect parameters
Reply by: ForumAdmin
Date:10/16/2007 7:10:50 AM

The EffectOptions argument specifies how the effect is handled. It does not control any effect parameters.

I don't know why we didn't just expose the set-rate parameter, but we also don't seem to allow setting it directly on the filehost property.

The only way I can think of to change it is to create a new file with the desired rate and copy over to it (the warning you'd normally see will be skipped), then save it on top of the original, e.g.:

ISfFileHost file1 = app.CurrentFile;
SfWaveFormat fmt = new SfWaveFormat(file1.SampleType, file1.SampleRate/2, file1.Channels);
ISfFileHost file2 = app.NewFile(fmt, false);
file2.OverwriteAudio(0, 0, file1, new SfAudioSelection(file1));

I suppose you could also use the clipboard via DoMenu to copy the source off, delete most of the data, use DoResample to the desired rate, then just paste the original over it, but I think this will pop the rate-mismatch warning unless you disable it in prefs, which you probably don't want.

Rather than break the current API, I've changed the current method to treat a filter accuracy of -1 as set-rate-only. That will be available in 9.0d.

J.

Message last edited on10/16/2007 9:57:32 AM byForumAdmin.
Subject:RE: How to specify effect parameters
Reply by: Phil-H
Date:10/16/2007 1:19:11 PM

Thanks again J. I've got that method working now.

I assume that when the sample rate is applied as per the

src.DoResample(newRate, nFilterAccuracy, EffectOptions.EffectOnly);

method that the 'Apply an anti-alias filter during resample' is selected as default? The reason I ask is that after effectively altering the speed of the audio file by changing just the sample rate I then need to resample the file back to 44.1 kHz and I was planning on using this method.

As a small aside I assume that the general method I am using to change the speed of the recording is the best way to do it. I couldn't think of another way to do it Sound Forge.

My next step is to get the script to output the regions to a text file (I'm going to use 'DumpRegionsToFile.cs' as the basis) and record the percentage speed change and sample rate used to do the speed change. So I'm sure I'll have some more questions soon!

Phil

Subject:RE: How to specify effect parameters
Reply by: ForumAdmin
Date:10/16/2007 2:11:53 PM

Pitch Bend, Pitch Shift, or Time Stretch might be more efficient, but as they do not have scripted APIs, you'd have to create presets.

nFilterAccuracy appears to be an attempt to combine the AA filter option and resample quality settings. For anything above zero, the AA filter will be enabled. Setting it to zero is supposed to bypass the filter and use the lowest quality, but that currently doesn't work. I've since fixed that.

Really, we should just expose each option separately, which I will probably add.

J.

Message last edited on10/16/2007 2:13:05 PM byForumAdmin.
Subject:RE: How to specify effect parameters
Reply by: Phil-H
Date:10/18/2007 9:06:28 AM

Thanks J. I'll use the work-around for now and await the exposed options in a future release.

Phil

Go Back