mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-04 23:07:46 -04:00
sound, fix mcd cdda (mono, resampling), type cleanup, remove minimp3
This commit is contained in:
parent
9f1d5acdb4
commit
f7741cac91
14 changed files with 193 additions and 89 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -10,9 +10,6 @@
|
||||||
[submodule "pico/cd/libchdr"]
|
[submodule "pico/cd/libchdr"]
|
||||||
path = pico/cd/libchdr
|
path = pico/cd/libchdr
|
||||||
url = https://github.com/rtissera/libchdr.git
|
url = https://github.com/rtissera/libchdr.git
|
||||||
[submodule "platform/common/minimp3"]
|
|
||||||
path = platform/common/minimp3
|
|
||||||
url = https://github.com/lieff/minimp3
|
|
||||||
[submodule "platform/common/dr_libs"]
|
[submodule "platform/common/dr_libs"]
|
||||||
path = platform/common/dr_libs
|
path = platform/common/dr_libs
|
||||||
url = https://github.com/mackron/dr_libs
|
url = https://github.com/mackron/dr_libs
|
||||||
|
|
|
@ -266,7 +266,7 @@ void p32x_pwm_write16(u32 a, unsigned int d, SH2 *sh2, unsigned int m68k_cycles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p32x_pwm_update(int *buf32, int length, int stereo)
|
void p32x_pwm_update(s32 *buf32, int length, int stereo)
|
||||||
{
|
{
|
||||||
short *pwmb;
|
short *pwmb;
|
||||||
int step;
|
int step;
|
||||||
|
|
|
@ -23,7 +23,7 @@ extern void lprintf(const char *fmt, ...);
|
||||||
// external funcs for Sega/Mega CD
|
// external funcs for Sega/Mega CD
|
||||||
extern int mp3_get_bitrate(void *f, int size);
|
extern int mp3_get_bitrate(void *f, int size);
|
||||||
extern void mp3_start_play(void *f, int pos);
|
extern void mp3_start_play(void *f, int pos);
|
||||||
extern void mp3_update(int *buffer, int length, int stereo);
|
extern void mp3_update(s32 *buffer, int length, int stereo);
|
||||||
|
|
||||||
// this function should write-back d-cache and invalidate i-cache
|
// this function should write-back d-cache and invalidate i-cache
|
||||||
// on a mem region [start_addr, end_addr)
|
// on a mem region [start_addr, end_addr)
|
||||||
|
@ -253,7 +253,7 @@ void Pico32xSetClocks(int msh2_hz, int ssh2_hz);
|
||||||
#define PICO_SSH2_HZ ((int)(7670442.0 * 2.4))
|
#define PICO_SSH2_HZ ((int)(7670442.0 * 2.4))
|
||||||
|
|
||||||
// sound.c
|
// sound.c
|
||||||
extern void (*PsndMix_32_to_16l)(short *dest, int *src, int count);
|
extern void (*PsndMix_32_to_16l)(s16 *dest, s32 *src, int count);
|
||||||
void PsndRerate(int preserve_state);
|
void PsndRerate(int preserve_state);
|
||||||
|
|
||||||
// media.c
|
// media.c
|
||||||
|
|
|
@ -452,6 +452,7 @@ struct PicoSound
|
||||||
int len_e_cnt;
|
int len_e_cnt;
|
||||||
unsigned int clkl_mult; // z80 clocks per line in Q20
|
unsigned int clkl_mult; // z80 clocks per line in Q20
|
||||||
unsigned int smpl_mult; // samples per line in Q16
|
unsigned int smpl_mult; // samples per line in Q16
|
||||||
|
unsigned int cdda_mult, cdda_div; // 44.1 KHz resampling factor in Q16
|
||||||
short dac_val, dac_val2; // last DAC sample
|
short dac_val, dac_val2; // last DAC sample
|
||||||
unsigned int dac_pos; // last DAC position in Q20
|
unsigned int dac_pos; // last DAC position in Q20
|
||||||
unsigned int fm_pos; // last FM position in Q20
|
unsigned int fm_pos; // last FM position in Q20
|
||||||
|
@ -1025,7 +1026,7 @@ extern int Pico32xDrawMode;
|
||||||
// 32x/pwm.c
|
// 32x/pwm.c
|
||||||
unsigned int p32x_pwm_read16(u32 a, SH2 *sh2, unsigned int m68k_cycles);
|
unsigned int p32x_pwm_read16(u32 a, SH2 *sh2, unsigned int m68k_cycles);
|
||||||
void p32x_pwm_write16(u32 a, unsigned int d, SH2 *sh2, unsigned int m68k_cycles);
|
void p32x_pwm_write16(u32 a, unsigned int d, SH2 *sh2, unsigned int m68k_cycles);
|
||||||
void p32x_pwm_update(int *buf32, int length, int stereo);
|
void p32x_pwm_update(s32 *buf32, int length, int stereo);
|
||||||
void p32x_pwm_ctl_changed(void);
|
void p32x_pwm_ctl_changed(void);
|
||||||
void p32x_pwm_schedule(unsigned int m68k_now);
|
void p32x_pwm_schedule(unsigned int m68k_now);
|
||||||
void p32x_pwm_schedule_sh2(SH2 *sh2);
|
void p32x_pwm_schedule_sh2(SH2 *sh2);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "../pico_int.h"
|
||||||
|
|
||||||
#define MAXOUT (+32767)
|
#define MAXOUT (+32767)
|
||||||
#define MINOUT (-32768)
|
#define MINOUT (-32768)
|
||||||
|
@ -15,7 +16,7 @@
|
||||||
/* limitter */
|
/* limitter */
|
||||||
#define Limit16(val) \
|
#define Limit16(val) \
|
||||||
val -= val >> 3; /* reduce level to avoid clipping */ \
|
val -= val >> 3; /* reduce level to avoid clipping */ \
|
||||||
if ((short)val != val) val = (val < 0 ? MINOUT : MAXOUT)
|
if ((s16)val != val) val = (val < 0 ? MINOUT : MAXOUT)
|
||||||
|
|
||||||
int mix_32_to_16l_level;
|
int mix_32_to_16l_level;
|
||||||
|
|
||||||
|
@ -81,17 +82,17 @@ static inline int filter_null(struct iir *fi2, int x)
|
||||||
lfi2 = lf, rfi2 = rf; \
|
lfi2 = lf, rfi2 = rf; \
|
||||||
}
|
}
|
||||||
|
|
||||||
void mix_32_to_16l_stereo_lvl(short *dest, int *src, int count)
|
void mix_32_to_16l_stereo_lvl(s16 *dest, s32 *src, int count)
|
||||||
{
|
{
|
||||||
mix_32_to_16l_stereo_core(dest, src, count, mix_32_to_16l_level, filter);
|
mix_32_to_16l_stereo_core(dest, src, count, mix_32_to_16l_level, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mix_32_to_16l_stereo(short *dest, int *src, int count)
|
void mix_32_to_16l_stereo(s16 *dest, s32 *src, int count)
|
||||||
{
|
{
|
||||||
mix_32_to_16l_stereo_core(dest, src, count, 0, filter);
|
mix_32_to_16l_stereo_core(dest, src, count, 0, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mix_32_to_16_mono(short *dest, int *src, int count)
|
void mix_32_to_16_mono(s16 *dest, s32 *src, int count)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
struct iir lf = lfi2;
|
struct iir lf = lfi2;
|
||||||
|
@ -108,7 +109,7 @@ void mix_32_to_16_mono(short *dest, int *src, int count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void mix_16h_to_32(int *dest_buf, short *mp3_buf, int count)
|
void mix_16h_to_32(s32 *dest_buf, s16 *mp3_buf, int count)
|
||||||
{
|
{
|
||||||
while (count--)
|
while (count--)
|
||||||
{
|
{
|
||||||
|
@ -116,7 +117,7 @@ void mix_16h_to_32(int *dest_buf, short *mp3_buf, int count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mix_16h_to_32_s1(int *dest_buf, short *mp3_buf, int count)
|
void mix_16h_to_32_s1(s32 *dest_buf, s16 *mp3_buf, int count)
|
||||||
{
|
{
|
||||||
count >>= 1;
|
count >>= 1;
|
||||||
while (count--)
|
while (count--)
|
||||||
|
@ -127,7 +128,7 @@ void mix_16h_to_32_s1(int *dest_buf, short *mp3_buf, int count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mix_16h_to_32_s2(int *dest_buf, short *mp3_buf, int count)
|
void mix_16h_to_32_s2(s32 *dest_buf, s16 *mp3_buf, int count)
|
||||||
{
|
{
|
||||||
count >>= 1;
|
count >>= 1;
|
||||||
while (count--)
|
while (count--)
|
||||||
|
@ -138,6 +139,30 @@ void mix_16h_to_32_s2(int *dest_buf, short *mp3_buf, int count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mixes cdda audio @44.1 KHz into dest_buf, resampling with nearest neighbour
|
||||||
|
void mix_16h_to_32_resample_stereo(s32 *dest_buf, s16 *cdda_buf, int count, int fac16)
|
||||||
|
{
|
||||||
|
int pos16 = 0;
|
||||||
|
while (count--) {
|
||||||
|
int pos = 2 * (pos16>>16);
|
||||||
|
*dest_buf++ += cdda_buf[pos ] >> 1;
|
||||||
|
*dest_buf++ += cdda_buf[pos+1] >> 1;
|
||||||
|
pos16 += fac16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mixes cdda audio @44.1 KHz into dest_buf, resampling with nearest neighbour
|
||||||
|
void mix_16h_to_32_resample_mono(s32 *dest_buf, s16 *cdda_buf, int count, int fac16)
|
||||||
|
{
|
||||||
|
int pos16 = 0;
|
||||||
|
while (count--) {
|
||||||
|
int pos = 2 * (pos16>>16);
|
||||||
|
*dest_buf += cdda_buf[pos ] >> 2;
|
||||||
|
*dest_buf++ += cdda_buf[pos+1] >> 2;
|
||||||
|
pos16 += fac16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void mix_reset(int alpha_q16)
|
void mix_reset(int alpha_q16)
|
||||||
{
|
{
|
||||||
memset(&lfi2, 0, sizeof(lfi2));
|
memset(&lfi2, 0, sizeof(lfi2));
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
|
|
||||||
//void mix_32_to_32(int *dest, int *src, 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(s32 *dest, s16 *src, int count);
|
||||||
void mix_16h_to_32_s1(int *dest, short *src, int count);
|
void mix_16h_to_32_s1(s32 *dest, s16 *src, int count);
|
||||||
void mix_16h_to_32_s2(int *dest, short *src, int count);
|
void mix_16h_to_32_s2(s32 *dest, s16 *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);
|
void mix_16h_to_32_resample_stereo(s32 *dest, s16 *src, int count, int fac16);
|
||||||
|
void mix_16h_to_32_resample_mono(s32 *dest, s16 *src, int count, int fac16);
|
||||||
|
void mix_32_to_16l_stereo(s16 *dest, s32 *src, int count);
|
||||||
|
void mix_32_to_16_mono(s16 *dest, s32 *src, int count);
|
||||||
|
|
||||||
extern int mix_32_to_16l_level;
|
extern int mix_32_to_16l_level;
|
||||||
void mix_32_to_16l_stereo_lvl(short *dest, int *src, int count);
|
void mix_32_to_16l_stereo_lvl(s16 *dest, s32 *src, int count);
|
||||||
void mix_reset(int alpha_q16);
|
void mix_reset(int alpha_q16);
|
||||||
|
|
|
@ -153,6 +153,92 @@ m16_32_s2_no_unal2:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.global mix_16h_to_32_resample_stereo @ int *dest, short *src, int count, int fac16
|
||||||
|
|
||||||
|
mix_16h_to_32_resample_stereo:
|
||||||
|
stmfd sp!, {r4-r9,lr}
|
||||||
|
|
||||||
|
subs r2, r2, #2
|
||||||
|
mov r4, #0
|
||||||
|
bmi m16_32_rss_end
|
||||||
|
|
||||||
|
m16_32_rss_loop:
|
||||||
|
ldmia r0, {r5-r8}
|
||||||
|
lsr r9, r4, #16
|
||||||
|
ldr r12,[r1, r9, lsl #2]
|
||||||
|
add r4, r4, r3
|
||||||
|
lsr r9, r4, #16
|
||||||
|
ldr lr ,[r1, r9, lsl #2]
|
||||||
|
add r4, r4, r3
|
||||||
|
subs r2, r2, #2
|
||||||
|
add r6, r6, r12,asr #17
|
||||||
|
mov r12,r12,lsl #16
|
||||||
|
add r5, r5, r12,asr #17 @ we use half volume
|
||||||
|
add r8, r8, lr, asr #17
|
||||||
|
mov lr, lr, lsl #16
|
||||||
|
add r7, r7, lr, asr #17
|
||||||
|
stmia r0!,{r5-r8}
|
||||||
|
bpl m16_32_rss_loop
|
||||||
|
|
||||||
|
m16_32_rss_end:
|
||||||
|
tst r2, #1
|
||||||
|
ldmeqfd sp!, {r4-r9,pc}
|
||||||
|
lsr r9, r4, #16
|
||||||
|
ldr lr ,[r1, r9, lsl #2]
|
||||||
|
ldmia r0, {r5,r6}
|
||||||
|
mov r12,lr, lsl #16
|
||||||
|
add r5, r5, r12,asr #17
|
||||||
|
add r6, r6, lr, asr #17
|
||||||
|
stmia r0!,{r5,r6}
|
||||||
|
|
||||||
|
ldmfd sp!, {r4-r9,lr}
|
||||||
|
bx lr
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.global mix_16h_to_32_resample_mono @ int *dest, short *src, int count, int fac16
|
||||||
|
|
||||||
|
mix_16h_to_32_resample_mono:
|
||||||
|
stmfd sp!, {r4-r6,r9,lr}
|
||||||
|
|
||||||
|
subs r2, r2, #2
|
||||||
|
mov r4, #0
|
||||||
|
bmi m16_32_rsm_end
|
||||||
|
|
||||||
|
m16_32_rsm_loop:
|
||||||
|
ldmia r0, {r5-r6}
|
||||||
|
lsr r9, r4, #16
|
||||||
|
ldr r12,[r1, r9, lsl #2]
|
||||||
|
add r4, r4, r3
|
||||||
|
lsr r9, r4, #16
|
||||||
|
ldr lr ,[r1, r9, lsl #2]
|
||||||
|
add r4, r4, r3
|
||||||
|
subs r2, r2, #2
|
||||||
|
add r5, r5, r12,asr #18
|
||||||
|
mov r12,r12,lsl #16
|
||||||
|
add r5, r5, r12,asr #18 @ we use half volume (= quarter vol per channel)
|
||||||
|
add r6, r6, lr, asr #18
|
||||||
|
mov lr, lr, lsl #16
|
||||||
|
add r6, r6, lr, asr #18
|
||||||
|
stmia r0!,{r5-r6}
|
||||||
|
bpl m16_32_rsm_loop
|
||||||
|
|
||||||
|
m16_32_rsm_end:
|
||||||
|
tst r2, #1
|
||||||
|
ldmeqfd sp!, {r4-r6,r9,pc}
|
||||||
|
lsr r9, r4, #16
|
||||||
|
ldr lr ,[r1, r9, lsl #2]
|
||||||
|
ldr r5, [r0]
|
||||||
|
mov r12,lr, lsl #16
|
||||||
|
add r5, r5, r12,asr #18
|
||||||
|
add r5, r5, lr, asr #18
|
||||||
|
str r5, [r0]
|
||||||
|
|
||||||
|
ldmfd sp!, {r4-r6,r9,lr}
|
||||||
|
bx lr
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ limit
|
@ limit
|
||||||
@ reg=int_sample, r12=1, r8=tmp, kills flags
|
@ reg=int_sample, r12=1, r8=tmp, kills flags
|
||||||
.macro Limit reg
|
.macro Limit reg
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include "mix.h"
|
#include "mix.h"
|
||||||
#include "emu2413/emu2413.h"
|
#include "emu2413/emu2413.h"
|
||||||
|
|
||||||
void (*PsndMix_32_to_16l)(short *dest, int *src, int count) = mix_32_to_16l_stereo;
|
void (*PsndMix_32_to_16l)(s16 *dest, s32 *src, int count) = mix_32_to_16l_stereo;
|
||||||
|
|
||||||
// master int buffer to mix to
|
// master int buffer to mix to
|
||||||
// +1 for a fill triggered by an instruction overhanging into the next scanline
|
// +1 for a fill triggered by an instruction overhanging into the next scanline
|
||||||
|
@ -98,6 +98,9 @@ void PsndRerate(int preserve_state)
|
||||||
Pico.snd.smpl_mult = 65536LL * PicoIn.sndRate / (target_fps*target_lines);
|
Pico.snd.smpl_mult = 65536LL * PicoIn.sndRate / (target_fps*target_lines);
|
||||||
// samples per z80 clock (Q20)
|
// samples per z80 clock (Q20)
|
||||||
Pico.snd.clkl_mult = 16 * Pico.snd.smpl_mult * 15/7 / 488;
|
Pico.snd.clkl_mult = 16 * Pico.snd.smpl_mult * 15/7 / 488;
|
||||||
|
// samples per 44.1 KHz sample
|
||||||
|
Pico.snd.cdda_mult = 65536LL * 44100 / PicoIn.sndRate;
|
||||||
|
Pico.snd.cdda_div = 65536LL * PicoIn.sndRate / 44100;
|
||||||
|
|
||||||
// clear all buffers
|
// clear all buffers
|
||||||
memset32(PsndBuffer, 0, sizeof(PsndBuffer)/4);
|
memset32(PsndBuffer, 0, sizeof(PsndBuffer)/4);
|
||||||
|
@ -154,12 +157,12 @@ PICO_INTERNAL void PsndDoDAC(int cyc_to)
|
||||||
// y[n] = (x[n] + x[n-1])*(1/2) (3dB cutoff at 11025 Hz, no gain)
|
// y[n] = (x[n] + x[n-1])*(1/2) (3dB cutoff at 11025 Hz, no gain)
|
||||||
// 1 sample delay for correct IIR filtering over audio frame boundaries
|
// 1 sample delay for correct IIR filtering over audio frame boundaries
|
||||||
if (PicoIn.opt & POPT_EN_STEREO) {
|
if (PicoIn.opt & POPT_EN_STEREO) {
|
||||||
short *d = PicoIn.sndOut + pos*2;
|
s16 *d = PicoIn.sndOut + pos*2;
|
||||||
// left channel only, mixed ro right channel in mixing phase
|
// left channel only, mixed ro right channel in mixing phase
|
||||||
*d++ += Pico.snd.dac_val2; d++;
|
*d++ += Pico.snd.dac_val2; d++;
|
||||||
while (--len) *d++ += Pico.snd.dac_val, d++;
|
while (--len) *d++ += Pico.snd.dac_val, d++;
|
||||||
} else {
|
} else {
|
||||||
short *d = PicoIn.sndOut + pos;
|
s16 *d = PicoIn.sndOut + pos;
|
||||||
*d++ += Pico.snd.dac_val2;
|
*d++ += Pico.snd.dac_val2;
|
||||||
while (--len) *d++ += Pico.snd.dac_val;
|
while (--len) *d++ += Pico.snd.dac_val;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +203,7 @@ PICO_INTERNAL void PsndDoYM2413(int cyc_to)
|
||||||
{
|
{
|
||||||
int pos, len;
|
int pos, len;
|
||||||
int stereo = 0;
|
int stereo = 0;
|
||||||
short *buf;
|
s16 *buf;
|
||||||
|
|
||||||
// nothing to do if sound is off
|
// nothing to do if sound is off
|
||||||
if (!PicoIn.sndOut) return;
|
if (!PicoIn.sndOut) return;
|
||||||
|
@ -268,14 +271,11 @@ PICO_INTERNAL void PsndDoFM(int cyc_to)
|
||||||
}
|
}
|
||||||
|
|
||||||
// cdda
|
// cdda
|
||||||
static void cdda_raw_update(int *buffer, int length)
|
static void cdda_raw_update(s32 *buffer, int length, int stereo)
|
||||||
{
|
{
|
||||||
int ret, cdda_bytes, mult = 1;
|
int ret, cdda_bytes;
|
||||||
|
|
||||||
cdda_bytes = length*4;
|
cdda_bytes = (length * Pico.snd.cdda_mult >> 16) * 4;
|
||||||
if (PicoIn.sndRate <= 22050 + 100) mult = 2;
|
|
||||||
if (PicoIn.sndRate < 22050 - 100) mult = 4;
|
|
||||||
cdda_bytes *= mult;
|
|
||||||
|
|
||||||
ret = pm_read_audio(cdda_out_buffer, cdda_bytes, Pico_mcd->cdda_stream);
|
ret = pm_read_audio(cdda_out_buffer, cdda_bytes, Pico_mcd->cdda_stream);
|
||||||
if (ret < cdda_bytes) {
|
if (ret < cdda_bytes) {
|
||||||
|
@ -285,11 +285,13 @@ static void cdda_raw_update(int *buffer, int length)
|
||||||
}
|
}
|
||||||
|
|
||||||
// now mix
|
// now mix
|
||||||
switch (mult) {
|
if (stereo) switch (Pico.snd.cdda_mult) {
|
||||||
case 1: mix_16h_to_32(buffer, cdda_out_buffer, length*2); break;
|
case 0x10000: mix_16h_to_32(buffer, cdda_out_buffer, length*2); break;
|
||||||
case 2: mix_16h_to_32_s1(buffer, cdda_out_buffer, length*2); break;
|
case 0x20000: mix_16h_to_32_s1(buffer, cdda_out_buffer, length*2); break;
|
||||||
case 4: mix_16h_to_32_s2(buffer, cdda_out_buffer, length*2); break;
|
case 0x40000: mix_16h_to_32_s2(buffer, cdda_out_buffer, length*2); break;
|
||||||
}
|
default: mix_16h_to_32_resample_stereo(buffer, cdda_out_buffer, length, Pico.snd.cdda_mult);
|
||||||
|
} else
|
||||||
|
mix_16h_to_32_resample_mono(buffer, cdda_out_buffer, length, Pico.snd.cdda_mult);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cdda_start_play(int lba_base, int lba_offset, int lb_len)
|
void cdda_start_play(int lba_base, int lba_offset, int lb_len)
|
||||||
|
@ -326,7 +328,7 @@ PICO_INTERNAL void PsndClear(void)
|
||||||
if (PicoIn.opt & POPT_EN_STEREO)
|
if (PicoIn.opt & POPT_EN_STEREO)
|
||||||
memset32((int *) PicoIn.sndOut, 0, len); // assume PicoIn.sndOut to be aligned
|
memset32((int *) PicoIn.sndOut, 0, len); // assume PicoIn.sndOut to be aligned
|
||||||
else {
|
else {
|
||||||
short *out = PicoIn.sndOut;
|
s16 *out = PicoIn.sndOut;
|
||||||
if ((uintptr_t)out & 2) { *out++ = 0; len--; }
|
if ((uintptr_t)out & 2) { *out++ = 0; len--; }
|
||||||
memset32((int *) out, 0, len/2);
|
memset32((int *) out, 0, len/2);
|
||||||
if (len & 1) out[len-1] = 0;
|
if (len & 1) out[len-1] = 0;
|
||||||
|
@ -350,14 +352,14 @@ static int PsndRender(int offset, int length)
|
||||||
|
|
||||||
if (PicoIn.AHW & PAHW_PICO) {
|
if (PicoIn.AHW & PAHW_PICO) {
|
||||||
// XXX ugly hack, need to render sound for interrupts
|
// XXX ugly hack, need to render sound for interrupts
|
||||||
s16 *buf16 = PicoIn.sndOut ? PicoIn.sndOut : (short *)PsndBuffer;
|
s16 *buf16 = PicoIn.sndOut ? PicoIn.sndOut : (s16 *)PsndBuffer;
|
||||||
PicoPicoPCMUpdate(buf16+(offset<<stereo), length-offset, stereo);
|
PicoPicoPCMUpdate(buf16+(offset<<stereo), length-offset, stereo);
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill up DAC output in case of missing samples (Q rounding errors)
|
// Fill up DAC output in case of missing samples (Q rounding errors)
|
||||||
if (length-daclen > 0 && PicoIn.sndOut) {
|
if (length-daclen > 0 && PicoIn.sndOut) {
|
||||||
short *dacbuf = PicoIn.sndOut + (daclen << stereo);
|
s16 *dacbuf = PicoIn.sndOut + (daclen << stereo);
|
||||||
Pico.snd.dac_pos += (length-daclen) << 20;
|
Pico.snd.dac_pos += (length-daclen) << 20;
|
||||||
*dacbuf++ += Pico.snd.dac_val2;
|
*dacbuf++ += Pico.snd.dac_val2;
|
||||||
if (stereo) dacbuf++;
|
if (stereo) dacbuf++;
|
||||||
|
@ -370,7 +372,7 @@ static int PsndRender(int offset, int length)
|
||||||
|
|
||||||
// Add in parts of the PSG output not yet done
|
// Add in parts of the PSG output not yet done
|
||||||
if (length-psglen > 0 && PicoIn.sndOut) {
|
if (length-psglen > 0 && PicoIn.sndOut) {
|
||||||
short *psgbuf = PicoIn.sndOut + (psglen << stereo);
|
s16 *psgbuf = PicoIn.sndOut + (psglen << stereo);
|
||||||
Pico.snd.psg_pos += (length-psglen) << 20;
|
Pico.snd.psg_pos += (length-psglen) << 20;
|
||||||
if (PicoIn.opt & POPT_EN_PSG)
|
if (PicoIn.opt & POPT_EN_PSG)
|
||||||
SN76496Update(psgbuf, length-psglen, stereo);
|
SN76496Update(psgbuf, length-psglen, stereo);
|
||||||
|
@ -378,7 +380,7 @@ static int PsndRender(int offset, int length)
|
||||||
|
|
||||||
// Add in parts of the FM buffer not yet done
|
// Add in parts of the FM buffer not yet done
|
||||||
if (length-fmlen > 0 && PicoIn.sndOut) {
|
if (length-fmlen > 0 && PicoIn.sndOut) {
|
||||||
int *fmbuf = buf32 + ((fmlen-offset) << stereo);
|
s32 *fmbuf = buf32 + ((fmlen-offset) << stereo);
|
||||||
Pico.snd.fm_pos += (length-fmlen) << 20;
|
Pico.snd.fm_pos += (length-fmlen) << 20;
|
||||||
if (PicoIn.opt & POPT_EN_FM)
|
if (PicoIn.opt & POPT_EN_FM)
|
||||||
YM2612UpdateOne(fmbuf, length-fmlen, stereo, 1);
|
YM2612UpdateOne(fmbuf, length-fmlen, stereo, 1);
|
||||||
|
@ -395,11 +397,10 @@ static int PsndRender(int offset, int length)
|
||||||
&& Pico_mcd->cdda_stream != NULL
|
&& Pico_mcd->cdda_stream != NULL
|
||||||
&& !(Pico_mcd->s68k_regs[0x36] & 1))
|
&& !(Pico_mcd->s68k_regs[0x36] & 1))
|
||||||
{
|
{
|
||||||
// note: only 44, 22 and 11 kHz supported, with forced stereo
|
|
||||||
if (Pico_mcd->cdda_type == CT_MP3)
|
if (Pico_mcd->cdda_type == CT_MP3)
|
||||||
mp3_update(buf32, length-offset, stereo);
|
mp3_update(buf32, length-offset, stereo);
|
||||||
else
|
else
|
||||||
cdda_raw_update(buf32, length-offset);
|
cdda_raw_update(buf32, length-offset, stereo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((PicoIn.AHW & PAHW_32X) && (PicoIn.opt & POPT_EN_PWM))
|
if ((PicoIn.AHW & PAHW_32X) && (PicoIn.opt & POPT_EN_PWM))
|
||||||
|
@ -439,14 +440,14 @@ static int PsndRenderMS(int offset, int length)
|
||||||
|
|
||||||
// Add in parts of the PSG output not yet done
|
// Add in parts of the PSG output not yet done
|
||||||
if (length-psglen > 0) {
|
if (length-psglen > 0) {
|
||||||
short *psgbuf = PicoIn.sndOut + (psglen << stereo);
|
s16 *psgbuf = PicoIn.sndOut + (psglen << stereo);
|
||||||
Pico.snd.psg_pos += (length-psglen) << 20;
|
Pico.snd.psg_pos += (length-psglen) << 20;
|
||||||
if (PicoIn.opt & POPT_EN_PSG)
|
if (PicoIn.opt & POPT_EN_PSG)
|
||||||
SN76496Update(psgbuf, length-psglen, stereo);
|
SN76496Update(psgbuf, length-psglen, stereo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length-ym2413len > 0) {
|
if (length-ym2413len > 0) {
|
||||||
short *ym2413buf = PicoIn.sndOut + (ym2413len << stereo);
|
s16 *ym2413buf = PicoIn.sndOut + (ym2413len << stereo);
|
||||||
Pico.snd.ym2413_pos += (length-ym2413len) << 20;
|
Pico.snd.ym2413_pos += (length-ym2413len) << 20;
|
||||||
int len = (length-ym2413len);
|
int len = (length-ym2413len);
|
||||||
if (PicoIn.opt & POPT_EN_YM2413){
|
if (PicoIn.opt & POPT_EN_YM2413){
|
||||||
|
@ -461,8 +462,8 @@ static int PsndRenderMS(int offset, int length)
|
||||||
// upmix to "stereo" if needed
|
// upmix to "stereo" if needed
|
||||||
if (PicoIn.opt & POPT_EN_STEREO) {
|
if (PicoIn.opt & POPT_EN_STEREO) {
|
||||||
int i;
|
int i;
|
||||||
short *p;
|
s16 *p;
|
||||||
for (i = length, p = (short *)PicoIn.sndOut; i > 0; i--, p+=2)
|
for (i = length, p = (s16 *)PicoIn.sndOut; i > 0; i--, p+=2)
|
||||||
*(p + 1) = *p;
|
*(p + 1) = *p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1127,7 +1127,7 @@ static int update_algo_channel(chan_rend_context *ct, unsigned int eg_out, unsig
|
||||||
return smp;
|
return smp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void chan_render_loop(chan_rend_context *ct, int *buffer, int length)
|
static void chan_render_loop(chan_rend_context *ct, s32 *buffer, int length)
|
||||||
{
|
{
|
||||||
int scounter; /* sample counter */
|
int scounter; /* sample counter */
|
||||||
|
|
||||||
|
@ -1244,7 +1244,7 @@ disabled:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void chan_render_loop(chan_rend_context *ct, int *buffer, unsigned short length);
|
void chan_render_loop(chan_rend_context *ct, s32 *buffer, unsigned short length);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static chan_rend_context crct;
|
static chan_rend_context crct;
|
||||||
|
@ -1255,7 +1255,7 @@ static void chan_render_prep(void)
|
||||||
crct.lfo_inc = ym2612.OPN.lfo_inc;
|
crct.lfo_inc = ym2612.OPN.lfo_inc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void chan_render_finish(int *buffer, unsigned short length, int active_chans)
|
static void chan_render_finish(s32 *buffer, unsigned short length, int active_chans)
|
||||||
{
|
{
|
||||||
ym2612.OPN.eg_cnt = crct.eg_cnt;
|
ym2612.OPN.eg_cnt = crct.eg_cnt;
|
||||||
ym2612.OPN.eg_timer = crct.eg_timer;
|
ym2612.OPN.eg_timer = crct.eg_timer;
|
||||||
|
@ -1290,7 +1290,7 @@ static UINT32 update_lfo_phase(FM_SLOT *SLOT, UINT32 block_fnum)
|
||||||
return SLOT->Incr;
|
return SLOT->Incr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int chan_render(int *buffer, int length, int c, UINT32 flags) // flags: stereo, ?, disabled, ?, pan_r, pan_l
|
static int chan_render(s32 *buffer, int length, int c, UINT32 flags) // flags: stereo, ?, disabled, ?, pan_r, pan_l
|
||||||
{
|
{
|
||||||
crct.CH = &ym2612.CH[c];
|
crct.CH = &ym2612.CH[c];
|
||||||
crct.mem = crct.CH->mem_value; /* one sample delay memory */
|
crct.mem = crct.CH->mem_value; /* one sample delay memory */
|
||||||
|
@ -1781,7 +1781,7 @@ static int OPNWriteReg(int r, int v)
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
|
||||||
/* Generate samples for YM2612 */
|
/* Generate samples for YM2612 */
|
||||||
int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty)
|
int YM2612UpdateOne_(s32 *buffer, int length, int stereo, int is_buf_empty)
|
||||||
{
|
{
|
||||||
int pan;
|
int pan;
|
||||||
int active_chs = 0;
|
int active_chs = 0;
|
||||||
|
|
|
@ -167,7 +167,7 @@ extern YM2612 ym2612;
|
||||||
|
|
||||||
void YM2612Init_(int baseclock, int rate, int flags);
|
void YM2612Init_(int baseclock, int rate, int flags);
|
||||||
void YM2612ResetChip_(void);
|
void YM2612ResetChip_(void);
|
||||||
int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty);
|
int YM2612UpdateOne_(s32 *buffer, int length, int stereo, int is_buf_empty);
|
||||||
|
|
||||||
int YM2612Write_(unsigned int a, unsigned int v);
|
int YM2612Write_(unsigned int a, unsigned int v);
|
||||||
//unsigned char YM2612Read_(void);
|
//unsigned char YM2612Read_(void);
|
||||||
|
|
|
@ -24,7 +24,7 @@ static char *mystrip(char *str);
|
||||||
|
|
||||||
#include "menu_pico.h"
|
#include "menu_pico.h"
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
#include <pico/pico.h>
|
#include <pico/pico_int.h>
|
||||||
|
|
||||||
// always output DOS endlines
|
// always output DOS endlines
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 95864e8e0d3b34402a49ae9af6c66f7e98c13c35
|
|
|
@ -128,10 +128,10 @@ void mp3_start_play(void *f_, int pos1024)
|
||||||
mp3dec_decode(mp3_current_file, &mp3_file_pos, mp3_file_len);
|
mp3dec_decode(mp3_current_file, &mp3_file_pos, mp3_file_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp3_update(int *buffer, int length, int stereo)
|
void mp3_update(s32 *buffer, int length, int stereo)
|
||||||
{
|
{
|
||||||
int length_mp3, shr = 0;
|
int length_mp3;
|
||||||
void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;
|
void (*mix_samples)(int *dest_buf, short *mp3_buf, int count, int fac16) = mix_16h_to_32_resample_stereo;
|
||||||
|
|
||||||
if (mp3_current_file == NULL || mp3_file_pos >= mp3_file_len)
|
if (mp3_current_file == NULL || mp3_file_pos >= mp3_file_len)
|
||||||
return; /* no file / EOF */
|
return; /* no file / EOF */
|
||||||
|
@ -139,35 +139,29 @@ void mp3_update(int *buffer, int length, int stereo)
|
||||||
if (!decoder_active)
|
if (!decoder_active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
length_mp3 = length;
|
length_mp3 = length * Pico.snd.cdda_mult >> 16;
|
||||||
if (PicoIn.sndRate <= 11025 + 100) {
|
if (!stereo)
|
||||||
mix_samples = mix_16h_to_32_s2;
|
mix_samples = mix_16h_to_32_resample_mono;
|
||||||
length_mp3 <<= 2; shr = 2;
|
|
||||||
}
|
|
||||||
else if (PicoIn.sndRate <= 22050 + 100) {
|
|
||||||
mix_samples = mix_16h_to_32_s1;
|
|
||||||
length_mp3 <<= 1; shr = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (1152 - cdda_out_pos >= length_mp3) {
|
if (1152 - cdda_out_pos >= length_mp3) {
|
||||||
mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
|
mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
|
||||||
length * 2);
|
length, Pico.snd.cdda_mult);
|
||||||
|
|
||||||
cdda_out_pos += length_mp3;
|
cdda_out_pos += length_mp3;
|
||||||
} else {
|
} else {
|
||||||
int ret, left = 1152 - cdda_out_pos;
|
int left = (1152 - cdda_out_pos) * Pico.snd.cdda_div >> 16;
|
||||||
|
int ret, sm = stereo ? 2 : 1;
|
||||||
|
|
||||||
if (left > 0)
|
if (left > 0)
|
||||||
mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
|
mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
|
||||||
(left >> shr) * 2);
|
left, Pico.snd.cdda_mult);
|
||||||
|
|
||||||
ret = mp3dec_decode(mp3_current_file, &mp3_file_pos,
|
ret = mp3dec_decode(mp3_current_file, &mp3_file_pos,
|
||||||
mp3_file_len);
|
mp3_file_len);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
cdda_out_pos = length_mp3 - left;
|
mix_samples(buffer + left * sm, cdda_out_buffer,
|
||||||
mix_samples(buffer + (left >> shr) * 2,
|
length-left, Pico.snd.cdda_mult);
|
||||||
cdda_out_buffer,
|
cdda_out_pos = (length-left) * Pico.snd.cdda_mult >> 16;
|
||||||
(cdda_out_pos >> shr) * 2);
|
|
||||||
} else
|
} else
|
||||||
cdda_out_pos = 0;
|
cdda_out_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,16 +386,14 @@ void mp3_start_play(void *f, int pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void mp3_update(int *buffer, int length, int stereo)
|
void mp3_update(s32 *buffer, int length, int stereo)
|
||||||
{
|
{
|
||||||
int length_mp3;
|
int length_mp3;
|
||||||
|
|
||||||
// playback was started, track not ended
|
// playback was started, track not ended
|
||||||
if (mp3_handle < 0 || mp3_src_pos >= mp3_src_size) return;
|
if (mp3_handle < 0 || mp3_src_pos >= mp3_src_size) return;
|
||||||
|
|
||||||
length_mp3 = length;
|
length_mp3 = length * Pico.snd.cdda_mult >> 16;
|
||||||
if (PicoIn.sndRate == 22050) length_mp3 <<= 1; // mp3s are locked to 44100Hz stereo
|
|
||||||
else if (PicoIn.sndRate == 11025) length_mp3 <<= 2; // so make length 44100ish
|
|
||||||
|
|
||||||
/* do we have to wait? */
|
/* do we have to wait? */
|
||||||
if (mp3_job_started && mp3_samples_ready < length_mp3)
|
if (mp3_job_started && mp3_samples_ready < length_mp3)
|
||||||
|
@ -409,30 +407,30 @@ void mp3_update(int *buffer, int length, int stereo)
|
||||||
/* mix mp3 data, only stereo */
|
/* mix mp3 data, only stereo */
|
||||||
if (mp3_samples_ready >= length_mp3)
|
if (mp3_samples_ready >= length_mp3)
|
||||||
{
|
{
|
||||||
int shr = 0;
|
void (*mix_samples)(s32 *dest_buf, s16 *mp3_buf, int count, int fac16) = mix_16h_to_32_resample_stereo;
|
||||||
void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;
|
if (!stereo)
|
||||||
if (PicoIn.sndRate == 22050) { mix_samples = mix_16h_to_32_s1; shr = 1; }
|
mix_samples = mix_16h_to_32_resample_mono;
|
||||||
else if (PicoIn.sndRate == 11025) { mix_samples = mix_16h_to_32_s2; shr = 2; }
|
|
||||||
|
|
||||||
if (1152 - mp3_buffer_offs >= length_mp3) {
|
if (1152 - mp3_buffer_offs >= length_mp3) {
|
||||||
mix_samples(buffer, mp3_mix_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, length<<1);
|
mix_samples(buffer, mp3_mix_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, length, Pico.snd.cdda_mult);
|
||||||
|
|
||||||
mp3_buffer_offs += length_mp3;
|
mp3_buffer_offs += length_mp3;
|
||||||
} else {
|
} else {
|
||||||
// collect samples from both buffers..
|
// collect samples from both buffers..
|
||||||
int left = 1152 - mp3_buffer_offs;
|
int left = (1152 - mp3_buffer_offs) * Pico.snd.cdda_div >> 16;
|
||||||
|
int sm = stereo ? 2 : 1;
|
||||||
|
|
||||||
if (mp3_play_bufsel == 0)
|
if (mp3_play_bufsel == 0)
|
||||||
{
|
{
|
||||||
mix_samples(buffer, mp3_mix_buffer[0] + mp3_buffer_offs*2, length<<1);
|
mix_samples(buffer, mp3_mix_buffer[0] + mp3_buffer_offs*2, length, Pico.snd.cdda_mult);
|
||||||
mp3_buffer_offs = length_mp3 - left;
|
|
||||||
mp3_play_bufsel = 1;
|
mp3_play_bufsel = 1;
|
||||||
} else {
|
} else {
|
||||||
mix_samples(buffer, mp3_mix_buffer[1] + mp3_buffer_offs*2, (left>>shr)<<1);
|
mix_samples(buffer, mp3_mix_buffer[1] + mp3_buffer_offs*2, left, Pico.snd.cdda_mult);
|
||||||
mp3_buffer_offs = length_mp3 - left;
|
mix_samples(buffer + left * sm,
|
||||||
mix_samples(buffer + ((left>>shr)<<1),
|
mp3_mix_buffer[0], (length-left), Pico.snd.cdda_mult);
|
||||||
mp3_mix_buffer[0], (mp3_buffer_offs>>shr)<<1);
|
|
||||||
mp3_play_bufsel = 0;
|
mp3_play_bufsel = 0;
|
||||||
}
|
}
|
||||||
|
mp3_buffer_offs = (length-left) * Pico.snd.cdda_mult >> 16;
|
||||||
}
|
}
|
||||||
mp3_samples_ready -= length_mp3;
|
mp3_samples_ready -= length_mp3;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue