Ejemplo n.º 1
0
        protected virtual void Callback(IntPtr handle, WaveMsg msg, UIntPtr user, WaveHeader header, UIntPtr reserved)
        {
            if (_hWaveOut != handle)
            {
                return; //message does not belong to this waveout instance
            }
            if (msg == WaveMsg.WOM_DONE)
            {
                GCHandle      hBuffer = (GCHandle)header.userData;
                WaveOutBuffer buffer  = hBuffer.Target as WaveOutBuffer;
                System.Threading.Interlocked.Decrement(ref _activeBuffers);

                if (buffer == null)
                {
                    return;
                }
                if (_playbackState != SoundOut.PlaybackState.Stopped)
                {
                    lock (_lockObj)
                    {
                        if (buffer.WriteData())
                        {
                            System.Threading.Interlocked.Increment(ref _activeBuffers);
                        }
                    }
                }

                if (_activeBuffers == 0)
                {
                    _playbackState = SoundOut.PlaybackState.Stopped;
                    RaiseStopped();
                }
            }
            else if (msg == WaveMsg.WOM_CLOSE)
            {
                var state = _playbackState;
                _playbackState = SoundOut.PlaybackState.Stopped;
                if (state != SoundOut.PlaybackState.Stopped)
                {
                    RaiseStopped();
                }
                Debug.WriteLine("WaveOut::Callback: Closing WaveOut.");
            }
        }
Ejemplo n.º 2
0
    /// <summary>
    /// ������Ʈ���ı�
    /// </summary>
    /// <param name="msg"></param>
    public void ShowWaveText(string msg, float time = 10f)
    {
        WaveMsg waveMsg = new WaveMsg()
        {
            m_msg = msg, m_time = time
        };

        m_waveTextQueue.Enqueue(waveMsg);

        DoShowWaveText();
        ////����һ���ı�������Ʈ
        //AssetCacheMgr.GetUIInstance("MsgBoxWave.prefab", (str, id, obj) =>
        //{
        //    GameObject go = obj as GameObject;
        //    Mogo.Util.Utils.MountToSomeObjWithoutPosChange(go.transform, transform);
        //    //WaveMsg waveMsg = go.GetComponent<WaveMsg>();
        //    WaveMsg waveMsg = go.AddComponent<WaveMsg>();
        //    waveMsg.Show(msg, time, transform.FindChild("MsgBoxWavePosEnd").position,
        //        transform.FindChild("MsgBoxWavePosFrom").position, () => { AssetCacheMgr.ReleaseInstance(go); });

        //});
    }
Ejemplo n.º 3
0
    private void DoShowWaveText()
    {
        if (m_isShowingWaveText || m_waveTextQueue.Count <= 0)
        {
            return;
        }
        m_isShowingWaveText = true;
        if (!m_waveMsg.gameObject.activeSelf)
        {
            m_waveMsg.SetActive(true);
        }
        WaveMsg waveMsg = m_waveTextQueue.Dequeue() as WaveMsg;
        string  msg     = waveMsg.m_msg;
        float   t       = waveMsg.m_time;

        m_waveMsgLbl.text             = msg;
        m_waveMsgTweenPostion.enabled = true;
        m_waveMsgTweenPostion.Reset();

        m_waveMsgTweenPostion.from     = new Vector3(Mogo.Game.UIConfig.WIDTH / 2, 0, 0);
        m_waveMsgTweenPostion.to       = new Vector3(-Mogo.Game.UIConfig.WIDTH / 2 - m_waveMsgLbl.relativeSize.x * m_waveMsgLbl.transform.localScale.x, 0, 0);
        m_waveMsgTweenPostion.duration = t;

        m_waveMsgTweenPostion.onFinished = (uiTween) =>
        {
            m_isShowingWaveText = false;
            if (m_waveTextQueue.Count <= 0)
            {
                m_waveMsg.SetActive(false);
            }
            else
            {
                DoShowWaveText();
            }
        };
    }
Ejemplo n.º 4
0
 protected virtual void Callback(IntPtr handle, WaveMsg msg, UIntPtr user, WaveHeader header, UIntPtr reserved)
 {
     if (msg == WaveMsg.WIM_DATA)
     {
         if (!stopped)
         {
             var buffer = ((GCHandle)header.userData).Target as WaveInBuffer;
             RaiseDataAvailable(buffer);
             try
             {
                 buffer.Reset();
             }
             catch (MmException)
             {
                 stopped = true;
                 RaiseStopped();
             }
         }
     }
     else if (msg == WaveMsg.WIM_CLOSE)
     {
         RaiseStopped();
     }
 }
