Changes

Correct dsp status
Line 1: Line 1: −
'''Some of this is known to be incorrect. I'll correct this in a few months after a bit more RE work. [[User:Merry|Merry]] ([[User talk:Merry|talk]]) 21:10, 28 January 2016 (CET)'''
+
''Note that everything below may vary depending on the exact DSP firmware used and different variants have slightly different behaviours.''
   −
----
+
The DSP communicates with the application through two shared memory areas 0x8000 bytes long each (at 0x1FF50000 and 0x1FF70000 respectively). The DSP alternates between the use of these two areas (much like a double-buffer). Each area has 15 structures within it. The location of these structures can be obtained by [[DSP:ReadPipe|reading channel 2 of the DSP pipe]]. A list of structures in the order the DSP addresses are read from the pipe follows:
    +
1. Frame count
   −
The DSP communicates with userland through memory locations 0x1ff40000-0x1ff77fff. Within this region are two areas of structures that are exact duplicates of each other. The DSP alternates between the use of these two areas (much like a double-buffer). Each area has 15 structures within it. The location of these structures can be obtained by [[DSP:ReadPipe|reading channel 2 of the DSP pipe]].
+
2. Input configurations
   −
The mixer has 24 channels, each of which are individually configurable.
+
3. Input status
   −
{| class="wikitable"
+
4. Input ADPCM coefficients
|-
+
 
| Structure Number
+
5. DSP configuration
| DSP memory address
+
 
| Size
+
6. DSP status
| Description
+
 
|-
+
7. Output samples
| 5
+
 
| 0x8400
+
8. Intermediate mix samples
| 0x20
+
 
| Status (?)
+
9. Compressor table
|-
+
 
| 9
+
10. DSP debug statistics
| 0x8410
+
 
| 0x260
+
11. Unknown Coefficients
| Debug (?)
+
 
|-
+
12. Unknown Coefficients
| 6
+
 
| 0x8540
+
13. Unknown Coefficients
| 0x280
+
 
| Loopback Samples (PCM16)
+
14. Surround sound biquad filter 1
|-
+
 
| 2
+
15. Surround sound biquad filter 2
| 0x8680
+
 
| 0x120
+
The DSP has 24 inputs, each of which are individually configurable. These 24 inputs each produce three sets of 4 audio channels (two left, two right).
| Channel Status (x24)
+
 
|-
+
These four audio channels feed into three intermediate mixers. Two of these intermediate mixers are used for effects and aux.
| 8  
+
 
| 0x9710
+
== Frame Count ==
| 0x1A40
+
 
| ?
+
The frame count of the first region must be even and the frame count of the second region must be odd.
|-
+
 
| 4
+
The frame with the higher count is the "current region".
| 0x9430
+
 
| 0xC4
+
The DSP firmware only responds if the first frame count is 4.
| Main Configuration
  −
|-
  −
| 7
  −
| 0x9492
  −
| 0x1400
  −
| ?
  −
|-
  −
| 1
  −
| 0x9e92
  −
| 0x1200
  −
| Channel Config (x24)
  −
|-
  −
| 3
  −
| 0x9430
  −
| 0x300
  −
| GC-ADPCM Coefficients (x24)
  −
|-
  −
| 10
  −
| 0xa912
  −
| 0x200
  −
|
  −
|-
  −
| 11
  −
| 0xaa12
  −
| 0x180
  −
|
  −
|-
  −
| 12
  −
| 0xaad2
  −
| 0x300
  −
|
  −
|-
  −
| 13
  −
| 0xac52
  −
| 0x14
  −
|
  −
|-
  −
| 14
  −
| 0xac5c
  −
| 0x2476
  −
| -
  −
|-
  −
| 0
  −
| 0xbfff
  −
| 0x2
  −
| Frame Counter
  −
|}
     −
== Channel Config ==
+
== Input Config ==
    
A 192 byte long structure. There are 24 of them.
 
A 192 byte long structure. There are 24 of them.
Line 106: Line 60:  
|-
 
|-
 
| 4
 
| 4
| 70 bytes
+
| f32[3][2][2]
| TODO
+
| Input Gain (Each input has 12 channels)
 +
|-
 +
| 52
 +
| f32
 +
| Rate multiplier (1.0x == native DSP rate)
 +
|-
 +
| 56
 +
| u8
 +
| Interpolation mode
 +
|-
 +
| 57
 +
| u8
 +
| Polyphase filter select
 +
|-
 +
| 58
 +
| u16
 +
