public bool Load(string path, Guid device) { var cext = path.GetExt(); _myWaveOut = new DirectSoundOut(device); try { _myWaveStream = _codecs.First(v => v.Extensions.Contains(cext)).CreateWaveStream(path); } catch { return false; } if (_myWaveStream == null) return false; if (_myWaveStream.WaveFormat.Channels == 2) { _myBalanceSampleProvider = new BalanceSampleProvider(_myWaveStream.ToSampleProvider()); _myVolumeSampleProvider = new VolumeSampleProvider(_myBalanceSampleProvider); _myBalanceSampleProvider.Pan = (float)Balance; } else _myVolumeSampleProvider = new VolumeSampleProvider(_myWaveStream.ToSampleProvider()); _myEqualizer = new Equalizer(_myVolumeSampleProvider, _equalizerBands) { Enabled = _enableEqualizer }; _myWaveOut.Init(_myEqualizer); _myWaveOut.PlaybackStopped += MyWaveOutOnPlaybackStopped; _myVolumeSampleProvider.Volume = (float)Volume; return true; }
/// <summary> /// Initialises a new instance of SampleChannel /// </summary> /// <param name="waveProvider">Source wave provider, must be PCM or IEEE</param> /// <param name="forceStereo">force mono inputs to become stereo</param> public SampleChannel(IWaveProvider waveProvider, bool forceStereo) { ISampleProvider sampleProvider = SampleProviderConverters.ConvertWaveProviderIntoSampleProvider(waveProvider); if (sampleProvider.WaveFormat.Channels == 1 && forceStereo) { sampleProvider = new MonoToStereoSampleProvider(sampleProvider); } this.waveFormat = sampleProvider.WaveFormat; // let's put the meter before the volume (useful for drawing waveforms) this.preVolumeMeter = new MeteringSampleProvider(sampleProvider); this.volumeProvider = new VolumeSampleProvider(preVolumeMeter); }
public sourceSatellite(MixingSampleProvider targetMixer) { volume = 1f; sourceState = "OFF"; //Open channel inputSat = new WaveInEvent(); inputSat.DeviceNumber = devNum; inputSat.WaveFormat = new WaveFormat(); inputSat.BufferMilliseconds = 400; //Volume VSP //inputSatVSP = new VolumeSampleProvider(new Pcm16BitToSampleProvider(new WaveInProvider(inputSat))); inputSatVSP = new VolumeSampleProvider(new WaveInProvider(inputSat).ToSampleProvider()); //Send to mixer targetMixer.AddMixerInput(inputSatVSP); }
/// <summary> /// Initialises a new instance of SampleChannel /// </summary> /// <param name="waveProvider">Source wave provider, must be PCM or IEEE</param> public SampleChannel(IWaveProvider waveProvider) { ISampleProvider sampleProvider; if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.Pcm) { // go to float if (waveProvider.WaveFormat.BitsPerSample == 8) { sampleProvider = new Pcm8BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 16) { sampleProvider = new Pcm16BitToSampleProvider(waveProvider); } else if (waveProvider.WaveFormat.BitsPerSample == 24) { sampleProvider = new Pcm24BitToSampleProvider(waveProvider); } else { throw new InvalidOperationException("Unsupported operation"); } } else if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat) { sampleProvider = new WaveToSampleProvider(waveProvider); } else { throw new ArgumentException("Unsupported source encoding"); } if (sampleProvider.WaveFormat.Channels == 1) { sampleProvider = new MonoToStereoSampleProvider(sampleProvider); } this.waveFormat = sampleProvider.WaveFormat; // let's put the meter before the volume (useful for drawing waveforms) this.preVolumeMeter = new MeteringSampleProvider(sampleProvider); this.volumeProvider = new VolumeSampleProvider(preVolumeMeter); }
private void _play() { /* Audio chain */ // Sampling _wavesampler = new WaveToSampleProvider(new Wave16ToFloatProvider(_wavebuffer)); // Fading component _fade = new FadeInOutSampleProvider(_wavesampler); _fade.BeginFadeIn(1500); // Notifying component var _notify = new NotifyingSampleProvider(_fade); _notify.Sample += new EventHandler<SampleEventArgs>(_notify_Sample); // Gain adjustment component _volume = new VolumeSampleProvider(_notify); _volume.Volume = this.Volume; // Output Output.Init(new SampleToWaveProvider16(_volume)); /* Playback loop */ do { if (_cancel_play.IsCancellationRequested) { Console.WriteLine("[Playback thread] Cancellation requested."); // Fade out and stop Console.WriteLine("[Playback thread] Fading out and stopping..."); _fade.BeginFadeOut(500); Thread.Sleep(500); Output.Stop(); Console.WriteLine("[Playback thread] Output stopped."); this.Status = StreamStatus.Stopped; Console.WriteLine("[Playback thread] Acknowledged as status."); //_cancel_play_token.ThrowIfCancellationRequested(); //Console.WriteLine("[Playback thread] WARNING: Cancellation token is not cleanly set!"); return; } if (Output.PlaybackState != PlaybackState.Playing && _wavebuffer.BufferedDuration.TotalMilliseconds > 2750) { // Buffer is filled enough Console.WriteLine("[Playback thread] Buffer is okay now, start playback!"); this.Status = StreamStatus.Playing; Output.Play(); } else if (Output.PlaybackState == PlaybackState.Playing && _wavebuffer.BufferedDuration.TotalMilliseconds < 2250) { // Buffer is underrunning Console.WriteLine("[Playback thread] Buffer is underrunning, pausing playback..."); this.Status = StreamStatus.Buffering; Output.Pause(); } if (_bufferThread.Exception != null) { Console.WriteLine("[Playback thread] Buffering thread is faulted, aborting playback"); throw new Exception("Buffering thread faulted, aborting playback"); } Thread.Sleep(100); } while (true); }
public void Unload() { if (_myWaveOut != null) { _myWaveOut.PlaybackStopped -= MyWaveOutOnPlaybackStopped; _myWaveOut.Stop(); } if (_myWaveStream != null) { _myWaveStream.Dispose(); _myWaveStream = null; } _myBalanceSampleProvider = null; _myVolumeSampleProvider = null; _myEqualizer = null; }
/// <summary> /// Changes the volume. /// </summary> /// <param name="inputFile">The input file.</param> /// <param name="outputFile">The output file.</param> /// <param name="level">The level.</param> /// <returns> /// Path of changed file /// </returns> public static string ChangeVolume(string inputFile, string outputFile, double level) { using (var reader = new AudioFileReader(inputFile)) { var provider = new VolumeSampleProvider(reader) { Volume = Convert.ToSingle(level) }; WaveFileWriter.CreateWaveFile16(outputFile, provider); } return outputFile; }
/// <summary> /// Initializes a new instance of AudioFileReader /// </summary> /// <param name="fileName">The file to open</param> public AudioFileReaderVVVV(string fileName) { FLockObject = new object(); this.FFileName = fileName; CreateReaderStream(fileName); FSourceBytesPerSample = (FReaderStream.WaveFormat.BitsPerSample / 8) * FReaderStream.WaveFormat.Channels; this.FSampleChannel = new VolumeSampleProvider(FReaderStream.ToSampleProvider()); FDestBytesPerSample = 4*FSampleChannel.WaveFormat.Channels; FLength = SourceToDest(FReaderStream.Length); }
public static void SaveSong(IEnumerable<Track> tracks, string filePath) { var waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(48000, 1); MediaBankBase bank = new FenderStratCleanB(waveFormat); MediaBankBase bassBank = new RockdaleBassBridge(waveFormat); var mixer = new MixingSampleProvider(waveFormat); foreach(var track in tracks) { var trackSampleProvider = new TrackSampleProvider(track.Patch == MediaPatch.CleanGuitar ? bank : bassBank, track); var resultingSampleProvider = new VolumeSampleProvider(trackSampleProvider) { Volume = 0.7f }; mixer.AddMixerInput(resultingSampleProvider); } WaveFileWriter.CreateWaveFile(filePath, new SampleToWaveProvider(mixer)); }
public TrackSampleProvider() { mix = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 2)); //pan = new PanningSampleProvider(mix); volume = new VolumeSampleProvider(mix); }
public static string GenerateAudio(ControllerContext context, string captcha) { var mixed = Path.GetTempFileName(); var back = Path.GetTempFileName(); var main = Path.GetTempFileName(); //gera audio principal List<String> chars = new List<string>(); foreach (var item in captcha) { chars.Add(context.HttpContext.Server.MapPath("~/Content/Audios/" + item.ToString() + ".wav")); } Concatenate(main, chars, 1000); chars = new List<string>(); //gera audio aleatorio para sujeira for (int i = 0; i < 4; i++) { var randtext = Captcha.GenerateRandomCode(i); foreach (var item in randtext) { chars.Add(context.HttpContext.Server.MapPath("~/Content/Audios/" + item.ToString() + ".wav")); } } Concatenate(mixed, chars, 0, true); ReverseWaveFile(mixed, back); using (var reader1 = new WaveFileReader(main)) using (var reader2 = new WaveFileReader(back)) { var volumeProvider = new VolumeSampleProvider(reader2.ToSampleProvider()); volumeProvider.Volume = 0.15f; var inputs = new List<ISampleProvider>() { reader1.ToSampleProvider(), volumeProvider }; var mixer = new MixingSampleProvider(inputs); WaveFileWriter.CreateWaveFile16(mixed, mixer); } var mp3file = Path.GetTempFileName(); WavToMp3(mixed, mp3file, context); return mp3file; }