コード例 #1
0
        public Synthesizer(int sampleRate, int audioChannels, int bufferSize, int bufferCount, int polyphony)
        {
            const int MinSampleRate = 8000;
            const int MaxSampleRate = 96000;

            //Setup synth parameters
            if (sampleRate < MinSampleRate || sampleRate > MaxSampleRate)
            {
                throw new ArgumentException("Invalid paramater: (sampleRate) Valid ranges are " + MinSampleRate + " to " + MaxSampleRate, "sampleRate");
            }
            this.sampleRate = sampleRate;
            if (audioChannels < 1 || audioChannels > 2)
            {
                throw new ArgumentException("Invalid paramater: (audioChannels) Valid ranges are " + 1 + " to " + 2, "audioChannels");
            }
            this.audioChannels    = audioChannels;
            this.microBufferSize  = SynthHelper.Clamp(bufferSize, (int)(MinBufferSize * sampleRate), (int)(MaxBufferSize * sampleRate));
            this.microBufferSize  = (int)Math.Ceiling(this.microBufferSize / (double)DefaultBlockSize) * DefaultBlockSize; //ensure multiple of block size
            this.microBufferCount = Math.Max(1, bufferCount);
            sampleBuffer          = new float[microBufferSize * microBufferCount * audioChannels];
            littleEndian          = true;
            //Setup Controllers
            synthChannels = new SynthParameters[DefaultChannelCount];
            for (int x = 0; x < synthChannels.Length; x++)
            {
                synthChannels[x] = new SynthParameters(this);
            }
            //Create synth voices
            voiceManager = new VoiceManager(SynthHelper.Clamp(polyphony, MinPolyphony, MaxPolyphony));
            //Create midi containers
            midiEventQueue  = new Queue <MidiMessage>();
            midiEventCounts = new int[this.microBufferCount];
            layerList       = new Patch[15];
        }
コード例 #2
0
        public Synthesizer(int sampleRate, int audioChannels, int bufferSize, int bufferCount, int polyphony)
        {
            const int MinSampleRate = 8000;
            const int MaxSampleRate = 96000;

            //Setup synth parameters
            if (sampleRate < MinSampleRate || sampleRate > MaxSampleRate)
            {
                throw new ArgumentException("Invalid paramater: (sampleRate) Valid ranges are " + MinSampleRate + " to " + MaxSampleRate, "sampleRate");
            }
            this.sampleRate = sampleRate;
            if (audioChannels < 1 || audioChannels > 2)
            {
                throw new ArgumentException("Invalid paramater: (audioChannels) Valid ranges are " + 1 + " to " + 2, "audioChannels");
            }
            this.audioChannels    = audioChannels;
            this.microBufferSize  = SynthHelper.Clamp(bufferSize, (int)(MinBufferSize * sampleRate), (int)(MaxBufferSize * sampleRate));
            this.microBufferSize  = (int)Math.Ceiling(this.microBufferSize / (double)DefaultBlockSize) * DefaultBlockSize; //ensure multiple of block size
            this.microBufferCount = Math.Max(1, bufferCount);
            sampleBuffer          = new float[microBufferSize * microBufferCount * audioChannels];
            littleEndian          = true;
            //Setup Controllers
            bankSelect       = new int[DefaultChannelCount];
            programs         = new int[DefaultChannelCount];
            channelPressure  = new float[DefaultChannelCount];
            pan              = new short[DefaultChannelCount];
            volume           = new short[DefaultChannelCount];
            expression       = new short[DefaultChannelCount];
            modRange         = new short[DefaultChannelCount];
            pitchBend        = new short[DefaultChannelCount];
            pitchBendRange   = new short[DefaultChannelCount];
            masterCoarseTune = new short[DefaultChannelCount];
            masterFineTune   = new short[DefaultChannelCount];
            holdPedal        = new bool[DefaultChannelCount];
            rpn              = new short[DefaultChannelCount];
            modWheel         = new double[DefaultChannelCount];
            panPositions     = new PanComponent[DefaultChannelCount];
            totalPitch       = new int[DefaultChannelCount];
            totalVolume      = new float[DefaultChannelCount];
            //set controls to default values
            ResetSynthControls();
            //create synth voices
            voiceManager = new VoiceManager(SynthHelper.Clamp(polyphony, MinPolyphony, MaxPolyphony), this);
            //create midi containers
            midiEventQueue  = new Queue <MidiMessage>();
            midiEventCounts = new int[this.microBufferCount];
        }
コード例 #3
0
ファイル: Synthesizer.Main.cs プロジェクト: n-yoda/unity-midi
 public Synthesizer(int sampleRate, int audioChannels, int bufferSize, int bufferCount, int polyphony)
 {
     const int MinSampleRate = 8000;
     const int MaxSampleRate = 96000;
     //Setup synth parameters
     if (sampleRate < MinSampleRate || sampleRate > MaxSampleRate)
         throw new ArgumentException("Invalid paramater: (sampleRate) Valid ranges are " + MinSampleRate + " to " + MaxSampleRate, "sampleRate");
     this.sampleRate = sampleRate;
     if (audioChannels < 1 || audioChannels > 2)
         throw new ArgumentException("Invalid paramater: (audioChannels) Valid ranges are " + 1 + " to " + 2, "audioChannels");
     this.audioChannels = audioChannels;
     this.microBufferSize = SynthHelper.Clamp(bufferSize, (int)(MinBufferSize * sampleRate), (int)(MaxBufferSize * sampleRate));
     this.microBufferSize = (int)Math.Ceiling(this.microBufferSize / (double)DefaultBlockSize) * DefaultBlockSize; //ensure multiple of block size
     this.microBufferCount = Math.Max(1, bufferCount);
     sampleBuffer = new float[microBufferSize * microBufferCount * audioChannels];
     littleEndian = true;
     //Setup Controllers
     synthChannels = new SynthParameters[DefaultChannelCount];
     for (int x = 0; x < synthChannels.Length; x++)
         synthChannels[x] = new SynthParameters(this);            
     //Create synth voices
     voiceManager = new VoiceManager(SynthHelper.Clamp(polyphony, MinPolyphony, MaxPolyphony));
     //Create midi containers
     midiEventQueue = new Queue<MidiMessage>();
     midiEventCounts = new int[this.microBufferCount];
     layerList = new Patch[15]; 
 }