Exemplo n.º 1
0
        static void Test()
        {
            var soundIn = new WasapiCapture();

            soundIn.Initialize();
            var soundInSource = new RealTimeSoundInSource(soundIn);

            var soundOut = new WasapiOut();

            soundOut.Initialize(soundInSource);
            soundIn.Start();
            soundOut.Play();

            soundOut.Stopped += (s, e) =>
            {
                Console.WriteLine("I'm dead but not dead, P.P.A.P");
                Task.Run(() =>
                {
                    soundOut.Play();
                });
            };

            while (true)
            {
                Console.ReadLine();
            }
        }
        public long RunMeasurementRoutine()
        {
            Console.WriteLine($"We will take {c_sampleCount} samples to calculate the end-to-end system latency.");
            Console.WriteLine("Setting up audio devices...");

            InterceptKeys.Instance.OnKey += OnKey;
            InterceptKeys.Start();
            Thread.Sleep(1000);
            _capture.Initialize();
            _capture.DataAvailable += OnData;
            _tracker.Start();
            _capture.Start();

            _output.Initialize(new SampleToIeeeFloat32(new MetronomeGenerator()));
            _output.Play();

            _done.WaitOne();

            float delta = 0;

            for (int i = 0; i < c_sampleCount; i++)
            {
                delta += _keyTicks[i] - _audioTicks[i];
            }
            delta /= c_sampleCount;
            Console.WriteLine($"End-to-end latency: {delta / 10000}ms");
            Thread.Sleep(5000);
            return((long)(delta));
        }
Exemplo n.º 3
0
        public void Initialize()
        {
            _wasapiOut   = new WasapiOut();
            _opusDecoder = OpusDecoder.Create(48000, 1);

            //var waveForm = new WaveFormatExtensible(48000, 16, 1, Guid.Parse("00000003-0000-0010-8000-00aa00389b71"));
            var waveForm = new WaveFormat(48000, 16, 1);

            _writeableBufferingSource = new WriteableBufferingSource(waveForm)
            {
                FillWithZeros = true
            };

            IWaveSource waveSource;

            if (_triggerSingleBlockRead)
            {
                var singleBlockNotificationStream =
                    new SingleBlockNotificationStream(_writeableBufferingSource.ToSampleSource());
                singleBlockNotificationStream.SingleBlockRead += SingleBlockNotificationStreamOnSingleBlockRead;
                waveSource = singleBlockNotificationStream.ToWaveSource();
            }
            else
            {
                waveSource = _writeableBufferingSource;
            }

            _wasapiOut.Initialize(waveSource);
            _wasapiOut.Play();
        }
Exemplo n.º 4
0
        public void SoundInToSoundOutTest_Wasapi()
        {
            for (int i = 0; i < 10; i++)
            {
                var waveIn = new WasapiCapture();
                waveIn.Initialize();
                waveIn.Start();

                var waveInToSource = new SoundInSource(waveIn)
                {
                    FillWithZeros = true
                };

                var soundOut = new WasapiOut();
                soundOut.Initialize(waveInToSource);
                soundOut.Play();

                Thread.Sleep(2000);

                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Dispose();
                waveIn.Dispose();
            }
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            MMDevice dev = (MMDevice)comboBox.SelectedItem;

            if (mmdevicesOut.Contains(dev))
            {
                capture = new WasapiLoopbackCapture();
            }
            else
            {
                capture = new WasapiCapture();
            }
            capture.Device = dev;

            capture.Initialize();

            w = new WasapiOut();

            w.Device = (MMDevice)comboBox_Copy.SelectedItem;

            w.Initialize(new SoundInSource(capture)
            {
                FillWithZeros = true
            });

            capture.Start();
            w.Play();
        }
        public void TestDistortion()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    foreach (InstalledVoice voice in synth.GetInstalledVoices())
                    {
                        Console.WriteLine(voice.VoiceInfo.Name);
                    }

                    synth.SetOutputToWaveStream(stream);
                    synth.Speak("Anaconda golf foxtrot lima one niner six eight requesting docking.");
                    stream.Seek(0, SeekOrigin.Begin);

                    IWaveSource         source          = new WaveFileReader(stream);
                    DmoDistortionEffect distortedSource = new DmoDistortionEffect(source);
                    distortedSource.Edge             = 10;
                    distortedSource.PreLowpassCutoff = 4800;

                    var soundOut = new WasapiOut();
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    soundOut.Initialize(distortedSource);
                    soundOut.Play();

                    waitHandle.WaitOne();

                    soundOut.Dispose();
                    distortedSource.Dispose();
                    source.Dispose();
                }
        }