Ejemplo n.º 5
0
        private void Callback(IntPtr handle, WaveMsg msg, IntPtr user, WaveHeader header, IntPtr reserved)
        {
            Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + "|" + msg);
            if (_waveInHandle != handle)
                return;

            if (msg == WaveMsg.WIM_DATA)
            {
                if (_callbackThread == null)
                    _callbackThread = Thread.CurrentThread;

                //Debug.Assert(_callbackThread == Thread.CurrentThread, "Strange thread?");
                if(_callbackThread != Thread.CurrentThread)
                    Debugger.Break();

                var index = (int) header.userData;
                WaveInBuffer buffer = _buffers[index];

                Interlocked.Decrement(ref _activeBuffers);

                if (Monitor.TryEnter(_lockObj, 10))
                {
                    try
                    {
                        callback0:
                        //only add buffer to queue again, if we are still recording
                        if (buffer != null && RecordingState != RecordingState.Stopped)
                        {
                            try
                            {
                                //todo: should we care about recordingstate when firing dataavailable?
                                RaiseDataAvailable(buffer);
                                FireUpBuffer(buffer);
                            }
                            catch (Exception exception)
                            {
                                StopFromCallback(exception);
                            }
                        }

                        if (_failedBuffers.Count > 0)
                        {
                            while (_failedBuffers.Count > 0
                                   && (buffer = _buffers[(index = _failedBuffers.Dequeue())]).IsInQueue == false)
                            {
                                Debug.WriteLine("Already queued.");
                            }
                            if (buffer != null && !buffer.IsInQueue)
                            {
                                Debug.WriteLine("Failed buffer: " + index);
                                goto callback0;
                            }
                        }
                    }
                    finally
                    {
                        Monitor.Exit(_lockObj);
                    }
                }
                else
                {
                    _failedBuffers.Enqueue(index);
                }

                if (_activeBuffers <= 0)
                    StopFromCallback(null);

                _callbackThread = null;
            }
            else if (msg == WaveMsg.WIM_CLOSE)
            {
                if (RecordingState != RecordingState.Stopped)
                    StopFromCallback(null);
            }
        }
Ejemplo n.º 6
0
        protected virtual void Callback(IntPtr handle, WaveMsg msg, UIntPtr user, WaveHeader header, UIntPtr reserved)
        {
            if (_hWaveOut != handle)
                return; //message does not belong to this waveout instance
            if (msg == WaveMsg.WOM_DONE)
            {
                GCHandle hBuffer = (GCHandle)header.userData;
                WaveOutBuffer buffer = hBuffer.Target as WaveOutBuffer;
                System.Threading.Interlocked.Decrement(ref _activeBuffers);

                if (buffer == null) return;
                if (_playbackState != SoundOut.PlaybackState.Stopped)
                {
                    lock (_lockObj)
                    {
                        if (buffer.WriteData())
                            System.Threading.Interlocked.Increment(ref _activeBuffers);
                    }
                }

                if (_activeBuffers == 0)
                {
                    _playbackState = SoundOut.PlaybackState.Stopped;
                    RaiseStopped();
                }
            }
            else if (msg == WaveMsg.WOM_CLOSE)
            {
                var state = _playbackState;
                _playbackState = SoundOut.PlaybackState.Stopped;
                if (state != SoundOut.PlaybackState.Stopped)
                    RaiseStopped();
                Debug.WriteLine("WaveOut::Callback: Closing WaveOut.");
            }
        }
