Difference between revisions of "CSND Shared Memory"

From 3dbrew
Jump to navigation Jump to search
Line 279: Line 279:
 
|}
 
|}
  
This command is used for initializing IMA-ADPCM state(when IMA-ADPCM encoding is used), prior to using command 0xE.
+
This command is used for initializing IMA-ADPCM state(when IMA-ADPCM encoding is used), prior to using command 0xE. [[CSND]] <nowiki>channelslotregister+0x18 = (u16)cmdword[3] | ((cmdword[4] & 0xFF)<<16)</nowiki>. [[CSND]] channelslotregister+0x1C = 0.
  
 
=Command 0xE=
 
=Command 0xE=

Revision as of 23:24, 26 August 2013

This page describes the structure of the CSND shared memory.

Type0 Command Structure

Index Byte Size Description
0x0 2 Offset in shared-memory for the command to process immediately after this one, when not 0xFFFF.
0x2 2 CommandID
0x4 1 This is initially zero when this command data is written by the user process, once the CSND module finishes processing the command this is set to 0x1. This flag is only set to value 1 for the first command(once processing for the entire command chain is finished) at the offset specified in the service command, not all type0 commands in the chain.
0x5 3 Padding?
0x8 4 The low 5-bits for this field is the the channel-index. This word is used for command parameters as well.
0xC 0x14 Command parameters

Type0 Commands

Command 0x1

Index Byte Size Description
0x2 2 CmdID 0x1
0xC 4 Value
0x10 0x10 Unused, all-zero.

This command starts playing the audio channel with value=1. Once the audio channel is playing, value=0 pauses the audio channel playback, and value=1 resumes the audio channel playback. Value=1 has no affect when the audio channel is already playing, likewise for value=0 when the audio channel is not playing.

Command 0x2

Index Byte Size Description
0x2 2 CmdID 0x2
0xC 1 Encoding, this is the same as the values used with command 0xE.
0x10 0x10 Unused, all-zero.

This sets the encoding field in the CSND channel CNT register(that field is cleared to zero first), command 0xE also sets this field.

Command 0x3

Index Byte Size Description
0x2 2 CmdID 0x3
0xC 4 Physical address of the first audio sample in the loop.
0x10 4 Total byte-size of the loop sample-data.

This initializes state for looping, when looping is used. This command is used immediately after command 0x8. CSND module writes these fields to the channel register for the second physical-address, and the channel register for the byte-size.

Command 0x4

Index Byte Size Description
0x2 2 CmdID 0x4
0xC 1 Looping value, this is the same as the values used with command 0xE.
0x10 0x10 Unused, all-zero.

This is the same as cmd2 except for the looping field. CSND will only write to this channel CNT register for updating the looping field if bit15 in the channel CNT register is value zero.


Command 0x5

Index Byte Size Description
0x2 2 CmdID 0x4
0xC 4 Value
0x10 0x10 Unused, all-zero.

When value=0, CSND module will clear bit7 in the channel CNT register. Otherwise, CSND module sets bit7 in the channel CNT register.

Command 0x6

Index Byte Size Description
0x2 2 CmdID 0x4
0xC 4 Value
0x10 0x10 Unused, all-zero.

This is the same as cmd5, except this updates channel CNT bit6 instead. CSND module will only update CNT here if bit15=0 in CNT.

Command 0x7

Index Byte Size Description
0x2 2 CmdID 0x4
0xC 1 Value
0x10 0x10 Unused, all-zero.

This is similar to cmd2, except this updates channel CNT bit1-bit0.

Command 0x8

Index Byte Size Description
0x2 2 CmdID 0x8
0xC 4 s32 value = (s32)(6.7027964E+07f / ((float)samplerate * 1.0f))

This sets the sample rate. This value is written to the channel CNT high-u16, which command 0xE also writes to. This command is used immediately after command 0xE.

Command 0x9

Index Byte Size Description
0x2 2 CmdID 0x9
0xC 4 Unknown
0x10 0x10 Usually zero?

This command must be used after command 0x8(user processes use cmd8 a second time before using this command). The parameter values seem to have no affect when not using IMA-ADPCM encoding?

Command 0xA

Index Byte Size Description
0x2 2 CmdID 0xA
0xC 4 Main physical address
0x10 0x4 Audio data byte-size
0x14 0xC Unused, all-zero.

Like command 0xE, this writes the specified parameters to the CSND channel slot registers for the main audio-data physical address, and the register for the data byte-size.

Command 0xB

Index Byte Size Description
0x2 2 CmdID 0xB
0xC 2 User processes set this to: cwav_imaadpcminfo.data
0x10 1 User processes set this to: cwav_imaadpcminfo.tableindex
0x11 0xF Unused, all-zero.

This command is used for initializing IMA-ADPCM state(when IMA-ADPCM encoding is used), prior to using command 0xE. CSND channelslotregister+0x18 = (u16)cmdword[3] | ((cmdword[4] & 0xFF)<<16). CSND channelslotregister+0x1C = 0.

Command 0xE

Index Byte Size Description
0x2 2 CmdID 0xE
0x8 4 See below.
0xC 4 See below. Usually zero?
0x10 4 See below. Usually zero?
0x14 4 Physical address for the audio data, for the main channel.
0x18 4 Physical address for the audio data, for the second channel(only needs set if a flag is set which enables using this address).
0x1C 4 Total byte-size for the audio data.

This initializes the CSND channel registers located at: 0x1EC03400 + (channel_index*0x20). Whether mono/stereo audio is used is determined via an unknown flag. When looping is used, audio playback initially begins with playing from the first physical address(using the byte-size from the channel register when audio playback was triggered). Once looping begins after the initial audio playback finishes, the second physical address is used for the beginning of the audio data instead(using the same byte-size used with the initial audio playback).

Parameter word 0x8

Bit Description
5-0 Channel index
9-6 ?
11-10 1 = enable looping, 2 = disable looping.
13-12 This sets the encoding, the names for the following encodings are from here. 0 = PCM8 and DSPADPCM, 1 = PCM16, 2 = IMAADPCM.
15-14 ?
31-16 Sample rate clamped to the following range(by the user process): 0x42-0xFFFF. This is the same value used with Cmd 0x8, except clamped.

Parameter word 0xC

Bit Description
15-0 Unknown, this value is clamped to the following range(by the user process): 0x0-0x8000.
31-16 Unknown, this value is clamped to the following range(by the user process): 0x0-0x8000.

Parameter word 0x10

Bit Description
15-0 Unknown, this value is clamped to the following range(by the user process): 0x0-0x8000.
31-16 Unknown, this value is clamped to the following range(by the user process): 0x0-0x8000.

Command 0x300

Index Byte Size Description
0x2 2 CmdID 0x300
0x8 0x18 Unused, all-zero.

CSND module writes state info(including state from CSND registers) for each audio channel to shared-memory for this command.