Sound Forge Scripting -

rory-w wrote on 4/24/2024, 6:03 AM

Hi could anyone help me with the following script..

I want to select the first and last 6 frames of audio of any audio file and mute it.

 

 

 

using System;
using SoundForge;

namespace SoundForgeScript
{
    public class ScriptMain
    {
        public static void EntryPoint(IScriptableApp app)
        {
            // Get the active audio file
            var activeFile = app.CurrentFile;

            if (activeFile == null || !activeFile.IsAudio)
            {
                app.SetStatusText("No audio file is open.");
                return;
            }

            // Get audio data
            var audioData = activeFile.GetAudioData();

            // Get frame rate
            var frameRate = audioData.SampleRate / audioData.Channels;

            // Mute the first 6 frames
            MuteFrames(audioData, 0, 6 * frameRate);

            // Mute the last 6 frames
            MuteFrames(audioData, audioData.Length - 6 * frameRate, audioData.Length);

            // Save changes
            activeFile.Save();
        }

        private static void MuteFrames(AudioData audioData, long startFrame, long endFrame)
        {
            // Get audio data as a byte array
            var audioBytes = audioData.GetBytes(startFrame, endFrame);

            // Mute audio by setting all bytes to 0
            for (int i = 0; i < audioBytes.Length; i++)
            {
                audioBytes[i] = 0;
            }

            // Set the modified audio data
            audioData.SetBytes(startFrame, audioBytes);
        }
    }
}

 

 

 

Thanks

Comments

No comments yet - be the first to write a comment...