public Sound(string bank,string midifile) { midiStreamSynthesizer = new StreamSynthesizer(StreamSynthesizer.SampleRateType.High); sampleBuffer = new float[midiStreamSynthesizer.BufferSize]; midiStreamSynthesizer.LoadBank(bank); midiSequencer = new MidiSequencer(midiStreamSynthesizer); midiSequencer.LoadMidi(midifile, false); midiSequencer.Play(); }
// Awake is called when the script instance // is being loaded. void Awake() { midiStreamSynthesizer = new StreamSynthesizer (44100, 2, bufferSize, 40); sampleBuffer = new float[midiStreamSynthesizer.BufferSize]; midiStreamSynthesizer.LoadBank (bankFilePath); midiSequencer = new MidiSequencer (midiStreamSynthesizer); midiSequencer.LoadMidi ((Resources.Load(midiFilePath) as TextAsset).bytes, false); //These will be fired by the midiSequencer when a song plays. Check the console for messages midiSequencer.NoteOnEvent += new MidiSequencer.NoteOnEventHandler (MidiNoteOnHandler); midiSequencer.NoteOffEvent += new MidiSequencer.NoteOffEventHandler (MidiNoteOffHandler); }
// Awake is called when the script instance // is being loaded. void Awake() { midiStreamSynthesizer = new StreamSynthesizer (44100, 2, bufferSize, 40); sampleBuffer = new float[midiStreamSynthesizer.BufferSize]; midiStreamSynthesizer.LoadBank (GetBankFilePath(bankFileType)); midiSequencer = new MidiSequencer (midiStreamSynthesizer); if (midiFile != null) midiSequencer.LoadMidi (midiFile, false); else midiSequencer.LoadMidi (testMidiFilePath, false); //These will be fired by the midiSequencer when a song plays. Check the console for messages midiSequencer.NoteOnEvent += new MidiSequencer.NoteOnEventHandler (MidiNoteOnHandler); midiSequencer.NoteOffEvent += new MidiSequencer.NoteOffEventHandler (MidiNoteOffHandler); if (playOnAwake) PlayMIDI(); }
void Awake() { // For now, imitating the behavior of UnitySynthTest.cs with two goals: // 1. Understand how UnitySynth loads and plays midi files // 2. Figure out where in that process to get the data for the markov chain // copied straight from UnitySynthTest.cs, almost midiStreamSynthesizer = new StreamSynthesizer(44100, 2, bufferSize, 40); sampleBuffer = new float[midiStreamSynthesizer.BufferSize]; midiStreamSynthesizer.LoadBank(bankFilePath); midiSequencer = new MidiSequencer(midiStreamSynthesizer); midiSequencer.LoadMidi(testMidiFile, false); midiSequencer.NoteOnEvent += new MidiSequencer.NoteOnEventHandler (MidiNoteOnHandler); midiSequencer.NoteOffEvent += new MidiSequencer.NoteOffEventHandler (MidiNoteOffHandler); initializeMatrix(16, 128*128,128); }
protected override void OpenMediaAsync() { System.Diagnostics.Debug.WriteLine("OpenMediaAsync"); Dictionary<MediaStreamAttributeKeys, string> streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>(); Dictionary<MediaSourceAttributesKeys, string> sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>(); List<MediaStreamDescription> availableStreams = new List<MediaStreamDescription>(); string codec = ""; codec += ToLittleEndianString(string.Format("{0:X4}", 1)); codec += ToLittleEndianString(string.Format("{0:X4}", 1)); codec += ToLittleEndianString(string.Format("{0:X8}", SamplesPerSec)); codec += ToLittleEndianString(string.Format("{0:X8}", AvgBytesPerSec)); codec += ToLittleEndianString(string.Format("{0:X4}", BlockAlign)); codec += ToLittleEndianString(string.Format("{0:X4}", BitsPerSample)); codec += ToLittleEndianString(string.Format("{0:X4}", 0)); streamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = codec; sourceAttributes[MediaSourceAttributesKeys.Duration] = "0"; sourceAttributes[MediaSourceAttributesKeys.CanSeek] = "false"; MediaStreamDescription msd = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes); _audioDesc = msd; availableStreams.Add(_audioDesc); String bankName = "SoundBanks/GMBank/gmpiano.txt"; var file = Application.GetResourceStream(new Uri(bankName, UriKind.Relative)); String result = ""; using (var reader = new StreamReader(file.Stream)) { result += reader.ReadToEnd(); } synth = new StreamSynthesizer(44100, 1, 1000, 2); CSharpSynth.Banks.BankManager.addBank(new InstrumentBank(44100, bankName)); int bankfile = BankManager.Count - 1; synth.SwitchBank(bankfile); byte[] buffer = new byte[synth.BufferSize]; midiSeq = new MidiSequencer(synth); midiSeq.LoadMidi("temp.mid", false); //System.Diagnostics.Debug.WriteLine("midi file is "); //System.Diagnostics.Debug.WriteLine(midifile.OriginalString); //midiSeq.LoadMidi(midifile.OriginalString, false); midiSeq.Looping = true; midiSeq.Play(); startTime = DateTime.Now; ReportOpenMediaCompleted(sourceAttributes, availableStreams); }