mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
PCM sound, refactored code940
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@27 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
7573607016
commit
4f265db776
28 changed files with 914 additions and 312 deletions
|
@ -49,7 +49,8 @@ int PicoInit(void)
|
|||
// to be called once on emu exit
|
||||
void PicoExit(void)
|
||||
{
|
||||
PicoExitMCD();
|
||||
if (PicoMCD&1)
|
||||
PicoExitMCD();
|
||||
z80_exit();
|
||||
|
||||
// notaz: sram
|
||||
|
@ -322,7 +323,8 @@ static __inline void getSamples(int y)
|
|||
if (emustatus&1) emustatus|=2; else emustatus&=~2;
|
||||
if (PicoWriteSound) PicoWriteSound();
|
||||
// clear sound buffer
|
||||
memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));
|
||||
sound_clear();
|
||||
//memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));
|
||||
}
|
||||
else if(emustatus & 3) {
|
||||
emustatus|= 2;
|
||||
|
|
|
@ -23,13 +23,14 @@ extern "C" {
|
|||
int mp3_get_bitrate(FILE *f, int size);
|
||||
void mp3_start_play(FILE *f, int pos);
|
||||
int mp3_get_offset(void); // 0-1023
|
||||
void mp3_update(int *buffer, int length, int stereo);
|
||||
|
||||
|
||||
// Pico.c
|
||||
// PicoOpt bits LSb->MSb:
|
||||
// enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound,
|
||||
// alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites,
|
||||
// draw_no_32col_border, external_ym2612
|
||||
// draw_no_32col_border, external_ym2612, enable_pcm, enable cdda
|
||||
extern int PicoOpt;
|
||||
extern int PicoVer;
|
||||
extern int PicoSkipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff
|
||||
|
|
|
@ -164,6 +164,22 @@ struct PicoSRAM
|
|||
#include "cd/LC89510.h"
|
||||
#include "cd/gfx_cd.h"
|
||||
|
||||
struct mcd_pcm
|
||||
{
|
||||
unsigned char control; // reg7
|
||||
unsigned char enabled; // reg8
|
||||
unsigned char cur_ch;
|
||||
unsigned char bank;
|
||||
int pad1;
|
||||
|
||||
struct pcm_chan
|
||||
{
|
||||
unsigned char regs[8];
|
||||
unsigned int addr; // played sample address
|
||||
int pad;
|
||||
} ch[8];
|
||||
};
|
||||
|
||||
struct mcd_misc
|
||||
{
|
||||
unsigned short hint_vector;
|
||||
|
@ -174,7 +190,9 @@ struct mcd_misc
|
|||
unsigned short audio_offset; // for savestates: play pointer offset (0-1023)
|
||||
unsigned char audio_track; // playing audio track # (zero based)
|
||||
char pad1;
|
||||
int pad[12];
|
||||
int timer_int3;
|
||||
unsigned int timer_stopwatch;
|
||||
int pad[10];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
|
@ -185,8 +203,13 @@ typedef struct
|
|||
unsigned char prg_ram_b[4][0x20000];
|
||||
};
|
||||
unsigned char word_ram[0x40000]; // 256K
|
||||
union {
|
||||
unsigned char pcm_ram[0x10000]; // 64K
|
||||
unsigned char pcm_ram_b[0x10][0x1000];
|
||||
};
|
||||
unsigned char bram[0x2000]; // 8K
|
||||
unsigned char s68k_regs[0x200];
|
||||
unsigned char s68k_regs[0x200]; // GA, not CPU regs
|
||||
struct mcd_pcm pcm;
|
||||
_scd_toc TOC; // not to be saved
|
||||
CDD cdd;
|
||||
CDC cdc;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// This is part of Pico Library
|
||||
|
||||
// (c) Copyright 2006 notaz, All rights reserved.
|
||||
// (c) Copyright 2007 notaz, All rights reserved.
|
||||
// Free for non-commercial use.
|
||||
|
||||
// For commercial use, separate licencing terms must be obtained.
|
||||
|
@ -31,12 +31,14 @@ typedef enum {
|
|||
CHUNK_S68K,
|
||||
CHUNK_PRG_RAM,
|
||||
CHUNK_WORD_RAM,
|
||||
CHUNK_BRAM, // 15
|
||||
CHUNK_PCM_RAM, // 15
|
||||
CHUNK_BRAM,
|
||||
CHUNK_GA_REGS,
|
||||
CHUNK_PCM,
|
||||
CHUNK_CDC,
|
||||
CHUNK_CDD,
|
||||
CHUNK_CDD, // 20
|
||||
CHUNK_SCD,
|
||||
CHUNK_RC, // 20
|
||||
CHUNK_RC,
|
||||
CHUNK_MISC_CD,
|
||||
} chunk_name_e;
|
||||
|
||||
|
@ -96,8 +98,10 @@ int PicoCdSaveState(void *file)
|
|||
CHECKED_WRITE_BUFF(CHUNK_S68K, buff);
|
||||
CHECKED_WRITE_BUFF(CHUNK_PRG_RAM, Pico_mcd->prg_ram);
|
||||
CHECKED_WRITE_BUFF(CHUNK_WORD_RAM, Pico_mcd->word_ram); // in 2M format
|
||||
CHECKED_WRITE_BUFF(CHUNK_PCM_RAM, Pico_mcd->pcm_ram);
|
||||
CHECKED_WRITE_BUFF(CHUNK_BRAM, Pico_mcd->bram);
|
||||
CHECKED_WRITE_BUFF(CHUNK_GA_REGS, Pico_mcd->s68k_regs);
|
||||
CHECKED_WRITE_BUFF(CHUNK_GA_REGS, Pico_mcd->s68k_regs); // GA regs, not CPU regs
|
||||
CHECKED_WRITE_BUFF(CHUNK_PCM, Pico_mcd->pcm);
|
||||
CHECKED_WRITE_BUFF(CHUNK_CDD, Pico_mcd->cdd);
|
||||
CHECKED_WRITE_BUFF(CHUNK_CDC, Pico_mcd->cdc);
|
||||
CHECKED_WRITE_BUFF(CHUNK_SCD, Pico_mcd->scd);
|
||||
|
@ -147,6 +151,7 @@ int PicoCdLoadState(void *file)
|
|||
CHECKED_READ(1, buff);
|
||||
CHECKED_READ(4, &len);
|
||||
if (len < 0 || len > 1024*512) R_ERROR_RETURN("bad length");
|
||||
if (buff[0] > CHUNK_FM && !(PicoMCD & 1)) R_ERROR_RETURN("cd chunk in non CD state?");
|
||||
|
||||
switch (buff[0])
|
||||
{
|
||||
|
@ -181,8 +186,10 @@ int PicoCdLoadState(void *file)
|
|||
|
||||
case CHUNK_PRG_RAM: CHECKED_READ_BUFF(Pico_mcd->prg_ram); break;
|
||||
case CHUNK_WORD_RAM: CHECKED_READ_BUFF(Pico_mcd->word_ram); break;
|
||||
case CHUNK_PCM_RAM: CHECKED_READ_BUFF(Pico_mcd->pcm_ram); break;
|
||||
case CHUNK_BRAM: CHECKED_READ_BUFF(Pico_mcd->bram); break;
|
||||
case CHUNK_GA_REGS: CHECKED_READ_BUFF(Pico_mcd->s68k_regs); break;
|
||||
case CHUNK_PCM: CHECKED_READ_BUFF(Pico_mcd->pcm); break;
|
||||
case CHUNK_CDD: CHECKED_READ_BUFF(Pico_mcd->cdd); break;
|
||||
case CHUNK_CDC: CHECKED_READ_BUFF(Pico_mcd->cdc); break;
|
||||
case CHUNK_SCD: CHECKED_READ_BUFF(Pico_mcd->scd); break;
|
||||
|
|
106
Pico/cd/Memory.c
106
Pico/cd/Memory.c
|
@ -17,6 +17,7 @@
|
|||
#include "../sound/sn76496.h"
|
||||
|
||||
#include "gfx_cd.h"
|
||||
#include "pcm.h"
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
|
@ -161,7 +162,8 @@ static u32 s68k_reg_read16(u32 a)
|
|||
goto end;
|
||||
case 0xC:
|
||||
dprintf("s68k stopwatch timer read");
|
||||
break;
|
||||
d = Pico_mcd->m.timer_stopwatch >> 16;
|
||||
goto end;
|
||||
case 0x30:
|
||||
dprintf("s68k int3 timer read");
|
||||
break;
|
||||
|
@ -212,10 +214,13 @@ static void s68k_reg_write8(u32 a, u32 d)
|
|||
dprintf("s68k set CDC dma addr");
|
||||
break;
|
||||
case 0xc:
|
||||
case 0xd:
|
||||
dprintf("s68k set stopwatch timer");
|
||||
break;
|
||||
Pico_mcd->m.timer_stopwatch = 0;
|
||||
return;
|
||||
case 0x31:
|
||||
dprintf("s68k set int3 timer");
|
||||
dprintf("s68k set int3 timer: %02x", d);
|
||||
Pico_mcd->m.timer_int3 = d << 16;
|
||||
break;
|
||||
case 0x33: // IRQ mask
|
||||
dprintf("s68k irq mask: %02x", d);
|
||||
|
@ -830,6 +835,21 @@ u8 PicoReadS68k8(u32 a)
|
|||
goto end;
|
||||
}
|
||||
|
||||
// PCM
|
||||
if ((a&0xff8000)==0xff0000) {
|
||||
dprintf("s68k_pcm r8: [%06x] @%06x", a, SekPc);
|
||||
a &= 0x7fff;
|
||||
if (a >= 0x2000)
|
||||
d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff];
|
||||
else if (a >= 0x20) {
|
||||
a &= 0x1e;
|
||||
d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT;
|
||||
if (a & 2) d >>= 8;
|
||||
}
|
||||
dprintf("ret = %02x", (u8)d);
|
||||
goto end;
|
||||
}
|
||||
|
||||
// bram
|
||||
if ((a&0xff0000)==0xfe0000) {
|
||||
d = Pico_mcd->bram[(a>>1)&0x1fff];
|
||||
|
@ -849,7 +869,7 @@ u8 PicoReadS68k8(u32 a)
|
|||
|
||||
u16 PicoReadS68k16(u32 a)
|
||||
{
|
||||
u16 d=0;
|
||||
u32 d=0;
|
||||
|
||||
a&=0xfffffe;
|
||||
|
||||
|
@ -898,12 +918,27 @@ u16 PicoReadS68k16(u32 a)
|
|||
if ((a&0xff0000)==0xfe0000) {
|
||||
dprintf("s68k_bram r16: [%06x] @%06x", a, SekPc);
|
||||
a = (a>>1)&0x1fff;
|
||||
d = Pico_mcd->bram[a++]; // Gens does little endian here, an so do we..
|
||||
d = Pico_mcd->bram[a++]; // Gens does little endian here, and so do we..
|
||||
d|= Pico_mcd->bram[a++] << 8;
|
||||
dprintf("ret = %04x", d);
|
||||
goto end;
|
||||
}
|
||||
|
||||
// PCM
|
||||
if ((a&0xff8000)==0xff0000) {
|
||||
dprintf("s68k_pcm r16: [%06x] @%06x", a, SekPc);
|
||||
a &= 0x7fff;
|
||||
if (a >= 0x2000)
|
||||
d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff];
|
||||
else if (a >= 0x20) {
|
||||
a &= 0x1e;
|
||||
d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT;
|
||||
if (a & 2) d >>= 8;
|
||||
}
|
||||
dprintf("ret = %04x", d);
|
||||
goto end;
|
||||
}
|
||||
|
||||
dprintf("s68k r16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k);
|
||||
|
||||
end:
|
||||
|
@ -964,6 +999,29 @@ u32 PicoReadS68k32(u32 a)
|
|||
goto end;
|
||||
}
|
||||
|
||||
// PCM
|
||||
if ((a&0xff8000)==0xff0000) {
|
||||
dprintf("s68k_pcm r32: [%06x] @%06x", a, SekPc);
|
||||
a &= 0x7fff;
|
||||
if (a >= 0x2000) {
|
||||
a >>= 1;
|
||||
d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][a&0xfff] << 16;
|
||||
d |= Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a+1)&0xfff];
|
||||
} else if (a >= 0x20) {
|
||||
a &= 0x1e;
|
||||
if (a & 2) {
|
||||
a >>= 2;
|
||||
d = (Pico_mcd->pcm.ch[a].addr >> (PCM_STEP_SHIFT-8)) & 0xff0000;
|
||||
d |= (Pico_mcd->pcm.ch[(a+1)&7].addr >> PCM_STEP_SHIFT) & 0xff;
|
||||
} else {
|
||||
d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT;
|
||||
d = ((d<<16)&0xff0000) | ((d>>8)&0xff); // PCM chip is LE
|
||||
}
|
||||
}
|
||||
dprintf("ret = %08x", d);
|
||||
goto end;
|
||||
}
|
||||
|
||||
// bram
|
||||
if ((a&0xff0000)==0xfe0000) {
|
||||
dprintf("s68k_bram r32: [%06x] @%06x", a, SekPc);
|
||||
|
@ -1004,9 +1062,6 @@ void PicoWriteS68k8(u32 a,u8 d)
|
|||
return;
|
||||
}
|
||||
|
||||
if (a != 0xff0011 && (a&0xff8000) == 0xff0000) // PCM hack
|
||||
return;
|
||||
|
||||
// regs
|
||||
if ((a&0xfffe00) == 0xff8000) {
|
||||
a &= 0x1ff;
|
||||
|
@ -1040,6 +1095,16 @@ void PicoWriteS68k8(u32 a,u8 d)
|
|||
return;
|
||||
}
|
||||
|
||||
// PCM
|
||||
if ((a&0xff8000)==0xff0000) {
|
||||
a &= 0x7fff;
|
||||
if (a >= 0x2000)
|
||||
Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff] = d;
|
||||
else if (a < 0x12)
|
||||
pcm_write(a>>1, d);
|
||||
return;
|
||||
}
|
||||
|
||||
// bram
|
||||
if ((a&0xff0000)==0xfe0000) {
|
||||
Pico_mcd->bram[(a>>1)&0x1fff] = d;
|
||||
|
@ -1101,6 +1166,16 @@ void PicoWriteS68k16(u32 a,u16 d)
|
|||
return;
|
||||
}
|
||||
|
||||
// PCM
|
||||
if ((a&0xff8000)==0xff0000) {
|
||||
a &= 0x7fff;
|
||||
if (a >= 0x2000)
|
||||
Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff] = d;
|
||||
else if (a < 0x12)
|
||||
pcm_write(a>>1, d & 0xff);
|
||||
return;
|
||||
}
|
||||
|
||||
// bram
|
||||
if ((a&0xff0000)==0xfe0000) {
|
||||
dprintf("s68k_bram w16: [%06x] %04x @%06x", a, d, SekPc);
|
||||
|
@ -1171,6 +1246,21 @@ void PicoWriteS68k32(u32 a,u32 d)
|
|||
return;
|
||||
}
|
||||
|
||||
// PCM
|
||||
if ((a&0xff8000)==0xff0000) {
|
||||
a &= 0x7fff;
|
||||
if (a >= 0x2000) {
|
||||
a >>= 1;
|
||||
Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][a&0xfff] = (d >> 16);
|
||||
Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a+1)&0xfff] = d;
|
||||
} else if (a < 0x12) {
|
||||
a >>= 1;
|
||||
pcm_write(a, (d>>16) & 0xff);
|
||||
pcm_write(a+1, d & 0xff);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// bram
|
||||
if ((a&0xff0000)==0xfe0000) {
|
||||
dprintf("s68k_bram w32: [%06x] %08x @%06x", a, d, SekPc);
|
||||
|
|
|
@ -32,11 +32,13 @@ int PicoResetMCD(int hard)
|
|||
{
|
||||
memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram));
|
||||
memset(Pico_mcd->word_ram, 0, sizeof(Pico_mcd->word_ram));
|
||||
memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram));
|
||||
if (hard) {
|
||||
memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram));
|
||||
memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - 8*0x10, formatted_bram, 8*0x10);
|
||||
}
|
||||
memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs));
|
||||
memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm));
|
||||
|
||||
*(unsigned int *)(Pico_mcd->bios + 0x70) = 0xffffffff; // reset hint vector (simplest way to implement reg6)
|
||||
Pico_mcd->m.state_flags |= 2; // s68k reset pending
|
||||
|
@ -97,6 +99,38 @@ static __inline void check_cd_dma(void)
|
|||
Update_CDC_TRansfer(ddx); // now go and do the actual transfer
|
||||
}
|
||||
|
||||
static __inline void update_chips(void)
|
||||
{
|
||||
int counter_timer, int3_set;
|
||||
int counter75hz_lim = Pico.m.pal ? 2080 : 2096;
|
||||
|
||||
// 75Hz CDC update
|
||||
if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) {
|
||||
Pico_mcd->m.counter75hz -= counter75hz_lim;
|
||||
Check_CD_Command();
|
||||
}
|
||||
|
||||
// update timers
|
||||
counter_timer = Pico.m.pal ? 0x21630 : 0x2121c; // 136752 : 135708;
|
||||
Pico_mcd->m.timer_stopwatch += counter_timer;
|
||||
if ((int3_set = Pico_mcd->s68k_regs[0x31])) {
|
||||
Pico_mcd->m.timer_int3 -= counter_timer;
|
||||
if (Pico_mcd->m.timer_int3 < 0) {
|
||||
if (Pico_mcd->s68k_regs[0x33] & (1<<3)) {
|
||||
dprintf("s68k: timer irq 3");
|
||||
SekInterruptS68k(3);
|
||||
Pico_mcd->m.timer_int3 += int3_set << 16;
|
||||
}
|
||||
// is this really what happens if irq3 is masked out?
|
||||
Pico_mcd->m.timer_int3 &= 0xffffff;
|
||||
}
|
||||
}
|
||||
|
||||
// update gfx chip
|
||||
if (Pico_mcd->rot_comp.Reg_58 & 0x8000)
|
||||
gfx_cd_update();
|
||||
}
|
||||
|
||||
// to be called on 224 or line_sample scanlines only
|
||||
static __inline void getSamples(int y)
|
||||
{
|
||||
|
@ -108,7 +142,8 @@ static __inline void getSamples(int y)
|
|||
if (emustatus&1) emustatus|=2; else emustatus&=~2;
|
||||
if (PicoWriteSound) PicoWriteSound();
|
||||
// clear sound buffer
|
||||
memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));
|
||||
sound_clear();
|
||||
//memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));
|
||||
}
|
||||
else if(emustatus & 3) {
|
||||
emustatus|= 2;
|
||||
|
@ -118,12 +153,10 @@ static __inline void getSamples(int y)
|
|||
}
|
||||
|
||||
|
||||
|
||||
// Accurate but slower frame which does hints
|
||||
static int PicoFrameHintsMCD(void)
|
||||
{
|
||||
struct PicoVideo *pv=&Pico.video;
|
||||
int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample,counter75hz_lim;
|
||||
int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample;
|
||||
const int cycles_68k=488,cycles_z80=228,cycles_s68k=795; // both PAL and NTSC compile to same values
|
||||
int skip=PicoSkipFrame || (PicoOpt&0x10);
|
||||
int hint; // Hint counter
|
||||
|
@ -133,13 +166,11 @@ static int PicoFrameHintsMCD(void)
|
|||
//cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228
|
||||
lines = 312; // Steve Snake says there are 313 lines, but this seems to also work well
|
||||
line_sample = 68;
|
||||
counter75hz_lim = 2080;
|
||||
if(pv->reg[1]&8) lines_vis = 240;
|
||||
} else {
|
||||
//cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488
|
||||
//cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228
|
||||
lines = 262;
|
||||
counter75hz_lim = 2096;
|
||||
line_sample = 93;
|
||||
}
|
||||
|
||||
|
@ -242,13 +273,7 @@ static int PicoFrameHintsMCD(void)
|
|||
total_z80+=z80_run(z80CycleAim-total_z80);
|
||||
}
|
||||
|
||||
if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) {
|
||||
Pico_mcd->m.counter75hz -= counter75hz_lim;
|
||||
Check_CD_Command();
|
||||
}
|
||||
|
||||
if (Pico_mcd->rot_comp.Reg_58 & 0x8000)
|
||||
gfx_cd_update();
|
||||
update_chips();
|
||||
}
|
||||
|
||||
// draw a frame just after vblank in alternative render mode
|
||||
|
|
57
Pico/sound/mix.c
Normal file
57
Pico/sound/mix.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
#define MAXOUT (+32767)
|
||||
#define MINOUT (-32768)
|
||||
|
||||
/* limitter */
|
||||
#define Limit(val, max,min) { \
|
||||
if ( val > max ) val = max; \
|
||||
else if ( val < min ) val = min; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void memcpy32(int *dest, int *src, int count)
|
||||
{
|
||||
while (count--)
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
|
||||
void memset32(int *dest, int c, int count)
|
||||
{
|
||||
while (count--)
|
||||
*dest++ = c;
|
||||
}
|
||||
|
||||
|
||||
void mix_32_to_16l_stereo(short *dest, int *src, int count)
|
||||
{
|
||||
int l, r;
|
||||
|
||||
for (; count > 0; count--)
|
||||
{
|
||||
l = r = *dest;
|
||||
l += *src++;
|
||||
r += *src++;
|
||||
Limit( l, MAXOUT, MINOUT );
|
||||
Limit( r, MAXOUT, MINOUT );
|
||||
*dest++ = l;
|
||||
*dest++ = r;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mix_32_to_16_mono(short *dest, int *src, int count)
|
||||
{
|
||||
int l;
|
||||
|
||||
for (; count > 0; count--)
|
||||
{
|
||||
l = *dest;
|
||||
l += *src++;
|
||||
Limit( l, MAXOUT, MINOUT );
|
||||
*dest++ = l;
|
||||
}
|
||||
}
|
||||
|
||||
|
10
Pico/sound/mix.h
Normal file
10
Pico/sound/mix.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
void memcpy32(int *dest, int *src, int count);
|
||||
void memset32(int *dest, int c, int count);
|
||||
//void mix_32_to_32(int *dest, int *src, int count);
|
||||
void mix_16h_to_32(int *dest, short *src, int count);
|
||||
void mix_16h_to_32_s1(int *dest, short *src, int count);
|
||||
void mix_16h_to_32_s2(int *dest, short *src, int count);
|
||||
void mix_32_to_16l_stereo(short *dest, int *src, int count);
|
||||
void mix_32_to_16_mono(short *dest, int *src, int count);
|
||||
|
350
Pico/sound/mix.s
Normal file
350
Pico/sound/mix.s
Normal file
|
@ -0,0 +1,350 @@
|
|||
@ vim:filetype=armasm
|
||||
|
||||
.global memcpy32 @ int *dest, int *src, int count
|
||||
|
||||
memcpy32:
|
||||
stmfd sp!, {r4,lr}
|
||||
|
||||
subs r2, r2, #4
|
||||
bmi mcp32_fin
|
||||
|
||||
mcp32_loop:
|
||||
ldmia r1!, {r3,r4,r12,lr}
|
||||
subs r2, r2, #4
|
||||
stmia r0!, {r3,r4,r12,lr}
|
||||
bpl mcp32_loop
|
||||
|
||||
mcp32_fin:
|
||||
tst r2, #3
|
||||
ldmeqfd sp!, {r4,pc}
|
||||
tst r2, #1
|
||||
ldrne r3, [r1], #4
|
||||
strne r3, [r0], #4
|
||||
|
||||
mcp32_no_unal1:
|
||||
tst r2, #2
|
||||
ldmneia r1!, {r3,r12}
|
||||
ldmfd sp!, {r4,lr}
|
||||
stmneia r0!, {r3,r12}
|
||||
bx lr
|
||||
|
||||
|
||||
|
||||
.global memset32 @ int *dest, int c, int count
|
||||
|
||||
memset32:
|
||||
stmfd sp!, {lr}
|
||||
|
||||
mov r3, r1
|
||||
subs r2, r2, #4
|
||||
bmi mst32_fin
|
||||
|
||||
mov r12,r1
|
||||
mov lr, r1
|
||||
|
||||
mst32_loop:
|
||||
subs r2, r2, #4
|
||||
stmia r0!, {r1,r3,r12,lr}
|
||||
bpl mst32_loop
|
||||
|
||||
mst32_fin:
|
||||
tst r2, #1
|
||||
strne r1, [r0], #4
|
||||
|
||||
tst r2, #2
|
||||
stmneia r0!, {r1,r3}
|
||||
|
||||
ldmfd sp!, {lr}
|
||||
bx lr
|
||||
|
||||
|
||||
|
||||
@ this assumes src is word aligned
|
||||
.global mix_16h_to_32 @ int *dest, short *src, int count
|
||||
|
||||
mix_16h_to_32:
|
||||
stmfd sp!, {r4-r6,lr}
|
||||
/*
|
||||
tst r1, #2
|
||||
beq m16_32_mo_unalw
|
||||
ldrsh r4, [r1], #2
|
||||
ldr r3, [r0]
|
||||
sub r2, r2, #1
|
||||
add r3, r3, r4, asr #1
|
||||
str r3, [r0], #4
|
||||
*/
|
||||
m16_32_mo_unalw:
|
||||
subs r2, r2, #4
|
||||
bmi m16_32_end
|
||||
|
||||
m16_32_loop:
|
||||
ldmia r0, {r3-r6}
|
||||
ldmia r1!,{r12,lr}
|
||||
subs r2, r2, #4
|
||||
add r4, r4, r12,asr #17 @ we use half volume
|
||||
mov r12,r12,lsl #16
|
||||
add r3, r3, r12,asr #17
|
||||
add r6, r6, lr, asr #17
|
||||
mov lr, lr, lsl #16
|
||||
add r5, r5, lr, asr #17
|
||||
stmia r0!,{r3-r6}
|
||||
bpl m16_32_loop
|
||||
|
||||
m16_32_end:
|
||||
tst r2, #2
|
||||
beq m16_32_no_unal2
|
||||
ldr r5, [r1], #4
|
||||
ldmia r0, {r3,r4}
|
||||
mov r12,r5, lsl #16
|
||||
add r3, r3, r12,asr #17
|
||||
add r4, r4, r5, asr #17
|
||||
stmia r0!,{r3,r4}
|
||||
|
||||
m16_32_no_unal2:
|
||||
tst r2, #1
|
||||
ldmeqfd sp!, {r4-r6,pc}
|
||||
ldrsh r4, [r1], #2
|
||||
ldr r3, [r0]
|
||||
add r3, r3, r4, asr #1
|
||||
str r3, [r0], #4
|
||||
|
||||
ldmfd sp!, {r4-r6,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
|
||||
.global mix_16h_to_32_s1 @ int *dest, short *src, int count
|
||||
|
||||
mix_16h_to_32_s1:
|
||||
stmfd sp!, {r4-r6,lr}
|
||||
|
||||
subs r2, r2, #4
|
||||
bmi m16_32_s1_end
|
||||
|
||||
m16_32_s1_loop:
|
||||
ldmia r0, {r3-r6}
|
||||
ldr r12,[r1], #8
|
||||
ldr lr, [r1], #8
|
||||
subs r2, r2, #4
|
||||
add r4, r4, r12,asr #17
|
||||
mov r12,r12,lsl #16
|
||||
add r3, r3, r12,asr #17 @ we use half volume
|
||||
add r6, r6, lr, asr #17
|
||||
mov lr, lr, lsl #16
|
||||
add r5, r5, lr, asr #17
|
||||
stmia r0!,{r3-r6}
|
||||
bpl m16_32_s1_loop
|
||||
|
||||
m16_32_s1_end:
|
||||
tst r2, #2
|
||||
beq m16_32_s1_no_unal2
|
||||
ldr r5, [r1], #8
|
||||
ldmia r0, {r3,r4}
|
||||
mov r12,r5, lsl #16
|
||||
add r3, r3, r12,asr #17
|
||||
add r4, r4, r5, asr #17
|
||||
stmia r0!,{r3,r4}
|
||||
|
||||
m16_32_s1_no_unal2:
|
||||
tst r2, #1
|
||||
ldmeqfd sp!, {r4-r6,pc}
|
||||
ldrsh r4, [r1], #2
|
||||
ldr r3, [r0]
|
||||
add r3, r3, r4, asr #1
|
||||
str r3, [r0], #4
|
||||
|
||||
ldmfd sp!, {r4-r6,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
|
||||
.global mix_16h_to_32_s2 @ int *dest, short *src, int count
|
||||
|
||||
mix_16h_to_32_s2:
|
||||
stmfd sp!, {r4-r6,lr}
|
||||
|
||||
subs r2, r2, #4
|
||||
bmi m16_32_s2_end
|
||||
|
||||
m16_32_s2_loop:
|
||||
ldmia r0, {r3-r6}
|
||||
ldr r12,[r1], #16
|
||||
ldr lr, [r1], #16
|
||||
subs r2, r2, #4
|
||||
add r4, r4, r12,asr #17
|
||||
mov r12,r12,lsl #16
|
||||
add r3, r3, r12,asr #17 @ we use half volume
|
||||
add r6, r6, lr, asr #17
|
||||
mov lr, lr, lsl #16
|
||||
add r5, r5, lr, asr #17
|
||||
stmia r0!,{r3-r6}
|
||||
bpl m16_32_s2_loop
|
||||
|
||||
m16_32_s2_end:
|
||||
tst r2, #2
|
||||
beq m16_32_s2_no_unal2
|
||||
ldr r5, [r1], #16
|
||||
ldmia r0, {r3,r4}
|
||||
mov r12,r5, lsl #16
|
||||
add r3, r3, r12,asr #17
|
||||
add r4, r4, r5, asr #17
|
||||
stmia r0!,{r3,r4}
|
||||
|
||||
m16_32_s2_no_unal2:
|
||||
tst r2, #1
|
||||
ldmeqfd sp!, {r4-r6,pc}
|
||||
ldrsh r4, [r1], #2
|
||||
ldr r3, [r0]
|
||||
add r3, r3, r4, asr #1
|
||||
str r3, [r0], #4
|
||||
|
||||
ldmfd sp!, {r4-r6,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
|
||||
@ limit
|
||||
@ reg=int_sample, lr=1, r3=tmp, kills flags
|
||||
.macro Limit reg
|
||||
add r3, lr, \reg, asr #16
|
||||
bics r3, r3, #1 @ in non-overflow conditions r3 is 0 or 1
|
||||
movne \reg, #0x8000
|
||||
submi \reg, \reg, #1
|
||||
.endm
|
||||
|
||||
|
||||
@ limit and shift up by 16
|
||||
@ reg=int_sample, lr=1, r3=tmp, kills flags
|
||||
.macro Limitsh reg
|
||||
@ movs r4, r3, asr #16
|
||||
@ cmnne r4, #1
|
||||
@ beq c32_16_no_overflow
|
||||
@ tst r4, r4
|
||||
@ mov r3, #0x8000
|
||||
@ subpl r3, r3, #1
|
||||
|
||||
add r3, lr, \reg, asr #16
|
||||
bics r3, r3, #1 @ in non-overflow conditions r3 is 0 or 1
|
||||
moveq \reg, \reg, lsl #16
|
||||
movne \reg, #0x80000000
|
||||
submi \reg, \reg, #0x00010000
|
||||
.endm
|
||||
|
||||
|
||||
@ mix 32bit audio (with 16bits really used, upper bits indicate overflow) with normal 16 bit audio with left channel only
|
||||
@ warning: this function assumes dest is word aligned
|
||||
.global mix_32_to_16l_stereo @ short *dest, int *src, int count
|
||||
|
||||
mix_32_to_16l_stereo:
|
||||
stmfd sp!, {r4-r8,lr}
|
||||
|
||||
mov lr, #1
|
||||
|
||||
mov r2, r2, lsl #1
|
||||
subs r2, r2, #4
|
||||
bmi m32_16l_st_end
|
||||
|
||||
m32_16l_st_loop:
|
||||
ldmia r0, {r8,r12}
|
||||
ldmia r1!, {r4-r7}
|
||||
mov r8, r8, lsl #16
|
||||
mov r12,r12,lsl #16
|
||||
add r4, r4, r8, asr #16
|
||||
add r5, r5, r8, asr #16
|
||||
add r6, r6, r12,asr #16
|
||||
add r7, r7, r12,asr #16
|
||||
Limitsh r4
|
||||
Limitsh r5
|
||||
Limitsh r6
|
||||
Limitsh r7
|
||||
subs r2, r2, #4
|
||||
orr r4, r5, r4, lsr #16
|
||||
orr r5, r7, r6, lsr #16
|
||||
stmia r0!, {r4,r5}
|
||||
bpl m32_16l_st_loop
|
||||
|
||||
m32_16l_st_end:
|
||||
@ check for remaining bytes to convert
|
||||
tst r2, #2
|
||||
beq m32_16l_st_no_unal2
|
||||
ldrsh r6, [r0]
|
||||
ldmia r1!,{r4,r5}
|
||||
add r4, r4, r6
|
||||
add r5, r5, r6
|
||||
Limitsh r4
|
||||
Limitsh r5
|
||||
orr r4, r5, r4, lsr #16
|
||||
str r4, [r0], #4
|
||||
|
||||
m32_16l_st_no_unal2:
|
||||
ldmfd sp!, {r4-r8,lr}
|
||||
bx lr
|
||||
|
||||
|
||||
@ mix 32bit audio (with 16bits really used, upper bits indicate overflow) with normal 16 bit audio (for mono sound)
|
||||
.global mix_32_to_16_mono @ short *dest, int *src, int count
|
||||
|
||||
mix_32_to_16_mono:
|
||||
stmfd sp!, {r4-r8,lr}
|
||||
|
||||
mov lr, #1
|
||||
|
||||
@ check if dest is word aligned
|
||||
tst r0, #2
|
||||
beq m32_16_mo_no_unalw
|
||||
ldrsh r5, [r0], #2
|
||||
ldr r4, [r1], #4
|
||||
sub r2, r2, #1
|
||||
add r4, r4, r5
|
||||
Limit r4
|
||||
strh r4, [r0], #2
|
||||
|
||||
m32_16_mo_no_unalw:
|
||||
subs r2, r2, #4
|
||||
bmi m32_16_mo_end
|
||||
|
||||
m32_16_mo_loop:
|
||||
ldmia r0, {r8,r12}
|
||||
ldmia r1!, {r4-r7}
|
||||
add r5, r5, r8, asr #16
|
||||
mov r8, r8, lsl #16
|
||||
add r4, r4, r8, asr #16
|
||||
add r7, r7, r12,asr #16
|
||||
mov r12,r12,lsl #16
|
||||
add r6, r6, r12,asr #16
|
||||
Limitsh r4
|
||||
Limitsh r5
|
||||
Limitsh r6
|
||||
Limitsh r7
|
||||
subs r2, r2, #4
|
||||
orr r4, r5, r4, lsr #16
|
||||
orr r5, r7, r6, lsr #16
|
||||
stmia r0!, {r4,r5}
|
||||
bpl m32_16_mo_loop
|
||||
|
||||
m32_16_mo_end:
|
||||
@ check for remaining bytes to convert
|
||||
tst r2, #2
|
||||
beq m32_16_mo_no_unal2
|
||||
ldr r6, [r0]
|
||||
ldmia r1!,{r4,r5}
|
||||
add r5, r5, r6, asr #16
|
||||
mov r6, r6, lsl #16
|
||||
add r4, r4, r6, asr #16
|
||||
Limitsh r4
|
||||
Limitsh r5
|
||||
orr r4, r5, r4, lsr #16
|
||||
str r4, [r0], #4
|
||||
|
||||
m32_16_mo_no_unal2:
|
||||
tst r2, #1
|
||||
ldmeqfd sp!, {r4-r8,pc}
|
||||
ldrsh r5, [r0], #2
|
||||
ldr r4, [r1], #4
|
||||
add r4, r4, r5
|
||||
Limit r4
|
||||
strh r4, [r0], #2
|
||||
|
||||
ldmfd sp!, {r4-r8,lr}
|
||||
bx lr
|
||||
|
|
@ -175,7 +175,7 @@ WRITE8_HANDLER( SN76496_4_w ) { SN76496Write(4,data); }
|
|||
*/
|
||||
|
||||
//static
|
||||
void SN76496Update(short *buffer,int length,int stereo)
|
||||
void SN76496Update(short *buffer, int length, int stereo)
|
||||
{
|
||||
int i;
|
||||
struct SN76496 *R = &ono_sn;
|
||||
|
@ -258,13 +258,10 @@ void SN76496Update(short *buffer,int length,int stereo)
|
|||
|
||||
if (out > MAX_OUTPUT * STEP) out = MAX_OUTPUT * STEP;
|
||||
|
||||
out /= STEP; // will be optimized to shift
|
||||
if(stereo) {
|
||||
// only left channel for stereo (will be copied to right by ym2612 mixing code)
|
||||
if ((out /= STEP)) // will be optimized to shift; max 0x47ff = 18431
|
||||
*buffer += out;
|
||||
buffer+=2;
|
||||
} else
|
||||
*buffer++ += out;
|
||||
if(stereo) buffer+=2; // only left for stereo, to be mixed to right later
|
||||
else buffer++;
|
||||
|
||||
length--;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,11 @@
|
|||
#endif
|
||||
|
||||
#include "../PicoInt.h"
|
||||
#include "../cd/pcm.h"
|
||||
#include "mix.h"
|
||||
|
||||
// master int buffer to mix to
|
||||
static int PsndBuffer[2*44100/50];
|
||||
|
||||
//int z80CycleAim = 0;
|
||||
|
||||
|
@ -77,7 +81,7 @@ static void dac_recalculate()
|
|||
dac_cnt -= lines;
|
||||
len++;
|
||||
}
|
||||
if (i == mid) // midpoint
|
||||
if (i == mid) // midpoint
|
||||
while(pos+len < PsndLen/2) {
|
||||
dac_cnt -= lines;
|
||||
len++;
|
||||
|
@ -124,9 +128,18 @@ void sound_rerate()
|
|||
{
|
||||
unsigned int state[28];
|
||||
|
||||
// not all rates are supported in MCD mode due to mp3 decoder
|
||||
if (PicoMCD & 1) {
|
||||
if (PsndRate != 11025 && PsndRate != 22050 && PsndRate != 44100) PsndRate = 22050;
|
||||
if (!(PicoOpt & 8)) PicoOpt |= 8;
|
||||
}
|
||||
|
||||
if ((PicoMCD & 1) && Pico_mcd->m.audio_track) Pico_mcd->m.audio_offset = mp3_get_offset();
|
||||
YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PsndRate);
|
||||
// feed it back it's own registers, just like after loading state
|
||||
YM2612PicoStateLoad();
|
||||
if ((PicoMCD & 1) && Pico_mcd->m.audio_track)
|
||||
mp3_start_play(Pico_mcd->TOC.Tracks[Pico_mcd->m.audio_track].F, Pico_mcd->m.audio_offset);
|
||||
|
||||
memcpy(state, sn76496_regs, 28*4); // remember old state
|
||||
SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PsndRate);
|
||||
|
@ -137,56 +150,102 @@ void sound_rerate()
|
|||
|
||||
// recalculate dac info
|
||||
dac_recalculate();
|
||||
|
||||
if (PicoMCD & 1)
|
||||
pcm_set_rate(PsndRate);
|
||||
}
|
||||
|
||||
|
||||
// This is called once per raster (aka line), but not necessarily for every line
|
||||
int sound_timers_and_dac(int raster)
|
||||
void sound_timers_and_dac(int raster)
|
||||
{
|
||||
if(raster >= 0 && PsndOut && (PicoOpt&1) && *ym2612_dacen) {
|
||||
short dout = (short) *ym2612_dacout;
|
||||
int pos=dac_info[raster], len=pos&0xf;
|
||||
short *d;
|
||||
pos>>=4;
|
||||
|
||||
if(PicoOpt&8) { // only left channel for stereo (will be copied to right by ym2612 mixing code)
|
||||
d=PsndOut+pos*2;
|
||||
while(len--) { *d = dout; d += 2; }
|
||||
} else {
|
||||
d=PsndOut+pos;
|
||||
while(len--) *d++ = dout;
|
||||
}
|
||||
}
|
||||
|
||||
//dprintf("s: %03i", raster);
|
||||
int pos, len;
|
||||
int do_dac = PsndOut && (PicoOpt&1) && *ym2612_dacen;
|
||||
// int do_pcm = PsndOut && (PicoMCD&1) && (PicoOpt&0x400);
|
||||
|
||||
// Our raster lasts 63.61323/64.102564 microseconds (NTSC/PAL)
|
||||
YM2612PicoTick(1);
|
||||
|
||||
return 0;
|
||||
if (!do_dac /*&& !do_pcm*/) return;
|
||||
|
||||
pos=dac_info[raster], len=pos&0xf;
|
||||
if (!len) return;
|
||||
|
||||
pos>>=4;
|
||||
|
||||
if (do_dac) {
|
||||
short *d = PsndOut + pos*2;
|
||||
int dout = *ym2612_dacout;
|
||||
if(PicoOpt&8) {
|
||||
// some manual loop unrolling here :)
|
||||
d[0] = dout;
|
||||
if (len > 1) {
|
||||
d[2] = dout;
|
||||
if (len > 2) {
|
||||
d[4] = dout;
|
||||
if (len > 3)
|
||||
d[6] = dout;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
short *d = PsndOut + pos;
|
||||
d[0] = dout;
|
||||
if (len > 1) {
|
||||
d[1] = dout;
|
||||
if (len > 2) {
|
||||
d[2] = dout;
|
||||
if (len > 3)
|
||||
d[3] = dout;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (do_pcm) {
|
||||
int *d = PsndBuffer;
|
||||
d += (PicoOpt&8) ? pos*2 : pos;
|
||||
pcm_update(d, len, 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void sound_clear(void)
|
||||
{
|
||||
if (PicoOpt & 8) memset32((int *) PsndOut, 0, PsndLen);
|
||||
else memset(PsndOut, 0, PsndLen<<1);
|
||||
// memset(PsndBuffer, 0, (PicoOpt & 8) ? (PsndLen<<3) : (PsndLen<<2));
|
||||
}
|
||||
|
||||
|
||||
int sound_render(int offset, int length)
|
||||
{
|
||||
int *buf32 = PsndBuffer+offset;
|
||||
int stereo = (PicoOpt & 8) >> 3;
|
||||
// emulating CD && PCM option enabled && PCM chip on && have enabled channels
|
||||
int do_pcm = (PicoMCD&1) && (PicoOpt&0x400) && (Pico_mcd->pcm.control & 0x80) && Pico_mcd->pcm.enabled;
|
||||
offset <<= stereo;
|
||||
|
||||
// PSG
|
||||
if(PicoOpt & 2)
|
||||
if (PicoOpt & 2)
|
||||
SN76496Update(PsndOut+offset, length, stereo);
|
||||
|
||||
// Add in the stereo FM buffer
|
||||
if(PicoOpt & 1) {
|
||||
YM2612UpdateOne(PsndOut+offset, length, stereo);
|
||||
} else {
|
||||
// YM2612 upmixes to stereo, so we have to do this manually here
|
||||
int i;
|
||||
short *s = PsndOut+offset;
|
||||
for (i = 0; i < length; i++) {
|
||||
*(s+1) = *s; s+=2;
|
||||
}
|
||||
}
|
||||
if (PicoOpt & 1)
|
||||
YM2612UpdateOne(buf32, length, stereo, 1);
|
||||
|
||||
if (do_pcm)
|
||||
pcm_update(buf32, length, stereo);
|
||||
|
||||
// CDDA audio
|
||||
// if ((PicoMCD & 1) && (PicoOpt & 0x800))
|
||||
// mp3_update(PsndBuffer+offset, length, stereo);
|
||||
|
||||
// convert + limit to normal 16bit output
|
||||
if (stereo)
|
||||
mix_32_to_16l_stereo(PsndOut+offset, buf32, length);
|
||||
else mix_32_to_16_mono (PsndOut+offset, buf32, length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -259,14 +318,14 @@ void z80_init()
|
|||
mz80init();
|
||||
// Modify the default context
|
||||
mz80GetContext(&z80);
|
||||
|
||||
|
||||
// point mz80 stuff
|
||||
z80.z80Base=Pico.zram;
|
||||
z80.z80MemRead=mz80_mem_read;
|
||||
z80.z80MemWrite=mz80_mem_write;
|
||||
z80.z80IoRead=mz80_io_read;
|
||||
z80.z80IoWrite=mz80_io_write;
|
||||
|
||||
|
||||
mz80SetContext(&z80);
|
||||
|
||||
#elif defined(_USE_DRZ80)
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int sound_timers_and_dac(int raster);
|
||||
int sound_render(int offset, int length);
|
||||
void sound_timers_and_dac(int raster);
|
||||
int sound_render(int offset, int length);
|
||||
void sound_clear(void);
|
||||
|
||||
//int YM2612PicoTick(int n);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** This is a bunch of remains of original fm.c from MAME project. All stuff
|
||||
** This is a bunch of remains of original fm.c from MAME project. All stuff
|
||||
** unrelated to ym2612 was removed, multiple chip support was removed,
|
||||
** some parts of code were slightly rewritten and tied to the emulator.
|
||||
**
|
||||
|
@ -112,6 +112,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "ym2612.h"
|
||||
#include "mix.h"
|
||||
|
||||
#ifndef EXTERNAL_YM2612
|
||||
#include <stdlib.h>
|
||||
|
@ -120,7 +121,6 @@ static YM2612 ym2612;
|
|||
|
||||
#else
|
||||
extern YM2612 *ym2612_940;
|
||||
extern int *mix_buffer;
|
||||
#define ym2612 (*ym2612_940)
|
||||
|
||||
#endif
|
||||
|
@ -1584,13 +1584,12 @@ INT32 *ym2612_dacout;
|
|||
|
||||
|
||||
/* Generate samples for YM2612 */
|
||||
void YM2612UpdateOne_(short *buffer, int length, int stereo)
|
||||
int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty)
|
||||
{
|
||||
int pan;
|
||||
#ifndef EXTERNAL_YM2612
|
||||
int i;
|
||||
static int *mix_buffer = 0, mix_buffer_length = 0;
|
||||
#endif
|
||||
|
||||
// if !is_buf_empty, it means it has valid samples to mix with, else it may contain trash
|
||||
if (is_buf_empty) memset32(buffer, 0, length<<stereo);
|
||||
|
||||
/* refresh PG and EG */
|
||||
refresh_fc_eg_chan( &ym2612.CH[0] );
|
||||
|
@ -1613,44 +1612,15 @@ void YM2612UpdateOne_(short *buffer, int length, int stereo)
|
|||
pan = ym2612.OPN.pan;
|
||||
if (stereo) stereo = 1;
|
||||
|
||||
#ifndef EXTERNAL_YM2612
|
||||
if (mix_buffer_length < length) {
|
||||
mix_buffer = realloc(mix_buffer, length*4<<stereo); // FIXME: need to free this at some point
|
||||
if (!mix_buffer) return;
|
||||
mix_buffer_length = length;
|
||||
}
|
||||
#endif
|
||||
memset(mix_buffer, 0, length*4<<stereo);
|
||||
/* mix to 32bit dest */
|
||||
chan_render(buffer, length, &ym2612.CH[0], stereo|((pan&0x003)<<4)); // flags: stereo, lastchan, disabled, ?, pan_r, pan_l
|
||||
chan_render(buffer, length, &ym2612.CH[1], stereo|((pan&0x00c)<<2));
|
||||
chan_render(buffer, length, &ym2612.CH[2], stereo|((pan&0x030) ));
|
||||
chan_render(buffer, length, &ym2612.CH[3], stereo|((pan&0x0c0)>>2));
|
||||
chan_render(buffer, length, &ym2612.CH[4], stereo|((pan&0x300)>>4));
|
||||
chan_render(buffer, length, &ym2612.CH[5], stereo|((pan&0xc00)>>6)|(ym2612.dacen<<2)|2);
|
||||
|
||||
/* mix to 32bit temporary buffer */
|
||||
chan_render(mix_buffer, length, &ym2612.CH[0], stereo|((pan&0x003)<<4)); // flags: stereo, lastchan, disabled, ?, pan_r, pan_l
|
||||
chan_render(mix_buffer, length, &ym2612.CH[1], stereo|((pan&0x00c)<<2));
|
||||
chan_render(mix_buffer, length, &ym2612.CH[2], stereo|((pan&0x030) ));
|
||||
chan_render(mix_buffer, length, &ym2612.CH[3], stereo|((pan&0x0c0)>>2));
|
||||
chan_render(mix_buffer, length, &ym2612.CH[4], stereo|((pan&0x300)>>4));
|
||||
chan_render(mix_buffer, length, &ym2612.CH[5], stereo|((pan&0xc00)>>6)|(ym2612.dacen<<2)|2);
|
||||
|
||||
#ifndef EXTERNAL_YM2612
|
||||
/* limit and mix to output buffer */
|
||||
if (stereo) {
|
||||
int *mb = mix_buffer;
|
||||
for (i = length; i > 0; i--) {
|
||||
int l, r;
|
||||
l = r = *buffer;
|
||||
l += *mb++, r += *mb++;
|
||||
Limit( l, MAXOUT, MINOUT );
|
||||
Limit( r, MAXOUT, MINOUT );
|
||||
*buffer++ = l; *buffer++ = r;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < length; i++) {
|
||||
int l = mix_buffer[i];
|
||||
l += buffer[i];
|
||||
Limit( l, MAXOUT, MINOUT );
|
||||
buffer[i] = l;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 1; // buffer updated
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ typedef struct
|
|||
|
||||
void YM2612Init_(int baseclock, int rate);
|
||||
void YM2612ResetChip_(void);
|
||||
void YM2612UpdateOne_(short *buffer, int length, int stereo);
|
||||
int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty);
|
||||
|
||||
int YM2612Write_(unsigned int a, unsigned int v);
|
||||
unsigned char YM2612Read_(void);
|
||||
|
@ -172,9 +172,9 @@ extern int PicoOpt;
|
|||
if (PicoOpt&0x200) YM2612ResetChip_940(); \
|
||||
else YM2612ResetChip_(); \
|
||||
}
|
||||
#define YM2612UpdateOne(buffer,length,stereo) { \
|
||||
if (PicoOpt&0x200) YM2612UpdateOne_940(buffer, length, stereo); \
|
||||
else YM2612UpdateOne_(buffer, length, stereo); \
|
||||
#define YM2612UpdateOne(buffer,length,stereo,is_buf_empty) { \
|
||||
if (PicoOpt&0x200) YM2612UpdateOne_940(buffer, length, stereo, is_buf_empty); \
|
||||
else YM2612UpdateOne_(buffer, length, stereo, is_buf_empty); \
|
||||
}
|
||||
#define YM2612Write(a,v) \
|
||||
(PicoOpt&0x200) ? YM2612Write_940(a, v) : YM2612Write_(a, v)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue