Skip to content

Commit bae31bf

Browse files
committed
Merge remote-tracking branch 'remotes/kraxel/tags/audio-20200619-pull-request' into staging
audio: bugfixes for jack backend and gus emulation. # gpg: Signature made Fri 19 Jun 2020 14:17:22 BST # gpg: using RSA key 4CB6D8EED3E87138 # 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-20200619-pull-request: hw/audio/gus: Fix registers 32-bit access audio/jack: simplify the re-init code path audio/jack: honour the enable state of the audio device audio/jack: do not remove ports when finishing audio/jack: remove invalid set of input support bool audio/jack: remove unused stopped state audio/jack: fix invalid minimum buffer size check Signed-off-by: Peter Maydell <[email protected]>
2 parents 06c4cc3 + 5868034 commit bae31bf

File tree

3 files changed

+40
-37
lines changed

3 files changed

+40
-37
lines changed

audio/jackaudio.c

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct QJack;
3838

3939
typedef enum QJackState {
4040
QJACK_STATE_DISCONNECTED,
41-
QJACK_STATE_STOPPED,
4241
QJACK_STATE_RUNNING,
4342
QJACK_STATE_SHUTDOWN
4443
}
@@ -57,7 +56,7 @@ typedef struct QJackClient {
5756
AudiodevJackPerDirectionOptions *opt;
5857

5958
bool out;
60-
bool finished;
59+
bool enabled;
6160
bool connect_ports;
6261
int packets;
6362

@@ -272,9 +271,17 @@ static int qjack_process(jack_nframes_t nframes, void *arg)
272271
}
273272

274273
if (c->out) {
275-
qjack_buffer_read_l(&c->fifo, buffers, nframes);
274+
if (likely(c->enabled)) {
275+
qjack_buffer_read_l(&c->fifo, buffers, nframes);
276+
} else {
277+
for(int i = 0; i < c->nchannels; ++i) {
278+
memset(buffers[i], 0, nframes * sizeof(float));
279+
}
280+
}
276281
} else {
277-
qjack_buffer_write_l(&c->fifo, buffers, nframes);
282+
if (likely(c->enabled)) {
283+
qjack_buffer_write_l(&c->fifo, buffers, nframes);
284+
}
278285
}
279286

