Exemplo n.º 1
0
        static void Main(string[] args)
        {
            WaveReader read = new WaveReader("bleed.wav");

            Console.Write("Reading samples...");
            read.ReadSamples();
            Console.WriteLine("OK");
            read.Close();
            Console.Write("Processing...");
            List <AudioData> Channels_In  = new List <AudioData>();
            List <AudioData> Channels_Out = new List <AudioData>();

            List <List <Spectrum> > Spectrums = new List <List <Spectrum> >();

            for (int channel = 0; channel < read.Channels; channel++)
            {
                Channels_In.Add(new AudioData());
                Channels_Out.Add(new AudioData());
                Channels_In[channel].Add(read.Samples[channel]);
                Spectrums.Add(new List <Spectrum>());
            }

            int sections = Convert.ToInt32(Math.Ceiling((decimal)(read.SamplesCount / Constants.FFT_SIZE)));

            for (int section = 0; section < sections; section++)
            {
                int start = section * Constants.FFT_SIZE;
                for (int channel = 0; channel < Channels_In.Count; channel++)
                {
                    Complex[] data = Channels_In[channel].Grab(start, Constants.FFT_SIZE).ToArray();
                    Transform.FourierForward(data);
                    Spectrums[channel].Add(new Spectrum(data));
                }
            }

            for (int spectrum = 0; spectrum < Spectrums[0].Count; spectrum++)
            {
                if (spectrum > 4 * 1024 * 1024 / Constants.FFT_SIZE)
                {
                    break;                                           // out of memory..
                }
                for (int channel = 0; channel < Channels_Out.Count; channel++)
                {
                    Complex[] data = Spectrums[channel][spectrum].ExportArray();
                    Transform.FourierInverse(data);
                    Channels_Out[channel].Add(data);
                }
            }

            // EXPORT
            List <List <int> > Samples = new List <List <int> >();

            for (int channel = 0; channel < Channels_Out.Count; channel++)
            {
                Samples.Add(Channels_Out[channel].ExportInt());
            }
            Console.WriteLine("OK");



            Console.WriteLine("Waiting for file access..");
            while (true)
            {
                try
                {
                    BinaryWriter w = new BinaryWriter(new FileStream("sample2wr.wav", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite));
                    w.Close();
                    break;
                }
                catch (Exception)
                {
                }
                System.Threading.Thread.Sleep(100);
            }
            Console.WriteLine("OK");

            WaveWriter write = new WaveWriter("sample2wr.wav", 2, 16, 44100);

            Console.Write("Writing samples...");
            write.WriteSamples(Samples);
            Console.WriteLine("OK");

            write.Close();


            Console.WriteLine("Done");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            WaveReader read = new WaveReader("bleed.wav");
            Console.Write("Reading samples...");
            read.ReadSamples();
            Console.WriteLine("OK");
            read.Close();
            Console.Write("Processing...");
            List<AudioData> Channels_In = new List<AudioData>();
            List<AudioData> Channels_Out = new List<AudioData>();

            List<List<Spectrum>> Spectrums = new List<List<Spectrum>>();
            for (int channel = 0; channel < read.Channels; channel++)
            {
                Channels_In.Add(new AudioData());
                Channels_Out.Add(new AudioData());
                Channels_In[channel].Add(read.Samples[channel]);
                Spectrums.Add(new List<Spectrum>());
            }

            int sections =Convert.ToInt32(Math.Ceiling((decimal)(read.SamplesCount/Constants.FFT_SIZE)));

            for (int section = 0; section < sections; section++)
            {
                int start = section*Constants.FFT_SIZE;
                for (int channel = 0; channel < Channels_In.Count; channel++)
                {
                    Complex[] data = Channels_In[channel].Grab(start, Constants.FFT_SIZE).ToArray();
                    Transform.FourierForward(data);
                    Spectrums[channel].Add(new Spectrum(data));
                }

            }

            for (int spectrum = 0; spectrum < Spectrums[0].Count; spectrum++)
            {
                if (spectrum > 4*1024*1024/Constants.FFT_SIZE) break;// out of memory..
                for(int channel =0 ; channel < Channels_Out.Count; channel++)
                {
                    Complex[] data = Spectrums[channel][spectrum].ExportArray();
                    Transform.FourierInverse(data);
                    Channels_Out[channel].Add(data);
                }
            }

            // EXPORT
            List<List<int>> Samples = new List<List<int>>();

            for(int channel = 0; channel < Channels_Out.Count; channel++)
            {
                Samples.Add(Channels_Out[channel].ExportInt());
            }
            Console.WriteLine("OK");

            Console.WriteLine("Waiting for file access..");
            while(true)
            {
                try
                {
                    BinaryWriter w= new BinaryWriter(new FileStream("sample2wr.wav", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite));
                    w.Close();
                    break;
                }
                catch(Exception)
                {
                }
                System.Threading.Thread.Sleep(100);

            }
            Console.WriteLine("OK");

            WaveWriter write = new WaveWriter("sample2wr.wav", 2, 16, 44100);

            Console.Write("Writing samples...");
            write.WriteSamples(Samples);
            Console.WriteLine("OK");

            write.Close();

            Console.WriteLine("Done");
            Console.ReadKey();
        }