Ejemplo n.º 1
0
 public void SetAudioChannelCount(int channels)
 {
     channels = SynthHelper.ClampI(channels, 1, 2);
     if (AudioChannels != channels)
     {
         AudioChannels = channels;
         SampleBuffer  = new SampleArray((MicroBufferSize * MicroBufferCount * AudioChannels));
     }
 }
Ejemplo n.º 2
0
        public Synthesizer(int sampleRate, int audioChannels, int bufferSize, int bufferCount, int polyphony)
        {
            var MinSampleRate = 8000;
            var MaxSampleRate = 96000;

            if (sampleRate < MinSampleRate || sampleRate > MaxSampleRate)
            {
                throw new Exception("Invalid paramater: (sampleRate) Valid ranges are " + MinSampleRate + " to " +
                                    MaxSampleRate);
            }
            if (audioChannels < 1 || audioChannels > 2)
            {
                throw new Exception("Invalid paramater: (audioChannels) Valid ranges are " + 1 + " to " + 2);
            }

            _midiMessageProcessed = new FastList <Action <MidiEvent> >();
            //
            // Setup synth parameters
            _synthGain    = 0.35f;
            _masterVolume = 1;

            SampleRate      = sampleRate;
            AudioChannels   = audioChannels;
            MicroBufferSize = SynthHelper.ClampI(bufferSize, (int)(SynthConstants.MinBufferSize * sampleRate),
                                                 (int)(SynthConstants.MaxBufferSize * sampleRate));
            MicroBufferSize =
                (int)
                (Math.Ceiling(MicroBufferSize / (double)SynthConstants.DefaultBlockSize) *
                 SynthConstants.DefaultBlockSize);     //ensure multiple of block size
            MicroBufferCount = (Math.Max(1, bufferCount));
            SampleBuffer     = new SampleArray((MicroBufferSize * MicroBufferCount * audioChannels));
            LittleEndian     = true;

            //Setup Controllers
            _synthChannels = new SynthParameters[SynthConstants.DefaultChannelCount];
            for (int x = 0; x < _synthChannels.Length; x++)
            {
                _synthChannels[x] = new SynthParameters(this);
            }
            //Create synth voices
            _voiceManager = new VoiceManager(SynthHelper.ClampI(polyphony, SynthConstants.MinPolyphony, SynthConstants.MaxPolyphony));
            //Create midi containers
            MidiEventQueue  = new LinkedList <SynthEvent>();
            MidiEventCounts = new int[MicroBufferCount];
            _layerList      = new Patch[15];

            _midiMessageProcessed = new FastList <Action <MidiEvent> >();
            ResetSynthControls();
        }
Ejemplo n.º 3
0
        public Synthesizer(int sampleRate, int audioChannels, int bufferSize, int bufferCount, int polyphony)
        {
            var MinSampleRate = 8000;
            var MaxSampleRate = 96000;

            //
            // Setup synth parameters
            MasterVolume = 1;

            SampleRate       = SynthHelper.ClampI(sampleRate, MinSampleRate, MaxSampleRate);
            MicroBufferSize  = SynthHelper.ClampI(bufferSize, (int)(SynthConstants.MinBufferSize * sampleRate), (int)(SynthConstants.MaxBufferSize * sampleRate));
            MicroBufferSize  = (int)(Math.Ceiling(MicroBufferSize / (double)SynthConstants.DefaultBlockSize) * SynthConstants.DefaultBlockSize); //ensure multiple of block size
            MicroBufferCount = (Math.Max(1, bufferCount));
            SampleBuffer     = new SampleArray((MicroBufferSize * MicroBufferCount * audioChannels));

            // Setup Controllers
            _synthChannels = new SynthParameters[SynthConstants.DefaultChannelCount];
            for (int x = 0; x < _synthChannels.Length; x++)
            {
                _synthChannels[x] = new SynthParameters(this);
            }

            // setup metronome channel
            _metronomeChannel = _synthChannels.Length - 1;

            // Create synth voices
            _voiceManager = new VoiceManager(SynthHelper.ClampI(polyphony, SynthConstants.MinPolyphony, SynthConstants.MaxPolyphony));

            // Create midi containers
            _midiEventQueue  = new LinkedList <SynthEvent>();
            _midiEventCounts = new int[MicroBufferCount];
            _layerList       = new Patch[15];

            _mutedChannels = new FastDictionary <int, bool>();
            _soloChannels  = new FastDictionary <int, bool>();

            ResetSynthControls();
        }