コード例 #1
0
        public static void WaveOutCallback(IntPtr hdrvr, int uMsg, int dwUser, ref WaveHeader wavhdr, int dwParam2)
        {
            if (uMsg == (int)WaveFormOutputMessage.Done)
            {
                GCHandle      handle = (GCHandle)wavhdr.UserData;
                WaveOutBuffer buffer = (WaveOutBuffer)handle.Target;

                if (buffer._Player.IsPlaying)
                {
                    buffer.NextBuffer.Play();

#if DEBUG
                    System.Diagnostics.Debug.WriteLine(string.Format("FillBuffer start at {0} ticks.", DateTime.Now.Ticks));
#endif

                    buffer._Player.FillBuffer(buffer);

#if DEBUG
                    System.Diagnostics.Debug.WriteLine(string.Format("FillBuffer end   at {0} ticks.", DateTime.Now.Ticks));
#endif
                    buffer._IsEmpty = false;
                    buffer._HasData.Set();
                }
                else
                {
                    buffer._Player.SignalDone();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates and prepares a WaveOutBuffer.
        /// </summary>
        /// <param name="device">Handle to WaveOut device to prepare the buffer for</param>
        /// <param name="size">Size of the buffer, in bytes</param>
        public WaveOutBuffer(WavePlayer player, IntPtr device, int size)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            _Player = player;

            if (device == IntPtr.Zero)
            {
                throw new ArgumentException("Device must be a a valid pointer to a wave out device.", "device");
            }

            if (size < 1)
            {
                throw new ArgumentOutOfRangeException("size", size, "Size must be greater than zero.");
            }

            _Length       = size;
            _DeviceHandle = device;

            // Allocate memory for the buffer, and set up a GCHandle pointed to it.
            byte[] buffer = new byte[Length];
            _DataHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            // Create the header and a GC handle pointed to it.
            _Header       = new WaveHeader();
            _HeaderHandle = GCHandle.Alloc(_Header, GCHandleType.Pinned);

            _Header.Data         = this.Data;
            _Header.BufferLength = Length;

            _Header.UserData = (IntPtr)GCHandle.Alloc(this);
            _Header.Loops    = 0;
            _Header.Flags    = 0;

            int result = WaveFormNative.waveOutPrepareHeader(_DeviceHandle,
                                                             ref _Header, Marshal.SizeOf(_Header));

            if (result != WaveError.MMSYSERR_NOERROR)
            {
                throw new SoundCoreException(WaveError.GetMessage(result), result);
            }
        }
コード例 #3
0
ファイル: WaveFormNative.cs プロジェクト: nernst/synth
 public static extern int waveOutWrite(IntPtr device, ref WaveHeader header, int size);
コード例 #4
0
ファイル: WaveFormNative.cs プロジェクト: nernst/synth
 public static extern int waveOutUnprepareHeader(IntPtr device, ref WaveHeader header, int size);
コード例 #5
0
        /// <summary>
        /// Callback that receives signal when completed
        /// </summary>
        /// <param name="audioDevice">Device that signaled the event</param>
        /// <param name="message">Message passed back to us.</param>
        /// <param name="instance">Not used</param>
        /// <param name="header">Header that is being signalled</param>
        /// <param name="reserved">Not used</param>
        internal static void WaveOutProcCallback(IntPtr audioDevice, int message, int instance, ref WaveHeader header, int reserved)
        {
            // Make sure that we're signalled done
            if (message == (int)WaveFormOutputMessage.Done)
            {
                // Get IntPtr to WaveOutBuffer
                GCHandle handle = (GCHandle)header.UserData;

                // Get buffer
                WaveOutBuffer buffer = (WaveOutBuffer)handle.Target;

                // Signal completed to buffer
                buffer.OnCompleted(EventArgs.Empty);
            }
        }