コード例 #1
0
ファイル: Form1.cs プロジェクト: LottAustin/WaveAnalyzer
        /*
         * play
         *
         * Function uses win32 to play the audio imported/recored by the progam
         *
         * Parameter:
         *      RecordDialog.AudioPlayBackDeleagate waveOut
         *
         * return void
         */
        private void play(RecordDialog.AudioPlayBackDelegate waveOut)
        {
            handle = new IntPtr();

            WAVEFORMAT format;

            format.wFormatTag      = (ushort)wave.fmtCode;
            format.nChannels       = (ushort)wave.channels;
            format.nSamplesPerSec  = (ushort)wave.sampleRate;
            format.wBitsPerSample  = (ushort)wave.bitDepth;
            format.nBlockAlign     = (ushort)wave.fmtBlockAlign;
            format.nAvgBytesPerSec = (ushort)wave.fmtAvgBPS;
            format.cbSize          = 0;
            int i = -1;

            i = waveOutOpen(ref handle, 4294967295, ref format, Marshal.GetFunctionPointerForDelegate(waveOut), 0, RecordDialog.CALLBACK_FUNCTION);
            if (i != 0)
            {
                this.Text = "Error: waveOutOpen";
                return;
            }

            i = waveOutPrepareHeader(handle, ref pWaveHdr, Convert.ToUInt32(Marshal.SizeOf(pWaveHdr)));
            if (i != 0)
            {
                return;
            }

            int ii = waveOutWrite(handle, ref pWaveHdr, Convert.ToUInt32(Marshal.SizeOf(pWaveHdr)));

            if (ii != 0)
            {
                return;
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: LottAustin/WaveAnalyzer
        /*
         * PlayBtn_Click
         *
         * Listener for the Play button on the main interface
         *
         * Parameter:
         *      sender
         *      e
         *
         * return void
         */
        private void PlayBtn_Click(object sender, EventArgs e)
        {
            // C# code for play back in the main form

            /*byte[] tmp;
             *
             * if(player == null)
             * {
             *  if(wave == null)
             *  {
             *      return;
             *  }
             *
             *  wave.rebuildWav(left);
             *  tmp =  wave.playWav();
             *
             *  if(tmp != null)
             *  {
             *      using (System.IO.MemoryStream ms = new System.IO.MemoryStream(tmp))
             *      {
             *          player = new System.Media.SoundPlayer(ms);
             *          player.Play();
             *      }
             *  }
             * } else
             * {
             *  wave.rebuildWav(left);
             *  tmp = wave.playWav();
             *
             *  if (tmp != null)
             *  {
             *      using (System.IO.MemoryStream ms = new System.IO.MemoryStream(tmp))
             *      {
             *          player = new System.Media.SoundPlayer(ms);
             *          player.Play();
             *      }
             *  }
             * }*/

            // win32 code for playback in the main form
            if (wave != null)
            {
                wave.rebuildWav(left, right);
                waveOut = this.callbackWaveOut;
                play(waveOut);
            }
        }