Skip to content

Commit

Permalink
audio: remove audio_MIN, audio_MAX
Browse files Browse the repository at this point in the history
There's already a MIN and MAX macro in include/qemu/osdep.h, use them
instead.

Signed-off-by: Kővágó, Zoltán <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-id: 303222477df6f7373217e0df768635fab5855745.1566168923.git.DirtY.iCE.hu@gmail.com
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
DirtYiCE authored and kraxel committed Aug 21, 2019
1 parent 8692bf7 commit 5893591
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 87 deletions.
6 changes: 3 additions & 3 deletions audio/alsaaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)

while (alsa->pending) {
int left_till_end_samples = hw->samples - alsa->wpos;
int len = audio_MIN (alsa->pending, left_till_end_samples);
int len = MIN (alsa->pending, left_till_end_samples);
char *src = advance (alsa->pcm_buf, alsa->wpos << hw->info.shift);

while (len) {
Expand Down Expand Up @@ -697,7 +697,7 @@ static int alsa_run_out (HWVoiceOut *hw, int live)
return 0;
}

decr = audio_MIN (live, avail);
decr = MIN (live, avail);
decr = audio_pcm_hw_clip_out (hw, alsa->pcm_buf, decr, alsa->pending);
alsa->pending += decr;
alsa_write_pending (alsa);
Expand Down Expand Up @@ -915,7 +915,7 @@ static int alsa_run_in (HWVoiceIn *hw)
}
}

decr = audio_MIN (dead, avail);
decr = MIN (dead, avail);
if (!decr) {
return 0;
}
Expand Down
20 changes: 10 additions & 10 deletions audio/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static int audio_pcm_hw_find_min_in (HWVoiceIn *hw)

for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
if (sw->active) {
m = audio_MIN (m, sw->total_hw_samples_acquired);
m = MIN (m, sw->total_hw_samples_acquired);
}
}
return m;
Expand All @@ -555,14 +555,14 @@ int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
int live, int pending)
{
int left = hw->samples - pending;
int len = audio_MIN (left, live);
int len = MIN (left, live);
int clipped = 0;

while (len) {
struct st_sample *src = hw->mix_buf + hw->rpos;
uint8_t *dst = advance (pcm_buf, hw->rpos << hw->info.shift);
int samples_till_end_of_buf = hw->samples - hw->rpos;
int samples_to_clip = audio_MIN (len, samples_till_end_of_buf);
int samples_to_clip = MIN (len, samples_till_end_of_buf);

hw->clip (dst, src, samples_to_clip);

Expand Down Expand Up @@ -616,7 +616,7 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size)
}

swlim = (live * sw->ratio) >> 32;
swlim = audio_MIN (swlim, samples);
swlim = MIN (swlim, samples);

while (swlim) {
src = hw->conv_buf + rpos;
Expand Down Expand Up @@ -664,7 +664,7 @@ static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)

for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
if (sw->active || !sw->empty) {
m = audio_MIN (m, sw->total_hw_samples_mixed);
m = MIN (m, sw->total_hw_samples_mixed);
nb_live += 1;
}
}
Expand Down Expand Up @@ -727,7 +727,7 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)

dead = hwsamples - live;
swlim = ((int64_t) dead << 32) / sw->ratio;
swlim = audio_MIN (swlim, samples);
swlim = MIN (swlim, samples);
if (swlim) {
sw->conv (sw->buf, buf, swlim);

Expand All @@ -739,7 +739,7 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)
while (swlim) {
dead = hwsamples - live;
left = hwsamples - wpos;
blck = audio_MIN (dead, left);
blck = MIN (dead, left);
if (!blck) {
break;
}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples)
n = samples;
while (n) {
int till_end_of_hw = hw->samples - rpos2;
int to_write = audio_MIN (till_end_of_hw, n);
int to_write = MIN (till_end_of_hw, n);
int bytes = to_write << hw->info.shift;
int written;

Expand All @@ -1049,7 +1049,7 @@ static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples)
}
}

