Subject:ISfWriteAudioStream and SfSampleType issues
Posted by: ghova
Date:11/11/2005 1:05:22 PM
I'm trying to use the ISfWriteAudioStream interface in one of my scripts. Here's my code (working in VB)... We'll assume that fileCurrent is an ISfFileHost that the script has already opened, and strNextFile is a string path to a file that I'd like to open and append to the end of strFileCurrent. If File.Exists(strNextFile) Then Dim fileTemp As ISfFileHost = app.OpenFile(strNextFile, False, False) Dim fileWriteTemp As ISfWriteAudioStream = fileTemp.OpenWriteAudioStream(SfSampleType.Wav16, 0, 0) fileCurrent.WriteAudio(New SfAudioSelection(fileCurrent.Length, 0), fileWriteTemp) fileTemp.Close(CloseOptions.DiscardChanges) End If I'm getting an error on the line... Dim fileWriteTemp As ISfWriteAudioStream = fileTemp.OpenWriteAudioStream(SfSampleType.Wav16, 0, 0) The error is " Value of type 'Integer' cannot be converted to 'SoundForge.SfSampleType'. " However, the documentation seems to indicate that this is where I put in a SfSampleType enumeration depending on the kind of file I'm trying to turn into an ISfWriteAudioStream. If I don't put a SfSampleType enumeration there, what do I put? Thanks! ~Gil |
Subject:RE: ISfWriteAudioStream and SfSampleType issu
Reply by: _TJ
Date:11/13/2005 2:47:17 PM
You are doing it the right way. OpenWriteAudioStream takes a member of SfSampleType enumeration as its first argument. But for some reason, VB insists on converting SfSampleType.Wav16 to an integer, and then it is unable to convert the integer back into a SfSampleType to pass to the function. VB is simply broken when it comes to the use of Enumerated types that aren't derived from Integer. If you switch to late binding, you might be able to work around this because with late binding, the compiler is unable to do type checking, and it's the backward compatible/broken type checking of VB that's causing the problem here. Dim fileTemp = app.OpenFile(strNextFile, False, False) Dim fileWriteTemp As ISfWriteAudioStream = fileTemp.OpenWriteAudioStream(SfSampleType.Wav16, 0, 0) note the removal of As ISfFileHost above. This causes VB to treat the file host as a late binding IDispatch object and thus it can't type check the arguments. This code compiles, but I'm not sure that it works since this is just a fragment. In case you want to try passing explicit integers as the first argument, here is the enumeration values table for SfSampleType. SfSampleType.Unknown = 0 SfSampleType.Wav8 = 16 SfSampleType.Wav16 = 17 SfSampleType.Wav24 = 18 SfSampleType.Wav32 = 19 SfSampleType.WavFloat = 32 SfSampleType.WavDouble = 33 SfSampleType.Unpacked24 = 48 SfSampleType.Signed8 = 49 SfSampleType.Aif16 = 64 SfSampleType.Aif24 = 65 SfSampleType.Aif32 = 66 SfSampleType.RightAligned16 = 128 SfSampleType.RightAligned24 = 129 My recommendation would be to just abandon VB and switch to a modern languange. JScript does not have this problem, and C# gives much better syntax checking than either JScript or VB. tj |
Subject:RE: ISfWriteAudioStream and SfSampleType issu
Reply by: ghova
Date:11/14/2005 9:22:56 AM
Thanks for the quick reply, TJ! Learning C# has been on my to-do list, so I guess this is another reason I should dive in. In the meantime, I'm getting around the problem by invoking copies and pastes from the app.DoMenuAndWait method. It's not pretty, but it works. ~Gil |
Subject:RE: ISfWriteAudioStream and SfSampleType issu
Reply by: _TJ
Date:11/14/2005 12:06:24 PM
You could also use ISfFileHost.OverwriteAudio(...) ISfFileHost.ReplaceAudio(...) ISfFileHost.MixAudio(...) ISfFileHost.DeleteAudio(...) ISfFileHost.CropAudio(...) ISfFileHost.InsertSilence(...) These methods are the building blocks of Cut/Copy/Paste. while OpenWriteAudioStream(..) is intended for use by people who want to actually manufacture audio or do signal processing algorithms with script. In fact, the code that you have above would OpenWriteAudioStream(), but that stream would be empty unless you called the Append() method of the ISfWriteAudioStream in order to add data to it. Then when you call WriteAudio(), nothing happens because the ISfWriteAudioStream is empty. I had assumed that you just left out the code in your example that put data into the ISfWriteAudioStream, but now I'm thinking that what you really meant to do was to copy from fileTemp to fileCurrent. Is that correct? To copy from fileTemp to fileCurrent, use fileCurrent.ReplaceAudio(aselDest, fileTemp, aselSrc) or fileCurrent.MixAudio(aselDest, dGainDest, dGainSrc, fileTemp, aselSrc); tj Message last edited on11/14/2005 12:15:16 PM by_TJ. |
Subject:RE: ISfWriteAudioStream and SfSampleType issu
Reply by: ghova
Date:11/14/2005 2:36:25 PM
Yeah, that's exactly what I need! I guess I misread the documentation. This will make things much easier. Thanks! ~Gil |