mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-06 15:48:05 -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
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