// Creating the Stream Input from MemoryStream private WaveStream CreateInputStream(MemoryStream memStream, soundFILETypes typ) { WaveStream Reader = CreateReaderStream(memStream, typ); if (Reader == null) { throw new InvalidOperationException("Unsupported extension"); } // class is created. WaveChannel32 attached to the stream to control the execution _volumeStream = new WaveChannel32(Reader); return(_volumeStream); }
// Creation of the stream reading stream based on passed soundFILETypes private WaveStream CreateReaderStream(MemoryStream memStream, soundFILETypes typ) { WaveStream readerStream = null; if (typ == soundFILETypes.WAVE) { readerStream = new WaveFileReader(memStream); if (readerStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm && readerStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) { readerStream = WaveFormatConversionStream.CreatePcmStream(readerStream); readerStream = new BlockAlignReductionStream(readerStream); } } else if (typ == soundFILETypes.MP3) { readerStream = new WaveFileReader(memStream); } else if (typ == soundFILETypes.AIFF) { readerStream = new WaveFileReader(memStream); } return(readerStream); }
// Creation of the stream reading stream based on passed soundFILETypes private WaveStream CreateReaderStream(MemoryStream memStream, soundFILETypes typ) { WaveStream readerStream = null; if (typ == soundFILETypes.WAVE) { readerStream = new WaveFileReader(memStream); if (readerStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm && readerStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) { readerStream = WaveFormatConversionStream.CreatePcmStream(readerStream); readerStream = new BlockAlignReductionStream(readerStream); } } else if (typ == soundFILETypes.MP3) { readerStream = new WaveFileReader(memStream); } else if (typ == soundFILETypes.AIFF) { readerStream = new WaveFileReader(memStream); } return readerStream; }
public VoiceThroughNetAudio(MemoryStream memStream, string typAsString, Guid outputDevice) { m_memStream = memStream; soundFILETypes typ = soundFILETypes.WAVE; if (typAsString.ToUpper() == "MP3") { typ = soundFILETypes.MP3; } if (typAsString.ToUpper() == "WAV") { typ = soundFILETypes.WAVE; } if (typAsString.ToUpper() == "AIFF") { typ = soundFILETypes.AIFF; } // Creating the interface class //_waveOutDevice = new WaveOut(); if (outputDevice == Guid.Empty) { _waveOutDevice = new DirectSoundOut(100); } else { LastAudioDevice = outputDevice; _waveOutDevice = new DirectSoundOut(outputDevice, 100); } try { // creation of Stream input from the given file _mainOutputStream = CreateInputStream(memStream, typ); if (_mainOutputStream == null) { throw new InvalidOperationException("Unsupported file extension"); } } catch (Exception createException) { if (Error != null) { Error("Audio - Play - CreateInputStream", createException.Message, createException.StackTrace); } return; } try { //Initialization _waveOutDevice.Init(_mainOutputStream); } catch (Exception initException) { if (Error != null) { Error("Audio - Play - Init", initException.Message, initException.StackTrace); } return; } // The event will stop execution -- hooked to that of class NAudio _waveOutDevice.PlaybackStopped += new EventHandler <StoppedEventArgs>(_waveOutDevice_PlaybackStopped); return; }
// Creating the Stream Input from MemoryStream private WaveStream CreateInputStream(MemoryStream memStream, soundFILETypes typ) { WaveStream Reader = CreateReaderStream(memStream, typ); if (Reader == null) { throw new InvalidOperationException("Unsupported extension"); } // class is created. WaveChannel32 attached to the stream to control the execution _volumeStream = new WaveChannel32(Reader); return _volumeStream; }