diff --git a/include/wav64internal.h b/include/wav64internal.h index 2d31853630..016dbd8782 100644 --- a/include/wav64internal.h +++ b/include/wav64internal.h @@ -32,8 +32,8 @@ typedef struct __attribute__((packed, aligned(8))) { int8_t order; ///< Order of the predictors int16_t padding; ///< Padding uint32_t current_rom_addr; ///< Current address in ROM - wav64_vadpcm_vector_t loop_state; ///< State at the loop point - wav64_vadpcm_vector_t state; ///< Current decompression state + wav64_vadpcm_vector_t loop_state[2];///< State at the loop point + wav64_vadpcm_vector_t state[2]; ///< Current decompression state wav64_vadpcm_vector_t codebook[]; ///< Codebook of the predictors } wav64_header_vadpcm_t; diff --git a/src/audio/rsp_mixer.S b/src/audio/rsp_mixer.S index 639f44abbd..4a6836b6f9 100644 --- a/src/audio/rsp_mixer.S +++ b/src/audio/rsp_mixer.S @@ -1171,12 +1171,12 @@ Mix8Loop: # Args: # a0: pointer to input buffer # a1: pointer to output buffer (+ numframes-1 in MSB) - # a2: pointer to state buffer + # a2: pointer to state buffer (+ bit 31 set if stereo) # a3: pointer to codebook # ######################################## -#define VADPCM_PROFILING 0 +#define VADPCM_PROFILING 1 #define VADPCM_ORDER_SHIFT 1 #define VADPCM_ORDER (1< 0 && nframes <= 256); + if (stereo) { + assert(nframes % 2 == 0); + nframes /= 2; + } rspq_write(__mixer_overlay_id, 0x1, PhysicalAddr(input), PhysicalAddr(output) | (nframes-1) << 24, - PhysicalAddr(state), + PhysicalAddr(state) | (stereo ? 1 : 0) << 31, PhysicalAddr(codebook)); } @@ -208,7 +212,7 @@ static void waveform_vadpcm_read(void *ctx, samplebuffer_t *sbuf, int wpos, int rspq_highpri_begin(); highpri = true; } - rsp_vadpcm_decompress(dest + wlen - 9*nframes/2, dest, nframes, + rsp_vadpcm_decompress(dest + wlen - 9*nframes/2, dest, wav->wave.channels==2, nframes, &vhead->state, vhead->codebook); #endif diff --git a/tools/audioconv64/conv_wav64.c b/tools/audioconv64/conv_wav64.c index 87ba19cf96..db5e63615d 100644 --- a/tools/audioconv64/conv_wav64.c +++ b/tools/audioconv64/conv_wav64.c @@ -114,8 +114,8 @@ int wav_convert(const char *infn, const char *outfn) { } break; case 1: { // vadpcm - if (cnt % kVADPCMFrameSampleCount) { - int newcnt = (cnt + kVADPCMFrameSampleCount - 1) / kVADPCMFrameSampleCount * kVADPCMFrameSampleCount; + if ((cnt / wav.channels) % kVADPCMFrameSampleCount) { + int newcnt = (cnt / wav.channels + kVADPCMFrameSampleCount - 1) / kVADPCMFrameSampleCount * kVADPCMFrameSampleCount * wav.channels; samples = realloc(samples, newcnt * sizeof(int16_t)); memset(samples + cnt, 0, (newcnt - cnt) * sizeof(int16_t)); cnt = newcnt; @@ -125,14 +125,21 @@ int wav_convert(const char *infn, const char *outfn) { int nframes = cnt / kVADPCMFrameSampleCount; void *scratch = malloc(vadpcm_encode_scratch_size(nframes)); - struct vadpcm_vector *codebook = alloca(kPREDICTORS * kVADPCMEncodeOrder * sizeof(struct vadpcm_vector)); + struct vadpcm_vector *codebook = alloca(kPREDICTORS * kVADPCMEncodeOrder * wav.channels * sizeof(struct vadpcm_vector)); struct vadpcm_params parms = { .predictor_count = kPREDICTORS }; void *dest = malloc(nframes * kVADPCMFrameByteSize); - - vadpcm_error err = vadpcm_encode(&parms, codebook, nframes, dest, samples, scratch); - if (err != 0) { - fprintf(stderr, "VADPCM encoding error: %s\n", vadpcm_error_name(err)); - return 1; + + int16_t *schan = malloc(cnt / wav.channels * sizeof(int16_t));; + uint8_t *destchan = dest; + for (int i=0;i