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); }
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(); } }
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; }