Exemplo n.º 7
0
 public void Prepare(Uri uri)
 {
     CleanUp();
     Source = CodecFactory.Instance.GetCodec(uri);
     Out    = new WasapiOut();
     Out.Initialize(Source);
 }
Exemplo n.º 8
0
        public void TestPhonemes()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    synth.SetOutputToWaveStream(stream);

                    //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>This is your <phoneme alphabet=\"ipa\" ph=\"leɪkɒn\">Lakon</phoneme>.</s></speak>");

                    //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈdɛltə\">delta</phoneme> system.</s></speak>");
                    synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈlaʊ.təns\">Luyten's</phoneme> <phoneme alphabet=\"ipa\" ph=\"stɑː\">Star</phoneme> system.</s></speak>");
                    //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"bliːiː\">Bleae</phoneme> <phoneme alphabet=\"ipa\" ph=\"θuːə\">Thua</phoneme> system.</s></speak>");
                    //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the Amnemoi system.</s></speak>");
                    //synth.Speak("You are travelling to the Barnard's Star system.");
                    stream.Seek(0, SeekOrigin.Begin);

                    IWaveSource source = new WaveFileReader(stream);

                    var soundOut = new WasapiOut();
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    soundOut.Initialize(source);
                    soundOut.Play();

                    waitHandle.WaitOne();
                    soundOut.Dispose();
                    source.Dispose();
                }
        }
        private void button_start_Click(object sender, EventArgs e)
        {
            wavein        = null;
            wavein        = new WasapiCapture(false, AudioClientShareMode.Exclusive, 5);
            wavein.Device = inputDevices[comboBox_mic.SelectedIndex];
            wavein.Initialize();
            wavein.Start();

            source = new SoundInSource(wavein)
            {
                FillWithZeros = true
            };
            //add my special effects in the chain
            efxProcs             = new EfxProcs(source.ToSampleSource().ToMono());
            efxProcs.gain        = linearGain; //keep track of this changing value
            efxProcs.pitchFactor = pitchShift; //keep track of pitch

            waveout        = null;
            waveout        = new WasapiOut(false, AudioClientShareMode.Exclusive, 5);
            waveout.Device = outputDevices[comboBox_speaker.SelectedIndex];
            waveout.Initialize(efxProcs.ToWaveSource()); //source.ToSampleSource().ToWaveSource());//
            waveout.Play();
            //CSCore.Streams.SampleConverter.SampleToIeeeFloat32 sampleToIeee = new CSCore.Streams.SampleConverter.SampleToIeeeFloat32(source.ToSampleSource());
            timer1.Enabled = true;
        }
Exemplo n.º 10
0
        private static void StartCapture(MMDevice sourceDevice, MMDevice targetDevice)
        {
            var soundIn = new WasapiLoopbackCapture {
                Device = sourceDevice
            };

            soundIn.Initialize();

            var soundOut = new WasapiOut()
            {
                Latency = 100, Device = targetDevice
            };

            soundOut.Initialize(new SoundInSource(soundIn));

            soundIn.Start();
            soundOut.Play();
            while (true)
            {
                if (soundOut.PlaybackState == PlaybackState.Playing)
                {
                    Thread.Sleep(500);
                }
                soundOut.Play();
            }
        }
