public AudioStreamHandler() { log = Logger.GetLogger(GetType()); WaveIn = new WasapiLoopbackCapture(); WaveIn.DataAvailable += DataAvailable; WaveIn.RecordingStopped += RecordingStopped; WaveOut = new WaveOut(); WaveOut.Init(new SilentWaveProvider()); }
private void playButton_Click(object sender, EventArgs e) { waveOut = new WaveOut(); waveOut.PlaybackStopped += waveOut_PlaybackStopped; reader = new WaveFileReader("sample.wav"); waveOut.Init(reader); waveOut.Play(); }
public IWavePlayer CreateDevice(int latency) { IWavePlayer device; WaveCallbackStrategy strategy = _waveOutSettingsPanel.CallbackStrategy; if (strategy == WaveCallbackStrategy.Event) { WaveOutEvent waveOut = new WaveOutEvent { DeviceNumber = _waveOutSettingsPanel.SelectedDeviceNumber, DesiredLatency = latency }; device = waveOut; } else { WaveCallbackInfo callbackInfo = strategy == WaveCallbackStrategy.NewWindow ? WaveCallbackInfo.NewWindow() : WaveCallbackInfo.FunctionCallback(); WaveOut outputDevice = new WaveOut(callbackInfo) { DeviceNumber = _waveOutSettingsPanel.SelectedDeviceNumber, DesiredLatency = latency }; device = outputDevice; } // TODO: configurable number of buffers return device; }
public GameMain() { // もとからあった初期化 InitializeComponent(); // セリフ用オブジェクト生成 pl = new NAudio.Wave.WaveOut(); // スプラッシュスクリーンの表示 SplashScreen ss = new SplashScreen(); ss.Show(); ss.Refresh(); Thread.Sleep(3200); ss.Close(); ss.Dispose(); // キャラクタ選択画面の表示 CharacterSelect cs = new CharacterSelect() { mm = this }; cs.ShowDialog(); cs.Dispose(); }
public void PlaySound(string name, Action done = null) { FileStream ms = File.OpenRead(_soundLibrary[name]); var rdr = new Mp3FileReader(ms); WaveStream wavStream = WaveFormatConversionStream.CreatePcmStream(rdr); var baStream = new BlockAlignReductionStream(wavStream); var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); waveOut.Init(baStream); waveOut.Play(); var bw = new BackgroundWorker(); bw.DoWork += (s, o) => { while (waveOut.PlaybackState == PlaybackState.Playing) { Thread.Sleep(100); } waveOut.Dispose(); baStream.Dispose(); wavStream.Dispose(); rdr.Dispose(); ms.Dispose(); if (done != null) done(); }; bw.RunWorkerAsync(); }
public void Stop() { try { udpSender.Close(); udpListener.Close(); if (waveout != null) { waveout.Stop(); waveout.Dispose(); waveout = null; } if (sourcestream != null) { sourcestream.StopRecording(); sourcestream.Dispose(); sourcestream = null; } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } }
public Form1() { _serialPort.PortName = "COM6"; _serialPort.BaudRate = 9600; _serialPort.Parity = Parity.None; _serialPort.DataBits = 8; _serialPort.StopBits = StopBits.Two; _serialPort.Handshake = Handshake.None; _serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived); _serialPort.Open(); //Set up audio outputs jaws[0] = new WaveOut(); jaws[1] = new WaveOut(); jaws[2] = new WaveOut(); var jawsAudio1 = new WaveChannel32(new WaveFileReader("Sounds/Jaws3.wav")); jaws[0].Init(jawsAudio1); var jawsAudio2 = new LoopStream(new WaveFileReader("Sounds/Jaws2.wav")); jaws[1].Init(jawsAudio2); var jawsAudio3 = new LoopStream(new WaveFileReader("Sounds/Jaws1.wav")); jaws[2].Init(jawsAudio3); //Set the shark to a random position resetShark(); InitializeComponent(); }
private void PlayAudioFromConnection(TcpClient client) { var inputStream = new BufferedStream(client.GetStream()); var bufferedWaveProvider = new BufferedWaveProvider(waveFormat); var savingWaveProvider = new SavingWaveProvider(bufferedWaveProvider, "temp.wav"); var player = new WaveOut(); player.Init(savingWaveProvider); player.Play(); while (client.Connected) { if (terminate) { client.Close(); break; } var available = client.Available; if (available > 0) { var buffer = new byte[available]; var bytes = inputStream.Read(buffer, 0, buffer.Length); bufferedWaveProvider.AddSamples(buffer, 0, bytes); Console.WriteLine("{0} \t {1} bytes", client.Client.RemoteEndPoint, bytes); } } player.Stop(); savingWaveProvider.Dispose(); }
//--------------------controls---------------------------------------- /// <summary> /// Starts to play a file /// </summary> public void play() { try { //Call a helper method (look in the botom) to reset the playback stop(); // open uncompresed strem pcm from mp3 file reader compresed stream. NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(this.songPath)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); volProvider = new VolumeWaveProvider16(stream); volProvider.Volume = vol; output = new NAudio.Wave.WaveOut();//new NAudio.Wave.DirectSoundOut(); output.PlaybackStopped += output_PlaybackStopped; output.Init(volProvider); output.Play(); checkPlayback(); } catch (Exception e) { Console.WriteLine(e.Message); } }
void StartEncoding() { _startTime = DateTime.Now; _bytesSent = 0; _segmentFrames = 960; _encoder = new OpusEncoder(48000, 1, OpusNet.OpusApplication.Voip); _encoder.Bitrate = 8192; _decoder = new OpusDecoder(48000, 1); _bytesPerSegment = _encoder.FrameByteCount(_segmentFrames); _waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback()); _waveIn.BufferMilliseconds = 50; _waveIn.DeviceNumber = comboBox1.SelectedIndex; _waveIn.DataAvailable += _waveIn_DataAvailable; _waveIn.WaveFormat = new WaveFormat(48000, 16, 1); _playBuffer = new BufferedWaveProvider(new WaveFormat(48000, 16, 1)); _waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); _waveOut.DeviceNumber = comboBox2.SelectedIndex; _waveOut.Init(_playBuffer); _waveOut.Play(); _waveIn.StartRecording(); if (_timer == null) { _timer = new Timer(); _timer.Interval = 1000; _timer.Tick += _timer_Tick; } _timer.Start(); }
public void Stop() { if (WaveOut != null) { WaveOut.Stop(); WaveOut.Dispose(); WaveOut = null; } if (WaveChannel != null) { WaveChannel.Dispose(); WaveChannel = null; } if (WaveFileReader != null) { WaveFileReader.Dispose(); WaveFileReader = null; } if (Mp3FileReader != null) { Mp3FileReader.Dispose(); Mp3FileReader = null; } }
public MainForm() { var start = DateTime.Now.Millisecond; InitializeComponent(); this.DoubleBuffered = true; _isPlay = false; listViewMusicCollection.View = View.Details; listViewMusicCollection.AllowColumnReorder = true; listViewMusicCollection.GridLines = false; //listViewMusicCollection.Columns.Add("№"); listViewMusicCollection.Columns.Add("File Name"); listViewMusicCollection.Columns.Add("Extension"); listViewMusicCollection.Columns.Add("asd"); listViewMusicCollection.Columns.Add("12423"); listViewMusicCollection.AllowDrop = true; listViewMusicCollection.DragDrop += listViewMusicCollection_DragDrop; listViewMusicCollection.DragEnter += listViewMusicCollection_DragEnter; _listViewLoadr = new ListViewLoader(listViewMusicCollection); _listViewLoadr.DirectoryPath = @"example\"; _listViewLoadr.GetItemToWrite = new ListViewLoader.GetItemDelegat( (fileInfo) => { return new object[]{fileInfo.Name, fileInfo.Extension}; }); _listViewLoadr.Load(); _mainMenuLoader = new MainMenuLoader(this.MainMenu); _mainMenuLoader.Load(); _waveOut = new WaveOut(); var tt = DateTime.Now.Millisecond - start; System.Diagnostics.Debug.WriteLine(tt); }
public AudioPlayer(DiscordVoiceConfig __config) { config = __config; callbackInfo = WaveCallbackInfo.FunctionCallback(); outputDevice = new WaveOut(callbackInfo); bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(48000, 16, config.Channels)); }
public APU() { this.audioBuffer = new AudioBuffer(); NESWaveProvider nesWaveProvider = new NESWaveProvider(audioBuffer); waveOut = new WaveOut(); waveOut.Init(nesWaveProvider); }
static void Main(string[] args) { // for recording waveFileWriter = new WaveFileWriter(@"C:\rec\out.wav", new WaveFormat(44100, 2)); var sound = new MySound(); sound.SetWaveFormat(44100, 2); sound.init(); waveOut = new WaveOut(); waveOut.Init(sound); waveOut.Play(); ConsoleKeyInfo keyInfo; bool loop = true; while (loop) { keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.Q) { waveOut.Stop(); waveOut.Dispose(); waveFileWriter.Close(); waveFileWriter.Dispose(); loop = false; } } }
public static Task Play(this Captcha captcha) { return Task.Run(() => { using (MemoryStream memory = new MemoryStream(captcha.Data, false)) { memory.Seek(0, SeekOrigin.Begin); using (Mp3FileReader reader = new Mp3FileReader(memory)) using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(reader)) using (WaveStream stream = new BlockAlignReductionStream(pcm)) { using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback())) { waveOut.Init(stream); waveOut.Play(); while (waveOut.PlaybackState == PlaybackState.Playing) { Thread.Sleep(100); } } } } }); }
private WaveFormat _waveFormat = new WaveFormat(8000, 16, 1); // The format that both the input and output audio streams will use, i.e. PCMU. #endregion Fields #region Constructors public AudioChannel() { // Set up the device that will play the audio from the RTP received from the remote end of the call. m_waveOut = new WaveOut(); m_waveProvider = new BufferedWaveProvider(_waveFormat); m_waveOut.Init(m_waveProvider); m_waveOut.Play(); // Set up the input device that will provide audio samples that can be encoded, packaged into RTP and sent to // the remote end of the call. m_waveInEvent = new WaveInEvent(); m_waveInEvent.BufferMilliseconds = 20; m_waveInEvent.NumberOfBuffers = 1; m_waveInEvent.DeviceNumber = 0; m_waveInEvent.DataAvailable += RTPChannelSampleAvailable; m_waveInEvent.WaveFormat = _waveFormat; // Create a UDP socket to use for sending and receiving RTP packets. int port = FreePort.FindNextAvailableUDPPort(DEFAULT_START_RTP_PORT); _rtpEndPoint = new IPEndPoint(_defaultLocalAddress, port); m_rtpChannel = new RTPChannel(_rtpEndPoint); m_rtpChannel.OnFrameReady += RTPChannelSampleReceived; _audioLogger.Debug("RTP channel endpoint " + _rtpEndPoint.ToString()); }
public SoundManager() { _musicMap = new Dictionary <string, NAudio.Vorbis.VorbisWaveReader>(); _soundMap = new Dictionary <string, NAudio.Vorbis.VorbisWaveReader>(); musicPlayer = new NAudio.Wave.WaveOut(); soundPlayer = new NAudio.Wave.WaveOut(); }
public TriggerPanel() { InitializeComponent(); mWaveOut = new WaveOut(); mWaveOut.PlaybackStopped += new EventHandler(mWaveOut_PlaybackStopped); AppController.Instance().AddPanel(this); }
public void Initialise(WaveFormat format, WaveOut driver) { if (driver == null) { throw new ArgumentNullException("driver", "Must specify a WaveIn device instance"); } if (format == null) { throw new ArgumentNullException("format", "Must specify an audio format"); } var caps = WaveOut.GetCapabilities(driver.DeviceNumber); device = new WaveOutDeviceData { Driver = driver, Name = caps.ProductName, Channels = caps.Channels, Buffers = new float[caps.Channels][] }; Format = WaveFormat.CreateIeeeFloatWaveFormat(format.SampleRate, caps.Channels); OutputBuffer = new BufferedWaveProvider(Format); OutputBuffer.DiscardOnBufferOverflow = true; driver.Init(OutputBuffer); mapOutputs(); }
private void Form1_Load(object sender, EventArgs e) { byte[] apk, ask, bpk, bsk; NaClClient.CreateKeys(out apk, out ask); NaClClient.CreateKeys(out bpk, out bsk); var hasher = System.Security.Cryptography.SHA256.Create(); _clientA = NaClClient.Create(apk, ask, bpk); _clientB = NaClClient.Create(bpk, bsk, apk); _sw = new Stopwatch(); _sw.Start(); _wave = new WaveIn(this.Handle); _wave.WaveFormat = new WaveFormat(12000, 8, 1); _wave.BufferMilliseconds = 100; _wave.DataAvailable += _wave_DataAvailable; _wave.StartRecording(); _playback = new BufferedWaveProvider(_wave.WaveFormat); _waveOut = new WaveOut(); _waveOut.DesiredLatency = 100; _waveOut.Init(_playback); _waveOut.Play(); }
public void Start() { if (WaveIn.DeviceCount < 1) throw new Exception("Insufficient input device(s)!"); if (WaveOut.DeviceCount < 1) throw new Exception("Insufficient output device(s)!"); frame_size = toxav.CodecSettings.audio_sample_rate * toxav.CodecSettings.audio_frame_duration / 1000; toxav.PrepareTransmission(CallIndex, false); WaveFormat format = new WaveFormat((int)toxav.CodecSettings.audio_sample_rate, (int)toxav.CodecSettings.audio_channels); wave_provider = new BufferedWaveProvider(format); wave_provider.DiscardOnBufferOverflow = true; wave_out = new WaveOut(); //wave_out.DeviceNumber = config["device_output"]; wave_out.Init(wave_provider); wave_source = new WaveIn(); //wave_source.DeviceNumber = config["device_input"]; wave_source.WaveFormat = format; wave_source.DataAvailable += wave_source_DataAvailable; wave_source.RecordingStopped += wave_source_RecordingStopped; wave_source.BufferMilliseconds = (int)toxav.CodecSettings.audio_frame_duration; wave_source.StartRecording(); wave_out.Play(); }
static void Main(string[] args) { var adj = new AdjustableTFunc {Value = 1600}; var tFuncWaveProvider = new TFuncWaveProvider { // Amplitude = TFunc.Sin(new Frequency(adj.TFunc)) // Amplitude = TFunc.Sin(new Frequency(t => TFuncs.Sin(Frequency.Hertz(1))(t) + 1000)) Amplitude = TFunc.Sin(TFunc.Sin(Frequency.Hertz(2)) + 1000) }; var waveOut = new WaveOut(); waveOut.Init(tFuncWaveProvider); waveOut.Play(); Console.WriteLine("Press q to kill"); char k; while ((k = Console.ReadKey().KeyChar) != 'q') { if (k == 'u') { adj.Value+=10; } if (k == 'd') { adj.Value-=10; } Console.Write(" "); Console.WriteLine(adj.Value); } waveOut.Stop(); waveOut.Dispose(); }
public void Init(string path) { durationStopwatch = new Stopwatch(); waveIn = new WasapiLoopbackCapture(); wri = new LameMP3FileWriter(@path + ".mp3", waveIn.WaveFormat, 32); waveOut = new WaveOut(); waveOut.Init(new SilenceGenerator()); }
private void StartPlayback() { masterMix = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 2)); foreach (var source in trackSources) masterMix.AddMixerInput(source); outDevice = new WaveOut(); outDevice.Init(masterMix); outDevice.Play(); }
public Player(NAudio.Wave.IWaveProvider provider) { _provider = provider; _waveOut = new NAudio.Wave.WaveOut(); _waveOut.DeviceNumber = SelectedDevice; _waveOut.Init(_provider); Play(); }
//------------------------------------------------------------------------------------------------------------------------ #endregion #region Constructor //------------------------------------------------------------------------------------------------------------------------ public Speaker() { waveout = new WaveOut(); bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(8000, 16, 2)); waveout.PlaybackStopped += Waveout_PlaybackStopped; volumeProvider = new VolumeWaveProvider16(bufferedWaveProvider); waveout.Init(volumeProvider); }
/// <summary> /// Первоначальная инициализация звуковой системы /// </summary> public static void InitAudio() { player = new Player(); player.SetWaveFormat(SampleRate, 1); waveOut = new WaveOut(); waveOut.DesiredLatency = 200; // длина буфера /2=50 миллисекунд waveOut.Init(player); }
public void Play() { Stop(); SetWaveFormat(44100, 2); // 16kHz mono Out = new WaveOut(); Out.Init(this); Out.Play(); }
private void CreateWaveOut() { if (_waveOut == null) { _waveOut = new WaveOut(); _waveOut.Init(_inStream); _waveOut.PlaybackStopped += HandleWaveOutPlaybackStopped; } }
private void playnhac() { IWavePlayer waveOutDevice; AudioFileReader audioFileReader; waveOutDevice = new WaveOut(); audioFileReader = new AudioFileReader("animal.mp3"); waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); }
private void button3_Click_1(object sender, EventArgs e) { //waveOut var reader = new WaveFileReader("v.wav"); var waveOut = new WaveOut(); // or WaveOutEvent() waveOut.Init(reader); waveOut.Play(); }
public void Stop() { Output.Stop(); Stream.Close(); Stream.Dispose(); Stream = null; Output = new WaveOut(); timer1.Stop(); timer1.Enabled = false; }
public void playSound(int deviceNumber, string fileName) { disposeWave();// stop previous sounds before starting waveReader = new NAudio.Wave.WaveFileReader(fileName); var waveOut = new NAudio.Wave.WaveOut(); waveOut.DeviceNumber = deviceNumber; output = waveOut; output.Init(waveReader); output.Play(); }
public Recoder() { Random rand = new Random(); recoding = false; InitializeComponent(); spectrumCurr.Title = "Your Voice :"; spectrumRefer.Title = "Referrence :"; //waveViewer.SelectedTimeEvent += SelectedTimeEventHandler; waveOut = new NAudio.Wave.WaveOut(); initSampleRate_cbx(); FreshListDevices(); }
public MainControl() { option = VCContext.Instance.MFCCOptions; //ExtractionWrapper.OptionWrapper.SetLog(option.EnableLog); recoding = false; InitializeComponent(); waveViewer.TimeSelectedChanged += SelectedTimeEventHandler; _waveOut = new NAudio.Wave.WaveOut(); _selectedChart = showChart.Selected; initSampleRate_cbx(); //initListWords(); FreshListDevices(); }
public void play_sound(string file) { NAudio.Wave.DirectSoundOut waveOut = new NAudio.Wave.DirectSoundOut(); NAudio.Wave.WaveFileReader wfr = new NAudio.Wave.WaveFileReader(file); NAudio.Wave.WaveOut wOut = new NAudio.Wave.WaveOut(); wOut.DeviceNumber = 0; wOut.Init(wfr); wOut.Play(); waveOut.Init(wfr); waveOut.Play(); }
// セリフ音声の再生 private async void Speach(string s) { NAudio.Wave.WaveOut player; player = new NAudio.Wave.WaveOut(); byte[] buffer = (byte[])Properties.Resources.ResourceManager.GetObject(s); using var stream = new MemoryStream(buffer); using WaveStream pcm = new Mp3FileReader(stream); player.Init(pcm); player.Play(); while (player.PlaybackState == PlaybackState.Playing) { await Task.Delay(10); } player.Dispose(); }
public void Dispose() { if (soundPlayer.PlaybackState == NAudio.Wave.PlaybackState.Playing) { soundPlayer.Stop(); } if (musicPlayer.PlaybackState == NAudio.Wave.PlaybackState.Playing) { musicPlayer.Stop(); } soundPlayer.Dispose(); musicPlayer.Dispose(); soundPlayer = null; musicPlayer = null; _musicMap.Clear(); _soundMap.Clear(); }
/// <summary> /// play sound /// </summary> /// <param name="deviceNumber">device to play on. 0 == defulet</param> /// <param name="path">path to file</param> public void playSound(int deviceNumber, byte number) { try { this.disposeWave(); string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\HotKey\\sounder\\Sound" + number + ".wav"; var waveReader = new NAudio.Wave.WaveFileReader(path); var waveOut = new NAudio.Wave.WaveOut(); waveOut.DeviceNumber = deviceNumber; output = waveOut; output.Init(waveReader); output.Play(); } catch { } }
public void DisposeWave() { try { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); output.Dispose(); output = null; } } if (stream != null) { stream.Dispose(); stream = null; } if (outputLocal != null) { if (outputLocal.PlaybackState == NAudio.Wave.PlaybackState.Playing) { outputLocal.Stop(); outputLocal.Dispose(); outputLocal = null; } } if (stream2 != null) { stream2.Dispose(); stream2 = null; } } catch (NAudio.MmException) { throw; } }
public void ChangeDevice() { var state = _waveOut.PlaybackState; var latency = _waveOut.DesiredLatency; var numberOfBuffers = _waveOut.NumberOfBuffers; var waveFormat = _waveOut.OutputWaveFormat; var volume = _waveOut.Volume; _waveOut.Dispose(); _waveOut = new WaveOut(); _waveOut.DeviceNumber = SelectedDevice; _waveOut.Init(_provider); switch (state) { case PlaybackState.Paused: Pause(); break; case PlaybackState.Playing: Play(); break; } }
private IEnumerator ImportAudioNAudioRoutine(string url) { var loader = new WWW(url); while (!loader.isDone) { yield return(loader); } Debug.Log("NAudio file play"); NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(); NAudio.Wave.WaveFileReader wavReader = new NAudio.Wave.WaveFileReader("bardintro.wav"); Debug.Log("Format : " + wavReader.WaveFormat.ToString() + "sample count : " + wavReader.SampleCount + " :: " + wavReader.Length); var pcmLength = (int)wavReader.Length; var buffer = new byte[pcmLength]; var bytesRead = wavReader.Read(buffer, 0, pcmLength); using (FileStream fs = File.Open("generatedaudiofile", FileMode.Create)) { StreamWriter sw = new StreamWriter(fs); int i = 0; for (i = 0; i < buffer.Length; i += 3) { short int16 = (short)(((buffer[i] & 0xFF) << 8) | (buffer[i + 1] & 0xFF)); float f = int16; sw.WriteLine(f); } } //waveOut.Play(); yield return(new WaitForSeconds(3)); //waveOut.Stop(); wavReader.Dispose(); waveOut.Dispose(); }
public static String playSound(int deviceNumber, String audioPatch, EventHandler Stopped_Event = null) { disposeWave(); try { if (audioPatch.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(audioPatch)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (audioPatch.EndsWith(".wav")) { NAudio.Wave.WaveChannel32 pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(audioPatch)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); pcm.PadWithZeroes = false; } else { return("Not a valid audio file"); } output = new NAudio.Wave.WaveOut(); output.DeviceNumber = deviceNumber; output.Init(stream); output.Play(); if (Stopped_Event != null) { output.PlaybackStopped += new EventHandler <StoppedEventArgs>(Stopped_Event); } } catch (Exception ex) { return(ex.Message); } return("true"); }
public RegControl() { _regMode = false; bool designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime); if (!designMode) { ExtractionWrapper.OptionWrapper.SetLog(VCContext.Instance.MFCCOptions.LogLevel); recoding = false; _trainTask = new TrainingTask(); trainFrom = new TrainingFilesForm(_trainTask); trainFrom.RecalledEntry += RecalledRow; } InitializeComponent(); waveViewer.TimeSelectedChanged += SelectedTimeEventHandler; _waveOut = new NAudio.Wave.WaveOut(); _selectedChart = showChart.Selected; regMode_cbx.Checked = _regMode; initSampleRate_cbx(); FreshListDevices(); }
/// <summary> /// Stops play back and relise all resorces. /// </summary> public void stop() { try { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); } output.Dispose(); output = null; } if (stream != null) { stream.Dispose(); stream = null; } } catch (Exception) { stream = null; } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { string outputFileName = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Wave File (*.wav) | *.wav|MP3 Files (*.mp3) | *.mp3|All Files (*.*) | *.*"; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { outputFileName = openFileDialog.FileName; } else { return; } if (openFileDialog.FileName.Contains(".mp3")) { outputFileName = outputFileName.Substring(0, outputFileName.Length - 3) + "wav"; Mp3ToWav(openFileDialog.FileName, outputFileName); } //OpenFileDialog open = new OpenFileDialog(); //open.Filter = "Wave File (*.wav) | *.wav"; //if (open.ShowDialog() != DialogResult.OK) return; waveViewer1.WaveStream = new NAudio.Wave.WaveFileReader(outputFileName); waveViewer1.GetTotal = true; waveViewer1.Refresh(); var datalow = waveViewer1.Datax; var datahigh = waveViewer1.Datay; //take the data and look for patterns in the frame of 8 secs var peaks = detectpeak(200, datahigh, true); var trough = detectpeak(200, datahigh, false); peaks = filterpeak(20, peaks); trough = filterpeak(20, trough); waveViewer1.peaks = peaks; waveViewer1.trough = trough; double[][] highamp = new double[peaks.Count][]; for (int a = 0; a < peaks.Count - 1; a++) { highamp[a] = new double[2]; highamp[a][0] = peaks[a + 1] - peaks[a]; highamp[a][1] = datahigh[peaks[a]]; } highamp[peaks.Count - 1] = new double[2]; highamp[peaks.Count - 1][0] = 0; highamp[peaks.Count - 1][1] = 0; double[][] lowamp = new double[trough.Count][]; for (int a = 0; a < trough.Count - 1; a++) { lowamp[a] = new double[2]; lowamp[a][0] = trough[a + 1] - trough[a]; lowamp[a][1] = datahigh[trough[a]]; } lowamp[trough.Count - 1] = new double[2]; lowamp[trough.Count - 1][0] = 0; lowamp[trough.Count - 1][1] = 0; //cluster both Accord.MachineLearning.KMeans gm = new Accord.MachineLearning.KMeans(5); Accord.MachineLearning.KMeans gml = new Accord.MachineLearning.KMeans(5); var ans = gm.Compute(highamp); var lans = gml.Compute(lowamp); var fclus = filtercluster(ans, peaks); cluspos = MixerControls.ToDict(fclus); var flans = filtercluster(lans, trough);//ignore bot waveViewer1.peakclus = ans; waveViewer1.troughclus = lans; IWavePlayer play; play = new NAudio.Wave.WaveOut(); audio = new AudioFileReader(outputFileName); play.Init(audio); play.Play(); Application.Idle += Application_Idle; timer1.Interval = 20; timer1.Enabled = true; timer1.Start(); Rectangle workingArea = Screen.GetWorkingArea(this); this.Location = new Point(workingArea.Right - Size.Width - 20, workingArea.Bottom - Size.Height - 20); //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.TopMost = true; this.Opacity = .8; openToolStripMenuItem.Visible = false; menuStrip1.Visible = false; this.pictureBox1.Image = Image.FromFile("D:\\AllVSProject232015\\AudioMix\\AudioMix\\Hypnoctivity-Logo.png"); }
/// <summary> /// 根据获取的输出设备id获取输出设备名称 /// </summary> /// <param name="deviceId">设备id</param> /// <returns></returns> public string GetCapabilities(int deviceId) { var capabilities = WaveOut.GetCapabilities(deviceId); return(String.Format("Device {0} ({1})", deviceId, capabilities.ProductName)); }
public void LoadFile(string filePath) { DisposeWave(); pausePlay = true; if (filePath.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(filePath)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (filePath.EndsWith(".wav")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(filePath)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else { throw new InvalidOperationException("oh my god just put in the right file type you twat"); } output = new NAudio.Wave.WaveOut(); output.DeviceNumber = comboBox2.SelectedIndex; textBox2.Text = comboBox2.GetItemText(comboBox2.SelectedItem); var audioFileReader = new AudioFileReader(filePath); string min = Convert.ToInt32(audioFileReader.TotalTime.TotalMinutes).ToString(); string sec = Convert.ToInt32(audioFileReader.TotalTime.TotalSeconds % 60).ToString(); string mil = Convert.ToInt32(audioFileReader.TotalTime.TotalMilliseconds % 1000).ToString(); if (min.Length < 2) { min = "0" + min; } if (sec.Length < 2) { sec = "0" + sec; } if (mil.Length < 2) { mil = "00" + mil; } else if (mil.Length < 3) { mil = "0" + mil; } textBox9.Text = "Total " + min + ":" + sec + ":" + mil; audioFileReader.Volume = vol2.Volume; output.Init(audioFileReader); Stopwatch time = new Stopwatch(); time.Start(); stopwatches.Add(time, "time"); totalMil = Convert.ToInt64(audioFileReader.TotalTime.TotalMilliseconds); output.Play(); if (comboBox1.SelectedIndex != comboBox2.SelectedIndex) { if (filePath.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm2 = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(filePath)); stream2 = new NAudio.Wave.BlockAlignReductionStream(pcm2); } else if (filePath.EndsWith(".wav")) { NAudio.Wave.WaveStream pcm2 = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(filePath)); stream2 = new NAudio.Wave.BlockAlignReductionStream(pcm2); } else { throw new InvalidOperationException("Not a compatabible audio file type."); } outputLocal = new NAudio.Wave.WaveOut(); outputLocal.DeviceNumber = comboBox1.SelectedIndex; textBox4.Text = comboBox1.GetItemText(comboBox1.SelectedItem); var audioFileReader2 = new AudioFileReader(filePath); audioFileReader2.Volume = volumeSlider1.Volume; outputLocal.Init(audioFileReader2); outputLocal.Play(); //float a = volumeSlider1.Volume; //outputLocal.Volume = a; //outputLocal.Init(stream2); //outputLocal.Play(); } }
static void Main(string[] args) { string mp3FilesDir = Directory.GetCurrentDirectory(); if (args.Length > 0) { mp3FilesDir = args.First(); } var waveOutDevice = new WaveOut(); var idToFile = Directory.GetFiles(mp3FilesDir, "*.mp3", SearchOption.AllDirectories).ToDictionary(k => int.Parse(Regex.Match(Path.GetFileName(k), @"^\d+").Value)); while (true) { Console.WriteLine("Wprowadz numer nagrania"); var trackId = int.Parse(Console.ReadLine()); using (var audioFileReader = new AudioFileReader(idToFile[trackId])) { waveOutDevice.Init(audioFileReader); waveOutDevice.Play(); Console.ReadLine(); } } }