]> Chaos Git - corbenik/ctrulib.git/commitdiff
Some additions to NDSP code (thanks to Lectem)
authorfincs <fincs.alt1@gmail.com>
Sun, 18 Oct 2015 21:06:11 +0000 (23:06 +0200)
committerfincs <fincs.alt1@gmail.com>
Sun, 18 Oct 2015 21:06:11 +0000 (23:06 +0200)
libctru/include/3ds/ndsp/channel.h
libctru/include/3ds/ndsp/ndsp.h
libctru/source/ndsp/ndsp-channel.c
libctru/source/ndsp/ndsp.c

index 8328f7e2ac0f10854b9ce16dd7be93568b28d20c..518667f32385c43dc810bbc1c0e45b211ad49b51 100644 (file)
@@ -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
index a4aa8eb173b44c50a91b9231b62f7f977edd97ea..cfaf933ea94d3621f985af48f57fb024649dbadb 100644 (file)
@@ -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, ///<?
+       NDSP_SPKPOS_WIDE   = 1, ///<?
+       NDSP_SPKPOS_NUM    = 2, ///<?
+};
+
 /// ADPCM data.
 typedef struct
 {
@@ -17,6 +40,15 @@ typedef struct
 /// Wave buffer type.
 typedef struct tag_ndspWaveBuf ndspWaveBuf;
 
+/// Wave buffer status.
+enum
+{
+       NDSP_WBUF_FREE    = 0, ///< The wave buffer is not queued.
+       NDSP_WBUF_QUEUED  = 1, ///< The wave buffer is queued and has not been played yet.
+       NDSP_WBUF_PLAYING = 2, ///< The wave buffer is playing right now.
+       NDSP_WBUF_DONE    = 3, ///< The wave buffer has finished being played.
+};
+
 /// Wave buffer struct.
 struct tag_ndspWaveBuf
 {
@@ -32,7 +64,7 @@ struct tag_ndspWaveBuf
 
        u32  offset;  ///< Buffer offset. Only used for capture.
        bool looping; ///< Whether to loop the buffer.
-       u8   padding; ///< Padding.
+       u8   status;  ///< Queuing/playback status.
 
        u16 sequence_id;   ///< Sequence ID. Assigned automatically by ndspChnWaveBufAdd.
        ndspWaveBuf* next; ///< Next buffer to play. Used internally, do not modify.
@@ -84,13 +116,13 @@ void ndspSetMasterVol(float volume);
 
 /**
  * @brief Sets the output mode.
- * @param mode Output mode to set. Defaults to 0.
+ * @param mode Output mode to set. Defaults to NDSP_OUTPUT_STEREO.
  */
 void ndspSetOutputMode(int mode);
 
 /**
  * @brief Sets the clipping mode.
- * @param mode Clipping mode to set. Defaults to 1.
+ * @param mode Clipping mode to set. Defaults to NDSP_CLIP_SOFT.
  */
 void ndspSetClippingMode(int mode);
 
@@ -124,7 +156,7 @@ void ndspSurroundSetDepth(u16 depth);
 
 /**
  * @brief Sets the surround sound position.
- * @param pos Position to set. Defaults to 0.
+ * @param pos Position to set. Defaults to NDSP_SPKPOS_SQUARE.
  */
 void ndspSurroundSetPos(u16 pos);
 
index 8d533571e096d519e68fbe527eb9c4cb8192b1d2..4970bdeff6482a020b558e4816d7fcf8a955976c 100644 (file)
@@ -147,6 +147,7 @@ void ndspChnWaveBufAdd(int id, ndspWaveBuf* buf)
        if (!buf->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;
        }
index 959caa3c9557ee5321b4a9222bb1275d9b99d213..acaabbf05a83b682e96afe95366b16da8c8e46c1 100644 (file)
@@ -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;