fix BEEP PCM with time

This commit is contained in:
Tomohiro Yoshidomi 2017-10-16 18:42:11 +09:00
parent d36386ce93
commit ce3dd56f32
4 changed files with 55 additions and 78 deletions

View File

@ -333,32 +333,38 @@ static void IOOUTCALL pit_o71(UINT port, REG8 dat) {
(void)port;
}
static int beep_mode_bit = 0;
static int beep_mode_bit_c = 0;
// beep
static void IOOUTCALL pit_o73(UINT port, REG8 dat) {
PITCH pitch;
switch(beep_mode_bit) {
case 0:
beep_data[g_beep.beep_data_load_loc] = dat;
break;
case 1:
beep_data[g_beep.beep_data_load_loc] = dat << 8;
break;
case 2:
if(beep_mode_bit_c == 0)
if(g_beep.mode == 0) {
switch(beep_mode_bit) {
case 0:
beep_data[g_beep.beep_data_load_loc] = dat;
else
beep_data[g_beep.beep_data_load_loc] += dat << 8;
break;
break;
case 1:
beep_data[g_beep.beep_data_load_loc] = dat << 8;
break;
case 2:
if(beep_mode_bit_c == 0)
beep_data[g_beep.beep_data_load_loc] = dat;
else
beep_data[g_beep.beep_data_load_loc] += dat << 8;
break;
}
beep_time[g_beep.beep_data_load_loc] = CPU_CLOCK;
if(!(beep_mode_bit == 2 && beep_mode_bit_c == 0)) {
g_beep.beep_data_load_loc++;
if(g_beep.beep_data_load_loc >= BEEPDATACOUNT)
g_beep.beep_data_load_loc = 0;
g_beep.beep_laskclk = CPU_CLOCK;
}
beep_mode_bit_c ^= 1;
}
if(!(beep_mode_bit == 2 && beep_mode_bit_c == 0)) {
g_beep.beep_data_load_loc++;
if(g_beep.beep_data_load_loc >= BEEPDATACOUNT)
g_beep.beep_data_load_loc = 0;
g_beep.beep_laskclk = CPU_CLOCK;
}
beep_mode_bit_c ^= 1;
pitch = pit.ch + 1;
if (pit_setcount(pitch, dat)) {
@ -392,45 +398,14 @@ static void IOOUTCALL pit_o77(UINT port, REG8 dat) {
UINT chnum;
PITCH pitch;
if(CPU_CLOCK - g_beep.beep_laskclk >= 20000000) {
g_beep.beep_data_load_loc = 0;
g_beep.beep_data_curr_loc = 0;
g_beep.beep_cnt = 0;
if((dat & 0xC0) == 0x40) {
if(CPU_CLOCK - g_beep.beep_laskclk >= 20000000) {
g_beep.beep_data_load_loc = 0;
g_beep.beep_data_curr_loc = 0;
}
beep_mode_bit = ((dat >> 4) & 3) - 1;
beep_mode_bit_c = 0;
}
switch(dat & 0x30) {
case 0x10:
beep_mode_bit = 0;
if(port == 0x77 && dat == 0x50) {
if(beep_mode_temp == 0x70) /* for TOKIO */
beep_mode_freq = 42;
else
beep_mode_freq = 56;
} else
beep_mode_freq = 56;
break;
case 0x20:
beep_mode_bit = 1;
beep_mode_freq = 56;
break;
case 0x30:
beep_mode_bit = 2;
#if defined(__LIBRETRO__)
#if defined(_WIN32)
beep_mode_freq = 112;
#else
beep_mode_freq = 56;
#endif
#else
#if defined(_MSC_VER)
beep_mode_freq = 56;
#else
beep_mode_freq = 112;
#endif
#endif
break;
}
beep_mode_bit_c = 0;
beep_mode_temp = dat;
chnum = (dat >> 6) & 3;
if (chnum != 3) {

View File

@ -29,7 +29,6 @@ typedef struct {
UINT32 beep_data_curr_loc;
UINT32 beep_data_load_loc;
UINT32 beep_laskclk;
UINT32 beep_cnt;
UINT events;
BPEVENT event[BEEPEVENT_MAX];
} _BEEP, *BEEP;
@ -47,12 +46,9 @@ extern "C" {
#endif
extern _BEEP g_beep;
#define BEEPDATACOUNT 0x10000
#define BEEPDATACOUNT 0x100000
extern UINT16 beep_data[BEEPDATACOUNT];
extern int beep_mode_freq;
extern int beep_mode_temp;
extern int beep_mode_bit;
extern int beep_mode_bit_c;
extern UINT32 beep_time[BEEPDATACOUNT];
void beep_initialize(UINT rate);
void beep_deinitialize(void);

View File

@ -11,6 +11,7 @@
_BEEP g_beep;
BEEPCFG beepcfg;
UINT16 beep_data[BEEPDATACOUNT];
UINT32 beep_time[BEEPDATACOUNT];
// #define BEEPLOG

View File

@ -1,33 +1,38 @@
#include "compiler.h"
#include "cpucore.h"
#include "sound.h"
#include "beep.h"
extern BEEPCFG beepcfg;
extern UINT16 beep_data[BEEPDATACOUNT];
int beep_mode_freq = 56; // 56:normal 42:TOKIO
int beep_mode_temp = 0;
int beep_mode_bit = 0;
int beep_mode_bit_c = 0;
static void oneshot(BEEP bp, SINT32 *pcm, UINT count) {
SINT32 samp;
double sampbias = soundcfg.rate / 44100.0;
UINT32 firsttime = beep_time[bp->beep_data_curr_loc];
UINT32 time = firsttime;
UINT32 bound;
if(bp->beep_data_load_loc != 0)
bound = (beep_time[bp->beep_data_load_loc - 1] - firsttime) / count;
else
bound = (beep_time[BEEPDATACOUNT - 1] - firsttime) / count;
while(count--) {
samp = (double)beep_data[bp->beep_data_curr_loc] / 0x100 * (0x5000 * beepcfg.vol) - (0x2500 * beepcfg.vol);
while(time >= beep_time[bp->beep_data_curr_loc] && bp->beep_data_curr_loc != bp->beep_data_load_loc) {
bp->beep_data_curr_loc++;
if(bp->beep_data_curr_loc >= BEEPDATACOUNT)
bp->beep_data_curr_loc = 0;
}
if(bp->beep_data_curr_loc != 0)
samp = beep_data[bp->beep_data_curr_loc - 1];
else
samp = beep_data[BEEPDATACOUNT - 1];
samp = (double)samp / 0x100 * (0x5000 * beepcfg.vol) - (0x2500 * beepcfg.vol);
pcm[0] += samp;
pcm[1] += samp;
pcm += 2;
bp->beep_cnt += 20 * (1.0 / sampbias);
if((bp->beep_data_curr_loc < bp->beep_cnt / beep_mode_freq) && (bp->beep_data_curr_loc != bp->beep_data_load_loc)) {
bp->beep_data_curr_loc = bp->beep_cnt / beep_mode_freq;
if(bp->beep_data_curr_loc >= BEEPDATACOUNT) {
bp->beep_data_curr_loc = 0;
bp->beep_cnt %= beep_mode_freq;
}
}
time += bound;
}
}