Example #1
0
 //--Public Methods
 public MidiSequencer(StreamSynthesizer synth)
 {
     currentPrograms = new int[16]; //16 channels
     this.synth = synth;
     this.synth.setSequencer(this);
     blockList = new List<byte>();
     seqEvt = new MidiSequencerEvent();
 }
Example #2
0
 // Use this for initialization
 void Awake()
 {
     sliderManager = GameObject.Find("InstrumentsSlider").GetComponent<SliderManager> ();
     playMidi = sliderManager.playMidi;
     audioSource = GetComponent<AudioSource> ();
     midiStreamSynthesizer = new StreamSynthesizer(44100, 2, bufferSize, 40);
     midiStreamSynthesizer.LoadBank(bankFilePath);
     sampleBuffer = new float[midiStreamSynthesizer.BufferSize];
 }
Example #3
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();
        }
Example #4
0
 //--Public Methods
 /// <summary>
 /// A simple echo effect.
 /// </summary>
 /// <param name="synth">A constructed synthesizer instance.</param>
 /// <param name="delaytime">Echo delay in seconds.</param>
 /// <param name="decay">Controls the volume of the echo.</param>
 public Echo(StreamSynthesizer synth, float delaytime, float decay)
     : base()
 {
     if (delaytime <= 0.0f)
         throw new ArgumentException("delay time must be positive non-zero for echo effect.");
     this.decay = SynthHelper.Clamp(decay, 0.0f, 1.0f);
     this.EffectBuffer = new float[synth.Channels, SynthHelper.getSampleFromTime(synth.SampleRate, delaytime)];
     channels = this.EffectBuffer.GetLength(0);
     secondarybufferlen = this.EffectBuffer.GetLength(1);
 }
Example #5
0
    // Awake is called when the script instance
    // is being loaded.
    void Awake()
    {
        midiStreamSynthesizer = new StreamSynthesizer(44100, 2, bufferSize, 40);
        midiStreamSynthesizer.LoadBank(bankFilePath);
        sampleBuffer = new float[midiStreamSynthesizer.BufferSize];

        audioFiles = Resources.LoadAll<AudioClip> ("Audio/Instruments");

        soundAreaSelector = GameObject.Find("SoundManagers").GetComponent<SoundAreaSelector>();
        pitchRangeSelector = GameObject.Find("SoundManagers").GetComponent<PitchRangeSelector>();
    }
Example #6
0
    // Awake is called when the script instance
    // is being loaded.
    void Awake()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        midiStreamSynthesizer = new StreamSynthesizer(44100, 1, bufferSize, 40);
#else 
        midiStreamSynthesizer = new StreamSynthesizer(44100, 2, bufferSize, 40);
#endif
        sampleBuffer = new float[midiStreamSynthesizer.BufferSize];

        midiStreamSynthesizer.LoadBank(bankFilePath);
    }
Example #7
0
	// 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);
		//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);	
		
	}
Example #8
0
    // 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();
    }
Example #9
0
 //--Public Methods
 public Voice(StreamSynthesizer synth)
 {
     resetVoice();
     this.synth = synth;
     this.inst = null;
 }
Example #10
0
        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);
        }
Example #11
0
    void Awake()
    {
        InitRandomTable();

        int dspBufferCount;
        int dspBufferLength;

        AudioSettings.GetDSPBufferSize(out dspBufferLength, out dspBufferCount);
        _midiStreamSynthesizer = new StreamSynthesizer(44100, 2, dspBufferLength, 40);
        _sampleBuffer = new float[_midiStreamSynthesizer.BufferSize];

        _midiStreamSynthesizer.LoadBank("GM Bank/gm");
        _midiSequencer = new iMUSEMidiSequencer(this, _midiStreamSynthesizer);
    }
Example #12
0
 public void Dispose()
 {
     Stop(true);
     //Set anything that may become a circular reference to null...
     synth = null;
     _MidiFile = null;
     seqEvt = null;
 }
Example #13
0
 //--Public Methods
 public SincFilter(StreamSynthesizer synth, int filtersize, double cornerfreq)
     : base()
 {
     sfilter = new SincLowPass(synth.Channels, filtersize, cornerfreq);
 }
 public Voice(StreamSynthesizer synth, Instrument inst)
 {
     resetVoice();
     this.synth = synth;
     setInstrument(inst);
 }
Example #15
0
 public Voice(StreamSynthesizer synth, Instrument inst)
 {
     resetVoice();
     this.synth = synth;
     setInstrument(inst);
 }
Example #16
0
    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);
    }
 public virtual bool HandleEndOfTrack(StreamSynthesizer synth)
 {
     return false;
 }
Example #18
0
 public override bool HandleEndOfTrack(StreamSynthesizer synth)
 {
     return _iMuse.HandleEndOfTrack();
 }
Example #19
0
 public iMUSEMidiSequencer(iMUSE iMuse, StreamSynthesizer synth)
     : base(synth)
 {
     _iMuse = iMuse;
     Looping = false;
 }
 //--Public Methods
 public Voice(StreamSynthesizer synth)
 {
     resetVoice();
     this.synth = synth;
     this.inst  = null;
 }
Example #21
0
    void Awake()
    {
        synthesizer = new StreamSynthesizer (44100, 2, sampleBufferSize, 40);
        sampleBuffer = new float[synthesizer.BufferSize];
        synthesizer.LoadBank(bankPath);
        sequencer = new MidiSequencer (synthesizer);

        //These will be fired by the sequencer when a song plays. Check the console for messages
        sequencer.NoteOnEvent += HandleNoteOn;
        sequencer.NoteOffEvent += HandleNoteOff;
        sequencer.OtherMidiEvent += HandleMidiEvent;
    }