Batch Converter for 3ms microfades (in/out)

Belibat ha scritto il 19.01.2022 ore 16:43

Hey everyone!

i’m using Sound Forge Pro 15 on a Windows 10 pc.

i just discovered the batch converter which would be very helpful if i would be able to create a custom preset routine to add 3ms micro fades in and out to batches of files.

does anyone know if that’s possible?

the batch converter has both a fade in and fade out preset actions in the effect section but i can’t decide the fades length.

thank you so much for your help!

Commenti

SP. ha scritto il 19.01.2022 ore 18:08

@Belibat If I understand it correctly Fade In and Fade Out are always applied to the entire selection or the entire file. There are no presets to change the settings.

I think you need to write a script to handle your problem automatically. There is a "Crop and Fade.cs" example in the script folder which you can modify. Do you know how to program in C#?

Belibat ha scritto il 19.01.2022 ore 18:15

@Belibat If I understand it correctly Fade In and Fade Out are always applied to the entire selection or the entire file. There are no presets to change the settings.

I think you need to write a script to handle your problem automatically. There is a "Crop and Fade.cs" example in the script folder which you can modify. Do you know how to program in C#?

Thanks a lot for your reply!

unfortunately i’m not able to program in C# (or any other programming language).
I think this should be a pretty common task by the way. In the quick actions there’s a fade in/fade out action which only requires to put the length in ms.

would be awesome to have it listed in the actions for the batch converter.

by the way, do you know any resources on how to program that in C#? Maybe i will find someone to do that..

SP. ha scritto il 19.01.2022 ore 18:19

@Belibat Maybe I can change the script to make it run on a folder of audio files and apply a fade in and fade out. I will look into it later and post it here.

Belibat ha scritto il 19.01.2022 ore 18:21

@Belibat Maybe I can change the script to make it run on a folder of audio files and apply a fade in and fade out. I will look into it later and post it here.

Oh that would awesome! A script to apply a 3ms fade in and out to a batch of files. Wow! Thank you so much!

SP. ha scritto il 19.01.2022 ore 20:42

@Belibat

Here is the script. You can choose a folder where your files are located. Sound Forge will try to open each file in the folder and all its subfolders and try to run the 'Graphic Fade' effect with the presets '-6 dB exponential fade in' and '-6 dB exponential fade out' in the first and last 3ms at the beginning and the end of the file.

Be careful and do not use this script without a backup of your files, just to be on the save side. Do not select the wrong folder (for example your drive C or the script will try to run on all files on C. It should stop when it tries to open a file that SF cannot open) I added a MessageBox that asks you if you are sure you selected the correct folder.

You can open the Script Editor under the View menu. Just copy the script inside an run it. You can modify the values in the script if you want. Just ask if you have a question.

using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;

