Esempio n. 1
0
 private void tickSweep(Pulse pulse)
 {
     if (pulse.sweep_period_counter == 0)
     {
         if (pulse.SWEEP_ENABLED)
         {
             int periodAdjustment = pulse.TIMER >> pulse.SWEEP_SHIFT;
             int newPeriod;
             if (pulse.SWEEP_NEGATE)
             {
                 newPeriod = pulse.TIMER - periodAdjustment;
             }
             else
             {
                 newPeriod = (pulse.TIMER + periodAdjustment);
             }
             if (0 < newPeriod && newPeriod < 0x7FF && pulse.SWEEP_SHIFT != 0)
             {
                 pulse.TIMER = (ushort)newPeriod;
             }
         }
         pulse.sweep_period_counter = pulse.SWEEP_PERIOD;
     }
     else
     {
         pulse.sweep_period_counter--;
     }
 }
Esempio n. 2
0
 private void tickLengthCounter(Pulse pulse)
 {
     if (!pulse.LENGTH_COUNTER_HALT)
     {
         pulse.current_length_counter -= 1;
         if (pulse.current_length_counter < 0)
         {
             pulse.current_length_counter = 0;
         }
     }
 }
Esempio n. 3
0
 private void tickEnvelopCounter(Pulse pulse)
 {
     if (pulse.envelope_counter == 0)
     {
         if (pulse.envelope_volume == 0)
         {
             if (pulse.ENVELOPE_LOOP)
             {
                 pulse.envelope_volume = 15;
             }
         }
         else
         {
             pulse.envelope_volume--;
         }
         pulse.envelope_counter = pulse.ENVELOPE_DIVIDER_PERIOD_OR_VOLUME;
     }
     else
     {
         pulse.envelope_counter--;
     }
 }
Esempio n. 4
0
        public float getPulseAudio(Pulse pulse, int timeInSamples)
        {
            if (!pulse.ENABLED || pulse.current_length_counter == 0)
            {
                return(0.0f);
            }

            //Frequency is the clock speed of the CPU ~ 1.7MH divided by 16 divied by the timer.
            //TODO pretty much everything here, only looking at frequency flag right now
            double frequency            = 106250.0 / pulse.TIMER;
            double normalizedSampleTime = timeInSamples * frequency / sampleRate;

            double fractionalNormalizedSampleTime = normalizedSampleTime - Math.Floor(normalizedSampleTime);
            float  dutyPulse = fractionalNormalizedSampleTime < dutyMap[pulse.DUTY] ? 1 : -1;

            byte volume = pulse.ENVELOPE_DIVIDER_PERIOD_OR_VOLUME;

            if (!pulse.CONSTANT_VOLUME)
            {
                volume = pulse.envelope_volume;
            }

            return(dutyPulse * volume / 15);
        }