Merge pull request #3876 from superctr/zsg2_filter

zsg2.cpp: Optimized the filters a little bit
This commit is contained in:
ajrhacker 2018-08-20 13:32:59 -04:00 committed by GitHub
commit 6811c15785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,7 +85,7 @@
TODO:
- Filter and ramping behavior might not be perfect.
- sometimes clicking
- sometimes clicking / popping noises. e.g. raycris song #12 in the sound test.
- memory reads out of range sometimes
*/
@ -97,11 +97,16 @@ TODO:
#include <fstream>
#include <cmath>
//#define EMPHASIS_CUTOFF_BASE 0x0800
//#define EMPHASIS_INITIAL_BIAS 0x00400000
#define EMPHASIS_INITIAL_BIAS 0
#define EMPHASIS_OUTPUT_SHIFT (16-11)
#define SAMPLE_OUTPUT_SHIFT 12
// Adjusts the cutoff constant of the filter by right-shifting the filter state.
// The current value gives a -6dB cutoff frequency at about 81.5 Hz, assuming
// sample playback at 32.552 kHz.
#define EMPHASIS_FILTER_SHIFT (16-10)
#define EMPHASIS_ROUNDING 0x20
// Adjusts the output amplitude by right-shifting the filtered output. Should be
// kept relative to the filter shift. A too low value will cause clipping, while
// too high will cause quantization noise.
#define EMPHASIS_OUTPUT_SHIFT 1
// device type definition
DEFINE_DEVICE_TYPE(ZSG2, zsg2_device, "zsg2", "ZOOM ZSG-2")
@ -269,7 +274,7 @@ void zsg2_device::filter_samples(zchan *ch)
{
ch->samples[i+1] = raw_samples[i];
ch->emphasis_filter_state += raw_samples[i]-(ch->emphasis_filter_state>>EMPHASIS_OUTPUT_SHIFT);
ch->emphasis_filter_state += raw_samples[i]-((ch->emphasis_filter_state+EMPHASIS_ROUNDING)>>EMPHASIS_FILTER_SHIFT);
ch->samples[i+1] = ch->emphasis_filter_state >> EMPHASIS_OUTPUT_SHIFT;
}
}
@ -333,7 +338,7 @@ void zsg2_device::sound_stream_update(sound_stream &stream, stream_sample_t **in
if (elem.output_gain[output] & 0x80) // perhaps ?
output_sample = -output_sample;
mix[output] += (output_sample * m_gain_tab[output_gain&0x1f]) >> SAMPLE_OUTPUT_SHIFT;
mix[output] += (output_sample * m_gain_tab[output_gain&0x1f]) >> 16;
}
// Apply ramping every other update
@ -523,6 +528,7 @@ void zsg2_device::control_w(int reg, uint16_t data)
m_chan[ch].vol = 0; // m_chan[ch].vol_initial;
m_chan[ch].vol_delta = 0x0400; // register 06 ?
m_chan[ch].output_cutoff = m_chan[ch].output_cutoff_initial;
m_chan[ch].output_filter_state = 0;
}
}
break;