n = audio_MIN (samples, hw->samples - rpos);
n = MIN (samples, hw->samples - rpos);
mixeng_clear (hw->mix_buf + rpos, n);
mixeng_clear (hw->mix_buf, samples - n);
}
Expand Down Expand Up @@ -1205,7 +1205,7 @@ static void audio_run_capture (AudioState *s)
rpos = hw->rpos;
while (live) {
int left = hw->samples - rpos;
int to_capture = audio_MIN (live, left);
int to_capture = MIN (live, left);
struct st_sample *src;
struct capture_callback *cb;

Expand Down
17 changes: 0 additions & 17 deletions audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,6 @@ static inline void *advance (void *p, int incr)
return (d + incr);
}

#ifdef __GNUC__
#define audio_MIN(a, b) ( __extension__ ({ \
__typeof (a) ta = a; \
__typeof (b) tb = b; \
((ta)>(tb)?(tb):(ta)); \
}))

#define audio_MAX(a, b) ( __extension__ ({ \
__typeof (a) ta = a; \
__typeof (b) tb = b; \
((ta)<(tb)?(tb):(ta)); \
}))
#else
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
#endif

int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
int freq, int bits, int nchannels);

Expand Down
2 changes: 1 addition & 1 deletion audio/coreaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ static int coreaudio_run_out (HWVoiceOut *hw, int live)
core->live);
}

decr = audio_MIN (core->decr, live);
decr = MIN (core->decr, live);
core->decr -= decr;

core->live = live - decr;
Expand Down
2 changes: 1 addition & 1 deletion audio/dsoundaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ static int dsound_run_in (HWVoiceIn *hw)
if (!len) {
return 0;
}
len = audio_MIN (len, dead);
len = MIN (len, dead);

err = dsound_lock_in (
dscb,
Expand Down
10 changes: 5 additions & 5 deletions audio/noaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ static int no_run_out (HWVoiceOut *hw, int live)
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
ticks = now - no->old_ticks;
bytes = muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
bytes = audio_MIN(bytes, INT_MAX);
bytes = MIN(bytes, INT_MAX);
samples = bytes >> hw->info.shift;

no->old_ticks = now;
decr = audio_MIN (live, samples);
decr = MIN (live, samples);
hw->rpos = (hw->rpos + decr) % hw->samples;
return decr;
}
Expand Down Expand Up @@ -111,9 +111,9 @@ static int no_run_in (HWVoiceIn *hw)
muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);

no->old_ticks = now;
bytes = audio_MIN (bytes, INT_MAX);
bytes = MIN (bytes, INT_MAX);
samples = bytes >> hw->info.shift;
samples = audio_MIN (samples, dead);
samples = MIN (samples, dead);
}
return samples;
}
Expand All @@ -124,7 +124,7 @@ static int no_read (SWVoiceIn *sw, void *buf, int size)
* useless resampling/mixing */
int samples = size >> sw->info.shift;
int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
int to_clear = audio_MIN (samples, total);
int to_clear = MIN (samples, total);
sw->total_hw_samples_acquired += total;
audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
return to_clear << sw->info.shift;
Expand Down
6 changes: 3 additions & 3 deletions audio/ossaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static void oss_write_pending (OSSVoiceOut *oss)
int samples_written;
ssize_t bytes_written;
int samples_till_end = hw->samples - oss->wpos;
int samples_to_write = audio_MIN (oss->pending, samples_till_end);
int samples_to_write = MIN (oss->pending, samples_till_end);
int bytes_to_write = samples_to_write << hw->info.shift;
void *pcm = advance (oss->pcm_buf, oss->wpos << hw->info.shift);

Expand Down Expand Up @@ -437,7 +437,7 @@ static int oss_run_out (HWVoiceOut *hw, int live)

