Ejemplo n.º 1
0
 virtual public void LoadFromStream(Stream st)
 {
     while (true)
     {
         MMChunk ck = MMChunk.FromStream(st);
         if (ck == null)
         {
             break;
         }
         m_chunkList.Add(ck);
     }
 }
Ejemplo n.º 2
0
 virtual public void LoadFromStream(Stream st)
 {
     m_posStart = st.Position - 4;
     byte[] data = new byte[4];
     st.Read(data, 0, 4);
     m_nSize = BitConverter.ToInt32(data, 0);
     while (st.Position - m_posStart != m_nSize + 8)
     {
         MMChunk ck = MMChunk.FromStream(st);
         if (ck == null)
         {
             break;
         }
         m_chunkList.Add(ck);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Plays waveform contained in the given stream. Stream is exepcted to contain full riff header
        /// </summary>
        /// <param name="playStream">Stream with the waveform</param>
        public void Play(Stream playStream)
        {
            if (m_playing)
            {
                return;
            }


            MMChunk ck = MMChunk.FromStream(playStream);

            if (ck != null && ck.FourCC == FourCC.Riff)
            {
                if (ck[0] is WaveChunk)
                {
                    DataChunk dck = ck[0].FindChunk(FourCC.Data) as DataChunk;
                    if (dck != null)
                    {
                        playStream = dck.BeginRead();
                    }
                    FmtChunk fck = ck[0].FindChunk(FourCC.Fmt) as FmtChunk;
                    if (fck != null)
                    {
                        m_format = fck.WaveFormat;
                    }
                }
            }
            if (playStream == null)
            {
                throw new Exception("No valid WAV file has been opened");
            }

#if !NDOC
            if (m_qBuffers == null)
            {
                m_qBuffers = new Queue(MaxBuffers);
            }
            if (m_HandleMap == null)
            {
                m_HandleMap = new Hashtable(MaxBuffers);
            }

            // create a window to catch waveOutxxx messages
            SoundMessageWindow mw = new SoundMessageWindow();

            // wire in events
            mw.WaveOpenMessage  += new WaveOpenHandler(mw_WaveOpenMessage);
            mw.WaveCloseMessage += new WaveCloseHandler(mw_WaveCloseMessage);
            mw.WaveDoneMessage  += new WaveDoneHandler(mw_WaveDoneMessage);

            // add it to the global array
            int i = m_mwArray.Add(mw);
            m_streamArray.Add(playStream);

            // open the waveOut device and register the callback
            CheckWaveError(Wave.waveOutOpen(out m_hWaveOut, m_deviceID, m_format, ((SoundMessageWindow)m_mwArray[i]).Hwnd, 0, CALLBACK_WINDOW));

            RefillPlayBuffers();

            Monitor.Enter(m_qBuffers.SyncRoot);
            WaveHeader hdr = m_qBuffers.Dequeue() as WaveHeader;
            Monitor.Exit(m_qBuffers.SyncRoot);

            // play the file
            int ret = Wave.waveOutWrite(m_hWaveOut, hdr.Header, hdr.HeaderLength);
            CheckWaveError(ret);

            m_playing = true;
#endif
        }