1 // --------------------------------------------------------------------------- 2 // This file is part of reSID, a MOS6581 SID emulator engine. 3 // Copyright (C) 2004 Dag Lem <resid@nimrod.no> 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 2 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 // --------------------------------------------------------------------------- 19 20 #ifndef __SID_FP_H__ 21 #define __SID_FP_H__ 22 23 #include "siddefs-fp.h" 24 #include "voice.h" 25 #include "filter.h" 26 #include "extfilt.h" 27 #include "pot.h" 28 29 class SIDFP 30 { 31 public: 32 SIDFP(); 33 ~SIDFP(); 34 35 static float kinked_dac(const int x, const float nonlinearity, const int bits); sse_enabled()36 bool sse_enabled() { return can_use_sse; } 37 38 void set_chip_model(chip_model model); get_filter()39 FilterFP& get_filter() { return filter; } 40 void enable_filter(bool enable); 41 void enable_external_filter(bool enable); 42 bool set_sampling_parameters(float clock_freq, sampling_method method, 43 float sample_freq, float pass_freq = -1); 44 void adjust_sampling_frequency(float sample_freq); 45 void set_voice_nonlinearity(float nonlinearity); 46 47 void clock(); 48 int clock(cycle_count& delta_t, short* buf, int n, int interleave = 1); 49 void reset(); 50 51 // Read/write registers. 52 reg8 read(reg8 offset); 53 void write(reg8 offset, reg8 value); 54 55 // Read/write state. 56 class State 57 { 58 public: 59 State(); 60 61 char sid_register[0x20]; 62 63 reg8 bus_value; 64 cycle_count bus_value_ttl; 65 66 reg24 accumulator[3]; 67 reg24 shift_register[3]; 68 reg16 rate_counter[3]; 69 reg16 rate_counter_period[3]; 70 reg16 exponential_counter[3]; 71 reg16 exponential_counter_period[3]; 72 reg8 envelope_counter[3]; 73 EnvelopeGeneratorFP::State envelope_state[3]; 74 bool hold_zero[3]; 75 }; 76 77 State read_state(); 78 void write_state(const State& state); 79 80 // 16-bit input (EXT IN). 81 void input(int sample); 82 83 // output in range -32768 .. 32767, not clipped (AUDIO OUT) 84 float output(); 85 86 protected: 87 static double I0(double x); 88 RESID_INLINE int clock_interpolate(cycle_count& delta_t, short* buf, int n, 89 int interleave); 90 RESID_INLINE int clock_resample_interpolate(cycle_count& delta_t, short* buf, 91 int n, int interleave); 92 RESID_INLINE void age_bus_value(cycle_count); 93 94 VoiceFP voice[3]; 95 FilterFP filter; 96 ExternalFilterFP extfilt; 97 PotentiometerFP potx; 98 PotentiometerFP poty; 99 100 reg8 bus_value; 101 cycle_count bus_value_ttl; 102 103 float clock_frequency; 104 105 // External audio input. 106 float ext_in; 107 108 enum { RINGSIZE = 16384 }; 109 110 // Sampling variables. 111 sampling_method sampling; 112 float cycles_per_sample; 113 float sample_offset; 114 int sample_index; 115 int fir_N; 116 int fir_RES; 117 118 // Linear interpolation helper 119 float sample_prev; 120 121 // Ring buffer with overflow for contiguous storage of RINGSIZE samples. 122 float* sample; 123 124 // FIR_RES filter tables (FIR_N*FIR_RES). 125 float* fir; 126 127 bool can_use_sse; 128 }; 129 130 #endif // not __SID_H__ 131