Beispiel #1
0
 public WaveOutPlayer(int device, WaveFormat format, int bufferSize, int bufferCount, BufferFillEventHandler fillProc)
 {
     m_zero = format.wBitsPerSample == 8 ? (byte)128 : (byte)0;
     m_FillProc = fillProc;
     WaveOutHelper.Try(WaveNative.waveOutOpen(out m_WaveOut, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION));
     AllocateBuffers(bufferSize, bufferCount);
     m_Thread = new Thread(new ThreadStart(ThreadProc));
     m_Thread.Start();
 }
Beispiel #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();
 }
Beispiel #3
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 len = Reader.ReadInt32();
            if (len < 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();

            // advance in the stream to skip the wave format block
            len -= 16; // minimum format size
            while (len > 0)
            {
                Reader.ReadByte();
                len--;
            }

            // 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;
        }
Beispiel #4
0
        public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount)
        {
          SaveBufSize = bufferSize;
            SaveBufCount = bufferCount;
            WaveInFormat = format;

            //* 
           WaveInHelper.Try(WINMM_DLL.waveInOpen(out m_WaveIn, device, format, m_BufferProc, 0, WINMM_DLL.CALLBACK_FUNCTION));
           AllocateBuffers(bufferSize, bufferCount);
           for (int i = 0; i < bufferCount; i++)
           {
               SelectNextBuffer();
               m_CurrentBuffer.Record();
           }
           WaveInHelper.Try(WINMM_DLL.waveInStart(m_WaveIn));
           m_Thread = new Thread(new ThreadStart(ThreadProc));
           m_Thread.Start();//*/
        }
Beispiel #5
0
 private void OnWaveRecorded(IntPtr ptrData, int iSize, WaveFormat format)
 {
     VoiceCapturedEventArgs e = new VoiceCapturedEventArgs();// {Date = DateTime.Now, Format = format};
     e.Source = new byte[iSize];
     Marshal.Copy(ptrData, e.Source, 0, iSize);
     if (WaveRecorded!=null) //Igor 08.31
     WaveRecorded(this,e);
 }
 private void Start()
 {
     Stop();
     try
     {
         WaveFormat fmt = new WaveFormat(44100, 16, 2);
         m_Player = new WaveOutPlayer(-1, fmt, 16384, 3, new BufferFillEventHandler(Filler));
         m_Recorder = new WaveInRecorder(-1, fmt, 16384, 3, new BufferDoneEventHandler(Voice_Out));
     }
     catch
     {
         Stop();
         throw;
     }
 }
Beispiel #7
0
        public WaveOutPlayer(WavInDevice device, WaveFormat format, int bufferSize, int bufferCount)
        {
            SaveBufSize = bufferSize;
            SaveBufCount = bufferCount;
            WaveOutHelper.Try(WINMM_DLL.waveOutOpen(out m_WaveOut, device.Index, format, m_BufferProc, 0, WINMM_DLL.CALLBACK_FUNCTION));
            WaveOutFormat = format;
            AllocateBuffers(bufferSize, bufferCount);

            m_Thread = new Thread(new ThreadStart(ThreadProc));
            m_Thread.Start();
        }
 public static extern int waveOutOpen(out IntPtr hWaveOut, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
Beispiel #9
0
        private void InitCall()
        {
            ShowStatus("연결 완료");
            SetBtn(1);
            //원격 연결점 생성
            targetDataIP = tempIP;
            targetVoiceIP = new IPEndPoint(tempIP.Address, 2000);

            WaveFormat fmt = new WaveFormat(44100, 16, 2);
            wavePlayer = new WaveOutPlayer(-1, fmt, 16384, 3, new BufferFillEventHandler(Filler));
            waveRecorder = new WaveInRecorder(-1, fmt, 16384, 3, new BufferDoneEventHandler(Voice_Out));
            //음성 비동기 수신 대기
            udpVoice.BeginReceive(new AsyncCallback(ReceiveVoiceCallback), udpVoice);
        }
Beispiel #10
0
 public static extern int waveOutOpen(out IntPtr hWaveOut, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);