Ejemplo n.º 7
0
        private void Callback(IntPtr handle, WaveMsg msg, IntPtr user, WaveHeader header, IntPtr reserved)
        {
            Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + "|" + msg);
            if (_waveInHandle != handle)
            {
                return;
            }

            if (msg == WaveMsg.WIM_DATA)
            {
                if (_callbackThread == null)
                {
                    _callbackThread = Thread.CurrentThread;
                }

                //Debug.Assert(_callbackThread == Thread.CurrentThread, "Strange thread?");
                if (_callbackThread != Thread.CurrentThread)
                {
                    Debugger.Break();
                }

                var          index  = (int)header.userData;
                WaveInBuffer buffer = _buffers[index];

                Interlocked.Decrement(ref _activeBuffers);

                if (Monitor.TryEnter(_lockObj, 10))
                {
                    try
                    {
callback0:
                        //only add buffer to queue again, if we are still recording
                        if (buffer != null && RecordingState != RecordingState.Stopped)
                        {
                            try
                            {
                                //todo: should we care about recordingstate when firing dataavailable?
                                RaiseDataAvailable(buffer);
                                FireUpBuffer(buffer);
                            }
                            catch (Exception exception)
                            {
                                StopFromCallback(exception);
                            }
                        }

                        if (_failedBuffers.Count > 0)
                        {
                            while (_failedBuffers.Count > 0 &&
                                   (buffer = _buffers[(index = _failedBuffers.Dequeue())]).IsInQueue == false)
                            {
                                Debug.WriteLine("Already queued.");
                            }
                            if (buffer != null && !buffer.IsInQueue)
                            {
                                Debug.WriteLine("Failed buffer: " + index);
                                goto callback0;
                            }
                        }
                    }
                    finally
                    {
                        Monitor.Exit(_lockObj);
                    }
                }
                else
                {
                    _failedBuffers.Enqueue(index);
                }

                if (_activeBuffers <= 0)
                {
                    StopFromCallback(null);
                }

                _callbackThread = null;
            }
            else if (msg == WaveMsg.WIM_CLOSE)
            {
                if (RecordingState != RecordingState.Stopped)
                {
                    StopFromCallback(null);
                }
            }
        }
Ejemplo n.º 8
0
        private void Callback(IntPtr handle, WaveMsg msg, IntPtr user, WaveHeader header, IntPtr reserved)
        {
            Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + "|" + msg);

            if (_waveOutHandle != handle)
            {
                return;
            }

            if (msg == WaveMsg.WOM_DONE)
            {
                if (_callbackThread == null)
                {
                    _callbackThread = Thread.CurrentThread;
                    Debug.WriteLine("CallbackThread: " + Thread.CurrentThread.ManagedThreadId);
                }

                Debug.Assert(_callbackThread == Thread.CurrentThread, "Strange thread?");
                var           index  = (int)header.userData;
                WaveOutBuffer buffer = _buffers[index];

                Interlocked.Decrement(ref _activeBuffers);

                /*
                 * The Play method starts all buffers.
                 * In order to do that, it calls the waveOutWrite function.
                 * If there is a delay between buffer0 and buffer1
                 * and buffer0 gets fired through this callback, the
                 * waveOutWrite method for buffer1 can't be called
                 * -> deadlock since the callback method waits until the
                 * Play method releases the lock.
                 * In order to avoid that, we are using a timeout of 10ms.
                 * If the timeout exceeds, the index of the buffer gets
                 * saved and fired within the next callback.
                 *
                 */
                if (Monitor.TryEnter(_lockObject, 10))
                {
                    try
                    {
callback0:
                        if (buffer != null && PlaybackState != PlaybackState.Stopped)
                        {
                            try
                            {
                                FireUpBuffer(buffer);
                            }
                            catch (Exception exception)
                            {
                                StopFromCallback(exception);
                            }
                        }

                        if (_failedBuffers.Count > 0)
                        {
                            //continue until we find a buffer that failed and is not in queue.
                            while (_failedBuffers.Count > 0 &&
                                   (buffer = _buffers[(index = _failedBuffers.Dequeue())]).IsQueued == false)
                            {
                                Debug.WriteLine("Already queued:" + index);
                            }
                            if (buffer != null && !buffer.IsQueued)
                            {
                                Debug.WriteLine("Failed buffer: " + index);
                                goto callback0;
                            }
                        }
                    }
                    finally
                    {
                        Monitor.Exit(_lockObject);
                    }
                }
                else
                {
                    _failedBuffers.Enqueue(index);
                }

                if (_activeBuffers <= 0)
                {
                    StopFromCallback(null);
                }
            }
            else if (msg == WaveMsg.WOM_CLOSE)
            {
                if (PlaybackState != PlaybackState.Stopped)
                {
                    StopFromCallback(null);
                }
            }
            else if (msg == WaveMsg.WOM_OPEN)
            {
                Debug.WriteLine("open");
            }
        }