| bit[0]: Simple Filter enabled, bit[1]: Biquadratic Filter enabled
 +
|-
 +
| 60
 +
| SimpleFilter
 +
| Simple Filter (One pole normalized recursive linear filter)
 +
|-
 +
| 64
 +
| BiquadFilter
 +
| Biquadratic Filter (Two poles two zeros normalized recursive linear filter)
 
|-
 
|-
 
| 74
 
| 74
Line 130: Line 108:  
|-
 
|-
 
| 164
 
| 164
| 8
+
| u32
| TODO
+
| Play position
 +
|-
 +
| 168
 +
| 4
 +
| ?
 
|-
 
|-
 
| 172
 
| 172
 
| u32
 
| u32
| Physical address of current buffer
+
| Physical address of embedded buffer
 
|-
 
|-
 
| 176
 
| 176
 
| u32
 
| u32
| Number of samples in current buffer
+
| Number of samples in embedded buffer
 
|-
 
|-
 
| 180
 
| 180
 
| u16
 
| u16
| bits[0:1]: 1 = mono, 2 = stereo; bits[2:3]: buffer format
+
| Format
 
|-
 
|-
 
| 182
 
| 182
| u16
+
| AdpcmData
| ADPCM predictor
+
| ADPCM data associated with embedded buffer
|-
  −
| 184
  −
| s16
  −
| ADPCM yn1
  −
|-
  −
| 186
  −
| s16
  −
| ADPCM yn2
   
|-
 
|-
 
| 188
 
| 188
 
| u16
 
| u16
| bit[0]: Has ADPCM data?; bit[1]: Is looping?
+
| bit[0]: ADPCM updated?; bit[1]: Is looping?r
 
|-
 
|-
 
| 190
 
| 190
 
| u16
 
| u16
| Buffer Id of this current buffer
+
| Buffer Id of embedded buffer
 +
|}
 +
 
 +
There is a 2 sample delay in this preprocessing stage, likely due to the interpolation step.
 +
 
 +
=== Format ===
 +
 
 +
This is a u16.
 +
 
 +
{| class="wikitable"
 +
|-
 +
| Bits
 +
| Desciption
 +
|-
 +
| 0-1
 +
| Number of channels: 0,1,3 = mono; 2 = stereo
 +
|-
 +
| 2-3
 +
| Buffer codec: [[BCWAV#Encoding|0:PCM8; 1:PCM16; 2:ADPCM]]
 +
|-
 +
| 5
 +
| Fade
 
|}
 
|}
   Line 183: Line 178:  
|-
 
|-
 
| 8
 
| 8
| u16
+
| AdpcmData
| ADPCM P/S
+
| ADPCM data
|-
  −
| 10
  −
| s16[2]
  −
| ADPCM yn[1,2]
   
|-
 
|-
 
| 14
 
| 14
 
| u8
 
| u8
| Has ADPCM?
+
| ADPCM data dirty?
 
|-
 
|-
 
| 15
 
| 15
Line 207: Line 198:  
|}
 
|}
   −
=== Dirty Bits ===
+
=== Adpcm Data ===  
    
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
| Bit
+
| 0
| What Changed
+
| u8
 +
| ADPCM predictor/scale
 
|-
 
|-
| 3
+
| 1
| ADPCM Coefficients
+
| u8
 +
| -
 
|-
 
|-
| 5
+
| 2
| Embedded buffer
+
| s16
 +
| ADPCM y[n-1]
 
|-
 
|-
| 13
+
| 4
| Is Active
+
| s16
 +
| ADPCM y[n-2]
 +
|}
 +
 
 +
 
 +
=== Simple Filter ===
 +
 
 +
This is a standard single-pole filter. The fall-off is 6dB per octave as you would expect.
 +
 
 +
{| class="wikitable"
 +
|-
 +
| Offset
 +
| Type
 +
| Description
 +
|-
 +
| 0
 +
| s1.15
 +
| b0
 +
|-
 +
| 2
 +
| s1.15
 +
| a1 (negated)
 +
|}
 +
 
 +
=== Biquad Filter ===
 +
 
 +
This is a [[wikipedia:Digital_biquad_filter|biquadratic filter]].
 +
 
 +
{| class="wikitable"
 +
|-
 +
| Offset
 +
| Type
 +
| Description
 +
|-
 +
| 0
 +
| s2.14
 +
| a2 (negated)
 +
|-
 +
| 2
 +
| s2.14
 +
| a1 (negated)
 +
|-
 +
| 4
 +
| s2.14
 +
| b2
 +
|-
 +
| 6
 +
| s2.14
 +
| b1
 +
|-
 +
| 8
 +
| s2.14
 +
| b0
 +
|}
 +
 
 +
