Esempio n. 1
0
        public DigitalAudio ReadAudio()
        {
            int[][]      channels = null;
            DigitalAudio audio    = new DigitalAudio();

            audio.SampleRate = format.SampleRate;
            audio.SignificantBitsPerSample = format.SignificantBitsPerSample;
            channels = ReadPCMData();
            for (uint i = 0; i < format.NumberOfChannels; i++)
            {
                audio.AddChannel(channels[i]);
            }
            return(audio);
        }
Esempio n. 2
0
        public void WriteWavDefault(DigitalAudio audio)
        {
            WaveFormat format = new WaveFormat();

            format.SectionSize              = 16;
            format.NumberOfChannels         = audio.NumOfChannels;
            format.CompressionCode          = 1;
            format.SampleRate               = audio.SampleRate;
            format.SignificantBitsPerSample = audio.SignificantBitsPerSample;
            format.BlockAlign               = (ushort)((format.SignificantBitsPerSample * format.NumberOfChannels) / 8);
            format.AvarageBytesPerSecond    = format.SampleRate * format.BlockAlign;
            var  dataSize  = audio.DataSize * (audio.SignificantBitsPerSample / 8);
            uint data_Size = (uint)((dataSize % 2 == 0) ? dataSize : dataSize + 1);
            uint RIFF_Size =
                +4  /*RIFF Type = 'WAVE'*/
                + 8 /*fmt  section*/
                + format.SectionSize
                + 8 /*data  section*/
                + data_Size;

            BaseStream.SetLength(RIFF_Size + 8);// + 8 RIFF section
            Write(ID_RIFF);
            Write(RIFF_Size);
            Write(ID_WAVE);
            Write(ID_fmt_);
            Write(format.SectionSize);
            Write(format.CompressionCode);
            Write(format.NumberOfChannels);
            Write(format.SampleRate);
            Write(format.AvarageBytesPerSecond);
            Write(format.BlockAlign);
            Write(format.SignificantBitsPerSample);

            Write(ID_data);
            Write(data_Size);
            int[][] channels = audio.GetAllSignals();
            for (int i = 0; i < audio.SamplesInChannel; i++)
            {
                for (int j = 0; j < audio.NumOfChannels; j++)
                {
                    Write((short)channels[j][i]);
                }
            }
        }