Ejemplo n.º 9
0
        private void Callback(IntPtr handle, WaveMsg msg, IntPtr user, WaveHeader header, IntPtr reserved)
        {
            Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + "|" + msg);

            if (_waveOutHandle != handle)
                return;

            if (msg == WaveMsg.WOM_DONE)
            {
                if (_callbackThread == null)
                {
                    _callbackThread = Thread.CurrentThread;
                    Debug.WriteLine("CallbackThread: " + Thread.CurrentThread.ManagedThreadId);
                }

                Debug.Assert(_callbackThread == Thread.CurrentThread, "Strange thread?");
                var index = (int) header.userData;
                WaveOutBuffer buffer = _buffers[index];

                Interlocked.Decrement(ref _activeBuffers);

                /*
                 * The Play method starts all buffers.
                 * In order to do that, it calls the waveOutWrite function.
                 * If there is a delay between buffer0 and buffer1
                 * and buffer0 gets fired through this callback, the
                 * waveOutWrite method for buffer1 can't be called
                 * -> deadlock since the callback method waits until the
                 * Play method releases the lock.
                 * In order to avoid that, we are using a timeout of 10ms.
                 * If the timeout exceeds, the index of the buffer gets
                 * saved and fired within the next callback.
                 *
                 */
                if (Monitor.TryEnter(_lockObject, 10))
                {
                    try
                    {
                        callback0:
                        if (buffer != null && PlaybackState != PlaybackState.Stopped)
                        {
                            try
                            {
                                FireUpBuffer(buffer);
                            }
                            catch (Exception exception)
                            {
                                StopFromCallback(exception);
                            }
                        }

                        if (_failedBuffers.Count > 0)
                        {
                            //continue until we find a buffer that failed and is not in queue.
                            while (_failedBuffers.Count > 0 &&
                                   (buffer = _buffers[(index = _failedBuffers.Dequeue())]).IsQueued == false)
                            {
                                Debug.WriteLine("Already queued:" + index);
                            }
                            if (buffer != null && !buffer.IsQueued)
                            {
                                Debug.WriteLine("Failed buffer: " + index);
                                goto callback0;
                            }
                        }
                    }
                    finally
                    {
                        Monitor.Exit(_lockObject);
                    }
                }
                else
                {
                    _failedBuffers.Enqueue(index);
                }

                if (_activeBuffers <= 0)
                    StopFromCallback(null);
            }
            else if (msg == WaveMsg.WOM_CLOSE)
            {
                if (PlaybackState != PlaybackState.Stopped)
                    StopFromCallback(null);
            }
            else if (msg == WaveMsg.WOM_OPEN)
                Debug.WriteLine("open");
        }
Ejemplo n.º 10
0
    /// <summary>
    /// 从左到右飘的文本
    /// </summary>
    /// <param name="msg"></param>
    public void ShowWaveText(string msg, float time = 10f)
    {
        WaveMsg waveMsg = new WaveMsg() { m_msg = msg, m_time = time };
        m_waveTextQueue.Enqueue(waveMsg);

        DoShowWaveText();
        ////加载一个文本从左到右飘
        //AssetCacheMgr.GetUIInstance("MsgBoxWave.prefab", (str, id, obj) =>
        //{
        //    GameObject go = obj as GameObject;
        //    Mogo.Util.Utils.MountToSomeObjWithoutPosChange(go.transform, transform);
        //    //WaveMsg waveMsg = go.GetComponent<WaveMsg>();
        //    WaveMsg waveMsg = go.AddComponent<WaveMsg>();
        //    waveMsg.Show(msg, time, transform.FindChild("MsgBoxWavePosEnd").position,
        //        transform.FindChild("MsgBoxWavePosFrom").position, () => { AssetCacheMgr.ReleaseInstance(go); });

        //});
    }
Ejemplo n.º 11
0
 protected virtual void Callback(IntPtr handle, WaveMsg msg, UIntPtr user, WaveHeader header, UIntPtr reserved)
 {
     if (msg == WaveMsg.WIM_DATA)
     {
         if (!stopped)
         {
             var buffer = ((GCHandle)header.userData).Target as WaveInBuffer;
             RaiseDataAvailable(buffer);
             try
             {
                 buffer.Reset();
             }
             catch (MmException)
             {
                 stopped = true;
                 RaiseStopped();
             }
         }
     }
     else if (msg == WaveMsg.WIM_CLOSE)
     {
         RaiseStopped();
     }
 }