Beispiel #1
0
 public PatternChannel(int elementcnt)
 {
     _ElementCount = elementcnt;
     Elements = new PatternElement[elementcnt];
     for(int eel = 0; eel < elementcnt; eel++)
     {
         Elements[eel] = new PatternElement();
     }
 }
Beispiel #2
0
        public short[] GetSignal(PatternElement element, int note, int octave)
        {
            //	Return the sound data
            //	We need to determine how long one eighth of a beat is so that
            //	we can determine the number of frames in 1/8 beat

            /*if(Oscs == null)
            {
                Oscs = new Oscilator[3];

                for(int eos = 0; eos < Oscs.Length; eos++)
                {
                    if(Oscs[eos] == null)
                    {
                        Oscs[eos] = new Oscilator();
                        if(eos == 0) { Oscs[eos].Enabled = true; }
                    }
                }
            }

            if(Mixers == null)
            {
                Mixers = new MixerSettings[2];

                for(int emx = 0; emx < Mixers.Length; emx++)
                {
                    if(Mixers[emx] == null)
                    {
                        Mixers[emx] = new MixerSettings();
                    }
                }
            }*/

            if(Generators == null)
            {
                InitGenerators();
            }

            if(Processors == null)
            {
                InitProcessors();
            }

            if(!Running)
            {
                //if(note > -1)
                if(note > -1 && element != null)
                {
                    Console.WriteLine("Machine: Not running, but current note is set.");
                    Running = true;
                }
            }
            else if(Running && note == -2)
            {
                Console.WriteLine("Machine: Running, but current note is ===");
                Running = false;
            }

            if(!Running) { Console.WriteLine("Machine: Not running, so exiting."); return null; }
            //Console.WriteLine("Machine: Running, and now parsing data for audio output. Note: {0}", note);

            float freq = ((1f / 12f) * note);
            if(octave == 4) { freq = 0.5f + (freq * 0.5f); }
            if(octave == 5) { freq =  1.0f + freq; }
            if(octave == 6) { freq =  2.0f + (freq * 2.0f); }

            //float freq = (float)Engine.Configuration.NoteFreq[octave][note];

            //
            //	Each Row is 1/8 beat
            //	beat = row * 8
            //	time per beat = 60 / bpm
            //  tpb / 8 = row time
            double bps = ((double)(Engine.TheTrack.Tempo / 60f));
            double timeperrow = (double)((1f / bps) / 8f);

            //timeperrow = ((double)(60f / Engine.TheTrack.Tempo) / 8f);

            //int framecnt = (int)(Math.Ceiling((timeperrow * this.SampleRate) / bps));
            //int framecnt = (int)(Math.Ceiling(((timeperrow * this.SampleRate) / bps) / 2));
            int framecnt = (int)(Math.Ceiling(((double)this.SampleRate / freq)));
            //int playlength = Math.Ceiling(((double)(60f / ((float)Engine.TheTrack.Tempo) / 8f)) * this.SampleRate);

            //Console.WriteLine("GetSignal {0} {1} {2}", bps, timeperrow, framecnt);

            if(element != null)
            {
                if(element.Volume > -1)
                {
                    //Console.WriteLine("Changing volume for Machine");
                    this.Amplitude = (double)((double)element.Volume / 100f);
                }

            }

            //
            //	Now based on the mixers, we need to combine the oscillator
            //	sound data into one stream.
            //

            short[] toret = null;// = new short[oscone.Length];

            Signals = new Dictionary<string, short[]>();

            Console.WriteLine("Adding signals from generators.");
            for(int egen = 0; egen < Generators.Length; egen++)
            {
                if(Generators[egen] != null)
                {
                    Signals.Add(egen.ToString(), Generators[egen].GetData(framecnt, note, octave));
                }
            }

            Console.WriteLine("Creating output from processor chain.");
            bool newnote = this.IsNoteNew;
            for(int ep = 0; ep < this.Processors.Length; ep++)
            {
                if(this.Processors[ep] != null) { this.Processors[ep].IsNoteNew = newnote; }
            }
            toret = Process(0);

            return toret;
        }
Beispiel #3
0
        public short[] GetSignal(PatternElement element)
        {
            if(element == null) { return GetSignal(element, -1, 5); }

            return GetSignal(element, element.Note, element.Octave);
        }