예제 #1
0
        static void Main(string[] args)
        {
            SampleRateConverter converter = new SampleRateConverter(@"D:\Documents\visual studio 2015\Projects\EditorAudioConverter\EditorAudioConverter\wavs\");

            //converter.convertHighSample("16k.wav");
            //converter.convertHighSample("44k.wav");

            converter.convertLowSample("16k.wav");
            converter.convertLowSample("44k.wav");

            converter.replaceWavFiles();

            Console.ReadLine();
        }
예제 #2
0
        private void ExportLowFuncToCall(object context)
        {
            //Open file save dialog and save csv file
            Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
            dialog.Filter = "CSV|*.csv";

            if (dialog.ShowDialog() == true)
            {
                List <CSVInstanceObject> testObjects = CSVModel.populateInstanceObjects();
                List <CSVInstanceObject> reducedSampleRateObjects = SampleRateConverter.ConvertSampleRate(testObjects);
                var csv = CreateCSVFromList.CreateCSV(reducedSampleRateObjects);
                File.WriteAllText(dialog.FileName, csv.ToString());
            }
        }
예제 #3
0
        private void ExportGraphFuncToCall(object context)
        {
            //write CSV files locally in order to export them to excell
            string fullFilepath    = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Data\\100Hz.csv");
            string sampledFilepath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Data\\10Hz.csv");

            List <CSVInstanceObject> testObjects = CSVModel.populateInstanceObjects();
            var csvFull = CreateCSVFromList.CreateCSV(testObjects);

            File.WriteAllText(fullFilepath, csvFull.ToString());


            List <CSVInstanceObject> reducedSampleRateObjects = SampleRateConverter.ConvertSampleRate(testObjects);
            var shortCsv = CreateCSVFromList.CreateCSV(reducedSampleRateObjects);

            File.WriteAllText(sampledFilepath, shortCsv.ToString());

            AddExcelGraph.exportGraph(sampledFilepath, fullFilepath, reducedSampleRateObjects.Count, testObjects.Count);
        }
예제 #4
0
        static void Main(string[] args)
        {
            // Demo configuration
            double seconds    = 10;
            double inputRate  = 44100;
            double outputRate = 96000;
            double frequency  = 440.0; // Hz

            // Create a raw sine wave signal as source
            float[] sourceData = new float[(int)(inputRate * seconds)];
            for (int i = 0; i < sourceData.Length; i++)
            {
                sourceData[i] = (float)Math.Sin((2 * Math.PI) / inputRate * i * frequency);
            }

            // Create and configure resampler
            var src = new SampleRateConverter(ConverterType.SRC_SINC_MEDIUM_QUALITY, 1);

            src.SetRatio(outputRate / inputRate);

            // Setup variables for the resampling stream processing logic
            int inputSampleCount;
            int outputSampleCount;
            int totalInputSampleCount  = 0;
            int totalOutputSampleCount = 0;

            float[] inputBuffer           = new float[1000];
            int     inputBufferFillLevel  = 0;
            int     inputBufferReadOffset = 0;

            float[] outputBuffer = new float[1000];

            /*
             * Do the resampling block by block until all data has been read and no more data comes out
             *
             * The following block simulates a stream processing approach, where an inputBuffer is filled
             * from a source stream (here the sourceData array) block by block, and each block gets resampled
             * to an outputBuffer, until all the end of the stream has been reached and all buffered samples
             * have been output.
             */
            do
            {
                bool endOfInput = totalInputSampleCount == sourceData.Length;

                if (inputBufferFillLevel == 0)
                {
                    // Refill input buffer
                    inputBufferFillLevel  = Math.Min(1000, sourceData.Length - totalInputSampleCount);
                    inputBufferReadOffset = 0;
                    Array.Copy(sourceData, totalInputSampleCount, inputBuffer, 0, inputBufferFillLevel);
                }

                src.Process(inputBuffer, inputBufferReadOffset, inputBufferFillLevel,
                            outputBuffer, 0, outputBuffer.Length,
                            endOfInput, out inputSampleCount, out outputSampleCount);

                inputBufferReadOffset += inputSampleCount;
                inputBufferFillLevel  -= inputSampleCount;

                totalInputSampleCount  += inputSampleCount;
                totalOutputSampleCount += outputSampleCount;
            }while (inputSampleCount > 0 || outputSampleCount > 0);

            // Print result
            Console.WriteLine("{0} samples resampled to {1} samples (expected {2})",
                              totalInputSampleCount, totalOutputSampleCount,
                              sourceData.Length / inputRate * outputRate);
        }