private void InitWaveOut(EVLVoiceFormat format) { if (mWaveOut != null) { Stop(); } WaveFormat waveFormat; switch (format) { case EVLVoiceFormat.MT_MSGSM: waveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 16000, 2, 16); break; case EVLVoiceFormat.MT_MP3_32K_STEREO: waveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 2, 32000, 4, 16); break; default: Debug("Format not support"); return; } mWaveOut = new WaveOut(); mBufferedWaveProvider = new BufferedWaveProvider(waveFormat); mWaveOut.Init(mBufferedWaveProvider); }
private void PrepareWrite(EVLVoiceFormat format) { SubDebug(string.Format("Call PrepareWrite,voice format:{0}.", format)); if (mIsSrcWriteFile || mIsPcmWriteFile) { mWriter.PrepareWrite(format, mIsSrcWriteFile, mIsPcmWriteFile, mWaveDir); } }
private void PrepareConvert(EVLVoiceFormat format) { SubDebug(string.Format("Call PrepareConvert,voice format:{0}.", format)); if (mIsDecodeData) { mConvertor.PrepareConvert(format); } }
private void PreparePlay(EVLVoiceFormat format) { SubDebug(string.Format("Call PreparePlay,voice format:{0}.", format)); if (mIsPlayWave) { mPlayer.Init(format, mVolume); mPlayer.Play(); } }
public void Init(EVLVoiceFormat format, float volume) { SubDebug(string.Format("Call NMonPlayer init,wave format:{0}", format)); if (mWaveOut != null) { mWaveOut.Stop(); mWaveOut.Dispose(); } try { mWaveOut = new WaveOut(); mFormat = format; switch (mFormat) { case EVLVoiceFormat.MT_MSGSM: mPcmWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 16000, 2, 16); break; case EVLVoiceFormat.MT_MP3_32K_STEREO: mPcmWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 2, 32000, 4, 16); break; default: SubDebug(string.Format("Format not support,source wave format:{0}", mFormat)); return; } mBufferedWaveProvider = new BufferedWaveProvider(mPcmWaveFormat); mBufferedWaveProvider.DiscardOnBufferOverflow = true; mWaveOut.Init(mBufferedWaveProvider); if (volume >= 0 && volume <= 1) { mWaveOut.Volume = volume; } else if (volume >= 2 && volume <= 3) { volume = volume - 2; mWaveOut.LeftVolume = volume; } else if (volume >= 4 && volume <= 5) { volume = volume - 4; mWaveOut.RightVolume = volume; } else { SubDebug(string.Format("Volume invalid")); mWaveOut.Volume = 1; } SubDebug(string.Format("WaveOut initialed,\tPlay wave format:{0}", mPcmWaveFormat)); } catch (Exception ex) { SubDebug(string.Format("Wave out init fail.\t{0}", ex.Message)); } }
void Core_HeadReceived(object user, SNM_RESPONSE head) { SubDebug(string.Format("[VLNMon4Net]\t{0}\tVoice head received,voice format:{1}\tchannel:{2}", user, (EVLVoiceFormat)head.format, head.channel)); //to set audio format EVLVoiceFormat format = (EVLVoiceFormat)head.format; Dispatcher.Invoke(new Action(() => { if (RbDiretX.IsChecked == true) { mUseDxPlayer = true; IntPtr intPtr = (new WindowInteropHelper(this)).Handle; mDxPlayer = new DirectXPlayer(intPtr); mDxPlayer.Debug += I_DXPlayer_Debug; //I_DXPlayer.Prepare(format); SubDebug(string.Format("Use DirectX player")); } else { mUseDxPlayer = false; } if (RbVLNMon.IsChecked == true) { mUseVLNMonPlayer = true; mVLNMonCores[(string)user].IsPlayWave = true; SubDebug(string.Format("Use VLNMon player")); } else { mUseVLNMonPlayer = false; mVLNMonCores[(string)user].IsPlayWave = false; } if (RbNAudio.IsChecked == true) { mUseNAudioPlayer = true; mNAudioPlayer = new NAudioPlayer(); mNAudioPlayer.Debug += I_NAudioPlayer_Debug; mNAudioPlayer.Prepare(format); SubDebug(string.Format("Use NAudio player")); } else { mUseNAudioPlayer = false; } //if ((string)user == "VLNMon1") //{ // if (I_VLNMonCores["VLNMon0"] != null) // { // I_VLNMonCores["VLNMon0"].ReceiveHead(head); // } //} })); }
public void PrepareWrite(EVLVoiceFormat format, bool isSrcWriteFile, bool isPcmWriteFile, string wavePath) { SubDebug(string.Format("Call PrepareWrite,source wave format:{0}", format)); Stop(); mFormat = format; switch (mFormat) { case EVLVoiceFormat.MT_MSGSM: mSrcWaveFormat = new Gsm610WaveFormat(); break; case EVLVoiceFormat.MT_MP3_32K_STEREO: mSrcWaveFormat = new Mp3WaveFormat(8000, 2, 288, 32000); break; default: SubDebug(string.Format("Format not support,source wave format:{0}", format)); return; } if (mSrcWaveFormat.Channels == 2) { mPcmWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 2, 32000, 4, 16); //mPcmWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 16000, 2, 16); } else { mPcmWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 16000, 2, 16); } if (!Path.IsPathRooted(wavePath)) { wavePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, wavePath); } if (!Directory.Exists(wavePath)) { Directory.CreateDirectory(wavePath); } string srcPath, pcmPath; srcPath = Path.Combine(wavePath, "Src_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav"); pcmPath = Path.Combine(wavePath, "Pcm_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav"); if (isSrcWriteFile) { mSrcWriter = new WaveFileWriter(srcPath, mSrcWaveFormat); } if (isPcmWriteFile) { mPcmWriter = new WaveFileWriter(pcmPath, mPcmWaveFormat); } SubDebug(string.Format("Writer prepared,source wave format:{0},dest wave format:{1}", mSrcWaveFormat, mPcmWaveFormat)); }
public void PrepareConvert(EVLVoiceFormat format) { SubDebug(string.Format("Call PrepareConvert,source wave format:{0}", format)); Stop(); try { mFormat = format; switch (mFormat) { case EVLVoiceFormat.MT_MSGSM: mSrcWaveFormat = new Gsm610WaveFormat(); break; case EVLVoiceFormat.MT_MP3_32K_STEREO: mSrcWaveFormat = new Mp3WaveFormat(8000, 2, 288, 32000); break; default: SubDebug(string.Format("Format not support,source wave format:{0}", mFormat)); return; } if (mSrcWaveFormat.Channels == 2) { mPcmWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 2, 32000, 4, 16); } else { mPcmWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 16000, 2, 16); } mBufferedStream = new BufferedWaveStream(mSrcWaveFormat); mConvStream = new WaveFormatConversionStream(mPcmWaveFormat, mBufferedStream); SubDebug(string.Format("Convertor prepared,source wave format:{0},dest wave format:{1}", mSrcWaveFormat, mPcmWaveFormat)); } catch (Exception ex) { SubDebug(string.Format("PrepareConvert fail.\t{0}", ex.Message)); } }
public void Prepare(EVLVoiceFormat format) { InitWaveOut(format); Play(); }