コード例 #1
0
 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();
 }
コード例 #2
0
ファイル: Audio.cs プロジェクト: bisquitthe/RockNRolla
        public void Play()
        {
            asioOut = new AsioOut(settings.DeviceNumber);

            inputAudioBufferedWaveProvider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(Convert.ToInt32(settings.SampleRate), 1));
            incomingAudioBufferedWaveProvider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(Convert.ToInt32(settings.SampleRate), 1));

            inputAudioPanningProvider = new PanningSampleProvider(inputAudioBufferedWaveProvider.ToSampleProvider());
            incomingAudioPanningProvider = new PanningSampleProvider(incomingAudioBufferedWaveProvider.ToSampleProvider());

            inputAudioPanningProvider.Pan = 0.0f;

            mixingProvider = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(Convert.ToInt32(settings.SampleRate), 2));

            mixingProvider.AddMixerInput(inputAudioPanningProvider);
            mixingProvider.AddMixerInput(incomingAudioPanningProvider);
            mixingProvider.ReadFully = true;

            asioOut.InitRecordAndPlayback(new SampleToWaveProvider(mixingProvider), 2, Convert.ToInt32(settings.SampleRate));
            incomingBytes = new byte[Settings.GetInstance().BufferSize * 4];
            asioOut.AudioAvailable += AsioOut_AudioAvailable;
            asioOut.Play();
            connection.Connected += delegate (object source, EventArgs args)
            {
                inputAudioPanningProvider.Pan = +1.0f;
                incomingAudioPanningProvider.Pan = -1.0f;
                isAudioReceiving = true;
                isNewAudioAvailable = false;
                receivingAudio.Start();
            };
            connection.Disconnected += delegate (object source, EventArgs args)
            {
                inputAudioPanningProvider.Pan = 0.0f;
                isAudioReceiving = false;
            };
            connection.StartMessageReceiving();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: DrA1ex/GuitarSynthesizer
        public static void PlaySong(IEnumerable<Track> tracks)
        {
            var enumerator = new MMDeviceEnumerator();
            var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            var waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(defaultDevice.AudioClient.MixFormat.SampleRate, 1);

            var wasapiOut = new WasapiOut(AudioClientShareMode.Shared, false, 60);
            MediaBankBase bank = new FenderStratCleanB(waveFormat);
            MediaBankBase bankBass = new RockdaleBassBridge(waveFormat);

            var mixer = new MixingSampleProvider(waveFormat);

            var trackSampleProviders =
                tracks.Select(t => new TrackSampleProvider(t.Patch == MediaPatch.CleanGuitar ? bank : bankBass, t))
                    .ToArray();
            var playedTracks = new List<int>();

            foreach(var track in trackSampleProviders)
            {
                track.OnPhrasePlaying += (sender, args) =>
                {
                    var channel = args.Track.Channel;
                    var phrase = args.Phrase;

                    if(playedTracks.Contains(channel))
                    {
                        AsyncConsole.WriteLine();
                        PrintUtils.PrintContentTable();

                        playedTracks.Clear();
                    }

                    PrintUtils.PrintContent(phrase.Notes != null && phrase.Notes.Length > 0
                        ? string.Join(",", phrase.Notes)
                        : phrase.Command.ToString(), channel);

                    playedTracks.Add(channel);
                };
                mixer.AddMixerInput(track);
            }

            wasapiOut.Init(new VolumeSampleProvider(mixer)
            {
                Volume = 0.7f
            });

            PrintUtils.Init(trackSampleProviders.Length);

            PrintUtils.PrintHeaderOfTable();
            PrintUtils.PrintRowDividerTable();
            PrintUtils.PrintContentTable();

            wasapiOut.Play();

            var resetEvent = new ManualResetEvent(false);

            wasapiOut.PlaybackStopped += (sender, args) =>
            {
                resetEvent.Set();
                if(args.Exception != null)
                {
                    throw args.Exception;
                }
            };

            resetEvent.WaitOne();
            Console.WriteLine();
            PrintUtils.PrintFooterOfTable();
        }
コード例 #5
0
        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));
        }