Community Forums Archive

Go Back

Subject:file.MixAudio or file.DoEffect(“Edit.PasteMix”
Posted by: GPD
Date:10/15/2007 8:17:42 AM

I need to open a file, copy this file, execute some Do-Menu Commands, and then mix the result back with the orrignal.

at the recomendation of TJ, I've been avoiding Do-menu cut-paste and using sfselection methods instead such as:

file.MixAudio(aselOut, dGainMain, dGainMusic, file3, aselXXX);

Is it possible to use these methods with the above need, or do I have to use copy/paste since the file will change inbetween the copy action and the paste action? Do I have to use:

file.DoEffect(“Edit.Copy”
file.DoEffect(“Edit.PasteMix”

Message last edited on10/15/2007 8:23:52 AM byGPD.
Subject:RE: file.MixAudio or file.DoEffect(“Edit.Pas
Reply by: ForumAdmin
Date:10/15/2007 10:29:14 AM

If you create a new filehost for processing, it exists independent of the original. That is, to make a copy:

ISfFileHost file1 = app.CurrentFile; // or whatever the source file is
ISfFileHost file2 = app.NewFile(file1.DataFormat, false);
SfAudioSelection asel1 = new SfAudioSelection(file1);
file2.OverwriteAudio(0, 0, file1, asel1);

Then do whatever processing you want directly on file2:

file2.DoEffect("Normalize", "Maximize peak value", asel1, EffectOptions.EffectOnly | EffectOptions.WaitForDoneOrCancel);

And finally, mix the result with file1:

file1.MixAudio(asel1, 1.0, 1.0, file2, asel1);

If you must use DoMenu, you'll have to ensure that the copy you want to process has focus, which can be done with the IsCurrent property on the filehost.

If processing changes the length, you'll have to account for that in your selections, though that depends on what you're doing. If there are portions of file2 that you don't want mixed into file1, just use MuteAudio to silence those portions before you mix back to file1.

J.

Message last edited on10/15/2007 10:43:27 AM byForumAdmin.
Subject:RE: file.MixAudio or file.DoEffect(“Edit.Pas
Reply by: GPD
Date:10/15/2007 2:18:09 PM

When using:

file.MixAudio(asel1, 0.0, 1.0, file2, asel2) ; // Mix

SF does not seem to respect the selection values it seems to "copy" from the start of the source file and paste to the start of the desination even if "the asel defis specify something else.

Is this a bug?

Message last edited on10/15/2007 2:24:53 PM byGPD.
Subject:RE: file.MixAudio or file.DoEffect(“Edit.Pas
Reply by: ForumAdmin
Date:10/15/2007 3:20:39 PM

First, make sure you have the 9.0c update installed.

In 9.0c, I see the loop region jumping around incorrectly after the mix executes, but the mix itself appears to be happening at the right spot.

Perhaps a sample script?

Addendum: Hang on, I may see something.

J.

Message last edited on10/15/2007 3:39:04 PM byForumAdmin.
Subject:RE: file.MixAudio or file.DoEffect(“Edit.Pas
Reply by: GPD
Date:10/15/2007 8:14:27 PM

Thanks for all the help for me and everyone else on the forum....

Subject:RE: file.MixAudio or file.DoEffect(“Edit.Pas
Reply by: ForumAdmin
Date:10/16/2007 9:24:41 AM

Rats. This was indeed broken, though it was only exposed as a side effect of a different fix in 9.0c. Essentially, the destination selection is also being used as the source selection in ISfFileHost::MixAudio.

The easiest workaround is to extract the selections manually, mix them, and insert the result, effectively removing all the selection dependencies from MixAudio. Here is a wrapper function that will do the right thing.


public void MixAudio_90cWorkaround
(
ISfFileHost fileDst,
SfAudioSelection aselDst,
double dGainDst,
ISfFileHost fileSrc,
SfAudioSelection aselSrc,
double dGainSrc
)
{
// workaround for ISfFileHost::MixAudio bug exposed in 9.0c
// where aselDst is incorrectly used for aselSrc...
//
ISfFileHost fileSrcTmp = ForgeApp.NewFile(fileSrc.DataFormat, true);
fileSrcTmp.OverwriteAudio(0, 0, fileSrc, aselSrc);
ISfFileHost fileDstTmp = ForgeApp.NewFile(fileDst.DataFormat, true);
fileDstTmp.OverwriteAudio(0, 0, fileDst, aselDst);

fileDstTmp.MixAudio(null, dGainDst, dGainSrc, fileSrcTmp, null);
fileDst.ReplaceAudio(aselDst, fileDstTmp, new SfAudioSelection(fileDstTmp));

fileSrcTmp.Close(CloseOptions.DiscardChanges);
fileDstTmp.Close(CloseOptions.DiscardChanges);
}


Sorry, I should have caught this. It will be fixed in the next update.

J.

Subject:RE: file.MixAudio or file.DoEffect(“Edit.Pas
Reply by: GPD
Date:10/16/2007 10:40:10 AM

Thanks.

For clarity, I experienced this in 9.a, so I am not sure it is new to 9.c. I will update to 9.c today as suggested though.

I figured out a work around yesterday too. I repeated the audio in file2, and then crop.audio'd to the range I needed and then mixed the whole file to the distination I needed. It did what I needed, but your suggestion is better and more robust I am sure...

Go Back