ultimecia

A ps1 emulator in c
Log | Files | Refs

spu.txt (20313B)


      1 ==========================================================================
      2 SPU - Sound Processing Unit. Information & Documentation.
      3 ==========================================================================
      4 
      5 Disclaimer.
      6 --------------------------------------------------------------------------
      7 This document is a collection of all info on the SPU i could find and my
      8 own notes. Most of this is the result of experiment, so not all info might
      9 be correct. This document is most probably not complete, and not all
     10 capabilities and quirks of the SPU are documented. No responsibility is
     11 taken for anything that might occur using the information in this document.
     12 
     13 
     14 Introduction.
     15 --------------------------------------------------------------------------
     16 The SPU is the unit responsible for all aural capabilities of the psx. It
     17 handles 24 voices, has a 512kb sound buffer, has ADSR envelope filters for
     18 each voice and lots of other features.
     19 
     20 
     21 Notations and conventions
     22 When the format of data is given it's shown as a bitwise representation
     23 like this:
     24 
     25 
     26 bit  |0f|0e 0d 0c 0b 0a|09 08 07 06 05|04 03 02 01 00|
     27 desc.|                                               |
     28 
     29 The bit row shows which bits of the data are used, and separators are used
     30 to show where the different elements of the data stop and start. MSB is on
     31 the left, LSB is on the right. Stuff like |0f-08| means bit $0f to bit $08.
     32 The desc. row shows the description of the different elements. With
     33 separators where the element starts and ends.
     34 
     35 
     36 
     37 --------------------------------------------------------------------------
     38 The Sound Buffer
     39 --------------------------------------------------------------------------
     40 
     41 The SPU has control over a 512kb sound buffer. Data is stored compressed
     42 into blocks of 16 bytes. Each block contains 14 packed sample bytes and two
     43 header bytes, one for the packing and one for sample end and looping
     44 information. One such block is decoded into 28 sample bytes (= 14 16bit
     45 samples).
     46 
     47 In the first 4 kb of the buffer the SPU stores the decoded data of CD audio
     48 after volume processing and the sound data of voice 1 and voice 3 after
     49 envelope processing. The decoded data is stored as 16 bit signed values,
     50 one sample per clock (44.1 khz).
     51 
     52 Following this first 4kb are 8 bytes reserved by the system. The memory
     53 beyond that is free to store samples, up to the reverb work area if the
     54 effect processor is used. The size of this work area depends on which
     55 type of effect is being processed. More on that later.
     56 
     57 Memory layout:
     58 $00000-$003ff  CD audio left
     59 $00400-$007ff  CD audio right
     60 $00800-$00bff  Voice 1
     61 $00c00-$00fff  Voice 3
     62 $01000-$0100f  System area.
     63 $01008-$xxxxx  Sound data area.
     64 $0xxxx-$7ffff  Reverb work area.
     65 
     66 --------------------------------------------------------------------------
     67 Voices.
     68 --------------------------------------------------------------------------
     69 The SPU has 24 hardware voices. These voices can be used to reproduce sample
     70 data, noise or can be used as frequency modulator on the next voice.
     71 Each voice has it's own programmable ADSR envelope filter. The main volume
     72 can be programmed independently for left and right output.
     73 
     74 The ADSR envelope filter works as follows:
     75 Ar = Attack rate, which specifies the speed at which the volume increases
     76      from zero to it's maximum value, as soon as the note on is given. The
     77      slope can be set to lineair or exponential.
     78 Dr = Decay rate specifies the speed at which the volume decreases to the
     79      sustain level. Decay is always decreasing exponentially.
     80 Sl = Sustain level, base level from which sustain starts.
     81 Sr = Sustain rate is the rate at which the volume of the sustained note
     82      increases or decreases. This can be either lineair or exponential.
     83 Rr = Release rate is the rate at which the volume of the note decreases
     84      as soon as the note off is given.
     85 
     86      lvl |
     87        ^ |     /\Dr     __
     88      Sl _| _  / _ \__---  \
     89          |   /       ---__ \ Rr
     90          |  /Ar       Sr  \ \
     91          | /                \\
     92          |/___________________\________
     93                                   ->time
     94 
     95 The overal volume can also be set to sweep up or down lineairly or
     96 exponentially from it's current value. This can be done seperately
     97 for left and right.
     98 
     99 
    100 --------------------------------------------------------------------------
    101 SPU Operation
    102 --------------------------------------------------------------------------
    103 
    104 The SPU occupies the area $1f801c00-$1f801dff. All registers are 16 bit
    105 wide.
    106 
    107 =============================================================
    108 $1f801c00-        Voice data area. For each voice there are 8 16 bit
    109 $1f801d7f         registers structured like this:
    110 
    111 (xx = $c0 + voice number)
    112 -------------------------------------------------------------
    113 $1f801xx0         Volume Left
    114 $1f801xx2         Volume Right
    115 
    116 Volume mode:
    117 bit  |0f|0e|0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    118 desc.| 0| S|               VV                        |
    119 
    120 VV  $0000-$3fff   Voice volume.
    121 S        0        Phase Normal
    122          1              Inverted
    123 
    124 Sweep mode:
    125 bit  |0f|0e|0d|0c|0b 0a 09 08 07|06 05 04 03 02 01 00|
    126 desc.| 1|Sl|Dr|Ph|              |VV                  |
    127 
    128 VV  $0000-$007f   Voice volume.
    129 Sl       0        Lineair slope
    130          1        Exponential slope
    131 Dr       0        Increase
    132          1        Decrease
    133 Ph       0        Normal phase
    134          1        Inverted phase
    135 
    136 In sweep mode, the current volume increases to its maximum value,
    137 or decreases to its mimimum value, according to mode. Choose
    138 phase equal to the the phase of the current volume.
    139 -------------------------------------------------------------
    140 $1f801xx4         Pitch
    141 bit  |0f 0e|0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    142 desc.|     |Pt                                       |
    143 
    144 Pt  $0000-$3fff   Specifies pitch.
    145 
    146 Any value can be set, table shows only octaves:
    147 $0200  - 3 octaves
    148 $0400  - 2
    149 $0800  - 1
    150 $1000  sample pitch
    151 $2000  + 1
    152 $3fff  + 2
    153 -------------------------------------------------------------
    154 $1f801xx6         Startaddress of Sound
    155 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    156 desc.|Addr                                           |
    157 
    158 Addr     Startaddress of sound in Sound buffer /8
    159 -------------------------------------------------------------
    160 $1f801xx8         Attack/Decay/Sustain level
    161 bit  |0f|0e 0d 0c 0b 0a 09 08|07 06 05 04|03 02 01 00|
    162 desc.|Am|         Ar         |Dr         |Sl         |
    163 
    164 Am       0        Attack mode Linear
    165          1                    Exponential
    166 
    167 Ar       0-7f     attack rate
    168 Dr       0-f      decay rate
    169 Sl       0-f      sustain level
    170 -------------------------------------------------------------
    171 $1f801xxa         Sustain rate, Release Rate.
    172 bit  |0f|0e|0d|0c 0b 0a 09 08 07 06|05|04 03 02 01 00|
    173 desc.|Sm|Sd| 0|   Sr               |Rm|Rr            |
    174 
    175 Sm       0        sustain rate mode linear
    176          1                          exponential
    177 Sd       0        sustain rate mode increase
    178          1                          decrease
    179 Sr       0-7f     Sustain Rate
    180 Rm       0        Linear decrease
    181          1        Exponential decrease
    182 Rr       0-1f     Release Rate
    183 
    184 Note: decay mode is always Expontial decrease, and thus cannot
    185 be set.
    186 -------------------------------------------------------------
    187 $1f801xxc         Current ADSR volume
    188 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    189 desc.|ADSRvol                                        |
    190 
    191 ADSRvol           Returns the current envelope volume when
    192                   read.
    193 -------------------------------------------------------------
    194 $1f801xxe         Repeat address.
    195 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    196 desc.|Ra                                             |
    197 
    198 Ra  $0000-$ffff   Address sample loops to at end.
    199 
    200 Note: Setting this register only has effect after the voice
    201 has started (ie. KeyON), else the loop address gets reset
    202 by the sample.
    203 =============================================================
    204 $1f801d80         Mainvolume left
    205 $1f801d82         Mainvolume right
    206 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    207 desc.|                                               |
    208 
    209 Sets Main volume, these work the same as the channel volume
    210 registers. See those for details.
    211 -------------------------------------------------------------
    212 $1f801d84         Reverberation depth left
    213 $1f801d86         Reverberation depth right
    214 bit  |0f|0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    215 desc.|P |Rvd                                         |
    216 
    217 Rvd $0000-$7fff   Sets the wet volume for the effect.
    218 P        0        Normal phase
    219          1        Inverted phase
    220 =============================================================
    221 Following registers have a common layout:
    222 
    223 first register:
    224 bit  |0f|0e|0d|0c|0b|0a|09|08|07|06|05|04|03|02|01|00|
    225 desc.|cf|ce|cd|cc|cb|ca|c9|c8|c7|c6|c5|c4|c3|c2|c1|c0|
    226 
    227 second register:
    228 bit  |0f           08|07 |06 |05 |04 |03 |02 |01 | 00|
    229 desc.|              0|c17|c16|c15|c14|c13|c12|c11|c10|
    230 
    231 c0-c17   0        Mode for channel c?? off
    232          1        Mode for channel c?? on
    233 -------------------------------------------------------------
    234 $1f801d88         Voice ON  (0-15)
    235 $1f801d8a         Voice ON  (16-23)
    236 
    237 Sets the current voice to key on. (ie. start ads)
    238 -------------------------------------------------------------
    239 $1f801d8c         Voice OFF (0-15)
    240 $1f801d8e         Voice OFF (16-23)
    241 
    242 Sets the current voice to key off.(ie. release)
    243 -------------------------------------------------------------
    244 $1f801d90         Channel FM (pitch lfo) mode (0-15)
    245 $1f801d92         Channel FM (pitch lfo) mode (16-23)
    246 
    247 Sets the channel frequency modulation. Uses the previous channel
    248 as modulator.
    249 -------------------------------------------------------------
    250 $1f801d94         Channel Noise mode (0-15)
    251 $1f801d96         Channel Noise mode (16-23)
    252 
    253 Sets the channel to noise.
    254 -------------------------------------------------------------
    255 $1f801d98         Channel Reverb mode (0-15)
    256 $1f801d9a         Channel Reverb mode (16-23)
    257 
    258 Sets reverb for the channel. As soon as the sample ends, the
    259 reverb for that channel is turned off.
    260 -------------------------------------------------------------
    261 $1f801d9c         Channel ON/OFF (0-15)                 ?
    262 $1f801d9e         Channel ON/OFF (16-23)                ?
    263 
    264 Returns wether the channel is mute or not.              ?
    265 =============================================================
    266 $1f801da2         Reverb work area start
    267 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    268 desc.|Revwa                                          |
    269 
    270 Revwa $0000-$ffff Reverb work area start in sound buffer /8
    271 -------------------------------------------------------------
    272 $1f801da4         Sound buffer IRQ address.
    273 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    274 desc.|IRQa                                           |
    275 
    276 IRQa  $0000-$ffff IRQ address in sound buffer /8
    277 ??
    278 -------------------------------------------------------------
    279 $1f801da6         Sound buffer address
    280 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    281 desc.|Sba                                            |
    282 
    283 SBA $0000-$ffff   Address in sound buffer divided by eight.
    284                   Next transfer to this address.
    285 -------------------------------------------------------------
    286 $1f801da8         SPU data
    287 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    288 desc.|                                               |
    289 
    290 Data forwarding reg, for non DMA transfer.
    291 -------------------------------------------------------------
    292 $1f801daa         SPU control                sp0
    293 bit  |0f|0e|0d 0c 0b 0a 09 08|07|06 |05 04|03|02|01|00|
    294 desc.|En|Mu|Noise            |Rv|Irq|DMA  |Er|Cr|Ee|Ce|
    295 
    296 En       0        SPU off
    297          1        SPU on
    298 Mu       0        Mute SPU
    299          1        Unmute SPU
    300 Noise             Noise clock frequency
    301 Rv       0        Reverb Disabled
    302          1        Reverb Enabled
    303 Irq      0        Irq disabled
    304          1        Irq enabled
    305 DMA     00
    306         01        Non DMA write?  (transfer through data reg)
    307         10        DMA Write
    308         11        DMA Read
    309 Er       0        Reverb for external off
    310          1        Reverb for external on
    311 Cr       0        Reverb for CD off
    312          1        Reverb for CD on
    313 Ee       0        External audio off
    314          1        External audio on
    315 Ce       0        CD audio off
    316          1        CD audio on
    317 -------------------------------------------------------------
    318 $1f801dac         SPU status
    319 bit  |0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    320 desc.|                                               |
    321 
    322 Don't know what this is for, but in SPU init routines this
    323 register get loaded with $4.
    324 -------------------------------------------------------------
    325 $1f801dae         SPU status
    326 bit  |0f 0e 0d 0c|0b|0a|09 08 07 06 05 04 03 02 01 00|
    327 desc.|           |Dh|Rd|                             |
    328 
    329 Dh       0        Decoding in first half of buffer
    330          1        Decoding in second half of buffer
    331 Rd       0        Spu ready to transfer
    332          1        Spu not ready
    333 
    334 Some of bits 9-0 are also ready/not ready states. More on
    335 that later. Functions that wait for the SPU to be ready,
    336 wait for bits a-0 to become 0.
    337 -------------------------------------------------------------
    338 $1f801db0         CD volume left
    339 $1f801db2         CD volume right
    340 bit  |0f|0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    341 desc.|P |CDvol                                       |
    342 
    343 CDvol $0000-$7fff Set volume of CD input.
    344 P        0        Normal phase.
    345          1        Inverted phase.
    346 -------------------------------------------------------------
    347 $1f801db4         Extern volume left
    348 $1f801db6         Extern volume right
    349 bit  |0f|0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00|
    350 desc.|P |Exvol                                       |
    351 
    352 Exvol $0000-$7fff Set volume of External input.
    353 P        0        Normal phase.
    354          1        Inverted phase.
    355 -------------------------------------------------------------
    356 1dc0-1dff         Reverb configuration area
    357 $1f801dc0         
    358 $1f801dc2
    359 $1f801dc4         Lowpass Filter Frequency. 7fff = max value= no filtering
    360 $1f801dc6         Effect volume 0 - $7fff, bit 15 = phase.
    361 $1f801dc8
    362 $1f801dca
    363 $1f801dcc
    364 $1f801dce         Feedback
    365 $1f801dd0
    366 $1f801dd2
    367 $1f801dd4         Delaytime(see below)
    368 $1f801dd6         Delaytime(see below)
    369 $1f801dd8         Delaytime(see below)
    370 $1f801dda
    371 $1f801ddc
    372 $1f801dde
    373 $1f801de0         Delaytime(see below)
    374 $1f801de2
    375 $1f801de4
    376 $1f801de6
    377 $1f801de8
    378 $1f801dea
    379 $1f801dec
    380 $1f801dee
    381 $1f801df0
    382 $1f801df2
    383 $1f801df4         Delaytime
    384 $1f801df6         Delaytime
    385 $1f801df8
    386 $1f801dfa
    387 $1f801dfc
    388 $1f801dfe
    389 
    390 --------------------------------------------------------------------------
    391 Reverb
    392 --------------------------------------------------------------------------
    393 The SPU is equipped with an effect processor for reverb echo and delay type
    394 of effects. This effect processor can do one effect at a time, and for each
    395 voice you can specify wether it should have the effect applied or not.
    396 
    397 The effect is setup by initializing the registers $1dc0 to $1ffe to the
    398 desired effect. I do not exactly know how these work, but you can use
    399 the presets below.
    400 
    401 The effect processor needs a bit of sound buffer memory to perform it's
    402 calculations. The size of this depends on the effect type. For the presets
    403 the sizes are:
    404 
    405 Reverb off        $00000       Hall          $0ade0
    406 Room              $026c0       Space echo    $0f6c0
    407 Studio small      $01f40       Echo          $18040
    408 Studio medium     $04840       Delay         $18040
    409 Studio large      $06fe0       Half echo     $03c00
    410 
    411 The location at which the work area is location is set in register $1da2
    412 and it's value is the location in the sound buffer divided by eight. Common
    413 values are as follows:
    414 
    415 Reverb off        $FFFE        Hall          $EA44
    416 Room              $FB28        Space echo    $E128
    417 Studio small      $FC18        Echo          $CFF8
    418 Studio medium     $F6F8        Delay         $CFF8
    419 Studio large      $F204        Half echo     $F880
    420 
    421 For the delay and echo effects (not space echo or half echo) you can
    422 specify the delay time, and feedback. (range 0-127) Calculations are shown
    423 below.
    424 
    425 When you setup up a new reverb effect, take the following steps:
    426 
    427 -Turn off the reverb (bit 7 in sp0)
    428 -Set Depth to 0
    429 -First make delay & feedback calculations.
    430 -Copy the preset to the effect registers
    431 -Turn on the reverb
    432 -Set Depth to desired value.
    433 
    434 Also make sure there is the reverb work area is cleared, else you might get
    435 some unwanted noise.
    436 
    437 To use the effect on a voice, simple turn on the corresponing bit in the
    438 channel reverb registers. Note that these get turned off autmatically when
    439 the sample for the channel ends.
    440 
    441 
    442 -------------------------------------------------------------
    443 Effect presets: copy these in order to $1dc0-$1dfe
    444 
    445 Reverb off:
    446 $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000
    447 $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000
    448 $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000
    449 $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000
    450 
    451 Room:
    452 $007D, $005B, $6D80, $54B8, $BED0, $0000, $0000, $BA80
    453 $5800, $5300, $04D6, $0333, $03F0, $0227, $0374, $01EF
    454 $0334, $01B5, $0000, $0000, $0000, $0000, $0000, $0000
    455 $0000, $0000, $01B4, $0136, $00B8, $005C, $8000, $8000
    456 
    457 Studio Small:
    458 $0033, $0025  $70F0  $4FA8  $BCE0  $4410  $C0F0  $9C00
    459 $5280  $4EC0  $03E4  $031B  $03A4  $02AF  $0372  $0266
    460 $031C  $025D  $025C  $018E  $022F  $0135  $01D2  $00B7
    461 $018F  $00B5  $00B4  $0080  $004C  $0026  $8000  $8000
    462 
    463 Studio Medium:
    464 $00B1  $007F  $70F0  $4FA8  $BCE0  $4510  $BEF0  $B4C0
    465 $5280  $4EC0  $0904  $076B  $0824  $065F  $07A2  $0616
    466 $076C  $05ED  $05EC  $042E  $050F  $0305  $0462  $02B7
    467 $042F  $0265  $0264  $01B2  $0100  $0080  $8000  $8000
    468 
    469 Studio Large:
    470 $00E3  $00A9  $6F60  $4FA8  $BCE0  $4510  $BEF0  $A680
    471 $5680  $52C0  $0DFB  $0B58  $0D09  $0A3C  $0BD9  $0973
    472 $0B59  $08DA  $08D9  $05E9  $07EC  $04B0  $06EF  $03D2
    473 $05EA  $031D  $031C  $0238  $0154  $00AA  $8000  $8000
    474 
    475 Hall:
    476 $01A5  $0139  $6000  $5000  $4C00  $B800  $BC00  $C000
    477 $6000  $5C00  $15BA  $11BB  $14C2  $10BD  $11BC  $0DC1
    478 $11C0  $0DC3  $0DC0  $09C1  $0BC4  $07C1  $0A00  $06CD
    479 $09C2  $05C1  $05C0  $041A  $0274  $013A  $8000  $8000
    480 
    481 Space Echo:
    482 $033D  $0231  $7E00  $5000  $B400  $B000  $4C00  $B000
    483 $6000  $5400  $1ED6  $1A31  $1D14  $183B  $1BC2  $16B2
    484 $1A32  $15EF  $15EE  $1055  $1334  $0F2D  $11F6  $0C5D
    485 $1056  $0AE1  $0AE0  $07A2  $0464  $0232  $8000  $8000
    486 
    487 Echo:
    488 $0001  $0001  $7FFF  $7FFF  $0000  $0000  $0000  $8100
    489 $0000  $0000  $1FFF  $0FFF  $1005  $0005  $0000  $0000
    490 $1005  $0005  $0000  $0000  $0000  $0000  $0000  $0000
    491 $0000  $0000  $1004  $1002  $0004  $0002  $8000  $8000
    492 
    493 Delay:
    494 
    495 $0001  $0001  $7FFF  $7FFF  $0000  $0000  $0000  $0000
    496 $0000  $0000  $1FFF  $0FFF  $1005  $0005  $0000  $0000
    497 $1005  $0005  $0000  $0000  $0000  $0000  $0000  $0000
    498 $0000  $0000  $1004  $1002  $0004  $0002  $8000  $8000
    499 
    500 Half Echo:
    501 $0017  $0013  $70F0  $4FA8  $BCE0  $4510  $BEF0  $8500
    502 $5F80  $54C0  $0371  $02AF  $02E5  $01DF  $02B0  $01D7
    503 $0358  $026A  $01D6  $011E  $012D  $00B1  $011F  $0059
    504 $01A0  $00E3  $0058  $0040  $0028  $0014  $8000  $8000
    505 
    506 -------------------------------------------------------------
    507 Delay time calculation:
    508 Choose delay time in range 0-$7f. rXXXX means register $1f80XXXX.
    509 
    510 r1dd4 = dt*64.5 - r1dc0
    511 r1dd6 = dt*32.5 - r1dc2
    512 
    513 r1dd8 = r1dda + dt*32.5
    514 r1de0 = r1de2 + dt*32.5
    515 r1df4 = r1df8 + dt*32.5
    516 r1df6 = r1dfa + dt*32.5
    517 
    518 --------------------------------------------------------------------------
    519 doomed@c64.org <- corrections/additions     latest update -> psx.rules.org
    520 --------------------------------------------------------------------------
    521  5/jun/1999     First posting. Far from completion.
    522 
    523 (thanx to ppl in <>)
    524 --------------------------------------------------------------------------
    525 thanx & hello to the usual.
    526