fixed YM2612 output limiter

modified resampler frame length calculation
This commit is contained in:
ekeeke31 2009-08-09 16:10:44 +00:00
parent cfa4a08211
commit c0179e7ed4
4 changed files with 29 additions and 23 deletions

View File

@ -71,8 +71,8 @@ void config_default(void)
config.hq_fm = 1;
config.psgBoostNoise = 0;
config.filter = 1;
config.low_freq = 200;
config.high_freq = 8000;
config.low_freq = 880;
config.high_freq = 5000;
config.lg = 1.0;
config.mg = 1.0;
config.hg = 1.0;

View File

@ -1,6 +1,6 @@
/* Game_Music_Emu 0.5.2. http://www.slack.net/~ant/ */
/* Copyright (C) 2004-2006 Shay Green. */
/* Modified by Eke-Eke for use in Genesis Plus (2009). */
/* C Conversion by Eke-Eke for use in Genesis Plus (2009). */
#include "Fir_Resampler.h"
@ -23,7 +23,7 @@ static int step = STEREO;
static int input_per_cycle;
static double ratio = 1.0;
static void gen_sinc(double rolloff, int width, double offset, double spacing, double scale, int count, sample_t *out )
static void gen_sinc(double rolloff, int width, double offset, double spacing, double scale, int count, short *out )
{
double const maxh = 256;
double const fstep = M_PI / maxh * spacing;
@ -38,11 +38,11 @@ static void gen_sinc(double rolloff, int width, double offset, double spacing, d
double w = angle * to_w;
if ( fabs( w ) < M_PI )
{
double rolloff_cos_a = ROLLOFF * cos( angle );
double rolloff_cos_a = rolloff * cos( angle );
double num = 1 - rolloff_cos_a -
pow_a_n * cos( maxh * angle ) +
pow_a_n * ROLLOFF * cos( (maxh - 1) * angle );
double den = 1 - rolloff_cos_a - rolloff_cos_a + ROLLOFF * ROLLOFF;
pow_a_n * rolloff * cos( (maxh - 1) * angle );
double den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff;
double sinc = scale * num / den - scale;
out [-1] = (short) (cos( w ) * sinc + sinc);
@ -78,6 +78,12 @@ int Fir_Resampler_initialize( int new_size )
buffer = (sample_t *) realloc( buffer, (new_size + WRITE_OFFSET) * sizeof (sample_t) );
if ( !buffer && new_size ) return 0;
buffer_size = new_size + WRITE_OFFSET;
write_pos = 0;
res = 1;
imp_phase = 0;
skip_bits = 0;
step = STEREO;
ratio = 1.0;
Fir_Resampler_clear();
return 1;
}
@ -265,7 +271,7 @@ int Fir_Resampler_input_needed( unsigned long output_count )
unsigned long skip = skip_bits >> imp_phase;
int remain = res - imp_phase;
while ( (output_count -= 2) > 0 )
while ( (output_count) > 0 ) /* fixed (Eke_Eke) */
{
input_count += step + (skip & 1) * STEREO;
skip >>= 1;

View File

@ -137,9 +137,6 @@
#define FREQ_MASK ((1<<FREQ_SH)-1)
#define MAXOUT (+32767)
#define MINOUT (-32768)
/* envelope generator */
#define ENV_BITS 10
@ -162,6 +159,11 @@
#define TL_RES_LEN (256) /* 8 bits addressing (real chip) */
#define MAXOUT (+16383)
#define MINOUT (-16384)
/* TL_TAB_LEN is calculated as:
* 13 - sinus amplitude bits (Y axis)
* 2 - sinus sign bit (Y axis)
@ -1913,7 +1915,8 @@ void YM2612Update(int length)
/* Output samples buffers */
int16 *bufFIR = Fir_Resampler_buffer();
if (!bufFIR)
if (bufFIR) bufFIR += snd.fm.pos*2;
else
{
bufL = snd.fm.buffer[0] + snd.fm.pos;
bufR = snd.fm.buffer[1] + snd.fm.pos;
@ -2041,10 +2044,6 @@ void YM2612Update(int length)
/* timer B control */
INTERNAL_TIMER_B(length);
/* update FIR resampler */
if (bufFIR)
Fir_Resampler_write(length * 2);
}
/* initialize ym2612 emulator(s) */

View File

@ -73,8 +73,9 @@ void audio_update (int size)
/* resampling */
if (config.hq_fm)
{
int fm_len = (int) ((double)size * Fir_Resampler_ratio() + 0.5) ;
sound_update(fm_len,size);
int len = Fir_Resampler_input_needed(size * 2);
sound_update(len/2,size);
Fir_Resampler_write(len);
Fir_Resampler_read(fm,size);
}
else
@ -96,10 +97,10 @@ void audio_update (int size)
if (filter & 1)
{
/* single-pole low-pass filter (6 dB/octave) */
ll = (ll + l) >> 1;
rr = (rr + r) >> 1;
l = ll;
r = rr;
l = (ll + l) >> 1;
r = (rr + r) >> 1;
ll = l;
rr = r;
}
else if (filter & 2)
{
@ -141,7 +142,7 @@ int audio_init (int rate)
snd.sample_rate = rate;
/* Calculate the sound buffer size (for one frame) */
snd.buffer_size = (rate / vdp_rate) + 8;
snd.buffer_size = (rate / vdp_rate) + 32;
#ifndef NGC
/* Output buffers */