== Input status ==
 +
 
 +
Read only. This structure is set by the DSP. This structure is 12 bytes long and there are 24 of them.
 +
 
 +
{| class="wikitable"
 +
|-
 +
| Offset
 +
| Type
 +
| Description
 +
|-
 +
| 0
 +
| u8
 +
| Input Enabled?
 +
|-
 +
| 1
 +
| u8
 +
| Dirty flag for buffer id, set to 1 when buffer (after the first) starts playing
 +
|-
 +
| 2
 +
| u16
 +
| Sync count
 +
|-
 +
| 4
 +
| u32
 +
| Position (number of samples) into current buffer playback
 +
|-
 +
| 8
 +
| u16
 +
| Buffer id of the buffer that's just started playing.
 +
|-
 +
| 10
 +
| u16
 +
| -
 +
|}
 +
 
 +
== Input ADPCM coefficients ==
 +
 
 +
This is a 32 byte long structure. There are 24 of them.
 +
 
 +
{| class="wikitable"
 +
|-
 +
| Offset
 +
| Type
 +
| Description
 +
|-
 +
| 0
 +
| s5.11[16]
 +
| ADPCM coefficents
 +
|}
 +
 
 +
== DSP configuration ==
 +
 
 +
=== Delay Effect ===
 +
 
 +
Delay with feedback.
 +
 
 +
Length of delay is expressed in terms of number of audio frames (there are 160 samples per audio frame).
 +
 
 +
Feedback arm only has a gain on it. Under the feedback arm is a single-pole filter with the delay.
 +
 
 +
=== Reverb Effect ===
 +
 
 +
Reverb consists of two comb filters and one all-pass filter in standard configuration.
 +
 
 +
== DSP status ==
 +
 
 +
Read only. A 32 byte long structure.
 +
 
 +
{| class="wikitable"
 +
|-
 +
| Offset
 +
| Type
 +
| Description
 +
|-
 +
| 0
 +
| u16
 +
| ?
 +
|-
 +
| 2
 +
| u16
 +
| Number of dropped frames
 +
|-
 +
| 4
 +
| 28 bytes
 +
| ?
 +
|}
 +
 
 +
== Output samples ==
 +
 
 +
Read only. This structure is 640 bytes long. Output is stereo (the 3DS has two speakers).
 +
 
 +
{| class="wikitable"
 +
|-
 +
| Offset
 +
| Type
 +
| Description
 
|-
 
|-
| 18
+
| 0
| Interpolation Type
+
| s16[160]
 +
| Left-channel Samples
 
|-
 
|-
| 19
+
| 320
| Rate
+
| s16[160]
 +
| Right-channel Samples
 +
|}
 +
 
 +
This structure has separate arrays for the left and right channels.
 +
 
 +
== Intermediate mix samples ==
 +
 
 +
Read/Write.
 +
 
 +
PCM32. Also serves an aux function, allowing the ARM11 to apply custom effects to audio. Internal format of the DSP firmware is quadaphonic audio.
 +
 
 +
This structure is 5120 bytes long.
 +
 
 +
{| class="wikitable"
 
|-
 
|-
| 20
+
| Offset
| Buffer Queue
+
| Type
 +
| Description
 
|-
 
|-
| 22
+
| 0
| Embedded buffer
+
| IntermediateSample[160]
 +
| Samples
 +
|}
 +
 
 +
In contrast to the final output samples, this structure has the left/right channels interleaved.
 +
 
 +
=== Intermediate sample ===
 +
 
 +
A quadraphonic sample.
 +
 
 +
{| class="wikitable"
 
|-
 
|-
| 23
+
| Offset
| IRR Filter Type
+
| Type
 +
| Description
 
|-
 
|-
| 25
+
| 0
| Sync Count
+
| s32
 +
| Left Channel A
 
|-
 
|-
| 26-28
+
| 4
| Mix
+
| s32
 +
| Right Channel A
 
|-
 
|-
| 30
+
| 8
| First time init
+
| s32
 +
| Left Channel B
 
|-
 
|-
| 31
+
| 12
| Embedded Buffer
+
| s32
 +
| Right Channel B
 
|}
 
|}
 +
 +
== Compressor table ==
 +
 +
A precomputed response curve lookup table for the compressor.
 +
 +
[[Category:DSP]]
6

edits