Skip to content

Commit 825a215

Browse files
committed
Merge remote-tracking branch 'remotes/kraxel/tags/audio-20210115-pull-request' into staging
audio: improvements for sdl, pulse, fsound. audio: cleanups & codestyle fixes. # gpg: Signature made Fri 15 Jan 2021 13:20:56 GMT # gpg: using RSA key A0328CFFB93A17A79901FE7D4CB6D8EED3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <[email protected]>" [full] # gpg: aka "Gerd Hoffmann <[email protected]>" [full] # gpg: aka "Gerd Hoffmann (private) <[email protected]>" [full] # Primary key fingerprint: A032 8CFF B93A 17A7 9901 FE7D 4CB6 D8EE D3E8 7138 * remotes/kraxel/tags/audio-20210115-pull-request: (30 commits) audio: space prohibited between function name and parenthesis'(' audio: Suspect code indent for conditional statements audio: Don't use '%#' in format strings audio: Fix lines over 90 characters audio: foo* bar" should be "foo *bar". audio: Add spaces around operator/delete redundant spaces audio: Add braces for statements/fix braces' position dsoundaudio: fix log message dsoundaudio: enable f32 audio sample format dsoundaudio: rename dsound_open() dsoundaudio: replace GetForegroundWindow() paaudio: send recorded data in smaller chunks paaudio: limit minreq to 75% of audio timer_rate paaudio: comment bugs in functions qpa_init_* paaudio: remove unneeded code paaudio: wait until the playback stream is ready paaudio: wait for PA_STREAM_READY in qpa_write() paaudio: avoid to clip samples multiple times audio: remove remaining unused plive code sdlaudio: enable (in|out).mixing-engine=off ... Signed-off-by: Peter Maydell <[email protected]>
2 parents 7cb6b97 + 8abf3fe commit 825a215

17 files changed

+472
-236
lines changed

audio/alsaaudio.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,32 +278,28 @@ static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
278278
case AUDIO_FORMAT_S16:
279279
if (endianness) {
280280
return SND_PCM_FORMAT_S16_BE;
281-
}
282-
else {
281+
} else {
283282
return SND_PCM_FORMAT_S16_LE;
284283
}
285284

286285
case AUDIO_FORMAT_U16:
287286
if (endianness) {
288287
return SND_PCM_FORMAT_U16_BE;
289-
}
290-
else {
288+
} else {
291289
return SND_PCM_FORMAT_U16_LE;
292290
}
293291

294292
case AUDIO_FORMAT_S32:
295293
if (endianness) {
296294
return SND_PCM_FORMAT_S32_BE;
297-
}
298-
else {
295+
} else {
299296
return SND_PCM_FORMAT_S32_LE;
300297
}
301298

302299
case AUDIO_FORMAT_U32:
303300
if (endianness) {
304301
return SND_PCM_FORMAT_U32_BE;
305-
}
306-
else {
302+
} else {
307303
return SND_PCM_FORMAT_U32_LE;
308304
}
309305

@@ -599,7 +595,7 @@ static int alsa_open(bool in, struct alsa_params_req *req,
599595
}
600596

601597
#ifdef DEBUG
602-
alsa_dump_info(req, obt, obtfmt, pdo);
598+
alsa_dump_info(req, obt, obtfmt, apdo);
603599
#endif
604600
return 0;
605601

