DSP Memory Region: Difference between revisions

Merry (talk | contribs)
No edit summary
Peachy (talk | contribs)
No edit summary
 
(23 intermediate revisions by 3 users not shown)
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.''
 
----
 
*Note that everything below will 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:
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:
Line 33: Line 29:
13. Unknown Coefficients
13. Unknown Coefficients


14. Unknown Coefficients
14. Surround sound biquad filter 1


15. Unknown Coefficients
15. Surround sound biquad filter 2


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).  
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).  
Line 42: Line 38:


== Frame Count ==
== Frame Count ==
The frame count of the first region must be even and the frame count of the second region must be odd.
The frame with the higher count is the "current region".
The DSP firmware only responds if the first frame count is 4.


== Input Config ==
== Input Config ==
Line 58: 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 82: 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, bits[5]: fade in
| Format
|-
|-
| 182
| 182
| u16
| AdpcmData
| ADPCM predictor/scale
| ADPCM data associated with embedded buffer
|-
| 184
| s16
| ADPCM y[n-1]
|-
| 186
| s16
| ADPCM y[n-2]
|-
|-
| 188
| 188
| u16
| u16
| bit[0]: ADPCM updated?; 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 135: Line 178:
|-
|-
| 8
| 8
| u16
| AdpcmData
| 4 bits: ADPCM Predictor, 4 bits: ADPCM Scale
| ADPCM data
|-
| 10
| s16
| ADPCM y[n-1]
|-
| 11
| s16
| ADPCM y[n-2]
|-
|-
| 14
| 14
| u8
| u8
| ADPCM dirty?
| ADPCM data dirty?
|-
|-
| 15
| 15
Line 162: Line 197:
| -
| -
|}
|}
=== Adpcm Data ===
{| class="wikitable"
|-
| 0
| u8
| ADPCM predictor/scale
|-
| 1
| u8
| -
|-
| 2
| s16
| ADPCM y[n-1]
|-
| 4
| s16
| ADPCM y[n-2]
|}


=== Simple Filter ===
=== Simple Filter ===
Line 174: Line 231:
|-
|-
| 0
| 0
| s16
| s1.15
| b0
| b0
|-
| 2
| s1.15
| a1 (negated)
|}
=== Biquad Filter ===
This is a [[wikipedia:Digital_biquad_filter|biquadratic filter]].
{| class="wikitable"
|-
| Offset
| Type
| Description
|-
|-
| 0
| 0
| s16
| s2.14
| a1
| a2 (negated)
|-
| 2
| s2.14
| a1 (negated)
|-
| 4
| s2.14
| b2
|-
| 6
| s2.14
| b1
|-
| 8
| s2.14
| b0
|}
|}


== Input status ==
== Input status ==


Read only.
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 ==
== 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 ==
== DSP configuration ==
Line 194: Line 326:
Delay with feedback.
Delay with feedback.


Length of delay is a multiple of audio frames. There are 160 samples per audioframe.
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.
Feedback arm only has a gain on it. Under the feedback arm is a single-pole filter with the delay.


=== Reverb Effect ===
=== Reverb Effect ===
Reverb consists of two comb filters and one all-pass filter in standard configuration.


== DSP status ==
== DSP status ==


Read only.
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 ==
== Output samples ==


Read only.
Read only. This structure is 640 bytes long. Output is stereo (the 3DS has two speakers).


PCM16.
{| class="wikitable"
|-
| Offset
| Type
| Description
|-
| 0
| s16[160]
| Left-channel Samples
|-
| 320
| s16[160]
| Right-channel Samples
|}
 
This structure has separate arrays for the left and right channels.


== Intermediate mix samples ==
== Intermediate mix samples ==
Line 214: Line 382:
Read/Write.
Read/Write.


PCM32. Also serves an aux function, allowing the ARM11 to apply custom effects to audio.
PCM32. Also serves an aux function, allowing the ARM11 to apply custom effects to audio. Internal format of the DSP firmware is quadraphonic audio.
 
This structure is 5120 bytes long.
 
{| class="wikitable"
|-
| Offset
| Type
| Description
|-
| 0
| 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"
|-
| Offset
| Type
| Description
|-
| 0
| s32
| Left Channel A
|-
| 4
| s32
| Right Channel A
|-
| 8
| s32
| Left Channel B
|-
| 12
| s32
| Right Channel B
|}


== Compressor table ==
== Compressor table ==


A precomputed response curve lookup table for the compressor.
A precomputed response curve lookup table for the compressor.
[[Category:DSP]]