Exemplo n.º 11
0
        public void TestAudio()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    synth.SetOutputToWaveStream(stream);

                    synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s><audio src=\"C:\\Users\\jgm\\Desktop\\positive.wav\"/>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈlaʊ.təns\">Luyten's</phoneme> <phoneme alphabet=\"ipa\" ph=\"stɑː\">Star</phoneme> system.</s></speak>");
                    stream.Seek(0, SeekOrigin.Begin);

                    IWaveSource source = new WaveFileReader(stream);

                    var soundOut = new WasapiOut();
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    soundOut.Initialize(source);
                    soundOut.Play();

                    waitHandle.WaitOne();
                    soundOut.Dispose();
                    source.Dispose();
                }
        }
Exemplo n.º 12
0
        static void ReceiverMain(int tcpPort, int udpPort)
        {
            //UdpReceiver soundIn;
            soundIn = new UdpReceiver(tcpPort, udpPort);
            soundIn.Initialize();

            IWaveSource source = new SoundInSource(soundIn)
            {
                FillWithZeros = true
            };

            soundIn.Start();

            //create a soundOut instance to play the data
            soundOut = new WasapiOut();
            //initialize the soundOut with the echoSource
            //the echoSource provides data from the "source" and applies the echo effect
            //the "source" provides data from the "soundIn" instance
            soundOut.Initialize(source);

            //play
            soundOut.Play();

            /*System.Timers.Timer aTimer = new System.Timers.Timer();
             * aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
             * aTimer.Interval = 2000;
             * aTimer.Enabled = true;*/

            Console.WriteLine("Receiving audio... Press any key to exit the program.");
            Console.ReadKey();
        }
        public void TestPhonemes()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    synth.SetOutputToWaveStream(stream);

                    synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈprəʊˌsɪən\">Procyon</phoneme> system.</s></speak>");
                    //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈkaɪə\">Kaia</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈbɑːhɑːhɑː\">Bajaja</phoneme> system.</s></speak>");
                    //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the Amnemoi system.</s></speak>");
                    //synth.Speak("Anemoi");
                    stream.Seek(0, SeekOrigin.Begin);

                    IWaveSource source = new WaveFileReader(stream);

                    var soundOut = new WasapiOut();
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    soundOut.Initialize(source);
                    soundOut.Play();

                    waitHandle.WaitOne();
                    soundOut.Dispose();
                    source.Dispose();
                }
        }
Exemplo n.º 14
0
        public Audio()
        {
            try
            {
                CodecFactory.Instance.Register("ogg-vorbis",
                                               new CodecFactoryEntry(s => new OggSource(s).ToWaveSource(), ".ogg"));

                _mixer    = new SoundMixer();
                _soundOut = new WasapiOut();

                _soundOut.Initialize(_mixer.ToWaveSource());
                _soundOut.Play();
            }
            catch
            {
                Console.WriteLine("Could not load audio");
            }

            _menu = LoadSound(AppContext.BaseDirectory + "assets/sfx/menu.wav");
            LoadSound(AppContext.BaseDirectory + "assets/sfx/fill.wav");

            _random          = new Random();
            _playlist        = new List <string>();
            _playingPlaylist = false;
            var files = Directory.EnumerateFiles(AppContext.BaseDirectory + "/assets/bgm/playlist");

            foreach (var file in files)
            {
                if (!file.EndsWith(".ogg"))
                {
                    continue;
                }
                _playlist.Add(file);
            }
        }
Exemplo n.º 15
0
        public static void Play(string filePath, Func <bool> ShouldStop = null)
        {
            using (var enumerator = new MMDeviceEnumerator())
                using (var device = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active).Last())
                    using (var source =
                               CodecFactory.Instance.GetCodec(filePath)
                               .ToSampleSource()
                               .ToMono()
                               .ToWaveSource())

                        using (
                            var soundOut = new WasapiOut()
                        {
                            Latency = 100, Device = device
                        })
                        {
                            soundOut.Initialize(source);
                            soundOut.Play();
                            if (ShouldStop == null)
                            {
                                Thread.Sleep(source.GetLength());
                            }
                            else
                            {
                                while (!ShouldStop())
                                {
                                    Thread.Sleep(5000);
                                }
                            }
                            soundOut.Stop();
                        }
        }
