Skip to content

Commit

Permalink
opus: switch to dynamic rspq IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Oct 28, 2024
1 parent e36e91e commit 8551855
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 15 additions & 14 deletions src/audio/libopus_rsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@
DEFINE_RSP_UCODE(rsp_opus_dsp); ///< RSP ucode for DSP functions
DEFINE_RSP_UCODE(rsp_opus_imdct); ///< RSP ucode for IMDCT

static uint32_t RSP_OPUS_DSP_ID = 0;
static uint32_t RSP_OPUS_IMDCT_ID = 0;

static void fft_init(void);

/** @brief Initialize Opus RSP acceleration */
void rsp_opus_init(void)
{
static bool init = false;
if (!init) {
if (!RSP_OPUS_DSP_ID) {
rspq_init();
rspq_overlay_register_static(&rsp_opus_dsp, 0x8<<28);
rspq_overlay_register_static(&rsp_opus_imdct, 0x9<<28);
RSP_OPUS_DSP_ID = rspq_overlay_register(&rsp_opus_dsp);
RSP_OPUS_IMDCT_ID = rspq_overlay_register(&rsp_opus_imdct);
fft_init();
init = true;
}
}

static void rsp_cmd_deemphasis(int32_t *inch0, int32_t *inch1, int16_t *out, int32_t state[2], int nn, int downsample)
{
rspq_write(0x8<<28, 0x0,
rspq_write(RSP_OPUS_DSP_ID, 0x0,
PhysicalAddr(inch0),
PhysicalAddr(inch1) | (downsample<<24),
PhysicalAddr(out) | ((nn/4-1) << 24),
Expand All @@ -42,15 +43,15 @@ static void rsp_cmd_deemphasis(int32_t *inch0, int32_t *inch1, int16_t *out, int

static void rsp_cmd_comb_fetch(opus_val32 *x, int dmem_idx, int nsamples)
{
rspq_write(0x8<<28, 0x1,
rspq_write(RSP_OPUS_DSP_ID, 0x1,
PhysicalAddr(x),
(dmem_idx<<16) | nsamples);
}

static void rsp_cmd_comb_single(int nsamples, int i_idx, int t0_idx,
int16_t g10, int16_t g11, int16_t g12)
{
rspq_write(0x8<<28, 0x2,
rspq_write(RSP_OPUS_DSP_ID, 0x2,
(nsamples/8-1)<<8 | (i_idx/4)<<0,
(uint16_t)g10 | ((uint16_t)g11 << 16),
((uint16_t)g12),
Expand All @@ -61,7 +62,7 @@ static void rsp_cmd_comb_dual(int nsamples, int i_idx, int t0_idx, int t1_idx,
int16_t g00, int16_t g01, int16_t g02,
int16_t g10, int16_t g11, int16_t g12)
{
rspq_write(0x8<<28, 0x4,
rspq_write(RSP_OPUS_DSP_ID, 0x4,
(nsamples/8-1)<<8 | (i_idx/4)<<0,
(uint16_t)g00 | ((uint16_t)g01 << 16),
((uint16_t)g02) | ((uint16_t)g10 << 16),
Expand All @@ -71,22 +72,22 @@ static void rsp_cmd_comb_dual(int nsamples, int i_idx, int t0_idx, int t1_idx,

static void rsp_cmd_comb_result(opus_val32 *x, int i_idx, int nsamples)
{
rspq_write(0x8<<28, 0x3,
rspq_write(RSP_OPUS_DSP_ID, 0x3,
PhysicalAddr(x),
(i_idx<<16) | nsamples);
}

static void rsp_cmd_memmove(int32_t *dst, int32_t *src, int nsamples)
{
rspq_write(0x9<<28, 0x2,
rspq_write(RSP_OPUS_IMDCT_ID, 0x2,
PhysicalAddr(dst),
PhysicalAddr(src),
nsamples * sizeof(int32_t));
}

static void rsp_cmd_clear(int32_t *dst, int nsamples)
{
rspq_write(0x9<<28, 0x3,
rspq_write(RSP_OPUS_IMDCT_ID, 0x3,
PhysicalAddr(dst),
nsamples * sizeof(int32_t));
}
Expand Down Expand Up @@ -434,7 +435,7 @@ void rsp_clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_s
data_cache_hit_writeback_invalidate(in, N*2*stride); // FIXME: maybe *stride is wrong?
assertf(PhysicalAddr(in) % 8 == 0, "in=%p", in);
assert(PhysicalAddr(l->kfft[shift]->bitrev) % 8 == 0);
rspq_write(0x9<<28, 0x0,
rspq_write(RSP_OPUS_IMDCT_ID, 0x0,
PhysicalAddr(in),
(l->n-1) | ((stride-1)<<12) | (shift<<16),
PhysicalAddr(rsp_workram),
Expand Down Expand Up @@ -479,7 +480,7 @@ void rsp_clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_s

assert(overlap < 256);
for (int b=0; b<B; b++) {
rspq_write(0x9<<28, 0x1,
rspq_write(RSP_OPUS_IMDCT_ID, 0x1,
PhysicalAddr(out+NB*b),
(overlap << 24) | PhysicalAddr(rsp_window)
);
Expand Down
2 changes: 0 additions & 2 deletions src/audio/wav64_opus.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ static void waveform_opus_read(void *ctx, samplebuffer_t *sbuf, int wpos, int wl
void wav64_opus_init(wav64_t *wav, int fh) {
wav64_opus_header_ext xhead;
read(fh, &xhead, sizeof(xhead));
debugf("opus header: frame_size=%ld, max_cmp_frame_size=%ld, bitrate_bps=%ld\n", xhead.frame_size, xhead.max_cmp_frame_size, xhead.bitrate_bps);
debugf("frequency: %f\n", wav->wave.frequency);

rsp_opus_init();

Expand Down

0 comments on commit 8551855

Please sign in to comment.