Beispiel #1
0
        /// <summary>
        /// Starts processing of given text file(s) selected in inputTextBox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void processButtonClicked(object sender, EventArgs e)
        {
            StartLoading();
            var tuningChosen = GetNumTuning(chooseTuningBox.SelectedItem.ToString());

            if (tuningChosen > 0)
            {
                NoteDetector.TransposeUp(tuningChosen);
            }
            else
            {
                NoteDetector.TransposeDown(-tuningChosen);
            }

            var threadCount = CalculateThreadCount(inputSampleTextBox.Text);

            if (threadCount == 1)
            {
                //cutting away .wav and adding _notes.ly
                new MainProcessor().ProcessSoundFile(inputSampleTextBox.Text.Trim(';'), inputSampleTextBox.Text.Trim(';').Substring(0, inputSampleTextBox.Text.Length - 4) + "_notes.ly", this);
            }
            else
            {
                FillQueue(inputSampleTextBox.Text);
                var sideThreads = CreateThreads(threadCount);
                Array.ForEach(sideThreads, thread => thread.Start());
                new MainProcessor().ProcessSoundFiles(this);
                Array.ForEach(sideThreads, thread => thread.Join());
            }
            Done();
        }
Beispiel #2
0
        public static bool operator <=(Note note1, Note note2)
        {
            var noteDet = new NoteDetector();

            if (note1.GetType() == typeof(Pause) && note2.GetType() == typeof(Pause))
            {
                return(true);
            }
            return(note2.number > note1.number || ((note2.number == note1.number) && noteDet.noteTypes.IndexOf(note2.GetType()) >= noteDet.noteTypes.IndexOf(note1.GetType())));
        }
Beispiel #3
0
        public override int GetHashCode()
        {
            var noteDet = new NoteDetector();

            if (this is Pause)
            {
                return(0);
            }
            return(noteDet.noteTypes.IndexOf(this.GetType()) * 100 + number + 1);
        }
Beispiel #4
0
        public int CompareTo(Note note)
        {
            if (this == note)
            {
                return(0);
            }
            var noteDet = new NoteDetector();

            if (this.number > note.number || ((this.number == note.number) && noteDet.noteTypes.IndexOf(this.GetType()) > noteDet.noteTypes.IndexOf(note.GetType())))
            {
                return(1);
            }
            return(-1);
        }
Beispiel #5
0
        /// <summary>
        /// Main method for processing the whole music sample
        /// </summary>
        /// <param name="inputFilePath"></param>
        /// <param name="outputFileName"></param>
        /// <param name="form"></param>
        public void ProcessSoundFile(string inputFilePath, string outputFileName, SoundVisualizer form)
        {
            if (form.filesToProcess != null)
            {
                Monitor.Exit(form.filesToProcess);
            }
            #region processing header
            BinaryReader      headerStream = new BinaryReader(File.Open(inputFilePath, FileMode.Open));
            ISoundReader      soundReader  = new WavSoundReader();
            ProcessedMetaData metaData     = soundReader.ReadHeader(headerStream);
            SampleSize      = metaData.channelsCount * metaData.bitDepth / 8;
            sampleArraySize = (ChunkSize / SampleSize) + 1;
            headerStream.Close();
            #endregion

            #region skipping header
            FileStream dataStream = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read);
            dataStream.Seek(metaData.headerSize, SeekOrigin.Begin);
            #endregion

            #region processing data
            Complex[] complexSamples         = new Complex[sampleArraySize];
            Complex[] extendedComplexSamples = new Complex[2 * sampleArraySize - 2];

            IWindowFunction window      = new HannWindowFunction();
            byte[]          byteValues  = soundReader.ReadDataBuffer(dataStream, ChunkSize + SampleSize);
            MusicSample     musicSample = new MusicSample(metaData, inputFilePath);
            musicSample.Notes = new List <Note>();

            while (dataStream.Position < dataStream.Length - ChunkSize)
            {
                complexSamples = ToComplexSamples(metaData.channelsCount == 1 ? byteValues : ExtractByteChannel(byteValues, isEven: true), metaData.bitDepth, metaData.channelsCount);
                INoiseDetector noiseDetector = new RMSNoiseDetector(2 << (metaData.bitDepth - 1));
                if (noiseDetector.IsNoise(complexSamples))
                {
                    Note detectedNote = new Pause();
                    musicSample.Notes.Add(detectedNote);
                }
                else
                {
                    extendedComplexSamples = ExtendSamples(complexSamples);
                    window.Windowify(extendedComplexSamples);
                    extendedComplexSamples = extendedComplexSamples.MakeFFT().MakeHPS(HPSIterationsCount);
                    MaxFreqBin   maxFreqBin   = GetMaxFreqBin(extendedComplexSamples);
                    double       maxFreq      = CalculateMaxFreq(maxFreqBin.BinNumber, metaData, sampleArraySize);
                    NoteDetector noteDetector = new NoteDetector();
                    Note         detectedNote = noteDetector.GetClosestNote(maxFreq / 2);
                    musicSample.Notes.Add(detectedNote);
                }
                soundReader.MoveDataBuffer(dataStream, window.OverlapSize, byteValues);
            }
            IErrorCorrector corrector = new OverlapWindowCorrector();
            corrector.Correct(musicSample);

            INoteLengthProcessor noteLengthProcessor = new DefaultNoteLengthProcessor();
            noteLengthProcessor.ProcessSample(musicSample);

            StreamWriter writer2    = new StreamWriter(outputFileName);
            INoteWriter  noteWriter = new LillyPondNoteWriter();
            noteWriter.WriteAll(musicSample, writer2);
            #endregion
        }
Beispiel #6
0
        public static bool operator >(Note note1, Note note2)
        {
            var noteDet = new NoteDetector();

            return(note1 >= note2 && note1 != note2);
        }
Beispiel #7
0
        public static bool operator >=(Note note1, Note note2)
        {
            var noteDet = new NoteDetector();

            return(note1 == note2 || !(note1 <= note2));
        }