Exemplo n.º 16
0
        public void TestExtendedSource()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    synth.SetOutputToWaveStream(stream);
                    synth.Speak("Test.");
                    stream.Seek(0, SeekOrigin.Begin);

                    IWaveSource source = new ExtendedDurationWaveSource(new WaveFileReader(stream), 2000).AppendSource(x => new DmoWavesReverbEffect(x)
                    {
                        ReverbMix = -10
                    });

                    var soundOut = new WasapiOut();
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    soundOut.Initialize(source);
                    soundOut.Play();

                    waitHandle.WaitOne();
                    soundOut.Dispose();
                    source.Dispose();
                }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Plays silence.wav on loop in background to ensure there is sound coming out of the speakers at all times.
        /// </summary>
        private void playSilence()
        {
            soundout = new WasapiOut();
            var source = CodecFactory.Instance.GetCodec("silence.wav");

            soundout.Initialize(source.Loop());
            soundout.Play();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Plays the sound.
        /// </summary>
        /// <param name="source">The WaveSource.</param>
        private void Play(IWaveSource source)
        {
            Stop();
            var panSource = new PanSource(source);

            _panSource = panSource;
            _wasapiOut.Initialize(panSource.ToWaveSource());
            _wasapiOut.Play();
        }
Exemplo n.º 19
0
        unsafe static void Main(string[] args)
        {
            WasapiOut wasapi = new WasapiOut();

            wasapi.Initialize(new TestStream());
            wasapi.Play();

            Console.ReadKey();
        }
Exemplo n.º 20
0
        private static void Main(string[] args)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog()
            {
                Title  = "Select a file to play",
                Filter = CodecFactory.SupportedFilesFilterEn
            };

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            using (var soundOut = new WasapiOut()
            {
                Latency = 50
            })
            {
                using (var fadeInOut = CodecFactory.Instance.GetCodec(openFileDialog.FileName)
                                       .ToSampleSource()
                                       .AppendSource(x => new FadeInOut(x)))
                {
                    var linearFadeStrategy = new LinearFadeStrategy();
                    var eventHandle        = new AutoResetEvent(false);
                    linearFadeStrategy.FadingFinished += (s, e) => eventHandle.Set();
                    fadeInOut.FadeStrategy             = linearFadeStrategy;

                    soundOut.Initialize(fadeInOut.ToWaveSource());
                    soundOut.Play();

                    while (true)
                    {
                        Console.Write("Enter the target volume: ");
                        float to;
                        if (!Single.TryParse(Console.ReadLine(), out to) ||
                            to > 1 || to < 0)
                        {
                            Console.WriteLine("Invalid value.");
                            continue;
                        }

                        linearFadeStrategy.StartFading(0.3f, to, 5000); //fade from the current volume to the entered volume over a duration of 3000ms

                        do
                        {
                            ClearCurrentConsoleLine();
                            Console.WriteLine(linearFadeStrategy.CurrentVolume);
                            Console.CursorTop--;
                        } while (!eventHandle.WaitOne(50));

                        ClearCurrentConsoleLine();
                        Console.WriteLine(linearFadeStrategy.CurrentVolume);
                    }
                }
            }
        }