@@ -722,8 +718,7 @@ static int alsa_voice_ctl (snd_pcm_t *handle, const char *typ, int ctl)
722718
alsa_logerr (err, "Could not stop %s\n", typ);
723719
return -1;
724720
}
725-
}
726-
else {
721+
} else {
727722
err = snd_pcm_prepare (handle);
728723
if (err < 0) {
729724
alsa_logerr (err, "Could not prepare handle for %s\n", typ);
@@ -929,6 +924,7 @@ static struct audio_pcm_ops alsa_pcm_ops = {
929924
.init_in = alsa_init_in,
930925
.fini_in = alsa_fini_in,
931926
.read = alsa_read,
927+
.run_buffer_in = audio_generic_run_buffer_in,
932928
.enable_in = alsa_enable_in,
933929
};
934930

audio/audio.c

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
344344

345345
if (info->is_signed || info->is_float) {
346346
memset(buf, 0x00, len * info->bytes_per_frame);
347-
}
348-
else {
347+
} else {
349348
switch (info->bits) {
350349
case 8:
351350
memset(buf, 0x80, len * info->bytes_per_frame);
@@ -584,8 +583,7 @@ static size_t audio_pcm_sw_get_rpos_in(SWVoiceIn *sw)
584583
rpos = hw->conv_buf->pos - live;
585584
if (rpos >= 0) {
586585
return rpos;
587-
}
588-
else {
586+
} else {
589587
return hw->conv_buf->size + rpos;
590588
}
591589
}
@@ -788,10 +786,14 @@ static int audio_is_timer_needed(AudioState *s)
788786
HWVoiceOut *hwo = NULL;
789787

790788
while ((hwo = audio_pcm_hw_find_any_enabled_out(s, hwo))) {
791-
if (!hwo->poll_mode) return 1;
789+
if (!hwo->poll_mode) {
790+
return 1;
791+
}
792792
}
793793
while ((hwi = audio_pcm_hw_find_any_enabled_in(s, hwi))) {
794-
if (!hwi->poll_mode) return 1;
794+
if (!hwi->poll_mode) {
795+
return 1;
796+
}
795797
}
796798
return 0;
797799
}
@@ -908,8 +910,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on)
908910
audio_reset_timer (s);
909911
}
910912
}
911-
}
912-
else {
913+
} else {
913914
if (hw->enabled) {
914915
int nb_active = 0;
915916

@@ -956,8 +957,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
956957
}
957958
}
958959
sw->total_hw_samples_acquired = hw->total_samples_captured;
959-
}
960-
else {
960+
} else {
961961
if (hw->enabled) {
962962
int nb_active = 0;
963963

@@ -1132,7 +1132,7 @@ static void audio_run_out (AudioState *s)
11321132

11331133
while ((hw = audio_pcm_hw_find_any_enabled_out(s, hw))) {
11341134
size_t played, live, prev_rpos, free;
1135-
int nb_live, cleanup_required;
1135+
int nb_live;
11361136

11371137
live = audio_pcm_hw_get_live_out (hw, &nb_live);
11381138
if (!nb_live) {
@@ -1194,7 +1194,6 @@ static void audio_run_out (AudioState *s)
11941194
audio_capture_mix_and_clear (hw, prev_rpos, played);
11951195
}
11961196

1197-
cleanup_required = 0;
11981197
for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
11991198
if (!sw->active && sw->empty) {
12001199
continue;
@@ -1210,7 +1209,6 @@ static void audio_run_out (AudioState *s)
12101209

12111210
if (!sw->total_hw_samples_mixed) {
12121211
sw->empty = 1;
1213-
cleanup_required |= !sw->active && !sw->callback.fn;
12141212
}
12151213

12161214
if (sw->active) {
@@ -1220,19 +1218,6 @@ static void audio_run_out (AudioState *s)
12201218
}
12211219
}
12221220
}
1223-
1224-
if (cleanup_required) {
1225-
SWVoiceOut *sw1;
1226-
1227-
sw = hw->sw_head.lh_first;
1228-
while (sw) {
1229-
sw1 = sw->entries.le_next;
1230-
if (!sw->active && !sw->callback.fn) {
1231-
audio_close_out (sw);
1232-
}
1233-
sw = sw1;
1234-
}
1235-
}
12361221
}
12371222
}
12381223

@@ -1241,6 +1226,10 @@ static size_t audio_pcm_hw_run_in(HWVoiceIn *hw, size_t samples)
12411226
size_t conv = 0;
12421227
STSampleBuffer *conv_buf = hw->conv_buf;
12431228

