Play() public method

public Play ( ) : void
return void
Beispiel #1
0
        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();
        }
        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);
        }