h6. [[SoundDMA]] h6(. » [[SoundDMA SWI Calls|SWI Calls]] h6((. » [[Sound_Configure]] h2. Channel Handler The Channel Handler provides interfaces to control the sound produced by each channel, and maintains internal tables necessary for the rest of the Sound system to produce these sounds. The interfaces can be used to set the overall volume and tuning, to attach the channels to different Voice Generators, and to start sounds with given pitch, amplitude and duration. The following internal tables are built and maintained: a mapping of voice names to internal voice numbers; a record for each channel of its volume, voice, pitch and timbre; and linear and logarithmic lookup tables for Voice Generators to scale their amplitude to the current overall volume setting. Fill Requests issued by the DMA Handler (SoundDMA) are routed through the Channel Handler to the correct [[Sound Voice Generator|Voice Generators]]. This allows any tables involved to be updated. |_<^{width:4em}. Offset |_<^. Contents | |>^. +0 |<^. Pointer to fill code | |>^. +4 |<^. Pointer to overrun fixup code | |>^. +8 |<^. Pointer to linear-to-log table or 0| |>^. +12 |<^. Pointer to log-scale table or 0| h4. Fill code The fill code handles fill requests from the DMA Handler (SoundDMA) It should translate the fill request to a series of calls to the Voice Generators, passing the required buffer offsets so that data from all channels correctly interleaves. Any unused channels within the buffer should be set to zero by the Channel Handler so they are silent. |_<^{width:4em}. Entry | |<^. R4 |<^. Buffer length (in bytes) | |<^. R6 |<^. Negative if Channel Handler configuration has changed | |<^. R8 |<^. Sample period in µS (NOTE: Due to a bug RO3.50 thru 3.70 incorrectly pass the Sample length instead)| |<^. R9 |<^. Pointer to [[Sound Channel Handler|Channel Handler]] (value of R3 in [[Sound_Configure|Sound_Configure]]) | |<^. R10 |<^. Buffer end address (exclusive) | |<^. R11 |<^. Interleave increment (1, 2, 4 or 8) | |<^. R12 |<^. Buffer start address (inclusive) | |<^. R13 |<^. IRQ stack | |<^. R14 |<^. Return address | h4. Notes The channel handler is entered in IRQ mode, with IRQs disabled and should re-enable IRQ's before calling the [[Sound Voice Generator|Voice Generator]] entries. The overrun fixup code is no longer supported in RISC OS and is never called. The pointer to the linear-to-log table holds the address of the base of an 8 Kbyte table which maps 32-bit signed integers directly to 8-bit signed volume-scaled logarithms in a suitable format for output to the VIDC chip. The table lookup can be performed as follows: <pre>LDRB log,[table,linear,LSR #19]</pre> The table takes into account the current volume setting (as set by [[Sound_Volume]]). This is the same table as is accessed by [[Sound_SoundLog]]. Note that this table is not used by the 16-bit sound system, which uses linear values. The pointer to the log-scale table holds the address of a 256-byte table which scales the amplitude of VIDC-format 8-bit signed logarithms from their maximum range down to a value scaled to the current volume setting. Voice Generators which operate on log sample data should use this table to adjust their overall volume. This is the same table as is accessed by [[Sound_LogScale]]. This table is not used by the 16-bit sound system. When the default channel handler of SoundChannels is in use, the pitch accumulator/oscillator for a channel will be initialised by any calls to [[Sound_Control]] (or related SWIs). The buffer fill count will also be initialised, based around the specified duration of the sound. The timbre accumulator/oscillator is not used. h4. Sound Channel Control Block (SCCB) The Channel Handler maintains a 256 byte [[Sound Channel Control Block|SCCB]] for each channel, which contains parameters and flags used by Voice Generators and an extension area for programmers to pass further data. The 9 initial words hold values that are normally stored in R0 - R8 inclusive. They are loaded from the SCCB using the instruction *LDMIA R9,{R0-R8}* Each time a Voice Generator completes a buffer fill and returns to the Channel Handler it returns an updated value for the Flags field in R0. It is the responsibility of the Channel Handler to store the returned flag byte and to update the other fields of each [[Sound Channel Control Block|SCCB]] as necessary. h4. See also * [[Sound_Configure]], [[Sound Voice Generator]], [[Sound Channel Control Block|SCCB]]