pos = hw->rpos << hw->info.shift;
bytes = audio_ring_dist (cntinfo.ptr, pos, bufsize);
decr = audio_MIN (bytes >> hw->info.shift, live);
decr = MIN (bytes >> hw->info.shift, live);
}
else {
err = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &abinfo);
Expand All @@ -456,7 +456,7 @@ static int oss_run_out (HWVoiceOut *hw, int live)
return 0;
}

decr = audio_MIN (abinfo.bytes >> hw->info.shift, live);
decr = MIN (abinfo.bytes >> hw->info.shift, live);
if (!decr) {
return 0;
}
Expand Down
12 changes: 6 additions & 6 deletions audio/paaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static void *qpa_thread_out (void *arg)
}
}

decr = to_mix = audio_MIN(pa->live, pa->samples >> 5);
decr = to_mix = MIN(pa->live, pa->samples >> 5);
rpos = pa->rpos;

if (audio_pt_unlock(&pa->pt, __func__)) {
Expand All @@ -244,7 +244,7 @@ static void *qpa_thread_out (void *arg)

while (to_mix) {
int error;
int chunk = audio_MIN (to_mix, hw->samples - rpos);
int chunk = MIN (to_mix, hw->samples - rpos);
struct st_sample *src = hw->mix_buf + rpos;

hw->clip (pa->pcm_buf, src, chunk);
Expand Down Expand Up @@ -282,7 +282,7 @@ static int qpa_run_out (HWVoiceOut *hw, int live)
return 0;
}

decr = audio_MIN (live, pa->decr);
decr = MIN (live, pa->decr);
pa->decr -= decr;
pa->live = live - decr;
hw->rpos = pa->rpos;
Expand Down Expand Up @@ -327,7 +327,7 @@ static void *qpa_thread_in (void *arg)
}
}

incr = to_grab = audio_MIN(pa->dead, pa->samples >> 5);
incr = to_grab = MIN(pa->dead, pa->samples >> 5);
wpos = pa->wpos;

if (audio_pt_unlock(&pa->pt, __func__)) {
Expand All @@ -336,7 +336,7 @@ static void *qpa_thread_in (void *arg)

while (to_grab) {
int error;
int chunk = audio_MIN (to_grab, hw->samples - wpos);
int chunk = MIN (to_grab, hw->samples - wpos);
void *buf = advance (pa->pcm_buf, wpos);

if (qpa_simple_read (pa, buf,
Expand Down Expand Up @@ -375,7 +375,7 @@ static int qpa_run_in (HWVoiceIn *hw)

live = audio_pcm_hw_get_live_in (hw);
dead = hw->samples - live;
incr = audio_MIN (dead, pa->incr);
incr = MIN (dead, pa->incr);
pa->incr -= incr;
pa->dead = dead - incr;
hw->wpos = pa->wpos;
Expand Down
6 changes: 3 additions & 3 deletions audio/sdlaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)

/* dolog ("in callback samples=%d live=%d\n", samples, sdl->live); */

to_mix = audio_MIN(samples, sdl->live);
to_mix = MIN(samples, sdl->live);
decr = to_mix;
while (to_mix) {
int chunk = audio_MIN(to_mix, hw->samples - hw->rpos);
int chunk = MIN(to_mix, hw->samples - hw->rpos);
struct st_sample *src = hw->mix_buf + hw->rpos;

/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
Expand Down Expand Up @@ -236,7 +236,7 @@ static int sdl_run_out (HWVoiceOut *hw, int live)
sdl->live);
}

decr = audio_MIN (sdl->decr, live);
decr = MIN (sdl->decr, live);
sdl->decr -= decr;

sdl->live = live;
Expand Down
10 changes: 5 additions & 5 deletions audio/spiceaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,20 @@ static int line_out_run (HWVoiceOut *hw, int live)
}

decr = rate_get_samples (&hw->info, &out->rate);
decr = audio_MIN (live, decr);
decr = MIN (live, decr);

samples = decr;
rpos = hw->rpos;
while (samples) {
int left_till_end_samples = hw->samples - rpos;
int len = audio_MIN (samples, left_till_end_samples);
int len = MIN (samples, left_till_end_samples);

if (!out->frame) {
spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize);
out->fpos = out->frame;
}
if (out->frame) {
len = audio_MIN (len, out->fsize);
len = MIN (len, out->fsize);
hw->clip (out->fpos, hw->mix_buf + rpos, len);
out->fsize -= len;
out->fpos += len;
Expand Down Expand Up @@ -294,7 +294,7 @@ static int line_in_run (HWVoiceIn *hw)
}

delta_samp = rate_get_samples (&hw->info, &in->rate);
num_samples = audio_MIN (num_samples, delta_samp);
num_samples = MIN (num_samples, delta_samp);

ready = spice_server_record_get_samples (&in->sin, in->samples, num_samples);
samples = in->samples;
Expand All @@ -304,7 +304,7 @@ static int line_in_run (HWVoiceIn *hw)
ready = LINE_IN_SAMPLES;
}

