Пример #1
0
 public static void PlayGameSound(GameSound sound)
 {
     //var isSubscribed = SubscriptionModule.Get().IsSubscribed ?? false;
     //if (isSubscribed == false)return;
     if (Prefs.EnableGameSound == false)
     {
         return;
     }
     Log.InfoFormat("Playing game sound {0}", sound.Name);
     if (!sound.Src.ToLowerInvariant().EndsWith(".mp3"))
     {
         Log.InfoFormat("Playing game sound {0} as wav", sound.Name);
         PlaySound(sound.Src);
         return;
     }
     Task.Factory.StartNew(() =>
     {
         try
         {
             Log.InfoFormat("Playing game sound {0} as mp3", sound.Name);
             var mp3Reader = new Mp3FileReader(sound.Src);
             var stream    = new WaveChannel32(mp3Reader)
             {
                 PadWithZeroes = false
             };
             DisposeObjects.Add(mp3Reader);
             DisposeObjects.Add(stream);
             {
                 stream.Position = 0;
                 Mixer.AddMixerInput(stream);
                 lock (Mixer)
                 {
                     if (WaveOut == null)
                     {
                         Log.Info("Starting up wave out");
                         WaveOut = new WaveOutEvent();
                         WaveOut.Init(new SampleToWaveProvider(Mixer));
                         WaveOut.PlaybackStopped += (sender, args) =>
                         {
                             WaveOut.Dispose();
                             WaveOut = null;
                         };
                         WaveOut.Play();
                     }
                 }
                 Log.InfoFormat("Initializing game sound {0} as mp3", sound.Name);
             }
         }
         catch (Exception e)
         {
             Log.Warn("PlayGameSound Error", e);
             Program.GameMess.Warning("Cannot play sound {0}, it must be in the format 44100:2", sound.Name);
         }
     });
 }
Пример #2
0
 private void AddMixerInput(ISampleProvider input)
 {
     try
     {
         mixer.AddMixerInput(ConvertToRightChannelCount(input));
     }
     catch (ArgumentException)
     {
         // COS TUTAJ JEST BARDZO NIE TAK, ALE NIE ROZUMIEM
     }
 }
Пример #3
0
        private static void PlaySound(MixingSampleProvider mixer, CachedSound sound, SampleControl sampleControl,
                                      out ISampleProvider rootSample)
        {
            if (sound == null)
            {
                rootSample = default;
                return;
            }

            mixer.AddMixerInput(new CachedSoundSampleProvider(sound), sampleControl, out rootSample);
        }
Пример #4
0
        private void AddMixerInput(ISampleProvider input)
        {
            if (!Playing)
            {
                Playing = true;
                PlaybackStarted(this, new PlaybackEventArgs());
            }

            MixerInputsCount++;
            mixer.AddMixerInput(ConvertToRightChannelCount(input));
        }
Пример #5
0
        public PlaybackTrack(MixingSampleProvider parent)
        {
            parentMixer = parent;
            mixer       = new MixingSampleProvider(parent.WaveFormat)
            {
                ReadFully = true
            };
            meter = new MeteringSampleProvider(mixer);

            parentMixer.AddMixerInput(meter);
        }
Пример #6
0
 public void StartNote(string note)
 {
     byte[] data;
     if (sampleData.TryGetValue(note, out data))
     {
         var sampleStream   = new RawSourceWaveStream(new MemoryStream(data), new WaveFormat(44100, 32, 1));
         var sampleProvider = sampleStream.ToSampleProvider();
         mixerInputs[note] = sampleProvider;
         mixer.AddMixerInput(sampleProvider);
     }
 }
Пример #7
0
 private void StartPlayback()
 {
     masterMix = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 2));
     foreach (var source in trackSources)
     {
         masterMix.AddMixerInput(source);
     }
     outDevice = new WaveOutEvent();
     outDevice.Init(masterMix);
     outDevice.Play();
 }
Пример #8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var nota_do = new SignalGenerator(44100, 1)
            {
                Gain      = 0.5,
                Frequency = 730.8,
                Type      = SignalGeneratorType.Sin
            }.Take(TimeSpan.FromMilliseconds(250));

            mixer.AddMixerInput(nota_do);
        }
Пример #9
0
 private void AddMixerInput(ISampleProvider input)
 {
     try
     {
         mixer.AddMixerInput(ConvertToRightChannelCount(input));
     }
     catch (InvalidOperationException ioe)
     {
         Console.WriteLine("Error: AudioPlaybackEngine failure due to " + ioe);
     }
 }
