Skip to content

Commit

Permalink
Add psgplay_stereo_downsample_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
frno7 committed Sep 11, 2022
1 parent 5aee9e3 commit 98e7ddb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
23 changes: 23 additions & 0 deletions include/psgplay/stereo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
1 change: 1 addition & 0 deletions lib/psgplay/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
19 changes: 17 additions & 2 deletions lib/psgplay/psgplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 98e7ddb

Please sign in to comment.