From 07d5367ed40d525c2901d19ee766c83864294c5f Mon Sep 17 00:00:00 2001 From: fincs Date: Sun, 18 Oct 2015 23:06:11 +0200 Subject: [PATCH] Some additions to NDSP code (thanks to Lectem) --- libctru/include/3ds/ndsp/channel.h | 13 ++++++++-- libctru/include/3ds/ndsp/ndsp.h | 40 +++++++++++++++++++++++++++--- libctru/source/ndsp/ndsp-channel.c | 18 +++++++++----- libctru/source/ndsp/ndsp.c | 3 ++- 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/libctru/include/3ds/ndsp/channel.h b/libctru/include/3ds/ndsp/channel.h index 8328f7e..518667f 100644 --- a/libctru/include/3ds/ndsp/channel.h +++ b/libctru/include/3ds/ndsp/channel.h @@ -36,6 +36,15 @@ enum NDSP_FRONT_BYPASS = BIT(4), ///< Front bypass. NDSP_3D_SURROUND_PREPROCESSED = BIT(6), ///< (?) Unknown, under research }; + +/// Interpolation types. +enum +{ + NDSP_INTERP_POLYPHASE = 0, ///< Polyphase interpolation + NDSP_INTERP_LINEAR = 1, ///< Linear interpolation + NDSP_INTERP_NONE = 2, ///< No interpolation +}; + ///@} ///@name Basic channel operation @@ -139,9 +148,9 @@ void ndspChnWaveBufAdd(int id, ndspWaveBuf* buf); ///@name IIR filters ///@{ /** - * @brief Configures whether the IIR mono filter of a channel is enabled. + * @brief Configures whether the IIR monopole filter of a channel is enabled. * @param id ID of the channel (0..23). - * @param enable Whether to enable the IIR mono filter. + * @param enable Whether to enable the IIR monopole filter. */ void ndspChnIirMonoSetEnable(int id, bool enable); // ndspChnIirMonoSetParams diff --git a/libctru/include/3ds/ndsp/ndsp.h b/libctru/include/3ds/ndsp/ndsp.h index a4aa8eb..cfaf933 100644 --- a/libctru/include/3ds/ndsp/ndsp.h +++ b/libctru/include/3ds/ndsp/ndsp.h @@ -6,6 +6,29 @@ ///@name Data types ///@{ +/// Sound output modes. +enum +{ + NDSP_OUTPUT_MONO = 0, ///< Mono sound + NDSP_OUTPUT_STEREO = 1, ///< Stereo sound + NDSP_OUTPUT_SURROUND = 2, ///< 3D Surround sound +}; + +// Clipping modes. +enum +{ + NDSP_CLIP_NORMAL = 0, ///< "Normal" clipping mode (?) + NDSP_CLIP_SOFT = 1, ///< "Soft" clipping mode (?) +}; + +// Surround speaker positions. +enum +{ + NDSP_SPKPOS_SQUARE = 0, ///nsamples) return; buf->next = NULL; + buf->status = NDSP_WBUF_QUEUED; LightLock_Lock(&chn->lock); if (cb) @@ -243,16 +244,16 @@ void ndspiUpdateChn(void) if (flags & CFLAG_INTERPTYPE) { st->rim[0] = chn->interpType; - if (chn->interpType == 0) + if (chn->interpType == NDSP_INTERP_POLYPHASE) { if (chn->rate <= 1.0f) - st->rim[1] = 2; + st->rim[1] = NDSP_INTERP_NONE; else if (chn->rate <= (4.0f/3)) - st->rim[1] = 1; + st->rim[1] = NDSP_INTERP_LINEAR; else - st->rim[1] = 0; + st->rim[1] = NDSP_INTERP_POLYPHASE; } else - st->rim[1] = 1; + st->rim[1] = NDSP_INTERP_LINEAR; stflags |= 0x20000; } @@ -282,6 +283,7 @@ void ndspiUpdateChn(void) if (chn->wavBufCount == 0) { // This is the first buffer - set it up + wb->status = NDSP_WBUF_PLAYING; chn->wavBufIdNext = 0; st->seqId = wb->sequence_id; st->sampleCount = ndspiRotateVal(wb->nsamples); @@ -359,7 +361,6 @@ void ndspiReadChnState(void) { u16 seqId = st->curSeqId; ndspWaveBuf* wb = chn->waveBuf; - chn->waveBufSeqPos = seqId; chn->samplePos = ndspiRotateVal(st->samplePos); if ((st->flags & 0xFF00) && wb) @@ -370,15 +371,20 @@ void ndspiReadChnState(void) { chn->wavBufCount--; bool shouldBreak = seqId == 0 && (wb->sequence_id == st->lastSeqId || st->lastSeqId == 0); + wb->status = NDSP_WBUF_DONE; wb = wb->next; if (!wb || shouldBreak || chn->wavBufCount == 0) break; } + if (wb && wb->status != NDSP_WBUF_DONE) + wb->status = NDSP_WBUF_PLAYING; if (seqId == 0) chn->wavBufCount = 0; chn->waveBuf = wb; + chn->waveBufSeqPos = seqId; LightLock_Unlock(&chn->lock); } + } chn->playing = (st->flags & 0xFF) ? true : false; } diff --git a/libctru/source/ndsp/ndsp.c b/libctru/source/ndsp/ndsp.c index 959caa3..acaabbf 100644 --- a/libctru/source/ndsp/ndsp.c +++ b/libctru/source/ndsp/ndsp.c @@ -100,7 +100,8 @@ static void ndspInitMaster(void) memset(&ndspMaster, 0, sizeof(ndspMaster)); LightLock_Init(&ndspMaster.lock); ndspMaster.masterVol = 1.0f; - ndspMaster.clippingMode = 1; + ndspMaster.outputMode = NDSP_OUTPUT_STEREO; + ndspMaster.clippingMode = NDSP_CLIP_SOFT; ndspMaster.outputCount = 2; ndspMaster.surround.depth = 0x7FFF; ndspMaster.surround.rearRatio = 0x8000; -- 2.39.5