public SynthWaveProvider(Synthesizer synth, MidiFileSequencer mseq)
 {
     this.synth = synth;
     this.mseq = mseq;
     waveFormat = new WaveFormat(synth.SampleRate, 16, synth.AudioChannels);
     int bufferSize = (int)Math.Ceiling((2.0 * waveFormat.AverageBytesPerSecond) / synth.RawBufferSize) * synth.RawBufferSize;
     circularBuffer = new CircularBuffer(bufferSize);
     sbuff = new byte[synth.RawBufferSize];
     state = PlayerState.Stopped;
 }
        public SynthThread()
        {
            synth = new Synthesizer(Properties.Settings.Default.SampleRate, 2, Properties.Settings.Default.BufferSize, Properties.Settings.Default.BufferCount, Properties.Settings.Default.poly);
            mseq = new MidiFileSequencer(synth);
            synth_provider = new SynthWaveProvider(synth, mseq);

			if (Type.GetType ("Mono.Runtime") == null) { // if we are running on windows, use Microsoft DirectSound
				direct_out = new DirectSoundOutBroker (Properties.Settings.Default.Latency);
			} else { // if running on mono, then we should be on linux or mac. therefore, use OpenAL instead (actually, it should be better using OpenAL for everything
				direct_out = new OpenALSoundOut(Properties.Settings.Default.Latency);
			}

            direct_out.Init(synth_provider);
        }
Exemple #3
0
        public void Awake()
        {
            synthesizer = new Synthesizer(sampleRate, channel, bufferSize, 1);
            sequencer = new MidiFileSequencer(synthesizer);
            audioSource = GetComponent<AudioSource>();

            if (loadOnAwake)
            {
                LoadBank(new PatchBank(bankSource));
                LoadMidi(new MidiFile(midiSource));
            }

            if (playOnAwake)
            {
                Play();
            }
        }
Exemple #4
0
 //--Public Methods
 public VoiceManager(int voiceCount, Synthesizer synth)
 {
     stealingMethod = VoiceStealingMethod.Oldest;
     polyphony      = voiceCount;
     //initialize voice containers
     voicePool = new Voice[voiceCount];
     VoiceNode[] nodes = new VoiceNode[voiceCount];
     for (int x = 0; x < voicePool.Length; x++)
     {
         voicePool[x] = new Voice(synth);
         nodes[x]     = new VoiceNode();
     }
     vnodes = new Stack <VoiceNode>(nodes);
     //free voice list
     freeVoices   = new LinkedList <Voice>(voicePool);
     activeVoices = new LinkedList <Voice>();
     registry     = new VoiceNode[Synthesizer.DefaultChannelCount, Synthesizer.DefaultKeyCount];
 }
 public Lfo[] lfos;             //set by parameters (quicksetup)
 public VoiceParameters(Synthesizer synth)
 {
     this.synth  = synth;
     blockBuffer = new float[Synthesizer.DefaultBlockSize];
     //create default number of each component
     mixing          = new float[Synthesizer.MaxVoiceComponents];
     counters        = new double[Synthesizer.MaxVoiceComponents];
     generatorParams = new GeneratorParameters[Synthesizer.MaxVoiceComponents];
     generators      = null; //since this is set directly there is no need to initialize
     envelopes       = new Envelope[Synthesizer.MaxVoiceComponents];
     filters         = new Filter[Synthesizer.MaxVoiceComponents];
     lfos            = new Lfo[Synthesizer.MaxVoiceComponents];
     //initialize each component
     for (int x = 0; x < Synthesizer.MaxVoiceComponents; x++)
     {
         generatorParams[x] = new GeneratorParameters();
         envelopes[x]       = new Envelope();
         filters[x]         = new Filter();
         lfos[x]            = new Lfo();
     }
 }
 public MidiInputSequencer(Synthesizer synth)
 {
     this.synth = synth;
 }
 public SynthParameters(Synthesizer synth)
 {
     this.synth = synth;
     ResetControllers();
 }
 //--Public Methods
 public MidiFileSequencer(Synthesizer synth)
 {
     this.synth = synth;
     blockList = new bool[Synthesizer.DefaultChannelCount];
 }
Exemple #9
0
 // Public
 public Voice(Synthesizer synth)
 {
     voiceparams = new VoiceParameters(synth);
 }
        private bool InitSynth()
        {
            // Get peer AudioSource
            audioSource = GetComponent<AudioSource>();
            if (audioSource == null)
            {
                DaggerfallUnity.LogMessage("DaggerfallSongPlayer: Could not find AudioSource component.");
                return false;
            }

            // Create synthesizer and load bank
            if (midiSynthesizer == null)
            {
                // Get number of channels
                if (AudioSettings.driverCapabilities.ToString() == "Mono")
                    channels = 1;
                else
                    channels = 2;

                // Create synth
                AudioSettings.GetDSPBufferSize(out bufferLength, out numBuffers);
                midiSynthesizer = new Synthesizer(sampleRate, channels, bufferLength / numBuffers, numBuffers, polyphony);

                // Load bank data
                byte[] bankData = LoadBank(SoundBank);
                if (bankData == null)
                    return false;
                else
                {
                    midiSynthesizer.LoadBank(new MyMemoryFile(bankData, SoundBank));
                    midiSynthesizer.ResetSynthControls(); // Need to do this for bank to load properly, don't know why
                }
            }

            // Create sequencer
            if (midiSequencer == null)
                midiSequencer = new MidiFileSequencer(midiSynthesizer);

            // Check init
            if (midiSynthesizer == null || midiSequencer == null)
            {
                DaggerfallUnity.LogMessage("DaggerfallSongPlayer: Failed to init synth.");
                return false;
            }

            return true;
        }
 public SynthParameters(Synthesizer synth)
 {
     this.synth = synth;
     ResetControllers();
 }