Exemplo n.º 21
0
 public void StartAudio(MMDevice speaker)
 {
     if (_soundOut.PlaybackState == PlaybackState.Playing)
     {
         _soundOut.Stop();
     }
     _soundOut.Device = speaker;
     _soundOut.Initialize(_source);
     _soundOut.Play();
 }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            const string DefaultStream =
                @"http://stream.srg-ssr.ch/m/rsj/aacp_96";

            Console.WriteLine("01 - File");
            Console.WriteLine("02 - Stream");
            Console.WriteLine("99 - Test-Stream");

            int choice;

            do
            {
                Int32.TryParse(Console.ReadLine(), out choice);
            } while (choice != 1 && choice != 2 && choice != 99);

            Stream stream = null;
            string url    = null;

            if (choice == 1)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                if (openFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                stream = File.OpenRead(openFileDialog.FileName);
            }
            else if (choice == 2)
            {
                Console.WriteLine("Enter a stream url:");
                url = Console.ReadLine();
            }
            else
            {
                url = DefaultStream;
            }

            //we could also easily pass the filename as url
            //but since we want to test the decoding of System.IO.Stream, we
            //pass a FileStream as argument.
            FfmpegDecoder ffmpegDecoder = stream == null
                ? new FfmpegDecoder(url)
                : new FfmpegDecoder(stream);

            using (ffmpegDecoder)
                using (var wasapiOut = new WasapiOut())
                {
                    wasapiOut.Initialize(ffmpegDecoder);
                    wasapiOut.Play();

                    Console.ReadKey();
                }
        }
Exemplo n.º 23
0
        public async void Play()
        {
            MMDevice[] playDevices = GetEnabledDevices();
            Log.WriteLine("Playing \"{0}\" with volume {1:0.00} on devices: {2}", name, GetVolume(), String.Join <string>(", ", playDevices.Select(d => d.FriendlyName)));

            List <ManualResetEvent> mres = new List <ManualResetEvent>();

            foreach (MMDevice device in playDevices)
            {
                WasapiOut   audioOut = new WasapiOut();
                IWaveSource source   = CodecFactory.Instance.GetCodec(this.source);
                Log.WriteLine("Source format: {0}", source.WaveFormat.ToString());

                audioOut.Device = device;
                audioOut.Initialize(source);
                audioOut.Volume = GetVolume();

                ManualResetEvent mre = new ManualResetEvent(false);
                mres.Add(mre);
                audioOut.Stopped += (s, e) =>
                {
                    audioOut.Dispose();
                    source.Dispose();

                    mre.Set();
                    Log.WriteLine("\"{0}\" stopped on device \"{1}\"", name, device.FriendlyName);
                };

                audioOuts.Add(new Tuple <WasapiOut, IWaveSource>(audioOut, source));

                audioOut.Play();
            }

            Log.WriteLine("Waiting for all ({0}) events to trigger", mres.Count);

            await Task.Run(() =>
            {
                while (true)
                {
                    if (WaitHandle.WaitAll(mres.ToArray(), positionUpdateFreq))
                    {
                        return;
                    }

                    PositionUpdate(this, new PositionUpdateEventArgs(GetPosition()));
                }
            });

            Log.WriteLine("\"{0}\" stopped", name);
            audioOuts.Clear();
            if (Stopped != null)
            {
                Stopped(this, EventArgs.Empty);
            }
        }
Exemplo n.º 24
0
        private static Task Player(IWaveSource decoder, WasapiOut device)
        {
            if (device.PlaybackState != PlaybackState.Stopped)
            {
                device.Stop();
            }

            device.Initialize(decoder.ToMono()); //Mono > Stereo in micspams
            device.Play();
            return(Task.FromResult <object>(null));
        }
Exemplo n.º 25
0
        // Use this for initialization
        void MakeOutput(out WasapiOut output, out WritablePureDataSource outSource)
        {
            var ayy = new MMDeviceEnumerator();

            output        = new WasapiOut(false, AudioClientShareMode.Shared, 100);
            output.Device = ayy.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            outSource     = new WritablePureDataSource(new WaveFormat(inputSampleRate, 8, 1), new WaveFormat(output.Device.DeviceFormat.SampleRate, 8, output.Device.DeviceFormat.Channels));

            output.Initialize(outSource.ToWaveSource());

            output.Play();
        }
Exemplo n.º 26
0
        public Mixer(int channelCount)
        {
            output = new WasapiOut()
            {
                Latency = 4
            };
            MasterChannel = new MixerChannel("Master", channelCount, output.Device.DeviceFormat.SampleRate);

            var w = new MixerChannelToCSCore(MasterChannel).ToWaveSource();

            output.Initialize(w);
            output.Play();
        }