num_samples = audio_MIN (ready, num_samples);
num_samples = MIN (ready, num_samples);

if (hw->wpos + num_samples > hw->samples) {
len[0] = hw->samples - hw->wpos;
Expand Down
4 changes: 2 additions & 2 deletions audio/wavaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ static int wav_run_out (HWVoiceOut *hw, int live)
}

wav->old_ticks = now;
decr = audio_MIN (live, samples);
decr = MIN (live, samples);
samples = decr;
rpos = hw->rpos;
while (samples) {
int left_till_end_samples = hw->samples - rpos;
int convert_samples = audio_MIN (samples, left_till_end_samples);
int convert_samples = MIN (samples, left_till_end_samples);

src = hw->mix_buf + rpos;
dst = advance (wav->pcm_buf, rpos << hw->info.shift);
Expand Down
10 changes: 5 additions & 5 deletions hw/audio/ac97.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r,
uint32_t temp = r->picb << 1;
uint32_t written = 0;
int to_copy = 0;
temp = audio_MIN (temp, max);
temp = MIN (temp, max);

if (!temp) {
*stop = 1;
Expand All @@ -974,7 +974,7 @@ static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r,

while (temp) {
int copied;
to_copy = audio_MIN (temp, sizeof (tmpbuf));
to_copy = MIN (temp, sizeof (tmpbuf));
pci_dma_read (&s->dev, addr, tmpbuf, to_copy);
copied = AUD_write (s->voice_po, tmpbuf, to_copy);
dolog ("write_audio max=%x to_copy=%x copied=%x\n",
Expand Down Expand Up @@ -1020,7 +1020,7 @@ static void write_bup (AC97LinkState *s, int elapsed)
}

while (elapsed) {
int temp = audio_MIN (elapsed, sizeof (s->silence));
int temp = MIN (elapsed, sizeof (s->silence));
while (temp) {
int copied = AUD_write (s->voice_po, s->silence, temp);
if (!copied)
Expand All @@ -1041,7 +1041,7 @@ static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r,
int to_copy = 0;
SWVoiceIn *voice = (r - s->bm_regs) == MC_INDEX ? s->voice_mc : s->voice_pi;

temp = audio_MIN (temp, max);
temp = MIN (temp, max);

if (!temp) {
*stop = 1;
Expand All @@ -1050,7 +1050,7 @@ static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r,

while (temp) {
int acquired;
to_copy = audio_MIN (temp, sizeof (tmpbuf));
to_copy = MIN (temp, sizeof (tmpbuf));
acquired = AUD_read (voice, tmpbuf, to_copy);
if (!acquired) {
*stop = 1;
Expand Down
Loading

0 comments on commit 5893591

Please sign in to comment.