Пример #1
0
 public WaveWriter(Stream Output, WaveFormat Format)
     : base(Output, Format)
 {
     if ( !OutStream.CanSeek )
     {
         throw new ArgumentException("The stream must supports seeking if AudioDataSize is not supported", "Output");
     }
     OutStream.Seek(WaveHeaderSize+8, SeekOrigin.Current);
 }
Пример #2
0
 public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc)
 {
     m_DoneProc = doneProc;
     WaveInHelper.Try(WaveNative.waveInOpen(out m_WaveIn, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION));
     AllocateBuffers(bufferSize, bufferCount);
     for (int i = 0; i < bufferCount; i++)
     {
         SelectNextBuffer();
         m_CurrentBuffer.Record();
     }
     WaveInHelper.Try(WaveNative.waveInStart(m_WaveIn));
     m_Thread = new Thread(new ThreadStart(ThreadProc));
     m_Thread.Start();
 }
Пример #3
0
 public static extern int waveOutOpen(out IntPtr hWaveOut, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
Пример #4
0
        private void ReadHeader()
        {
            BinaryReader Reader = new BinaryReader(m_Stream);
                if (ReadChunk(Reader) != "RIFF")
                    throw new Exception("Invalid file format");

                Reader.ReadInt32(); // File length minus first 8 bytes of RIFF description, we don't use it

                if (ReadChunk(Reader) != "WAVE")
                    throw new Exception("Invalid file format");

                if (ReadChunk(Reader) != "fmt ")
                    throw new Exception("Invalid file format");

                int FormatLength = Reader.ReadInt32();
                if ( FormatLength < 16) // bad format chunk length
                    throw new Exception("Invalid file format");

                m_Format = new WaveFormat(22050, 16, 2); // initialize to any format
                m_Format.wFormatTag = Reader.ReadInt16();
                m_Format.nChannels = Reader.ReadInt16();
                m_Format.nSamplesPerSec = Reader.ReadInt32();
                m_Format.nAvgBytesPerSec = Reader.ReadInt32();
                m_Format.nBlockAlign = Reader.ReadInt16();
                m_Format.wBitsPerSample = Reader.ReadInt16();
                if ( FormatLength > 16)
                {
                    m_Stream.Position += (FormatLength-16);
                }
                // assume the data chunk is aligned
                while(m_Stream.Position < m_Stream.Length && ReadChunk(Reader) != "data")
                    ;

                if (m_Stream.Position >= m_Stream.Length)
                    throw new Exception("Invalid file format");

                m_Length = Reader.ReadInt32();
                m_DataPos = m_Stream.Position;

                Position = 0;
        }
Пример #5
0
 public WaveWriter(Stream Output, WaveFormat Format, uint AudioDataSize)
     : base(Output, Format)
 {
     m_AudioDataSize = AudioDataSize;
     WriteWaveHeader();
 }
Пример #6
0
 public AudioWriter(Stream Output, WaveFormat InputDataFormat)
     : base(Output, System.Text.Encoding.ASCII)
 {
     m_InputDataFormat = InputDataFormat;
 }