public Synthesizer CreateSynthesizer(int deviceId, int bufferSize, int sampleRate) { synth = new Synthesizer( "Lite Wave", deviceId, bufferSize, sampleRate, new VoiceFactory(delegate(SampleRate sr, StereoBuffer buffer, string name) { return new SynthVoice(sr, buffer, name); }), 8, delegate(SampleRate sr, StereoBuffer inputBuffer) { List<EffectComponent> myEffects = new List<EffectComponent>(); myEffects.Add(new Sanford.Multimedia.Synth.Chorus(sr, inputBuffer)); myEffects.Add(new Sanford.Multimedia.Synth.Echo(sr, inputBuffer)); return myEffects; }); if (File.Exists("LiteWaveDefaultBank.bnk")) { try { // Load default bank into Lite Wave synthesizer. synth.LoadBank("LiteWaveDefaultBank.bnk"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Stop); } } else { MessageBox.Show("No Soundbank Found", "Error", MessageBoxButton.OK, MessageBoxImage.Stop); } synth.SetParameterValue(11, (float)1.0); //Set to organ synth.SetSelectedProgramIndex(2); return 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; }
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 string filename = DaggerfallUnity.Settings.SoundFont; byte[] bankData = LoadBank(filename); if (bankData == null) { // Attempt to fallback to default internal soundfont bankData = LoadDefaultSoundFont(); filename = defaultSoundFontFilename; Debug.LogFormat("Using default SoundFont {0}", defaultSoundFontFilename); } else { Debug.LogFormat("Trying custom SoundFont {0}", filename); } // Assign to synth if (bankData == null) { return(false); } else { midiSynthesizer.LoadBank(new MyMemoryFile(bankData, filename)); 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 void LoadBank(PatchBank bank) { this.bank = bank; synthesizer.UnloadBank(); synthesizer.LoadBank(bank); }
public void LoadBank(string bankfile) { Stop(); synth.LoadBank(new MyFile(bankfile)); }