public class EntryPoint {
public void Begin(IScriptableApp app) {

    double dFadeSize = 0.003; //Change the length of the fade here. The value is the lenght is seconds. Example values: 2.0 or 1.5 or 0.75
    
    string folder = SfHelpers.ChooseDirectory("Choose a folder to process files from", @"C:\"); //The default folder is C:\, change it to something different if you want

    DialogResult dialogResult = MessageBox.Show("Are you sure to process " + folder + " and all its subfolders?", "WARNING", MessageBoxButtons.YesNo);
    
    if(dialogResult == DialogResult.Yes)
    {
        DirectoryInfo di = new DirectoryInfo(folder);
        
        foreach (FileInfo file in di.GetFiles("*", SearchOption.AllDirectories))
        {
           ISfFileHost openedFile = app.OpenFile(file.FullName, false, true);
        
           if(null == openedFile)
           {
               DPF("Could not open {0}", file.FullName);
               MessageBox.Show("Could not open " + file.FullName + "\n\nThe script will now stop.", "Error", MessageBoxButtons.OK);
               return;
           }
        
           Int64 ccFade = openedFile.SecondsToPosition(dFadeSize);

           bool fCancel = false;
           int idUndo = openedFile.BeginUndo("Fade in and out");

       //The script uses the 'Graphic Fade' effect with the presets '-6 dB exponential fade in' and '-6 dB exponential fade out'
           //You can change the script to a different effect and preset if you want. Just change the text between the " "-symbols

           openedFile.DoEffect("Graphic Fade", "-6 dB exponential fade in", new SfAudioSelection(0, ccFade), EffectOptions.EffectOnly);
           SfStatus result = openedFile.WaitForDoneOrCancel();
           if (result != SfStatus.Success)
              fCancel = true;
           else
           {
               openedFile.DoEffect("Graphic Fade", "-6 dB exponential fade out", new SfAudioSelection(openedFile.Length - ccFade, ccFade), EffectOptions.EffectOnly);
               result = openedFile.WaitForDoneOrCancel();
               if (result != SfStatus.Success)
                  fCancel = true;
           }

           openedFile.EndUndo(idUndo, fCancel);

           if(fCancel == true)
           {
               DPF("Could not process {0}", file.FullName);
               MessageBox.Show("Could not process " + file.FullName + "\n\nThe script will now stop.", "Error", MessageBoxButtons.OK);
               return;
           }

           openedFile.Save(SaveOptions.WaitForDoneOrCancel);

           openedFile.Close(CloseOptions.SaveChanges);

           File.Delete(Path.ChangeExtension(file.FullName, ".sfk")); //This command deletes all the sfk-files created by Sound Forge          
        
        }
    }

}

public void FromSoundForge(IScriptableApp app) {
   ForgeApp = app; //execution begins here
   app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
   Begin(app);
   app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, params object [] args) { ForgeApp.OutputText(String.Format(fmt, args)); }
} //EntryPoint

It should look like this if you copied it inside the script editor

Belibat ha scritto il 19.01.2022 ore 21:22

Thank you so much my friend!

this will be incredibly helpful!

i’m gonna try it in the next hours and let you know if have some questions.

again, thank you so much!

Belibat ha scritto il 19.01.2022 ore 21:38

Just one question before trying: can i change it to -8db (for example)?

 openedFile.DoEffect("Graphic Fade", "-8 dB exponential fade in", new SfAudioSelection(0, ccFade), EffectOptions.EffectOnly);

 

SP. ha scritto il 19.01.2022 ore 22:33

@Belibat This is the name of the preset in the Graphic Fader. You can create your own presets and use them in the script.

openedFile.DoEffect("Graphic Fade", "My Presetname here", new SfAudioSelection(0, ccFade), EffectOptions.EffectOnly);

Belibat ha scritto il 19.01.2022 ore 23:49

IT WORKS VERY WELL!! :D

Fantastic! I don't know how to thank you.
That's really awesome!

Belibat ha scritto il 20.01.2022 ore 10:42

Hello my friend!
Yesterday i tested the script on a test folder, made of 6 whitenoise wav files and it worked.
Today i tried to perform the action on an actual folder of files i need to fade in/out.
It gives an error (see screenshot).
The folder i'm trying to process is placed in the same directory as the test folder i processed yesterday and has the same permissions. It contains only wav files (divided in subfolders).
I also tried to process the individual subfolders (which contain just the wav files) getting the same error.
This error appears after the warning message where i should choose the folder and saying Yes to the question "Are you sure...".

Do you know what could be the reason for this?
The only things that comes to my mind is that maybe there too many files in this folder (1.77 Gb)..

Any help would be very much appreciated :)
Thanks a lot!

 

Belibat ha scritto il 20.01.2022 ore 12:17

Update: i tried removing some files from the folder to process, keeping just a few of them (like 10 or less) but i still get the same error. If i change the folder path to the test folder i used yesterday the script works without problems

Belibat ha scritto il 20.01.2022 ore 12:39

Update 2: if i move the files from their folder to the folder i used yesterday for the test, the script works. So the problem should be in the folder i added today (the folder containing the actual files to process). I can used yesterday's folder as a buffer folder, just to process files and then move them back, no problem. just wondering what could be causing the issue on today's folder..

SP. ha scritto il 20.01.2022 ore 15:17

@Belibat There is a file called .DS_Store in your folder. This is not an audio file and Sound Forge cannot open it. If you cannot see this file, it is likely hidden.

https://support.microsoft.com/en-us/windows/view-hidden-files-and-folders-in-windows-97fbc472-c603-9d90-91d0-1166d1d9f4b5#WindowsVersion=Windows_10

Belibat ha scritto il 20.01.2022 ore 15:54

Oh i see, it was an hidden file added on the mac where i created the folder.. Thank you again! :)