public void Start(MBROLASynthesizer Synth) { callback = new PlayCallbackProc(mbrCallback); this.Synth = Synth; t = new Thread(delegate() { while (Thread.CurrentThread.IsAlive) { if (Fragments.Count == 0) { Thread.Sleep(0); continue; } string fragment = Fragments.Dequeue(); if (fragment == "EOF") { while (!Finished) { Thread.Sleep(0); } Eof = true; Synth.Log("InvokeAudioFinished"); Synth.InvokeAudioFinished(); t.Abort(); return; } else { Synth.Log("Sent {0} characters to synth", fragment.Length); MbrPlay.Play(fragment, (int)MbrFlags.Queued | (int)MbrFlags.Wait | (int)MbrFlags.MsgInit | (int)MbrFlags.MsgWrite | (int)MbrFlags.MsgEnd | (int)MbrFlags.Callback | (int)MbrOut.Disabled, null, callback); StringBuilder error = new StringBuilder(256); MbrPlay.LastError(error, 255); if (error.Length > 0) { this.Error(this, error.ToString()); } } } }); t.Name = "MbrThread"; t.SetApartmentState(ApartmentState.STA); t.Start(); }
int mbrCallback(MbrMessage msg, IntPtr wParam, int lParam) { switch (msg) { case MbrMessage.Init: Synth.Log("Synth initialized"); // fout.Seek(0, SeekOrigin.End); break; // case MbrMessage.Read: // fwrite((short*)wParam, sizeof(short), lParam, fout); // Synth.Log("WM_MBR_READ wParam={0}, lParam={1}", wParam.ToInt32().ToString("X"), lParam); // break; case MbrMessage.Write: Synth.Log("{0} samples received from synth", lParam); byte[] buf = new byte[lParam * sizeof(short)]; Marshal.Copy(wParam, buf, 0, lParam * sizeof(short)); // AudioBufferInfo abuf = new AudioBufferInfo(); // abuf.Format // Synth.Emit(abuf); Synth.BufferReady(buf); // fout.Write(buf, 0, buf.Length); break; case MbrMessage.End: Synth.Log("Synth terminated"); Finished = true; // fout.Close(); break; default: Synth.Log("MbrMessage " + msg); break; } return(0); }