aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/sfx/mixer
diff options
context:
space:
mode:
authorMax Horn2009-02-15 22:34:41 +0000
committerMax Horn2009-02-15 22:34:41 +0000
commit29611bc7ead4d3d5fc9df63c04dd9e2577805557 (patch)
tree42d26aab7ab2e7e97fe5b4763281d8071d878eed /engines/sci/sfx/mixer
parent921e6ff5cf3944c1a62a3ad9a91c29bb21aa9942 (diff)
downloadscummvm-rg350-29611bc7ead4d3d5fc9df63c04dd9e2577805557.tar.gz
scummvm-rg350-29611bc7ead4d3d5fc9df63c04dd9e2577805557.tar.bz2
scummvm-rg350-29611bc7ead4d3d5fc9df63c04dd9e2577805557.zip
SCI: Run astyle to make the code be more compliant with our Code Formatting Guidelines: sfx dir
svn-id: r38322
Diffstat (limited to 'engines/sci/sfx/mixer')
-rw-r--r--engines/sci/sfx/mixer/dc.cpp45
-rw-r--r--engines/sci/sfx/mixer/mixers.cpp3
-rw-r--r--engines/sci/sfx/mixer/soft.cpp396
-rw-r--r--engines/sci/sfx/mixer/test.cpp96
4 files changed, 257 insertions, 283 deletions
diff --git a/engines/sci/sfx/mixer/dc.cpp b/engines/sci/sfx/mixer/dc.cpp
index 52b3ab5cbb..c3cc465c92 100644
--- a/engines/sci/sfx/mixer/dc.cpp
+++ b/engines/sci/sfx/mixer/dc.cpp
@@ -65,8 +65,7 @@ TAILQ_HEAD(feed_list, feed_state) feeds;
static char buf[BUF_SIZE * 2];
static feed_state_t *
-find_feed_state(snd_stream_hnd_t hnd)
-{
+find_feed_state(snd_stream_hnd_t hnd) {
feed_state_t *state;
TAILQ_FOREACH(state, &feeds, entry) {
if (state->handle == hnd)
@@ -77,8 +76,7 @@ find_feed_state(snd_stream_hnd_t hnd)
}
static void
-query_timestamp(feed_state_t *state)
-{
+query_timestamp(feed_state_t *state) {
sfx_pcm_feed_t *feed = state->feed;
if (feed->get_timestamp) {
@@ -117,8 +115,7 @@ query_timestamp(feed_state_t *state)
}
void
-U8_to_S16(char *buf, int frames, int stereo)
-{
+U8_to_S16(char *buf, int frames, int stereo) {
int samples = frames * (stereo ? 2 : 1);
int i;
@@ -129,8 +126,7 @@ U8_to_S16(char *buf, int frames, int stereo)
}
static void *
-callback(snd_stream_hnd_t hnd, sfx_timestamp_t timestamp, int bytes_req, int *bytes_recv)
-{
+callback(snd_stream_hnd_t hnd, sfx_timestamp_t timestamp, int bytes_req, int *bytes_recv) {
feed_state_t *state = find_feed_state(hnd);
sfx_pcm_feed_t *feed;
int channels, frames_req;
@@ -191,8 +187,7 @@ callback(snd_stream_hnd_t hnd, sfx_timestamp_t timestamp, int bytes_req, int *by
}
static int
-mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device)
-{
+mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device) {
if (snd_stream_init() < 0) {
fprintf(stderr, "[dc-mixer] Failed to initialize streaming sound driver\n");
return SFX_ERROR;
@@ -204,13 +199,12 @@ mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device)
}
static void
-mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed)
-{
+mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) {
feed_state_t *state = sci_malloc(sizeof(feed_state_t));
long secs, usecs;
if ((feed->conf.format != SFX_PCM_FORMAT_S16_LE) &&
- (feed->conf.format != SFX_PCM_FORMAT_U8)) {
+ (feed->conf.format != SFX_PCM_FORMAT_U8)) {
fprintf(stderr, "[dc-mixer] Unsupported feed format\n");
feed->destroy(feed);
return;
@@ -234,18 +228,16 @@ mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed)
sci_gettime(&secs, &usecs);
state->time = sfx_new_timestamp(secs, usecs, feed->conf.rate);
snd_stream_start(state->handle, feed->conf.rate,
- feed->conf.stereo != SFX_PCM_MONO);
+ feed->conf.stereo != SFX_PCM_MONO);
}
static void
-mix_exit(sfx_pcm_mixer_t *self)
-{
+mix_exit(sfx_pcm_mixer_t *self) {
snd_stream_shutdown();
}
static int
-mix_process(sfx_pcm_mixer_t *self)
-{
+mix_process(sfx_pcm_mixer_t *self) {
feed_state_t *state, *state_next;
TAILQ_FOREACH(state, &feeds, entry) {
@@ -260,11 +252,10 @@ mix_process(sfx_pcm_mixer_t *self)
snd_stream_destroy(state->handle);
state->feed->destroy(state->feed);
TAILQ_REMOVE(&feeds, state, entry);
- }
- else if (state->mode == FEED_MODE_RESTART) {
+ } else if (state->mode == FEED_MODE_RESTART) {
snd_stream_stop(state->handle);
snd_stream_start(state->handle, state->feed->conf.rate,
- state->feed->conf.stereo != SFX_PCM_MONO);
+ state->feed->conf.stereo != SFX_PCM_MONO);
state->mode = FEED_MODE_ALIVE;
}
state = state_next;
@@ -274,24 +265,20 @@ mix_process(sfx_pcm_mixer_t *self)
}
static void
-mix_pause(sfx_pcm_mixer_t *self)
-{
+mix_pause(sfx_pcm_mixer_t *self) {
}
static void
-mix_resume(sfx_pcm_mixer_t *self)
-{
+mix_resume(sfx_pcm_mixer_t *self) {
}
static int
-pcm_init(sfx_pcm_device_t *self)
-{
+pcm_init(sfx_pcm_device_t *self) {
return SFX_OK;
}
static void
-pcm_exit(sfx_pcm_device_t *self)
-{
+pcm_exit(sfx_pcm_device_t *self) {
}
sfx_pcm_device_t sfx_pcm_driver_dc = {
diff --git a/engines/sci/sfx/mixer/mixers.cpp b/engines/sci/sfx/mixer/mixers.cpp
index c0af0e3a53..6bda37487c 100644
--- a/engines/sci/sfx/mixer/mixers.cpp
+++ b/engines/sci/sfx/mixer/mixers.cpp
@@ -43,8 +43,7 @@ static sfx_pcm_mixer_t *mixers[] = {
};
sfx_pcm_mixer_t *
-sfx_pcm_find_mixer(char *name)
-{
+sfx_pcm_find_mixer(char *name) {
int i = 0;
if (name)
diff --git a/engines/sci/sfx/mixer/soft.cpp b/engines/sci/sfx/mixer/soft.cpp
index 7c5b7c12ee..20a4bdc7ad 100644
--- a/engines/sci/sfx/mixer/soft.cpp
+++ b/engines/sci/sfx/mixer/soft.cpp
@@ -86,8 +86,7 @@ struct mixer_private {
static int
-mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device)
-{
+mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device) {
self->dev = device;
self->private_bits /* = P */ = sci_malloc(sizeof(struct mixer_private));
P->outbuf = P->writebuf = NULL;
@@ -98,15 +97,14 @@ mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device)
P->paused = 0;
#ifdef DEBUG
sciprintf("[soft-mixer] Initialised device %s v%s (%d Hz, %d/%x)\n",
- device->name, device->version,
- device->conf.rate, device->conf.stereo, device->conf.format);
+ device->name, device->version,
+ device->conf.rate, device->conf.stereo, device->conf.format);
#endif
return SFX_OK;
}
static inline unsigned int
-gcd(unsigned int a, unsigned int b)
-{
+gcd(unsigned int a, unsigned int b) {
if (a == b)
return a;
@@ -122,8 +120,7 @@ gcd(unsigned int a, unsigned int b)
}
static sfx_pcm_urat_t
-urat(unsigned int nom, unsigned int denom)
-{
+urat(unsigned int nom, unsigned int denom) {
sfx_pcm_urat_t rv;
unsigned int g;
@@ -141,19 +138,18 @@ urat(unsigned int nom, unsigned int denom)
}
static void
-mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed)
-{
+mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) {
sfx_pcm_feed_state_t *fs;
ACQUIRE_LOCK();
if (!self->feeds) {
self->feeds_allocd = 2;
self->feeds = (sfx_pcm_feed_state_t*)sci_malloc(sizeof(sfx_pcm_feed_state_t)
- * self->feeds_allocd);
+ * self->feeds_allocd);
} else if (self->feeds_allocd == self->feeds_nr) {
self->feeds_allocd += 2;
self->feeds = (sfx_pcm_feed_state_t*)sci_realloc(self->feeds,
- sizeof(sfx_pcm_feed_state_t)
- * self->feeds_allocd);
+ sizeof(sfx_pcm_feed_state_t)
+ * self->feeds_allocd);
}
fs = self->feeds + self->feeds_nr++;
@@ -168,19 +164,22 @@ mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed)
*/
/* For the sake of people without 64 bit CPUs: */
fs->buf_size = 2 + /* Additional safety */
- (self->dev->buf_size *
- (1 + (feed->conf.rate / self->dev->conf.rate)));
-fprintf(stderr, " ---> %d/%d/%d/%d = %d\n",
- self->dev->buf_size,
- feed->conf.rate,
- self->dev->conf.rate,
- feed->frame_size,
- fs->buf_size);
+ (self->dev->buf_size *
+ (1 + (feed->conf.rate / self->dev->conf.rate)));
+ fprintf(stderr, " ---> %d/%d/%d/%d = %d\n",
+ self->dev->buf_size,
+ feed->conf.rate,
+ self->dev->conf.rate,
+ feed->frame_size,
+ fs->buf_size);
fs->buf = (byte*)sci_malloc(fs->buf_size * feed->frame_size);
-fprintf(stderr, " ---> --> %d for %p at %p\n", fs->buf_size * feed->frame_size, (void *)fs, (void *)fs->buf);
-{int i; for (i = 0; i < fs->buf_size * feed->frame_size; i++)
-fs->buf[i] = 0xa5; }
+ fprintf(stderr, " ---> --> %d for %p at %p\n", fs->buf_size * feed->frame_size, (void *)fs, (void *)fs->buf);
+ {
+ int i;
+ for (i = 0; i < fs->buf_size * feed->frame_size; i++)
+ fs->buf[i] = 0xa5;
+ }
fs->scount = urat(0, 1);
fs->spd = urat(feed->conf.rate, self->dev->conf.rate);
fs->scount.den = fs->spd.den;
@@ -191,22 +190,21 @@ fs->buf[i] = 0xa5; }
fs->mode = SFX_PCM_FEED_MODE_ALIVE;
/* If the feed can't provide us with timestamps, we don't need to wait for it to do so */
- fs->pending_review = (feed->get_timestamp)? 1 : 0;
+ fs->pending_review = (feed->get_timestamp) ? 1 : 0;
fs->frame_bufstart = 0;
#ifdef DEBUG
sciprintf("[soft-mixer] Subscribed %s-%x (%d Hz, %d/%x) at %d+%d/%d, buffer size %d\n",
- feed->debug_name, feed->debug_nr, feed->conf.rate, feed->conf.stereo, feed->conf.format,
- fs->spd.val, fs->spd.nom, fs->spd.den, fs->buf_size);
+ feed->debug_name, feed->debug_nr, feed->conf.rate, feed->conf.stereo, feed->conf.format,
+ fs->spd.val, fs->spd.nom, fs->spd.den, fs->buf_size);
#endif
RELEASE_LOCK();
}
static void
-_mix_unsubscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed)
-{
+_mix_unsubscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) {
int i;
#ifdef DEBUG
sciprintf("[soft-mixer] Unsubscribing %s-%x\n", feed->debug_name, feed->debug_nr);
@@ -230,29 +228,28 @@ _mix_unsubscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed)
/* Limit memory waste */
self->feeds_allocd >>= 1;
self->feeds
- = (sfx_pcm_feed_state_t*)sci_realloc(self->feeds,
- sizeof(sfx_pcm_feed_state_t)
- * self->feeds_allocd);
+ = (sfx_pcm_feed_state_t*)sci_realloc(self->feeds,
+ sizeof(sfx_pcm_feed_state_t)
+ * self->feeds_allocd);
}
for (i = 0; i < self->feeds_nr; i++)
fprintf(stderr, " Feed #%d: %s-%x\n",
- i, self->feeds[i].feed->debug_name,
- self->feeds[i].feed->debug_nr);
+ i, self->feeds[i].feed->debug_name,
+ self->feeds[i].feed->debug_nr);
return;
}
}
- fprintf(stderr, "[sfx-mixer] Assertion failed: Deleting invalid feed %p out of %d\n",
- (void *)feed, self->feeds_nr);
+ fprintf(stderr, "[sfx-mixer] Assertion failed: Deleting invalid feed %p out of %d\n",
+ (void *)feed, self->feeds_nr);
BREAKPOINT();
}
static void
-mix_exit(sfx_pcm_mixer_t *self)
-{
+mix_exit(sfx_pcm_mixer_t *self) {
ACQUIRE_LOCK();
while (self->feeds_nr)
_mix_unsubscribe(self, self->feeds[0].feed);
@@ -284,8 +281,7 @@ mix_exit(sfx_pcm_mixer_t *self)
v = 32767
static inline void
-mix_compute_output(sfx_pcm_mixer_t *self, int outplen)
-{
+mix_compute_output(sfx_pcm_mixer_t *self, int outplen) {
int frame_i;
sfx_pcm_config_t conf = self->dev->conf;
int use_16 = conf.format & SFX_PCM_FORMAT_16;
@@ -303,11 +299,11 @@ mix_compute_output(sfx_pcm_mixer_t *self, int outplen)
if (conf.stereo) {
if (conf.stereo == SFX_PCM_STEREO_RL) {
- lchan = P->writebuf + ((use_16)? 2 : 1);
+ lchan = P->writebuf + ((use_16) ? 2 : 1);
rchan = P->writebuf;
} else {
lchan = P->writebuf;
- rchan = P->writebuf + ((use_16)? 2 : 1);
+ rchan = P->writebuf + ((use_16) ? 2 : 1);
}
} else
lchan = P->writebuf;
@@ -380,8 +376,7 @@ mix_compute_output(sfx_pcm_mixer_t *self, int outplen)
}
static inline void
-mix_swap_buffers(sfx_pcm_mixer_t *self)
-{ /* Swap buffers */
+mix_swap_buffers(sfx_pcm_mixer_t *self) { /* Swap buffers */
byte *tmp = P->outbuf;
P->outbuf = P->writebuf;
P->writebuf = tmp;
@@ -395,10 +390,10 @@ mix_swap_buffers(sfx_pcm_mixer_t *self)
static inline int
mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames)
- /* Computes the number of frames we ought to write. It tries to minimise the number,
- ** in order to reduce latency. */
- /* It sets 'skip_frames' to the number of frames to assume lost by latency, effectively
- ** skipping them. */
+/* Computes the number of frames we ought to write. It tries to minimise the number,
+** in order to reduce latency. */
+/* It sets 'skip_frames' to the number of frames to assume lost by latency, effectively
+** skipping them. */
{
int free_frames;
int played_frames = 0; /* since the last call */
@@ -424,14 +419,13 @@ mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames)
if (P->skew > usecs) {
secs--;
usecs += (1000000 - P->skew);
- }
- else
+ } else
usecs -= P->skew;
frame_pos = FRAME_OFFSET(usecs);
played_frames = frame_pos - P->played_this_second
- + ((secs - P->lsec) * self->dev->conf.rate);
+ + ((secs - P->lsec) * self->dev->conf.rate);
/*
fprintf(stderr, "%d:%d - %d:%d => %d\n", secs, frame_pos,
P->lsec, P->played_this_second, played_frames);
@@ -454,8 +448,8 @@ mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames)
if (free_frames > self->dev->buf_size) {
if (!diagnosed_too_slow) {
sciprintf("[sfx-mixer] Your timer is too slow for your PCM output device (%d/%d), free=%d.\n"
- "[sfx-mixer] You might want to try changing the device, timer, or mixer, if possible.\n",
- played_frames, self->dev->buf_size, free_frames);
+ "[sfx-mixer] You might want to try changing the device, timer, or mixer, if possible.\n",
+ played_frames, self->dev->buf_size, free_frames);
}
diagnosed_too_slow = 1;
@@ -468,20 +462,20 @@ mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames)
if (P->delta_observations > MAX_DELTA_OBSERVATIONS)
P->delta_observations = MAX_DELTA_OBSERVATIONS;
-/* /\* Disabled, broken *\/ */
-/* if (0 && P->delta_observations > MIN_DELTA_OBSERVATIONS) { /\* Start improving after a while *\/ */
-/* int diff = self->dev->conf.rate - P->max_delta; */
+ /* /\* Disabled, broken *\/ */
+ /* if (0 && P->delta_observations > MIN_DELTA_OBSERVATIONS) { /\* Start improving after a while *\/ */
+ /* int diff = self->dev->conf.rate - P->max_delta; */
-/* /\* log-approximate P->max_delta over time *\/ */
-/* recommended_frames = P->max_delta + */
-/* ((diff * MIN_DELTA_OBSERVATIONS) / P->delta_observations); */
-/* /\* WTF? *\/ */
-/* } else */
-/* recommended_frames = self->dev->buf_size; /\* Initially, keep the buffer full *\/ */
+ /* /\* log-approximate P->max_delta over time *\/ */
+ /* recommended_frames = P->max_delta + */
+ /* ((diff * MIN_DELTA_OBSERVATIONS) / P->delta_observations); */
+ /* /\* WTF? *\/ */
+ /* } else */
+ /* recommended_frames = self->dev->buf_size; /\* Initially, keep the buffer full *\/ */
#if (DEBUG >= 1)
sciprintf("[soft-mixer] played since last time: %d, recommended: %d, free: %d\n",
- played_frames, recommended_frames, free_frames);
+ played_frames, recommended_frames, free_frames);
#endif
result_frames = free_frames;
@@ -498,7 +492,7 @@ mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames)
if (result_frames > self->dev->buf_size) {
fprintf(stderr, "[soft-mixer] Internal assertion failed: frames-to-write %d > %d\n",
- result_frames, self->dev->buf_size);
+ result_frames, self->dev->buf_size);
}
return result_frames;
}
@@ -551,9 +545,9 @@ static volatile int xx_size;
static void
mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
- int len, sfx_timestamp_t *ts, sfx_timestamp_t base_ts)
- /* if add_result is non-zero, P->outbuf should be added to rather than overwritten. */
- /* base_ts is the timestamp for the first frame */
+ int len, sfx_timestamp_t *ts, sfx_timestamp_t base_ts)
+/* if add_result is non-zero, P->outbuf should be added to rather than overwritten. */
+/* base_ts is the timestamp for the first frame */
{
sfx_pcm_feed_state_t *fs = self->feeds + add_result;
sfx_pcm_feed_t *f = fs->feed;
@@ -567,7 +561,7 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
byte *rsrc = fs->buf;
/* Location to write to */
int frames_nr;
- int bias = (conf.format & ~SFX_PCM_FORMAT_LMASK)? 0x8000 : 0;
+ int bias = (conf.format & ~SFX_PCM_FORMAT_LMASK) ? 0x8000 : 0;
/* We use this only on a 16 bit level here */
/* The two most extreme source frames we consider for a
@@ -584,18 +578,18 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
frames_nr = fs->spd.val * len;
/* A little complicated since we must consider partial frames */
frames_nr += (fs->spd.nom * len
- + (fs->scount.den - fs->scount.nom) /* remember that we may have leftovers */
- + (fs->spd.den - 1 /* round up */)
- )
- / fs->spd.den;
+ + (fs->scount.den - fs->scount.nom) /* remember that we may have leftovers */
+ + (fs->spd.den - 1 /* round up */)
+ )
+ / fs->spd.den;
ts->secs = -1;
if (frames_nr > fs->buf_size) {
fprintf(stderr, "%d (%d*%d + somethign) bytes, but only %d allowed!!!!!\n",
- frames_nr * f->frame_size,
- fs->spd.val, len,
- fs->buf_size);
+ frames_nr * f->frame_size,
+ fs->spd.val, len,
+ fs->buf_size);
BREAKPOINT();
}
@@ -616,8 +610,8 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
case PCM_FEED_TIMESTAMP: {
/* Compute the number of frames the returned timestamp is in the future: */
delay_frames =
- sfx_timestamp_frame_diff(sfx_timestamp_renormalise(*ts, base_ts.frame_rate),
- base_ts);
+ sfx_timestamp_frame_diff(sfx_timestamp_renormalise(*ts, base_ts.frame_rate),
+ base_ts);
if (delay_frames <= 0)
/* Start ASAP, even if it's too late */
@@ -627,7 +621,7 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
delay_frames = len;
fs->pending_review = 0;
}
- break;
+ break;
case PCM_FEED_EMPTY:
fs->mode = SFX_PCM_FEED_MODE_DEAD;
@@ -644,7 +638,7 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
default:
fprintf(stderr, "[soft-mixer] Fatal: Invalid mode returned by PCM feed %s-%d's get_timestamp(): %d\n",
- f->debug_name, f->debug_nr, newmode);
+ f->debug_name, f->debug_nr, newmode);
exit(1);
}
}
@@ -653,10 +647,10 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
/* Make sure we have sufficient information */
if (frames_nr > delay_frames + fs->frame_bufstart)
frames_read =
- f->poll(f, wr_dest,
- frames_nr
- - delay_frames
- - fs->frame_bufstart);
+ f->poll(f, wr_dest,
+ frames_nr
+ - delay_frames
+ - fs->frame_bufstart);
ACQUIRE_LOCK();
fs = self->feeds + add_result;
@@ -681,15 +675,15 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
#if (DEBUG >= 2)
sciprintf("[soft-mixer] Examining %s-%x (frame size %d); read %d/%d/%d, re-using %d frames\n",
- f->debug_name, f->debug_nr, frame_size, frames_read, frames_nr,
- fs->buf_size, fs->frame_bufstart);
+ f->debug_name, f->debug_nr, frame_size, frames_read, frames_nr,
+ fs->buf_size, fs->frame_bufstart);
#endif
if (conf.stereo == SFX_PCM_STEREO_LR)
- rsrc += (use_16)? 2 : 1;
+ rsrc += (use_16) ? 2 : 1;
else if (conf.stereo == SFX_PCM_STEREO_RL)
- lsrc += (use_16)? 2 : 1;
+ lsrc += (use_16) ? 2 : 1;
/* Otherwise, we let both point to the same place */
#if (DEBUG >= 2)
@@ -723,7 +717,7 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
sciprintf("[soft-mixer] Initial read %d:%d\n", c_new.left, c_new.right);
#endif
c_old = c_new;
- }
+ }
#endif
for (j = 0; j < frame_steps; j++) {
@@ -737,16 +731,16 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
** part analysis, so we add it to 'left' and 'right'
** later-- all others are added to (leftsum, rightsum).
*/
- if (j+1 < frame_steps) {
+ if (j + 1 < frame_steps) {
leftsum += c_new.left;
rightsum += c_new.right;
}
}
left = c_new.left * fs->scount.nom
- + c_old.left * (fs->scount.den - fs->scount.nom);
+ + c_old.left * (fs->scount.den - fs->scount.nom);
right = c_new.right * fs->scount.nom
- + c_old.right * (fs->scount.den - fs->scount.nom);
+ + c_old.right * (fs->scount.den - fs->scount.nom);
/* Normalise */
left /= fs->spd.den;
@@ -795,15 +789,15 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
xx_offset = ((frames_read - frames_left) * f->frame_size);
xx_size = frames_left * f->frame_size;
if (xx_offset + xx_size
- >= fs->buf_size * f->frame_size) {
+ >= fs->buf_size * f->frame_size) {
fprintf(stderr, "offset %d >= max %d!\n",
- (xx_offset + xx_size), fs->buf_size * f->frame_size);
+ (xx_offset + xx_size), fs->buf_size * f->frame_size);
BREAKPOINT();
}
memmove(fs->buf,
- fs->buf + ((frames_read - frames_left) * f->frame_size),
- frames_left * f->frame_size);
+ fs->buf + ((frames_read - frames_left) * f->frame_size),
+ frames_left * f->frame_size);
}
#if (DEBUG >= 2)
sciprintf("[soft-mixer] Leaving %d over\n", fs->frame_bufstart);
@@ -818,144 +812,142 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result,
}
static int
-mix_process_linear(sfx_pcm_mixer_t *self)
-{
-ACQUIRE_LOCK();
-{
- int src_i; /* source feed index counter */
- int frames_skip; /* Number of frames to discard, rather than to emit */
- int buflen = mix_compute_buf_len(self, &frames_skip); /* Compute # of frames we must compute and write */
- int fake_buflen;
- int timestamp_max_delta = 0;
- int have_timestamp = 0;
- sfx_timestamp_t start_timestamp; /* The timestamp at which the first frame will be played */
- sfx_timestamp_t min_timestamp;
- min_timestamp.secs = 0;
- sfx_timestamp_t timestamp;
-
- if (self->dev->get_output_timestamp)
- start_timestamp = self->dev->get_output_timestamp(self->dev);
- else {
- long sec, usec;
- sci_gettime(&sec, &usec);
- start_timestamp = sfx_new_timestamp(sec, usec, self->dev->conf.rate);
- }
+mix_process_linear(sfx_pcm_mixer_t *self) {
+ ACQUIRE_LOCK();
+ {
+ int src_i; /* source feed index counter */
+ int frames_skip; /* Number of frames to discard, rather than to emit */
+ int buflen = mix_compute_buf_len(self, &frames_skip); /* Compute # of frames we must compute and write */
+ int fake_buflen;
+ int timestamp_max_delta = 0;
+ int have_timestamp = 0;
+ sfx_timestamp_t start_timestamp; /* The timestamp at which the first frame will be played */
+ sfx_timestamp_t min_timestamp;
+ min_timestamp.secs = 0;
+ sfx_timestamp_t timestamp;
+
+ if (self->dev->get_output_timestamp)
+ start_timestamp = self->dev->get_output_timestamp(self->dev);
+ else {
+ long sec, usec;
+ sci_gettime(&sec, &usec);
+ start_timestamp = sfx_new_timestamp(sec, usec, self->dev->conf.rate);
+ }
- if ((P->outbuf) && (P->lastbuf_len)) {
- sfx_timestamp_t ts;
- int rv;
+ if ((P->outbuf) && (P->lastbuf_len)) {
+ sfx_timestamp_t ts;
+ int rv;
- if (P->have_outbuf_timestamp) {
- ts = sfx_timestamp_renormalise(P->outbuf_timestamp, self->dev->conf.rate);
- }
+ if (P->have_outbuf_timestamp) {
+ ts = sfx_timestamp_renormalise(P->outbuf_timestamp, self->dev->conf.rate);
+ }
- rv = self->dev->output(self->dev, P->outbuf,
- P->lastbuf_len,
- (P->have_outbuf_timestamp)? &ts : NULL);
+ rv = self->dev->output(self->dev, P->outbuf,
+ P->lastbuf_len,
+ (P->have_outbuf_timestamp) ? &ts : NULL);
- if (rv == SFX_ERROR) {
- RELEASE_LOCK();
- return rv; /* error */
+ if (rv == SFX_ERROR) {
+ RELEASE_LOCK();
+ return rv; /* error */
+ }
}
- }
#if (DEBUG >= 1)
- if (self->feeds_nr)
- sciprintf("[soft-mixer] Mixing %d output frames on %d input feeds\n", buflen, self->feeds_nr);
+ if (self->feeds_nr)
+ sciprintf("[soft-mixer] Mixing %d output frames on %d input feeds\n", buflen, self->feeds_nr);
#endif
- if (self->feeds_nr && !P->paused) {
- /* Below, we read out all feeds in case we have to skip frames first, then get the
- ** most current sound. 'fake_buflen' is either the actual buflen (for the last iteration)
- ** or a fraction of the buf length to discard. */
- do {
- if (frames_skip) {
- if (frames_skip > self->dev->buf_size)
- fake_buflen = self->dev->buf_size;
- else
- fake_buflen = frames_skip;
-
- frames_skip -= fake_buflen;
- } else {
- fake_buflen = buflen;
- frames_skip = -1; /* Mark us as being completely done */
- }
+ if (self->feeds_nr && !P->paused) {
+ /* Below, we read out all feeds in case we have to skip frames first, then get the
+ ** most current sound. 'fake_buflen' is either the actual buflen (for the last iteration)
+ ** or a fraction of the buf length to discard. */
+ do {
+ if (frames_skip) {
+ if (frames_skip > self->dev->buf_size)
+ fake_buflen = self->dev->buf_size;
+ else
+ fake_buflen = frames_skip;
+
+ frames_skip -= fake_buflen;
+ } else {
+ fake_buflen = buflen;
+ frames_skip = -1; /* Mark us as being completely done */
+ }
- for (src_i = 0; src_i < self->feeds_nr; src_i++) {
- mix_compute_input_linear(self, src_i,
- fake_buflen, &timestamp,
- start_timestamp);
-
- if (timestamp.secs >= 0) {
- if (have_timestamp) {
- int diff = sfx_timestamp_usecs_diff(min_timestamp, timestamp);
- if (diff > 0) {
- /* New earlier timestamp */
- timestamp = min_timestamp;
- timestamp_max_delta += diff;
- } else if (diff > timestamp_max_delta)
- timestamp_max_delta = diff;
- /* New max delta for timestamp */
- } else {
- min_timestamp = timestamp;
- have_timestamp = 1;
+ for (src_i = 0; src_i < self->feeds_nr; src_i++) {
+ mix_compute_input_linear(self, src_i,
+ fake_buflen, &timestamp,
+ start_timestamp);
+
+ if (timestamp.secs >= 0) {
+ if (have_timestamp) {
+ int diff = sfx_timestamp_usecs_diff(min_timestamp, timestamp);
+ if (diff > 0) {
+ /* New earlier timestamp */
+ timestamp = min_timestamp;
+ timestamp_max_delta += diff;
+ } else if (diff > timestamp_max_delta)
+ timestamp_max_delta = diff;
+ /* New max delta for timestamp */
+ } else {
+ min_timestamp = timestamp;
+ have_timestamp = 1;
+ }
}
}
- }
- /* Destroy all feeds we finished */
- for (src_i = 0; src_i < self->feeds_nr; src_i++)
- if (self->feeds[src_i].mode == SFX_PCM_FEED_MODE_DEAD)
- _mix_unsubscribe(self, self->feeds[src_i].feed);
- } while (frames_skip >= 0);
-
- } else { /* Zero it out */
- memset(P->compbuf_l, 0, sizeof(gint32) * buflen);
- memset(P->compbuf_r, 0, sizeof(gint32) * buflen);
- }
+ /* Destroy all feeds we finished */
+ for (src_i = 0; src_i < self->feeds_nr; src_i++)
+ if (self->feeds[src_i].mode == SFX_PCM_FEED_MODE_DEAD)
+ _mix_unsubscribe(self, self->feeds[src_i].feed);
+ } while (frames_skip >= 0);
+
+ } else { /* Zero it out */
+ memset(P->compbuf_l, 0, sizeof(gint32) * buflen);
+ memset(P->compbuf_r, 0, sizeof(gint32) * buflen);
+ }
#if (DEBUG >= 1)
- if (self->feeds_nr)
- sciprintf("[soft-mixer] Done mixing for this session, the result will be our next output buffer\n");
+ if (self->feeds_nr)
+ sciprintf("[soft-mixer] Done mixing for this session, the result will be our next output buffer\n");
#endif
#if (DEBUG >= 3)
- if (self->feeds_nr) {
- int i;
- sciprintf("[soft-mixer] Intermediate representation:\n");
- for (i = 0; i < buflen; i++)
- sciprintf("[soft-mixer] Offset %d:\t[%04x:%04x]\t%d:%d\n", i,
- P->compbuf_l[i] & 0xffff, P->compbuf_r[i] & 0xffff,
- P->compbuf_l[i], P->compbuf_r[i]);
- }
+ if (self->feeds_nr) {
+ int i;
+ sciprintf("[soft-mixer] Intermediate representation:\n");
+ for (i = 0; i < buflen; i++)
+ sciprintf("[soft-mixer] Offset %d:\t[%04x:%04x]\t%d:%d\n", i,
+ P->compbuf_l[i] & 0xffff, P->compbuf_r[i] & 0xffff,
+ P->compbuf_l[i], P->compbuf_r[i]);
+ }
#endif
- if (timestamp_max_delta > TIMESTAMP_MAX_ALLOWED_DELTA)
- sciprintf("[soft-mixer] Warning: Difference in timestamps between audio feeds is %d us\n", timestamp_max_delta);
+ if (timestamp_max_delta > TIMESTAMP_MAX_ALLOWED_DELTA)
+ sciprintf("[soft-mixer] Warning: Difference in timestamps between audio feeds is %d us\n", timestamp_max_delta);
- mix_compute_output(self, buflen);
- P->lastbuf_len = buflen;
+ mix_compute_output(self, buflen);
+ P->lastbuf_len = buflen;
- /* Finalize */
- mix_swap_buffers(self);
- if (have_timestamp)
- P->outbuf_timestamp = sfx_timestamp_add(min_timestamp,
- timestamp_max_delta >> 1);
- P->have_outbuf_timestamp = have_timestamp;
+ /* Finalize */
+ mix_swap_buffers(self);
+ if (have_timestamp)
+ P->outbuf_timestamp = sfx_timestamp_add(min_timestamp,
+ timestamp_max_delta >> 1);
+ P->have_outbuf_timestamp = have_timestamp;
-} RELEASE_LOCK();
+ }
+ RELEASE_LOCK();
return SFX_OK;
}
static void
-mix_pause(sfx_pcm_mixer_t *self)
-{
+mix_pause(sfx_pcm_mixer_t *self) {
ACQUIRE_LOCK();
P->paused = 1;
RELEASE_LOCK();
}
static void
-mix_resume(sfx_pcm_mixer_t *self)
-{
+mix_resume(sfx_pcm_mixer_t *self) {
ACQUIRE_LOCK();
P->paused = 0;
RELEASE_LOCK();
diff --git a/engines/sci/sfx/mixer/test.cpp b/engines/sci/sfx/mixer/test.cpp
index 20b3e952e1..1119f0933c 100644
--- a/engines/sci/sfx/mixer/test.cpp
+++ b/engines/sci/sfx/mixer/test.cpp
@@ -45,10 +45,10 @@ int dev_output(sfx_pcm_device_t *self, byte *buf, int count);
sfx_pcm_device_t devices[DEVICES_NR] = {
{ "test-1", "0", dev_init, dev_exit, dev_option, dev_output,
- { 200, SFX_PCM_MONO, SFX_PCM_FORMAT_U8 }, 1024, NULL },
+ { 200, SFX_PCM_MONO, SFX_PCM_FORMAT_U8 }, 1024, NULL },
#if (DEVICES_NR > 1)
- { "test-2", "0", dev_init, dev_exit, dev_option, dev_output,
- { 200, SFX_PCM_STEREO_LR, SFX_PCM_FORMAT_U8 }, 1024, NULL },
+ { "test-2", "0", dev_init, dev_exit, dev_option, dev_output, { 200, SFX_PCM_STEREO_LR, SFX_PCM_FORMAT_U8 }, 1024, NULL
+ },
{ "test-3", "0", dev_init, dev_exit, dev_option, dev_output,
{ 200, SFX_PCM_STEREO_RL, SFX_PCM_FORMAT_U8 }, 1024, NULL },
{ "test-4", "0", dev_init, dev_exit, dev_option, dev_output,
@@ -70,42 +70,38 @@ sfx_pcm_device_t devices[DEVICES_NR] = {
int output_count;
-int dev_init(sfx_pcm_device_t *self)
-{
+int dev_init(sfx_pcm_device_t *self) {
output_count = 0;
fprintf(stderr, "[DEV] Initialised device %p as follows:\n"
- "\trate = %d\n"
- "\tstereo = %s\n"
- "\tbias = %x\n"
- "\tbytes/sample = %d\n"
- "\tendianness = %s\n",
- self,
- self->conf.rate,
- self->conf.stereo? ((self->conf.stereo == SFX_PCM_STEREO_LR)? "Left, Right" : "Right, Left") : "No",
- self->conf.format & ~SFX_PCM_FORMAT_LMASK,
- (self->conf.format & SFX_PCM_FORMAT_16)? 2 : 1,
- ((self->conf.format & SFX_PCM_FORMAT_ENDIANNESS) == SFX_PCM_FORMAT_BE)? "big" : "little");
+ "\trate = %d\n"
+ "\tstereo = %s\n"
+ "\tbias = %x\n"
+ "\tbytes/sample = %d\n"
+ "\tendianness = %s\n",
+ self,
+ self->conf.rate,
+ self->conf.stereo ? ((self->conf.stereo == SFX_PCM_STEREO_LR) ? "Left, Right" : "Right, Left") : "No",
+ self->conf.format & ~SFX_PCM_FORMAT_LMASK,
+ (self->conf.format & SFX_PCM_FORMAT_16) ? 2 : 1,
+ ((self->conf.format & SFX_PCM_FORMAT_ENDIANNESS) == SFX_PCM_FORMAT_BE) ? "big" : "little");
return 0;
}
-void dev_exit(sfx_pcm_device_t *self)
-{
+void dev_exit(sfx_pcm_device_t *self) {
fprintf(stderr, "[DEV] Uninitialising device\n");
}
-int dev_option(sfx_pcm_device_t *self, char *name, char *value)
-{
+int dev_option(sfx_pcm_device_t *self, char *name, char *value) {
fprintf(stderr, "[DEV] Set option '%s' to '%s'\n", name, value);
return 0;
}
int dev_output_enabled = 0;
-int dev_output(sfx_pcm_device_t *self, byte *buf, int count)
-{
- int mono_sample_size = ((self->conf.format & SFX_PCM_FORMAT_16)? 2 : 1);
- int sample_size = (self->conf.stereo? 2 : 1) * mono_sample_size;
+int dev_output(sfx_pcm_device_t *self, byte *buf, int count) {
+ int mono_sample_size = ((self->conf.format & SFX_PCM_FORMAT_16) ? 2 : 1);
+ int sample_size = (self->conf.stereo ? 2 : 1) * mono_sample_size;
int bias = self->conf.format & ~SFX_PCM_FORMAT_LMASK;
int is_bigendian = (self->conf.format & SFX_PCM_FORMAT_ENDIANNESS) == SFX_PCM_FORMAT_BE;
byte *left_channel = buf;
@@ -125,7 +121,7 @@ int dev_output(sfx_pcm_device_t *self, byte *buf, int count)
while (count--) {
int right = right_channel[0];
int left = left_channel[0];
- int second_byte = ((self->conf.format & SFX_PCM_FORMAT_16)? 1 : 0);
+ int second_byte = ((self->conf.format & SFX_PCM_FORMAT_16) ? 1 : 0);
if (second_byte) {
@@ -186,18 +182,18 @@ typedef struct {
sfx_pcm_feed_t feeds[FEEDS_NR] = {
{ feed_poll, feed_destroy, &(private_bits[0]),
- { 200, SFX_PCM_MONO, SFX_PCM_FORMAT_S8 }, "test-feed", 0, 0}
+ { 200, SFX_PCM_MONO, SFX_PCM_FORMAT_S8 }, "test-feed", 0, 0}
#if FEEDS_NR > 1
- ,{ feed_poll, feed_destroy, &(private_bits[1]),
- { 400, SFX_PCM_MONO, SFX_PCM_FORMAT_U8 }, "test-feed", 1, 0}
+ , { feed_poll, feed_destroy, &(private_bits[1]),
+ { 400, SFX_PCM_MONO, SFX_PCM_FORMAT_U8 }, "test-feed", 1, 0}
#endif
#if FEEDS_NR > 2
- ,{ feed_poll, feed_destroy, &(private_bits[2]),
- { 20, SFX_PCM_MONO, SFX_PCM_FORMAT_S16_LE }, "test-feed", 2, 0}
+ , { feed_poll, feed_destroy, &(private_bits[2]),
+ { 20, SFX_PCM_MONO, SFX_PCM_FORMAT_S16_LE }, "test-feed", 2, 0}
#endif
#if FEEDS_NR > 3
- ,{ feed_poll, feed_destroy, &(private_bits[3]),
- { 150, SFX_PCM_STEREO_LR, SFX_PCM_FORMAT_S8 }, "test-feed", 3, 0}
+ , { feed_poll, feed_destroy, &(private_bits[3]),
+ { 150, SFX_PCM_STEREO_LR, SFX_PCM_FORMAT_S8 }, "test-feed", 3, 0}
#endif
/*
,{ feed_poll, feed_destroy, &(private_bits[4]),
@@ -208,46 +204,47 @@ sfx_pcm_feed_t feeds[FEEDS_NR] = {
};
byte feed_data_0[] = {0xfd, 0xfe, 0xff, 0, 1, 2, 3, 4, 5, 6};
-byte feed_data_1[] = {0x80, 0x90, 0xA0, 0xB0, 0xC0,
- 0xD0, 0xD0, 0xC0, 0xB0, 0xA0, 0x90, 0x80};
+byte feed_data_1[] = {0x80, 0x90, 0xA0, 0xB0, 0xC0,
+ 0xD0, 0xD0, 0xC0, 0xB0, 0xA0, 0x90, 0x80
+ };
byte feed_data_2[] = {0x00, 0x00,
- 0x00, 0x80,
- 0xe8, 0x03};
+ 0x00, 0x80,
+ 0xe8, 0x03
+ };
byte feed_data_3[] = {0x00, 0x10,
- 0x01, 0x20,
- 0x02, 0x30};
+ 0x01, 0x20,
+ 0x02, 0x30
+ };
sample_feed_t sample_feeds[FEEDS_NR] = {
{ 1, 10, feed_data_0 }
#if FEEDS_NR > 1
- ,{ 21, 12, feed_data_1 }
+ , { 21, 12, feed_data_1 }
#endif
#if FEEDS_NR > 2
- ,{ 0, 3, feed_data_2 }
+ , { 0, 3, feed_data_2 }
#endif
#if FEEDS_NR > 3
- ,{ 40, 3, feed_data_3 }
+ , { 40, 3, feed_data_3 }
#endif
};
void
-feed_destroy(sfx_pcm_feed_t *self)
-{
+feed_destroy(sfx_pcm_feed_t *self) {
int_struct *s = (int_struct *) self->internal;
s->i = 0; /* reset */
}
int
-feed_poll(sfx_pcm_feed_t *self, byte *dest, int size)
-{
+feed_poll(sfx_pcm_feed_t *self, byte *dest, int size) {
int_struct *s = (int_struct *) self->internal;
int sample_size = self->sample_size;
sample_feed_t *data = &(sample_feeds[self->debug_nr]);
int bias = self->conf.format & ~SFX_PCM_FORMAT_LMASK;
byte neutral[4] = {0, 0, 0, 0};
int i;
-fprintf(stderr, "[feed] Asked for %d at %p, ss=%d\n", size, dest, sample_size);
+ fprintf(stderr, "[feed] Asked for %d at %p, ss=%d\n", size, dest, sample_size);
if (bias) {
byte first = bias >> 8;
byte second = bias & 0xff;
@@ -295,8 +292,7 @@ extern FILE *con_file;
int
-main(int argc, char **argv)
-{
+main(int argc, char **argv) {
int dev_nr;
mix = sfx_pcm_find_mixer(NULL);
@@ -306,7 +302,7 @@ main(int argc, char **argv)
return 1;
} else {
fprintf(stderr, "Running %s, v%s\n",
- mix->name, mix->version);
+ mix->name, mix->version);
}
con_file = stderr;
@@ -332,7 +328,7 @@ main(int argc, char **argv)
mix->subscribe(mix, &(feeds[j]));
fprintf(stderr, "[test] Subscribed %d feeds.\n",
- FEEDS_NR);
+ FEEDS_NR);
while (output_count < MIN_OUTPUT) {
DELAY;