Example #1
0
File: Voice.cs Project: m4mm0n/HGE
        public Voice()
        {
            wave     = new WaveformGenerator();
            envelope = new EnvelopeGenerator();

            muted = false;
            set_chip_model(SIDDefs.chip_model.MOS6581);
        }
Example #2
0
File: Voice.cs Project: m4mm0n/HGE
        // deserializing
        protected void LoadFromReader(BinaryReader reader)
        {
            wave     = new WaveformGenerator(reader);
            envelope = new EnvelopeGenerator(reader);

            muted     = reader.ReadBoolean();
            wave_zero = reader.ReadInt32();
            voice_DC  = reader.ReadInt32();
        }
Example #3
0
        public State read_state()
        {
            State state = new State();
            int   j     = 0;

            WaveformGenerator wave     = voice0.wave;
            EnvelopeGenerator envelope = voice0.envelope;

            state.sid_register[j + 0] = (char)(wave.freq & 0xff);
            state.sid_register[j + 1] = (char)(wave.freq >> 8);
            state.sid_register[j + 2] = (char)(wave.pw & 0xff);
            state.sid_register[j + 3] = (char)(wave.pw >> 8);
            state.sid_register[j + 4] = (char)((wave.waveform << 4) | ((wave.test != 0) ? 0x08 : 0) | ((wave.ring_mod != 0) ? 0x04 : 0) | ((wave.sync != 0) ? 0x02 : 0) | ((envelope.gate != 0) ? 0x01 : 0));
            state.sid_register[j + 5] = (char)((envelope.attack << 4) | envelope.decay);
            state.sid_register[j + 6] = (char)((envelope.sustain << 4) | envelope.release);

            j++;
            wave     = voice1.wave;
            envelope = voice1.envelope;
            state.sid_register[j + 0] = (char)(wave.freq & 0xff);
            state.sid_register[j + 1] = (char)(wave.freq >> 8);
            state.sid_register[j + 2] = (char)(wave.pw & 0xff);
            state.sid_register[j + 3] = (char)(wave.pw >> 8);
            state.sid_register[j + 4] = (char)((wave.waveform << 4) | ((wave.test != 0) ? 0x08 : 0) | ((wave.ring_mod != 0) ? 0x04 : 0) | ((wave.sync != 0) ? 0x02 : 0) | ((envelope.gate != 0) ? 0x01 : 0));
            state.sid_register[j + 5] = (char)((envelope.attack << 4) | envelope.decay);
            state.sid_register[j + 6] = (char)((envelope.sustain << 4) | envelope.release);

            j++;
            wave     = voice2.wave;
            envelope = voice2.envelope;
            state.sid_register[j + 0] = (char)(wave.freq & 0xff);
            state.sid_register[j + 1] = (char)(wave.freq >> 8);
            state.sid_register[j + 2] = (char)(wave.pw & 0xff);
            state.sid_register[j + 3] = (char)(wave.pw >> 8);
            state.sid_register[j + 4] = (char)((wave.waveform << 4) | ((wave.test != 0) ? 0x08 : 0) | ((wave.ring_mod != 0) ? 0x04 : 0) | ((wave.sync != 0) ? 0x02 : 0) | ((envelope.gate != 0) ? 0x01 : 0));
            state.sid_register[j + 5] = (char)((envelope.attack << 4) | envelope.decay);
            state.sid_register[j + 6] = (char)((envelope.sustain << 4) | envelope.release);

            state.sid_register[j++] = (char)(filter.fc & 0x007);
            state.sid_register[j++] = (char)(filter.fc >> 3);
            state.sid_register[j++] = (char)((filter.res << 4) | filter.filt);
            state.sid_register[j++] = (char)(((filter.voice3off != 0) ? 0x80 : 0) | (filter.hp_bp_lp << 4) | filter.vol);

            // These registers are superfluous, but included for completeness.
            for (; j < 0x1d; j++)
            {
                state.sid_register[j] = (char)(read(j));
            }
            for (; j < 0x20; j++)
            {
                state.sid_register[j] = (char)0;
            }

            state.bus_value     = bus_value;
            state.bus_value_ttl = bus_value_ttl;

            state.accumulator0                = voice0.wave.accumulator;
            state.shift_register0             = voice0.wave.shift_register;
            state.rate_counter0               = voice0.envelope.rate_counter;
            state.rate_counter_period0        = voice0.envelope.rate_period;
            state.exponential_counter0        = voice0.envelope.exponential_counter;
            state.exponential_counter_period0 = voice0.envelope.exponential_counter_period;
            state.envelope_counter0           = voice0.envelope.envelope_counter;
            state.envelope_state0             = voice0.envelope.state;
            state.hold_zero0 = voice0.envelope.hold_zero;

            state.accumulator1                = voice1.wave.accumulator;
            state.shift_register1             = voice1.wave.shift_register;
            state.rate_counter1               = voice1.envelope.rate_counter;
            state.rate_counter_period1        = voice1.envelope.rate_period;
            state.exponential_counter1        = voice1.envelope.exponential_counter;
            state.exponential_counter_period1 = voice1.envelope.exponential_counter_period;
            state.envelope_counter1           = voice1.envelope.envelope_counter;
            state.envelope_state1             = voice1.envelope.state;
            state.hold_zero1 = voice1.envelope.hold_zero;

            state.accumulator2                = voice2.wave.accumulator;
            state.shift_register2             = voice2.wave.shift_register;
            state.rate_counter2               = voice2.envelope.rate_counter;
            state.rate_counter_period2        = voice2.envelope.rate_period;
            state.exponential_counter2        = voice2.envelope.exponential_counter;
            state.exponential_counter_period2 = voice2.envelope.exponential_counter_period;
            state.envelope_counter2           = voice2.envelope.envelope_counter;
            state.envelope_state2             = voice2.envelope.state;
            state.hold_zero2 = voice2.envelope.hold_zero;

            return(state);
        }