280287
return 0;
@@ -315,8 +322,8 @@ static void qjack_client_recover(QJackClient *c)
315322
if (c->state == QJACK_STATE_DISCONNECTED &&
316323
c->packets % 100 == 0) {
317324

318-
/* if not finished then attempt to recover */
319-
if (!c->finished) {
325+
/* if enabled then attempt to recover */
326+
if (c->enabled) {
320327
dolog("attempting to reconnect to server\n");
321328
qjack_client_init(c);
322329
}
@@ -388,7 +395,10 @@ static int qjack_client_init(QJackClient *c)
388395
char client_name[jack_client_name_size()];
389396
jack_options_t options = JackNullOption;
390397

391-
c->finished = false;
398+
if (c->state == QJACK_STATE_RUNNING) {
399+
return 0;
400+
}
401+
392402
c->connect_ports = true;
393403

394404
snprintf(client_name, sizeof(client_name), "%s-%s",
@@ -434,17 +444,6 @@ static int qjack_client_init(QJackClient *c)
434444
jack_set_xrun_callback(c->client, qjack_xrun, c);
435445
jack_on_shutdown(c->client, qjack_shutdown, c);
436446

437-
/*
438-
* ensure the buffersize is no smaller then 512 samples, some (all?) qemu
439-
* virtual devices do not work correctly otherwise
440-
*/
441-
if (c->buffersize < 512) {
442-
c->buffersize = 512;
443-
}
444-
445-
/* create a 2 period buffer */
446-
qjack_buffer_create(&c->fifo, c->nchannels, c->buffersize * 2);
447-
448447
/* allocate and register the ports */
449448
c->port = g_malloc(sizeof(jack_port_t *) * c->nchannels);
450449
for (int i = 0; i < c->nchannels; ++i) {
@@ -468,6 +467,17 @@ static int qjack_client_init(QJackClient *c)
468467
jack_activate(c->client);
469468
c->buffersize = jack_get_buffer_size(c->client);
470469

470+
/*
471+
* ensure the buffersize is no smaller then 512 samples, some (all?) qemu
472+
* virtual devices do not work correctly otherwise
473+
*/
474+
if (c->buffersize < 512) {
475+
c->buffersize = 512;
476+
}
477+
478+
/* create a 2 period buffer */
479+
qjack_buffer_create(&c->fifo, c->nchannels, c->buffersize * 2);
480+
471481
qjack_client_connect_ports(c);
472482
c->state = QJACK_STATE_RUNNING;
473483
return 0;
@@ -479,13 +489,13 @@ static int qjack_init_out(HWVoiceOut *hw, struct audsettings *as,
479489
QJackOut *jo = (QJackOut *)hw;
480490
Audiodev *dev = (Audiodev *)drv_opaque;
481491

482-
if (jo->c.state != QJACK_STATE_DISCONNECTED) {
483-
return 0;
484-
}
492+
qjack_client_fini(&jo->c);
485493

486494
jo->c.out = true;
495+
jo->c.enabled = false;
487496
jo->c.nchannels = as->nchannels;
488497
jo->c.opt = dev->u.jack.out;
498+
489499
int ret = qjack_client_init(&jo->c);
490500
if (ret != 0) {
491501
return ret;
@@ -515,13 +525,13 @@ static int qjack_init_in(HWVoiceIn *hw, struct audsettings *as,
515525
QJackIn *ji = (QJackIn *)hw;
516526
Audiodev *dev = (Audiodev *)drv_opaque;
517527

518-
if (ji->c.state != QJACK_STATE_DISCONNECTED) {
519-
return 0;
520-
}
528+
qjack_client_fini(&ji->c);
521529

522530
ji->c.out = false;
531+
ji->c.enabled = false;
523532
ji->c.nchannels = as->nchannels;
524533
ji->c.opt = dev->u.jack.in;
534+
525535
int ret = qjack_client_init(&ji->c);
526536
if (ret != 0) {
527537
return ret;
@@ -549,12 +559,6 @@ static void qjack_client_fini(QJackClient *c)
549559
{
550560
switch (c->state) {
551561
case QJACK_STATE_RUNNING:
552-
/* fallthrough */
553-
554-
case QJACK_STATE_STOPPED:
555-
for (int i = 0; i < c->nchannels; ++i) {
556-
jack_port_unregister(c->client, c->port[i]);
557-
}
558562
jack_deactivate(c->client);
559563
/* fallthrough */
560564

@@ -575,23 +579,25 @@ static void qjack_client_fini(QJackClient *c)
575579
static void qjack_fini_out(HWVoiceOut *hw)
576580
{
577581
QJackOut *jo = (QJackOut *)hw;
578-
jo->c.finished = true;
579582
qjack_client_fini(&jo->c);
580583
}
581584

582585
static void qjack_fini_in(HWVoiceIn *hw)
583586
{
584587
QJackIn *ji = (QJackIn *)hw;
585-
ji->c.finished = true;
586588
qjack_client_fini(&ji->c);
587589
}
588590

589591
static void qjack_enable_out(HWVoiceOut *hw, bool enable)
590592
{
593+
QJackOut *jo = (QJackOut *)hw;
594+
jo->c.enabled = enable;
591595
}
592596

593597
static void qjack_enable_in(HWVoiceIn *hw, bool enable)
594598
{
599+
QJackIn *ji = (QJackIn *)hw;
600+
ji->c.enabled = enable;
595601
}
596602

597603
static int qjack_thread_creator(jack_native_thread_t *thread,
@@ -611,9 +617,6 @@ static int qjack_thread_creator(jack_native_thread_t *thread,
611617
static void *qjack_init(Audiodev *dev)
612618
{
613619
assert(dev->driver == AUDIODEV_DRIVER_JACK);
614-
615-
dev->u.jack.has_in = false;
616-
617620
return dev;
618621
}
619622

hw/audio/gusemu_hal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#define GUSregb(position) (* (gusptr+(position)))
3434
#define GUSregw(position) (*(uint16_t *) (gusptr+(position)))
35-
#define GUSregd(position) (*(uint16_t *)(gusptr+(position)))
35+
#define GUSregd(position) (*(uint32_t *)(gusptr + (position)))
3636

3737
/* size given in bytes */
3838
unsigned int gus_read(GUSEmuState * state, int port, int size)

hw/audio/gusemu_mixer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#define GUSregb(position) (* (gusptr+(position)))
3030
#define GUSregw(position) (*(uint16_t *) (gusptr+(position)))
31-
#define GUSregd(position) (*(uint16_t *)(gusptr+(position)))
31+
#define GUSregd(position) (*(uint32_t *)(gusptr + (position)))
3232

3333
#define GUSvoice(position) (*(uint16_t *)(voiceptr+(position)))
3434

0 commit comments

Comments
 (0)