1229+
if (hw->pcm_ops->run_buffer_in) {
1230+
hw->pcm_ops->run_buffer_in(hw);
1231+
}
1232+
12441233
while (samples) {
12451234
size_t proc;
12461235
size_t size = samples * hw->info.bytes_per_frame;
@@ -1381,14 +1370,11 @@ void audio_run(AudioState *s, const char *msg)
13811370
#endif
13821371
}
13831372

1384-
void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size)
1373+
void audio_generic_run_buffer_in(HWVoiceIn *hw)
13851374
{
1386-
ssize_t start;
1387-
13881375
if (unlikely(!hw->buf_emul)) {
1389-
size_t calc_size = hw->conv_buf->size * hw->info.bytes_per_frame;
1390-
hw->buf_emul = g_malloc(calc_size);
1391-
hw->size_emul = calc_size;
1376+
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
1377+
hw->buf_emul = g_malloc(hw->size_emul);
13921378
hw->pos_emul = hw->pending_emul = 0;
13931379
}
13941380

@@ -1403,8 +1389,12 @@ void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size)
14031389
break;
14041390
}
14051391
}
1392+
}
1393+
1394+
void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size)
1395+
{
1396+
ssize_t start = (ssize_t)hw->pos_emul - hw->pending_emul;
14061397

1407-
start = ((ssize_t) hw->pos_emul) - hw->pending_emul;
14081398
if (start < 0) {
14091399
start += hw->size_emul;
14101400
}
@@ -1446,10 +1436,8 @@ void audio_generic_run_buffer_out(HWVoiceOut *hw)
14461436
void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size)
14471437
{
14481438
if (unlikely(!hw->buf_emul)) {
1449-
size_t calc_size = hw->mix_buf->size * hw->info.bytes_per_frame;
1450-
1451-
hw->buf_emul = g_malloc(calc_size);
1452-
hw->size_emul = calc_size;
1439+
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
1440+
hw->buf_emul = g_malloc(hw->size_emul);
14531441
hw->pos_emul = hw->pending_emul = 0;
14541442
}
14551443

@@ -1505,6 +1493,10 @@ size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
15051493
{
15061494
size_t total = 0;
15071495

1496+
if (hw->pcm_ops->run_buffer_in) {
1497+
hw->pcm_ops->run_buffer_in(hw);
1498+
}
1499+
15081500
while (total < size) {
15091501
size_t src_size = size - total;
15101502
void *src = hw->pcm_ops->get_buffer_in(hw, &src_size);
@@ -1540,8 +1532,7 @@ static int audio_driver_init(AudioState *s, struct audio_driver *drv,
15401532
audio_init_nb_voices_in(s, drv);
15411533
s->drv = drv;
15421534
return 0;
1543-
}
1544-
else {
1535+
} else {
15451536
if (msg) {
15461537
dolog("Could not init `%s' audio driver\n", drv->name);
15471538
}
@@ -1856,8 +1847,7 @@ CaptureVoiceOut *AUD_add_capture(
18561847
if (cap) {
18571848
QLIST_INSERT_HEAD (&cap->cb_head, cb, entries);
18581849
return cap;
1859-
}
1860-
else {
1850+
} else {
18611851
HWVoiceOut *hw;
18621852
CaptureVoiceOut *cap;
18631853

@@ -2003,7 +1993,7 @@ void audio_create_pdos(Audiodev *dev)
20031993
CASE(JACK, jack, Jack);
20041994
CASE(OSS, oss, Oss);
20051995
CASE(PA, pa, Pa);
2006-
CASE(SDL, sdl, );
1996+
CASE(SDL, sdl, Sdl);
20071997
CASE(SPICE, spice, );
20081998
CASE(WAV, wav, );
20091999

audio/audio_int.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,14 @@ struct audio_pcm_ops {
172172
int (*init_in) (HWVoiceIn *hw, audsettings *as, void *drv_opaque);
173173
void (*fini_in) (HWVoiceIn *hw);
174174
size_t (*read) (HWVoiceIn *hw, void *buf, size_t size);
175+
void (*run_buffer_in)(HWVoiceIn *hw);
175176
void *(*get_buffer_in)(HWVoiceIn *hw, size_t *size);
176177
void (*put_buffer_in)(HWVoiceIn *hw, void *buf, size_t size);
177178
void (*enable_in)(HWVoiceIn *hw, bool enable);
178179
void (*volume_in)(HWVoiceIn *hw, Volume *vol);
179180
};
180181

182+
void audio_generic_run_buffer_in(HWVoiceIn *hw);
181183
void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size);
182184
void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size);
183185
void audio_generic_run_buffer_out(HWVoiceOut *hw);

audio/audio_legacy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ static void handle_sdl(Audiodev *dev)
286286
{
287287
/* SDL is output only */
288288
get_samples_to_usecs("QEMU_SDL_SAMPLES", &dev->u.sdl.out->buffer_length,
289-
&dev->u.sdl.out->has_buffer_length, dev->u.sdl.out);
289+
&dev->u.sdl.out->has_buffer_length,
290+
qapi_AudiodevSdlPerDirectionOptions_base(dev->u.sdl.out));
290291
}
291292

292293
/* wav */

audio/audio_template.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
4747
#ifdef DAC
4848
dolog ("Driver `%s' does not support " NAME "\n", drv->name);
4949
#endif
50-
}
51-
else {
50+
} else {
5251
dolog ("Driver `%s' does not support %d " NAME " voices, max %d\n",
5352
drv->name,
5453
glue (s->nb_hw_voices_, TYPE),
@@ -204,13 +203,13 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
204203

205204
if (!hw->sw_head.lh_first) {
206205
#ifdef DAC
207-
audio_detach_capture (hw);
206+
audio_detach_capture(hw);
208207
#endif
209-
QLIST_REMOVE (hw, entries);
210-
glue (hw->pcm_ops->fini_, TYPE) (hw);
211-
glue (s->nb_hw_voices_, TYPE) += 1;
212-
glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
213-
g_free (hw);
208+
QLIST_REMOVE(hw, entries);
209+
glue(hw->pcm_ops->fini_, TYPE) (hw);
210+
glue(s->nb_hw_voices_, TYPE) += 1;
211+
glue(audio_pcm_hw_free_resources_ , TYPE) (hw);
212+
g_free(hw);
214213
*hwp = NULL;
215214
}
216215
}
@@ -337,7 +336,7 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
337336
case AUDIODEV_DRIVER_PA:
338337
return qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.TYPE);
339338
case AUDIODEV_DRIVER_SDL:
340-
return dev->u.sdl.TYPE;
339+
return qapi_AudiodevSdlPerDirectionOptions_base(dev->u.sdl.TYPE);
341340
case AUDIODEV_DRIVER_SPICE:
342341
return dev->u.spice.TYPE;
343342
case AUDIODEV_DRIVER_WAV:
@@ -387,8 +386,7 @@ static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
387386

388387
if (pdo->fixed_settings) {
389388
hw_as = audiodev_to_audsettings(pdo);
390-
}
391-
else {
389+
} else {
392390
hw_as = *as;
393391
}
394392

@@ -498,8 +496,7 @@ SW *glue (AUD_open_, TYPE) (
498496
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as)) {
499497
goto fail;
500498
}
501-
}
502-
else {
499+
} else {
503500
sw = glue(audio_pcm_create_voice_pair_, TYPE)(s, name, as);
504501
if (!sw) {
505502
dolog ("Failed to create voice `%s'\n", name);
@@ -553,8 +550,7 @@ uint64_t glue (AUD_get_elapsed_usec_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts)
553550

554551
if (cur_ts >= old_ts) {
555552
delta = cur_ts - old_ts;
556-
}
557-
else {
553+
} else {
558554
delta = UINT64_MAX - old_ts + cur_ts;
559555
}
560556

0 commit comments

Comments
 (0)