Exemplo n.º 1
0
        /// <summary>
        /// Detect BPM rate of <paramref name="inFile"/> and adjust tempo
        /// setting accordingly if necessary.
        /// </summary>
        private static void DetectBpm(WavInFile inFile, RunParameters parameters)
        {
            var bpm = BpmDetect <TSampleType, TLongSampleType> .NewInstance(inFile.GetNumChannels(), inFile.GetSampleRate());

            var sampleBuffer = new TSampleType[BUFF_SIZE];

            // detect bpm rate
            Console.Error.Write("Detecting BPM rate...");
            Console.Error.Flush();

            int nChannels = inFile.GetNumChannels();

            Debug.Assert(BUFF_SIZE % nChannels == 0);

            // Process the 'inFile' in small blocks, repeat until whole file has
            // been processed
            while (inFile.Eof() == false)
            {
                // Read sample data from input file
                int num = inFile.Read(sampleBuffer, BUFF_SIZE);

                // Enter the new samples to the bpm analyzer class
                int samples = num / nChannels;
                bpm.InputSamples(sampleBuffer, samples);
            }

            // Now the whole song data has been analyzed. Read the resulting bpm.
            float bpmValue = bpm.GetBpm();

            Console.Error.WriteLine("Done!");

            // rewind the file after bpm detection
            inFile.Rewind();

            if (bpmValue > 0)
            {
                Console.Error.WriteLine("Detected BPM rate {0:0.0}\n", bpmValue);
            }
            else
            {
                Console.Error.WriteLine("Couldn't detect BPM rate.\n");
                return;
            }

            if (parameters.GoalBpm > 0)
            {
                // adjust tempo to given bpm
                parameters.TempoDelta = (parameters.GoalBpm / bpmValue - 1.0f) * 100.0f;
                Console.Error.WriteLine("The file will be converted to {0:0.0} BPM\n", parameters.GoalBpm);
            }
        }
Exemplo n.º 2
0
        public static int Start(string[] args, float tempoChange, bool keepPitch)
        {
            WavInFile  inFile;
            WavOutFile outFile;
            var        soundTouch = new SoundTouch <TSampleType, TLongSampleType>();

            Console.Error.WriteLine(string.Format(string.Concat(HELLOTEXT), SoundTouch <TSampleType, TLongSampleType> .VersionString));

            try
            {
                // Parse command line parameters
                var parameters = new RunParameters(args, tempoChange, keepPitch);

                // Open input & output files
                OpenFiles(out inFile, out outFile, parameters);

                if (parameters.DetectBpm)
                {
                    // detect sound BPM (and adjust processing parameters
                    //  accordingly if necessary)
                    DetectBpm(inFile, parameters);
                }

                // Setup the 'SoundTouch' object for processing the sound
                Setup(soundTouch, inFile, parameters);

                // Process the sound
                Process(soundTouch, inFile, outFile);

                if (inFile != null)
                {
                    inFile.Dispose();
                }
                if (outFile != null)
                {
                    outFile.Dispose();
                }

                Console.Error.WriteLine("Done!");
                Console.ReadKey();
            }
            catch (Exception e)
            {
                // An exception occurred during processing, display an error message
                Console.Error.WriteLine(e.Message);
                return(-1);
            }

            return(0);
        }
Exemplo n.º 3
0
        private static void OpenFiles(out WavInFile inFile, out WavOutFile outFile, RunParameters parameters)
        {
            inFile = parameters.InFileName == "stdin" ? new WavInFile(Console.OpenStandardInput()) : new WavInFile(parameters.InFileName);

            // ... open output file with same sound parameters
            int bits       = (inFile).GetNumBits();
            int samplerate = (inFile).GetSampleRate();
            int channels   = (inFile).GetNumChannels();

            if (parameters.OutFileName != null)
            {
                outFile = parameters.OutFileName == "stdout" ? new WavOutFile(Console.OpenStandardOutput(), samplerate, bits, channels) : new WavOutFile(parameters.OutFileName, samplerate, bits, channels);
            }
            else
            {
                outFile = null;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the <c>SoundTouch</c> object up according to input file sound format & command line parameters
        /// </summary>
        private static void Setup(SoundTouch <TSampleType, TLongSampleType> pSoundTouch, WavInFile inFile, RunParameters parameters)
        {
            int sampleRate = inFile.GetSampleRate();
            int channels   = inFile.GetNumChannels();

            pSoundTouch.SetSampleRate(sampleRate);
            pSoundTouch.SetChannels(channels);

            pSoundTouch.SetTempoChange(parameters.TempoDelta);
            pSoundTouch.SetPitchSemiTones(parameters.PitchDelta);
            pSoundTouch.SetRateChange(parameters.RateDelta);

            pSoundTouch.SetSetting(SettingId.UseQuickseek, parameters.Quick);
            pSoundTouch.SetSetting(SettingId.UseAntiAliasFilter, (parameters.NoAntiAlias == 1) ? 0 : 1);

            if (parameters.Speech)
            {
                // use settings for speech processing
                pSoundTouch.SetSetting(SettingId.SequenceDurationMs, 40);
                pSoundTouch.SetSetting(SettingId.SeekwindowDurationMs, 15);
                pSoundTouch.SetSetting(SettingId.OverlapDurationMs, 8);
                Console.Error.WriteLine("Tune processing parameters for speech processing.");
            }

            // print processing information
            if (parameters.OutFileName != null)
            {
#if SOUNDTOUCH_INTEGER_SAMPLES
                Console.Error.WriteLine("Uses 16bit integer sample type in processing.\n");
#else
#if !SOUNDTOUCH_FLOAT_SAMPLES
    #error "Sampletype not defined"
#endif
                Console.Error.WriteLine("Uses 32bit floating point sample type in processing.\n");
#endif
                // print processing information only if outFileName given i.e. some processing will happen
                Console.Error.WriteLine("Processing the file with the following changes:");
                Console.Error.WriteLine("  tempo change = {0:0.00} %", parameters.TempoDelta);
                Console.Error.WriteLine("  pitch change = {0} semitones", parameters.PitchDelta);
                Console.Error.WriteLine("  rate change  = {0:0.00} %\n", parameters.RateDelta);
                Console.Error.Write("Working...");
            }
            else
            {
                // outFileName not given
                Console.Error.WriteLine("Warning: output file name missing, won't output anything.\n");
            }
            Console.Error.Flush();
        }