Пример #10
0
        private static void PlaySound(MixingSampleProvider mixer, CachedSound sound, float volume, float balance,
                                      out ISampleProvider rootSample)
        {
            if (sound == null)
            {
                rootSample = default;
                return;
            }

            mixer.AddMixerInput(new CachedSoundSampleProvider(sound), volume, balance, out rootSample);
        }
Пример #11
0
        public void StartNote(string note)
        {
            string file;

            if (noteFiles.TryGetValue(note, out file))
            {
                var reader = new AudioFileReader("samples\\" + file);
                mixerInputs[note] = reader;
                mixer.AddMixerInput((ISampleProvider)reader);
            }
        }
Пример #12
0
        public void PlayMusic(string fileName)
        {
            var vorbisStream = new NAudio.Vorbis.VorbisWaveReader(fileName);

            try
            {
                mixer.AddMixerInput((IWaveProvider)vorbisStream);
            }
            catch (ArgumentException)
            {
            }
        }
Пример #13
0
        public async Task Invoke(DataModel model, PipelineDelegate <DataModel> next)
        {
            var buffer = _buffers.GetOrAdd(model.Guid, (guid) =>
            {
                var dictionaryBuffer = new BufferedWaveProvider(_format);
                _mixer.AddMixerInput(dictionaryBuffer);
                return(dictionaryBuffer);
            });

            buffer.AddSamples(model.RawAudioSample, 0, model.RawAudioSample.Length);
            await next.Invoke(model);
        }
Пример #14
0
        public static void AddMixerInput(this MixingSampleProvider mixer, ISampleProvider input,
                                         SampleControl sampleControl, out ISampleProvider rootSample)
        {
            var adjustVolume  = input.AddToAdjustVolume(sampleControl.Volume);
            var adjustBalance = adjustVolume.AddToBalanceProvider(sampleControl.Balance);

            sampleControl.VolumeChanged  = f => adjustVolume.Volume = f;
            sampleControl.BalanceChanged = f => adjustBalance.Balance = f;

            rootSample = adjustBalance;
            mixer.AddMixerInput(adjustBalance);
        }
Пример #15
0
 public ISampleProvider play(ISampleProvider source)
 {
     lock (_lock) {
         try {
             source = SFXUtilities.ConvertSampleFormat(source, mixer.WaveFormat);
             mixer.AddMixerInput(source);
             return(source);
         } catch (UnsupportedAudioException) {
             return(null);
         }
     }
 }
Пример #16
0
 public static void Connected(ushort Id)
 {
     if (Active)
     {
         byte[] silence = new byte[10000];
         Array.Clear(silence, 0, 5000);
         BufferedWaveProvider player = new BufferedWaveProvider(new WaveFormat(48000, 16, 1));
         players[Id] = player;
         player.AddSamples(silence, 0, 5000);
         mixer.AddMixerInput(player.ToSampleProvider());
     }
 }
Пример #17
0
 /// <summary>
 /// Add track to the mixer (to play it)
 /// </summary>
 /// <param name="provider">Track to add</param>
 public void AddTrackNoOffset(ISampleProvider provider)
 {
     try
     {
         //Console.WriteLine("addind " + provider.ToString());
         mixer.AddMixerInput(provider);
     }
     catch (ArgumentException)
     {
         MessageBox.Show("File not recorded using Virtual Loop Pedal or recorded with different settings.", "Wrong file format");
     }
 }
        public void Init()
        {
            buffer = new BufferedWaveProvider(new WaveFormat(mixer.WaveFormat.SampleRate, 16, mixer.WaveFormat.Channels));
            buffer.BufferDuration          = TimeSpan.FromSeconds(10);
            buffer.DiscardOnBufferOverflow = true;
            sampleProvider = buffer.ToSampleProvider();
            mixer.AddMixerInput(sampleProvider);

            SpeakMessage(new TextToSpeechMessage()
            {
                Message = "IL2-SRS Text to Speech Active"
            });
        }
