public void RemoveSequencer(MyMMLSequencer sequencer) { lock (sequencers) { sequencers.Remove(sequencer); } }
public void AddSequencer(MyMMLSequencer sequencer) { lock (sequencer) { sequencers.Add(sequencer); } }
void OnDisable() { Synthesizer.Terminate(); Mixer.Terminate(); Sequencer = null; Synthesizer = null; Mixer = null; }
private LinkedList <float[]> generateAudioSamples() { MyMMLSequencer seq = station.acgState.sequencer; MyMixer mix = station.acgState.mixer; List <MySynthesizer> sss = station.acgState.synthesizers; if ((seq == null) || (mix == null) || (sss == null)) { return(null); } mix.Reset(); for (int j = 0; j < sss.Count; j++) { seq.SetSynthesizer(j, sss[j], toneSet, toneMap, 0xffffffffU); } seq.KeyShift = clip.Key; seq.VolumeScale = clip.Volume; seq.TempoScale = clip.Tempo; seq.Play(mml, 0.0f, false); LinkedList <float[]> temp = new LinkedList <float[]>(); const int workSize = 4096; float[] work = new float[workSize * AudioClipGeneratorState.numChannels]; bool zeroCross = false; for (;;) { if (station.disabled) { return(null); } if (seq.Playing) { mix.Update(); } Array.Clear(work, 0, work.Length); int numSamples = mix.Output(work, AudioClipGeneratorState.numChannels, workSize); if (numSamples == 0) { if (!zeroCross) { mix.Update(); continue; } break; } { float[] block = new float[numSamples * AudioClipGeneratorState.numChannels]; Array.Copy(work, block, numSamples * AudioClipGeneratorState.numChannels); temp.AddLast(block); float v0 = work[(numSamples - 1) * AudioClipGeneratorState.numChannels + 0]; float v1 = work[(numSamples - 1) * AudioClipGeneratorState.numChannels + 1]; zeroCross = (v0 == 0.0f) && (v1 == 0.0f); } } return(temp); }
private void OnDisable() { if (sequencer != null) { sequencer.Stop(0.0f); syntheStation.RemoveSequencer(sequencer); sequencer = null; } syntheStation = null; }
void OnEnable() { if (syntheStation == null) { return; } sequencer = new MyMMLSequencer(syntheStation.TickFrequency); syntheStation.AddSequencer(sequencer); state = PlayState.Stopped; //Debug.Log("start:" + Application.isPlaying); }
void OnEnable() { Mixer = new MyMixer((UInt32)AudioSettings.outputSampleRate, false); Synthesizer = new MySynthesizerPM8(Mixer); Sequencer = new MyMMLSequencer(Mixer.TickFrequency); Mixer.TickCallback = () => { Sequencer.Tick(); }; //UnityEngine.Debug.Log("sampleRate=" + AudioSettings.outputSampleRate + " numVoices=" + Synthesizer.MaxNumVoices); int len; int num; AudioSettings.GetDSPBufferSize(out len, out num); //UnityEngine.Debug.Log("len=" + len); //UnityEngine.Debug.Log("num=" + num); }
private void OnEnable() { syntheStation = GameObject.FindObjectOfType <MySyntheStation>(); if (syntheStation == null) { return; } sequencer = new MyMMLSequencer(syntheStation.TickFrequency); syntheStation.AddSequencer(sequencer); sequencer.AppDataEvent += appDataEvent; sequencer.PlayingEvent += playingEvent; sequencer.NextSectionEvent += nextSectionEvent; state = PlayState.Stopped; //Debug.Log("start:" + Application.isPlaying); }
void OnDisable() { //Debug.Log("OnDisable:" + Application.isPlaying); if (sequencer == null) { return; } if (sequencer.Playing) { sequencer.Stop(0.0f); } if (syntheStation != null) { syntheStation.RemoveSequencer(sequencer); } clip = null; sequencer = null; state = PlayState.Stopped; }
private void play(MyMMLClip clip) { if (sequencer == null) { sequencer = new MyMMLSequencer(syntheStation.TickFrequency); syntheStation.AddSequencer(sequencer); } else { sequencer.Stop(0.0f); } for (int j = 0; j < syntheStation.Synthesizers.Count; j++) { sequencer.SetSynthesizer(j, syntheStation.Synthesizers[j], clip.VoiceMask); } sequencer.VolumeScale = clip.Volume; sequencer.TempoScale = clip.TempoScale; sequencer.KeyShift = clip.Key; sequencer.Play(clip.Unit.Sequence, clip.Unit.ToneMap, 0.0f, false); }
private void OnDisable() { //Debug.Log("OnDisable:" + Application.isPlaying); if (sequencer == null) { return; } if (sequencer.Playing) { sequencer.Stop(0.0f); } if (syntheStation != null) { syntheStation.RemoveSequencer(sequencer); } sequencer.AppDataEvent -= appDataEvent; sequencer.PlayingEvent -= playingEvent; sequencer.NextSectionEvent -= nextSectionEvent; clip = null; sequencer = null; state = PlayState.Stopped; syntheStation = null; }
public AudioClip CreateAudioClip(string name, MyMMLSequence mml, List <object> toneSet, Dictionary <int, int> toneMap) { const int frequency = 44100; const int numChannels = 2; MyMixer mix = new MyMixer(frequency, true); MySynthesizer ss0 = new MySynthesizerPM8(mix); MyMMLSequencer seq = new MyMMLSequencer(mix.TickFrequency); mix.TickCallback = () => seq.Tick(); seq.SetSynthesizer(0, ss0, toneSet, toneMap, 0xffffffffU); seq.Play(mml, 0.0f, false); int totalSamples = 0; LinkedList <float[]> temp = new LinkedList <float[]>(); const int workSize = 4096; float[] work = new float[workSize * numChannels]; bool first = true; for (;;) { Array.Clear(work, 0, work.Length); if (seq.Playing) { mix.Update(); } int numSamples = mix.Output(work, numChannels, workSize); if (numSamples == 0) { break; } if (first) { // skip leading zeros. for (var i = 0; i < numSamples; i++) { if ((work[i * 2 + 0] != 0.0f) || (work[i * 2 + 1] != 0.0f)) { first = false; numSamples -= i; float[] block = new float[numSamples * numChannels]; Array.Copy(work, i * 2, block, 0, numSamples * numChannels); temp.AddLast(block); break; } } } else { float[] block = new float[numSamples * numChannels]; Array.Copy(work, block, numSamples * numChannels); temp.AddLast(block); } totalSamples += numSamples; } AudioClip clip = AudioClip.Create(name, totalSamples, numChannels, frequency, false); int pos = 0; foreach (var block in temp) { clip.SetData(block, pos); pos += block.Length / numChannels; } ss0.Terminate(); mix.Terminate(); return(clip); }
private void OnEnable() { syntheStation = FindObjectOfType <MySyntheStation>(); sequencer = null; }