Ejemplo n.º 1
0
        private static unsafe void SoundCallbackPlaying(IntPtr hwi, uint uMsg, SoundWrapper dwInstance, uint dwParam1, uint dwParam2)
        {
            if (uMsg == WOM_DONE)
            {
                WAVEHDR *bufptr = (WAVEHDR *)dwParam1;

                short[] data = new short[dwInstance.bufferLengthBytes / 2];
                dwInstance.OnNewDataRequested(data);

                Marshal.Copy(data, 0, bufptr->lpData, (int)(dwInstance.bufferLengthBytes / 2));

                if (!dwInstance.finishing)
                {
                    uint retval, retval2, retval3;

                    lock (dwInstance.locker)
                    {
                        retval  = waveOutUnprepareHeader(dwInstance.waveHandle, ref *bufptr, 32);
                        retval2 = waveOutPrepareHeader(dwInstance.waveHandle, ref *bufptr, 32);
                        retval3 = waveOutWrite(dwInstance.waveHandle, ref *bufptr, 32);
                    }

                    if (retval != 0 || retval2 != 0 || retval3 != 0)
                    {
                        System.Windows.Forms.MessageBox.Show(string.Format("error in WOM_DATA: {0} {1} {2}\n", retval, retval2, retval3));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static unsafe void SoundCallbackRecording(IntPtr hwi, uint uMsg, SoundWrapper dwInstance, uint dwParam1, uint dwParam2)
        {
            if (uMsg == WIM_DATA)
            {
                WAVEHDR *bufptr = (WAVEHDR *)dwParam1;

                short[] data = new short[dwInstance.bufferLengthBytes / 2];
                Marshal.Copy(bufptr->lpData, data, 0, (int)(bufptr->dwBytesRecorded / 2));

                if (!dwInstance.finishing)
                {
                    uint retval, retval2, retval3;

                    lock (dwInstance.locker)
                    {
                        retval  = waveInUnprepareHeader(dwInstance.waveHandle, ref *bufptr, 32);
                        retval2 = waveInPrepareHeader(dwInstance.waveHandle, ref *bufptr, 32);
                        retval3 = waveInAddBuffer(dwInstance.waveHandle, ref *bufptr, 32);
                    }

                    if (retval != 0 || retval2 != 0 || retval3 != 0)
                    {
                        System.Windows.Forms.MessageBox.Show(string.Format("error in WIM_DATA: {0} {1} {2}\n", retval, retval2, retval3));
                    }
                }

                dwInstance.OnNewDataPresent(data);
            }
        }
Ejemplo n.º 3
0
 private static extern uint waveOutOpen(ref IntPtr phwi, uint deviceID, ref WAVEFORMATEX wfx, SoundCallbackDelegate dwCallback, SoundWrapper dwInstance, uint dwFlags);