Пример #19
0
        public void StartWave(Double frequency)
        {
            // if this method is being called twice in a row before the call to StopWave...
            if (isStopped == false)
            {
                StopWave();
                Console.WriteLine("Consecutive StartWave call detected");
            }

            //if primary oscillator is active, chain effects
            if (primaryOscillator)
            {
                //wrap signal generator in adsr envelope and add to mixer
                //order of processing is Signal -> LPF -> ADSR -> Mixer
                sigGen1Array[_oscIndex].Frequency = DetuneOctave(frequency, OscillatorIndex.Primary);
                lpf1Array[_oscIndex]  = new LowPassFilterSampleProvider(sigGen1Array[_oscIndex].ToWaveProvider().ToSampleProvider());
                adsr1Array[_oscIndex] = new AdsrSampleProvider(sigGen1Array[_oscIndex].ToWaveProvider().ToSampleProvider(), primaryAttack, primaryDecay, primarySustain, primaryRelease);
                mixingSampleProvider.AddMixerInput(adsr1Array[_oscIndex]);
            } //same chaining process for secondary oscillator
            if (secondaryOscillator)
            {
                sigGen2Array[_oscIndex].Frequency = DetuneOctave(frequency, OscillatorIndex.Secondary);
                lpf2Array[_oscIndex]  = new LowPassFilterSampleProvider(sigGen2Array[_oscIndex].ToWaveProvider().ToSampleProvider());
                adsr2Array[_oscIndex] = new AdsrSampleProvider(sigGen2Array[_oscIndex].ToWaveProvider().ToSampleProvider(), secondaryAttack, secondaryDecay, secondarySustain, secondaryRelease);
                mixingSampleProvider.AddMixerInput(adsr2Array[_oscIndex]);
            }

            isStopped = false;

            //add LFO signalto mixer
            //if (LFO)
            //{
            //    LFSignalGenerator.Frequency = 5;
            //    OffsetSampleProvider offsetSampleProvider = new OffsetSampleProvider(LFSignalGenerator.ToWaveProvider().ToSampleProvider());
            //    mixingSampleProvider.AddMixerInput(offsetSampleProvider);
            //}
            // increment the play index upon each play
            // _oscIndex = _oscIndex == _polyPhony - 1 ? 0 : _oscIndex + 1;
        }
Пример #20
0
 public static void QueuePlay(int key, byte[] bytes, int count)
 {
     if (!Providers.ContainsKey(key))
     {
         Main.Log("Creating new Buffered Wave Provider for key '" + key + "'");
         BufferedWaveProvider bufferedWave = new BufferedWaveProvider(GetFormat());
         bufferedWave.BufferLength = (32 / 8) * SAMPLE_RATE * CHANNELS * 5; // 5 seconds of buffer.
         Mixer.AddMixerInput(bufferedWave);
         Providers[key] = bufferedWave;
     }
     Providers[key].AddSamples(bytes, 0, count);
     //Main.Log("Buffer @ " + Math.Round((float)Providers[key].BufferedBytes / Providers[key].BufferLength * 100f) + "%");
 }
Пример #21
0
        public void InitTracks(string songName)
        {
            if (!string.IsNullOrWhiteSpace(SongDirectory))
            {
                MapReader = new FileMapReader(SongDirectory + "\\mapping.txt");

                bool     isMSPInit = false;
                string[] tracks    = MapReader.GetAvailableTracks(songName);

                string musicDirectory = SongDirectory + "\\";

                loopSampleProviders   = new List <LoopSampleProvider>();
                volumeSampleProviders = new Dictionary <string, VolumeSampleProvider>();

                foreach (var track in tracks)
                {
                    string trackFile = MapReader.GetValue(songName, track);
                    int    loopStart = int.Parse(MapReader.GetValue(songName, "loop_start"));
                    int    loopEnd   = int.Parse(MapReader.GetValue(songName, "loop_end"));

                    int.TryParse(MapReader.GetValue(songName, "dly_" + track), out int startSample);

                    var reader = new CustomVorbisWaveReader(musicDirectory + trackFile);
                    loopSampleProviders.Add(new LoopSampleProvider(reader, loopStart, loopEnd, startSample)
                    {
                        Loop = Loop
                    });
                    volumeSampleProviders.Add(track, new VolumeSampleProvider(loopSampleProviders.Last())
                    {
                        Volume = 0.0f
                    });

                    Console.WriteLine($"Added track \"{track}\" for song \"{songName}\".");
                    Console.WriteLine();
                    Console.WriteLine($"Start offset is {startSample}.");
                    Console.WriteLine();

                    if (!isMSPInit)
                    {
                        mixingSampleProvider = new MixingSampleProvider(loopSampleProviders.First().WaveFormat);
                        isMSPInit            = true;
                    }

                    mixingSampleProvider.AddMixerInput(volumeSampleProviders.Last().Value);
                }

                currentSong = songName;

                MapReader.Dispose();
            }
        }
Пример #22
0
        public Task PlayAsync(PewPewPatch patch)
        {
            var synth = _synths.Take();

            synth.Play(patch);

            var tcs = new TaskCompletionSource <byte>(TaskCreationOptions.RunContinuationsAsynchronously);

            _tcsByProvider.Add(synth, tcs);

            _mixer.AddMixerInput(synth);

            return(tcs.Task);
        }
