From 98e7ddba1d21363e37ca5a1e9038efac33616c35 Mon Sep 17 00:00:00 2001 From: Fredrik Noring Date: Sun, 11 Sep 2022 10:28:43 +0200 Subject: [PATCH] Add psgplay_stereo_downsample_callback --- include/psgplay/stereo.h | 23 +++++++++++++++++++++++ lib/psgplay/Makefile | 1 + lib/psgplay/psgplay.c | 19 +++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/psgplay/stereo.h b/include/psgplay/stereo.h index ca79039..737212b 100644 --- a/include/psgplay/stereo.h +++ b/include/psgplay/stereo.h @@ -66,4 +66,27 @@ void psgplay_digital_to_stereo_linear(struct psgplay_stereo *stereo, void psgplay_digital_to_stereo_callback(struct psgplay *pp, const psgplay_digital_to_stereo_cb cb, void *arg); +/** + * psgplay_stereo_downsample_cb - callback type to downsample stereo samples + * @resample: downsampled stereo samples + * @stereo: 250 kHz stereo samples + * @count: number of stereo samples to downsample + * @arg: argument supplied to psgplay_stereo_downsample_callback() + * + * Return: number of resamples, must be equal or less than @count + */ +typedef size_t (*psgplay_stereo_downsample_cb)( + struct psgplay_stereo *resample, const struct psgplay_stereo *stereo, + size_t count, void *arg); + +/** + * psgplay_stereo_downsample_callback - invoke callback to downsample + * stereo samples + * @pp: PSG play object + * @cb: callback + * @arg: optional argument supplied to @cb, can be %NULL + */ +void psgplay_stereo_downsample_callback(struct psgplay *pp, + const psgplay_stereo_downsample_cb cb, void *arg); + #endif /* PSGPLAY_STEREO_H */ diff --git a/lib/psgplay/Makefile b/lib/psgplay/Makefile index 74b56d1..2fb11bc 100644 --- a/lib/psgplay/Makefile +++ b/lib/psgplay/Makefile @@ -60,6 +60,7 @@ LIBPSGPLAY_WEB_FUNCTIONS = \ _psgplay_read_digital \ _psgplay_digital_to_stereo_callback \ _psgplay_digital_to_stereo_linear \ + _psgplay_stereo_downsample_callback \ _psgplay_free \ _ice_identify \ _ice_crunched_size \ diff --git a/lib/psgplay/psgplay.c b/lib/psgplay/psgplay.c index 9584dfd..c18f319 100644 --- a/lib/psgplay/psgplay.c +++ b/lib/psgplay/psgplay.c @@ -60,6 +60,11 @@ struct psgplay { void *arg; } digital_to_stereo_callback; + struct { + psgplay_stereo_downsample_cb cb; + void *arg; + } stereo_downsample_callback; + const struct machine *machine; struct { @@ -260,6 +265,13 @@ static size_t stereo_downsample(struct psgplay_stereo *resample, return r; } +void psgplay_stereo_downsample_callback(struct psgplay *pp, + const psgplay_stereo_downsample_cb cb, void *arg) +{ + pp->stereo_downsample_callback.cb = cb; + pp->stereo_downsample_callback.arg = arg; +} + static void digital_to_stereo_downsample(struct psgplay *pp, const struct psgplay_digital *digital, const size_t count) { @@ -273,8 +285,8 @@ static void digital_to_stereo_downsample(struct psgplay *pp, pp->digital_to_stereo_callback.cb(stereo, &digital[i], n, pp->digital_to_stereo_callback.arg); - const size_t r = stereo_downsample( - resample, stereo, n, &pp->downsample); + const size_t r = pp->stereo_downsample_callback.cb(resample, + stereo, n, pp->stereo_downsample_callback.arg); pp->errno_ = buffer_stereo_sample(&pp->stereo_buffer, resample, r); @@ -356,6 +368,9 @@ struct psgplay *psgplay_init(const void *data, size_t size, psgplay_digital_to_stereo_callback(pp, psgplay_digital_to_stereo_linear, NULL); + psgplay_stereo_downsample_callback(pp, + stereo_downsample, &pp->downsample); + return pp; }