Exemplo n.º 27
0
        public void StartOutput()
        {
            if (!isCaptureAvailable)
            {
                throw new WasapiNotInitializedException("This instance has no WasapiCapture object initialized. Try using StartLoopback() or StartCaptureMicrophone().");
            }
            else
            {
                isOutputAvailable = true;

                output.Initialize(wave);
                output.Play();
            }
        }
Exemplo n.º 28
0
 public void PlaySound()
 {
     try
     {
         played = true;
         ISoundOut soundOut = new WasapiOut();
         soundOut.Initialize(GetSoundSource(soundstrm));
         soundOut.Volume = 1;
         soundOut.Play();
     } catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
Exemplo n.º 29
0
 public void ChangeSong(string file)
 {
     if (File.Exists(file))
     {
         source          = CodecFactory.Instance.GetCodec(file);
         tracker.Maximum = (int)source.Length;
         tracker.Value   = 0;
         audioOut.Stop();
         audioOut.Initialize(source);
     }
     else
     {
     }
 }
Exemplo n.º 30
0
        /*
         * unsafe class FilterTest : IWaveStream {
         *      private Convolver convolver;
         *      private AudioStream audioStream;
         *      private AudioResampler resampler;
         *      private AudioFrame inFrame, outFrame;
         *      private byte[] temp = new byte[4096 * 3];
         *      private WaveFormat inWaveFormat;
         *      private int over = 0;
         *
         *      public FilterTest(AudioStream audioStream) {
         *              this.audioStream = audioStream;
         *              this.convolver = new Convolver(new double[] { 1 });
         *              inWaveFormat = new WaveFormat(audioStream.Format.SampleRate, 32, audioStream.Format.Channels);
         *              audioStream.Resample(inWaveFormat);
         *              inFrame = new AudioFrame(audioStream.decoder.OutFormat.ToPacked());
         *      }
         *
         *      public WaveFormat Format => inWaveFormat;
         *
         *      public int Read(byte[] buffer, int start, int length) {
         *              if (over == 0) {
         *                      over = audioStream.Read(temp, 0, temp.Length);
         *                      inFrame.Update(over / inWaveFormat.BlockAlign, temp);
         *                      double[] input = new double[inFrame.SampleCount];
         *                      double* frameData = (double*) inFrame.Data[0];
         *                      for (int i = 0; i < input.Length; i++) {
         *                              input[i] = frameData[i * 2];
         *                      }
         *                      double[] output = new double[convolver.GetOutLength(input.Length)];
         *                      int len = convolver.Convolve(input, 0, input.Length, output, 0, output.Length);
         *
         *                      if (resampler != null) {
         *
         *                      }
         *              }
         *
         *              return 0;
         *      }
         *
         *      public void Resample(WaveFormat format) {
         *              resampler = new AudioResampler(
         *                      new AudioFormat(Format.SampleRate, Format.ValidBitsPerSample, Format.Channels),
         *                      new AudioFormat(format.SampleRate, format.ValidBitsPerSample, format.Channels)
         *                      );
         *              outFrame = new AudioFrame(new AudioFormat(format.SampleRate, format.Channels, format.ValidBitsPerSample, true));
         *      }
         * }
         */

        static void Main(string[] args)
        {
            var audioStream = new AudioStream(File.OpenRead(@"D:\MyDocuments\Downloads\09 - Interlude~ネムル森~2.flac"));

            using (var wasapi = new WasapiOut(ShareMode.Exclusive, true, Role.Multimedia, 640)) {
                wasapi.Resample += (sender, e) => {
                    audioStream.Resample(e.OutFormat);
                };
                wasapi.Initialize(audioStream);
                wasapi.Play();
                Console.WriteLine("播放...");
                Console.ReadKey();
            }
            Console.WriteLine("释放");
        }