Пример #23
0
        public ReceiverSampleProvider(WaveFormat waveFormat, ushort id, int voiceInputNumber)
        {
            WaveFormat = waveFormat;
            ID         = id;

            mixer = new MixingSampleProvider(WaveFormat)
            {
                ReadFully = true
            };

            voiceInputs = new List <CallsignSampleProvider>();
            for (int i = 0; i < voiceInputNumber; i++)
            {
                var voiceInput = new CallsignSampleProvider(WaveFormat, this);
                voiceInputs.Add(voiceInput);
                mixer.AddMixerInput(voiceInput);
            }
            ;

            blockTone = new BlockingToneSampleProvider(WaveFormat.SampleRate, 1)
            {
                Frequency = 180, Gain = 0
            };
            hfWhiteNoise = new ResourceSoundSampleProvider(Samples.Instance.HFWhiteNoise)
            {
                Looping = true, Gain = 0
            };

            mixer.AddMixerInput(blockTone.ToMono());
            if (!AudioConfig.Instance.HfSquelch)
            {
                mixer.AddMixerInput(hfWhiteNoise.ToMono());
            }
            volume = new VolumeSampleProvider(mixer);

            hfSquelchEn = AudioConfig.Instance.HfSquelch;
        }
Пример #24
0
        private ISampleProvider CreateSignal(float frequency, int duration, bool addToMixer = false)
        {
            var sampleProvider = new SignalGenerator(44100, 1)
            {
                Gain      = 0.2,
                Frequency = frequency,
                Type      = signalType
            }
            .Take(TimeSpan.FromMilliseconds(duration));

            if (addToMixer)
            {
                mixer.AddMixerInput(sampleProvider);
            }
            return(sampleProvider);
        }
        public int Read(float[] buffer, int offset, int count)
        {
            foreach (var mixerInput in Sequencer.GetNextMixerInputs(count))
            {
                mixer.AddMixerInput(mixerInput);
            }

            // now we just need to read from the mixer
            var samplesRead = mixer.Read(buffer, offset, count);

            while (samplesRead < count)
            {
                buffer[samplesRead++] = 0;
            }
            return(samplesRead);
        }
Пример #26
0
        // add mixer input
        public void AddMixerInput(ISampleProvider sampler, string closedCaption, float closedCaptionDuration)
        {
            mixer.AddMixerInput(sampler);
            float targetTime = StateMachine.totalGameTime + 3;

#if ADD_CLOSED_CAPTIONS
            if (closedCaptions.ContainsKey(closedCaption) == false)
            {
                closedCaptions.Add(closedCaption, StateMachine.totalGameTime + 3);
            }
            else
            {
                closedCaptions[closedCaption] = targetTime;
            }
#endif
        }
Пример #27
0
 public void Start()
 {
     _activeStream = new StreamedSampleProvider();
     try
     {
         _mixer           = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 1));
         _mixer.ReadFully = true;
         _outputDevice    = new WaveOutEvent();
         _outputDevice.Init(_mixer);
         _mixer.AddMixerInput(_activeStream);
         _outputDevice.Play();
     }
     catch (NAudio.MmException)
     {
         _outputDevice = null;
     }
 }
Пример #28
0
        public ISampleProvider Play(float volume)
        {
            ISampleProvider sampleProvider = new VorbisSampleProvider(new MemoryStream(Data));

            if (volume != 1.0f)
            {
                VolumeSampleProvider volumeProvider = new VolumeSampleProvider(sampleProvider);
                volumeProvider.Volume = volume;

                sampleProvider = volumeProvider;
            }

            _mixer.AddMixerInput(sampleProvider);
            _outputDevice.Play();

            return(sampleProvider);
        }
Пример #29
0
        private void PlayKeySound(string tone, object sender)
        {
            if (isPressed[tone] == true)
            {
                return;
            }
            isPressed[tone] = true;
            sampleProvider  = new AudioFileReader($@"..\..\Resources\{tembre}\{tone}.wav");
            mixer.AddMixerInput(sampleProvider);

            Button button = sender as Button;

            if (button != null)
            {
                button.BackColor = Color.LightBlue;
            }
        }
Пример #30
0
 public void ExportAudio()
 {
     Export = true;
     if (firstCheck)
     {
         BuildAudio(DocManager.Inst.Project);
         firstCheck = false;
     }
     else if (pendingParts == 0)
     {
         masterMix = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 2));
         foreach (var source in trackSources)
         {
             masterMix.AddMixerInput(source);
         }
         WaveFileWriter.CreateWaveFile("Export.wav", masterMix.ToWaveProvider());
     }
 }