/// <summary> /// Adds a WaveProvider as a Mixer input. /// Must be PCM or IEEE float already /// </summary> /// <param name="mixerInput">IWaveProvider mixer input</param> /*public void AddMixerInput(IWaveProvider mixerInput) * { * AddMixerInput(SampleProviderConverters.ConvertWaveProviderIntoSampleProvider(mixerInput)); * }*/ /// <summary> /// Adds a new mixer input /// </summary> /// <param name="mixerInput">Mixer input</param> public void AddMixerInput(MixerChannel mixerInput) { // we'll just call the lock around add since we are protecting against an AddMixerInput at // the same time as a Read, rather than two AddMixerInput calls at the same time lock (sources) { if (this.sources.Count >= maxInputs) { throw new InvalidOperationException("Too many mixer inputs"); } this.sources.Add(mixerInput); } if (this.waveFormat == null) { this.waveFormat = mixerInput.sampleProvider.WaveFormat; } else { if (this.WaveFormat.SampleRate != mixerInput.sampleProvider.WaveFormat.SampleRate || this.WaveFormat.Channels != mixerInput.sampleProvider.WaveFormat.Channels) { throw new ArgumentException("All mixer inputs must have the same WaveFormat"); } } }
// Called when data for any output pin is requested. public void Evaluate(int SpreadMax) { if ((FGain.IsChanged || startUp) && FMix != null) { FMix.gainCount = FGain.SliceCount; for (int i = 0; i < Math.Max(FGain.SliceCount, GainMixingSampleProvider.maxInputs); i++) { FMix.gain[i] = FGain[i]; } if (startUp) { startUp = false; } } if (FOutput[0] != this) { FMix = new GainMixingSampleProvider(this.WaveFormat); FMix.ReadFully = true; FOutput[0] = this; } for (int i = 0; i < FInputs.SliceCount; i++) { if (FInputs[i].IOObject.IsChanged) { FNeedsUpdate = true; } } if (FNeedsUpdate) { if (FMix != null) { FMix.RemoveAllMixerInputs(); for (int i = 0; i < FInputs.SliceCount; i++) { if (FInputs[i].IOObject[0] != null) { MixerChannel newChan = new MixerChannel(); newChan.index = i; newChan.sampleProvider = FInputs[i].IOObject[0]; FMix.AddMixerInput(newChan); } } } FNeedsUpdate = false; } }
/// <summary> /// Adds a WaveProvider as a Mixer input. /// Must be PCM or IEEE float already /// </summary> /// <param name="mixerInput">IWaveProvider mixer input</param> /*public void AddMixerInput(IWaveProvider mixerInput) { AddMixerInput(SampleProviderConverters.ConvertWaveProviderIntoSampleProvider(mixerInput)); }*/ /// <summary> /// Adds a new mixer input /// </summary> /// <param name="mixerInput">Mixer input</param> public void AddMixerInput(MixerChannel mixerInput) { // we'll just call the lock around add since we are protecting against an AddMixerInput at // the same time as a Read, rather than two AddMixerInput calls at the same time lock (sources) { if (this.sources.Count >= maxInputs) { throw new InvalidOperationException("Too many mixer inputs"); } this.sources.Add(mixerInput); } if (this.waveFormat == null) { this.waveFormat = mixerInput.sampleProvider.WaveFormat; } else { if (this.WaveFormat.SampleRate != mixerInput.sampleProvider.WaveFormat.SampleRate || this.WaveFormat.Channels != mixerInput.sampleProvider.WaveFormat.Channels) { throw new ArgumentException("All mixer inputs must have the same WaveFormat"); } } }