Skip to content

Commit

Permalink
apu: Add VP debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
JayFoxRox committed Feb 24, 2019
1 parent 1b5fbc1 commit cf61974
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
30 changes: 30 additions & 0 deletions hw/xbox/mcpx_apu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

#include "mcpx_apu_debug.h"

#if PLAYBACK_VP_BINS_MASK > 0
# include "audio/audio.h"
#endif

#include "hw/xbox/mcpx_apu.h"

#define NV_PAPU_ISTS 0x00001000
Expand Down Expand Up @@ -217,11 +221,28 @@ typedef struct MCPXAPUState {

uint32_t regs[0x20000];

/* Debug features */

#if PLAYBACK_VP_BINS_MASK > 0
QEMUSoundCard card;
#endif

#if PLAYBACK_VP_BINS_MASK > 0
SWVoiceOut *vp_bins_out;
#endif
#if DUMP_VP_BINS_MASK > 0
FILE *vp_bin_files[NUM_MIXBINS];
#endif

} MCPXAPUState;

#define MCPX_APU_DEVICE(obj) \
OBJECT_CHECK(MCPXAPUState, (obj), "mcpx-apu")

//FIXME: This is a hack, we already include the header above
// This file should be linked through Makefile.objs
#include "mcpx_apu_debug.c"

static uint32_t voice_get_mask(MCPXAPUState *d,
unsigned int voice_handle,
hwaddr offset,
Expand Down Expand Up @@ -866,6 +887,10 @@ static void se_frame(void *opaque)
}
#endif

#if (PLAYBACK_VP_BINS_MASK > 0) || (DUMP_VP_BINS_MASK > 0)
debug_vp_bins(d, mixbins);
#endif

/* Write VP results to the GP DSP MIXBUF */
for (mixbin = 0; mixbin < NUM_MIXBINS; mixbin++) {
for (sample = 0; sample < NUM_SAMPLES_PER_FRAME; sample++) {
Expand Down Expand Up @@ -919,6 +944,11 @@ static void mcpx_apu_realize(PCIDevice *dev, Error **errp)
d->se.frame_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, se_frame, d);
d->gp.dsp = dsp_init(d, gp_scratch_rw, gp_fifo_rw);
d->ep.dsp = dsp_init(d, ep_scratch_rw, ep_fifo_rw);

#if (PLAYBACK_VP_BINS_MASK > 0) || (DUMP_VP_BINS_MASK > 0)
/* Set up debuging */
initialize_audio_debugger(d);
#endif
}

static void mcpx_apu_class_init(ObjectClass *klass, void *data)
Expand Down
104 changes: 104 additions & 0 deletions hw/xbox/mcpx_apu_debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* QEMU MCPX APU debug helpers
*
* Copyright (c) 2019 Jannik Vogel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#include "mcpx_apu_debug.h"

#include <stddef.h>
#include <stdio.h>
#include "qemu/osdep.h"

#if PLAYBACK_VP_BINS_MASK > 0
# include "audio/audio.h"
#endif

#if PLAYBACK_VP_BINS_MASK > 0
static void vp_bins_out_callback(void *opaque, int free)
{
printf("VP bins host buffer ran out, %d free bytes\n", free);
}
#endif

#if (PLAYBACK_VP_BINS_MASK > 0) || (DUMP_VP_BINS_MASK > 0)
void debug_vp_bins(MCPXAPUState *d,
int32_t mixbin[NUM_MIXBINS][NUM_SAMPLES_PER_FRAME])
{

#if DUMP_VP_BINS_MASK > 0
MCPX_APU_DPRINTF("mcpx frame ping\n");
for (int i = 0; i < NUM_MIXBINS; i++) {
if (d->vp_bin_files[i] == NULL) {
continue;
}
fwrite(&mixbin[i][0], 1, sizeof(mixbin[i]), d->vp_bin_files[i]);
}
#endif

#if PLAYBACK_VP_BINS_MASK > 0
/* Output will be S32 mono; mix this now */
int32_t mixed[NUM_SAMPLES_PER_FRAME] = { 0 };
for (int i = 0; i < NUM_MIXBINS; i++) {
if (PLAYBACK_VP_BINS_MASK & (1 << i)) {
for (int j = 0; j < NUM_SAMPLES_PER_FRAME; j++) {
mixed[j] += mixbin[i][j] << 8;
}
}
}

/* Write frame to audio output */
int n = AUD_write(d->vp_bins_out, mixed, sizeof(mixed));
if (n < sizeof(mixed)) {
printf("VP bins host buffer overrun\n");
}
#endif

}
#endif

#if (PLAYBACK_VP_BINS_MASK > 0) || (DUMP_VP_BINS_MASK > 0)
void initialize_audio_debugger(MCPXAPUState *d)
{

#if PLAYBACK_VP_BINS_MASK > 0
AUD_register_card("MCPX APU", &d->card);
#endif

#if DUMP_VP_BINS_MASK > 0
for (unsigned int i = 0; i < NUM_MIXBINS; i++) {
if (DUMP_VP_BINS_MASK & (1 << i)) {
char path[32];
sprintf(path, "vp-bin-%d.bin", i);
d->vp_bin_files[i] = fopen(path, "wb");
} else {
d->vp_bin_files[i] = NULL;
}
}
#endif

#if PLAYBACK_VP_BINS_MASK > 0
struct audsettings vp_bins_as = { 48000, 1, AUD_FMT_S32, 0 };
d->vp_bins_out = AUD_open_out(&d->card,
d->vp_bins_out,
"mcpx-apu.vp_bins", d,
vp_bins_out_callback,
&vp_bins_as);
// AUD_set_active_out(d->vp_bins_out, 1); //FIXME: Why does this hang GTK UI?
#endif

}
#endif
4 changes: 4 additions & 0 deletions hw/xbox/mcpx_apu_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
/* Generate a tone in the MIXBIN for every channel */
#define GENERATE_MIXBIN_BEEP 0

/* Debug feature to enable VP audio output for debugging */
#define PLAYBACK_VP_BINS_MASK 0x00000001 /* 32-bits, 1 bit per bin */
#define DUMP_VP_BINS_MASK 0x00000001 /* 32-bits, 1 bit per bin */

#endif

0 comments on commit cf61974

Please sign in to comment.