AicaAudioDevice class
Dreamcast implementation of IAudioDevice on top of the AICA.
Talks to the sound processor through KallistiOS directly instead of going through an OpenAL port. The AICA is a 64-channel wavetable synthesizer with 2 MB of sound RAM of its own, which is what makes audio nearly free in main memory here: a fully loaded sound lives in that separate pool and the SH4 only ever touches it again to change a volume.
The two kinds of player map onto two different parts of the hardware:
- A AudioBufferPlayer becomes one AICA channel (two for a stereo buffer, since a channel is mono) playing a sample out of sound RAM. When it has finished is predicted from the sample's length and rate: the only state the hardware offers is the key-on bit
snd_is_playing()reads, which is a control bit the console never clears by itself when a one-shot sample runs out (emulators do), so a source that waited for it was never given back and the pool ran dry after a few seconds of play. - A AudioStreamPlayer becomes one of KallistiOS's
snd_streamhandles, whose driver on the ARM keeps a ring buffer in sound RAM topped up from a callback. The callback is served out of the queue this class keeps, so the streaming players still see the queue interface they expect. There are only MaxStreams of these. - A sound much longer than a channel can address (over MaxSamplesForHalving, about six seconds at 22 kHz) is an AudioBufferPlayer to the engine but a stream handle here: it stays in main memory and is fed to the driver from there while it plays, so it sounds whole and at its full rate. Such a player cannot change its pitch once started, like any stream. A sound between the two limits is played on a channel at half its rate.
As with AsndAudioDevice the hardware has no notion of a listener, so panning and distance attenuation are computed here and folded into the channel volume and pan. The AICA does have a low-pass filter per channel, but the driver leaves it switched off and does not expose it, so setSourceLowPass() does nothing.
Base classes
- class AudioDeviceBase
- Backend-independent part of an audio device.
Constructors, destructors, conversion operators
- AicaAudioDevice()
- ~AicaAudioDevice() override
Public functions
- auto isValid() const -> bool override
- Returns
trueif the device was initialized successfully. - auto name() const -> const char* override
- Returns the name of the underlying device.
- void setGain(float gain) override
- Sets the listener gain (master volume).
- void updateListener(const Vector3f& position, const Vector3f& velocity) override
- Updates the position and velocity of the listener.
-
auto nativeFrequency() -> std::
int32_t override - Returns the native sample rate of the device.
-
auto registerPlayer(IAudioPlayer* player) -> std::
uint32_t override - Registers a player so it receives state and buffer queue updates, returning its source id.
- void updatePlayers() override
- Updates the state of every registered player, including the buffer queue of stream players.
-
auto createBuffer(BufferUsage usage) -> std::
uint32_t override - Creates an empty backend buffer, returning its id or
0on failure. -
void deleteBuffer(std::
uint32_t bufferId) override - Destroys a buffer previously returned by createBuffer().
-
auto uploadBuffer(std::
uint32_t bufferId, BufferFormat format, const void* data, std:: int32_t size, std:: int32_t frequency) -> bool override - Replaces the contents of a buffer with the specified samples.
-
void setSourceBuffer(std::
uint32_t sourceId, std:: uint32_t bufferId) override - Attaches a buffer to a source for non-streamed playback,
0detaches the current one. -
void setSourceGain(std::
uint32_t sourceId, float gain) override - Sets the gain of a source.
-
void setSourcePitch(std::
uint32_t sourceId, float pitch) override - Sets the pitch of a source, as a multiplier of its natural playback rate.
-
void setSourceLooping(std::
uint32_t sourceId, bool looping) override - Sets whether a source repeats its attached buffer.
-
void setSourceRelative(std::
uint32_t sourceId, bool relative) override - Sets whether the position of a source is relative to the listener.
-
void setSourcePosition(std::
uint32_t sourceId, const Vector3f& position) override - Sets the position of a source, in physical units.
-
void setSourceLowPass(std::
uint32_t sourceId, float value) override - Sets the low-pass amount of a source,
1.0fdisables the filter. -
auto sourceSampleOffset(std::
uint32_t sourceId) -> std:: int32_t override - Returns the playback position of a source in samples.
-
void setSourceSampleOffset(std::
uint32_t sourceId, std:: int32_t offset) override - Sets the playback position of a source in samples.
-
void playSource(std::
uint32_t sourceId) override - Starts or resumes a source.
-
void pauseSource(std::
uint32_t sourceId) override - Pauses a source at its current position.
-
void stopSource(std::
uint32_t sourceId) override - Stops a source.
-
auto isSourcePlaying(std::
uint32_t sourceId) -> bool override - Returns
trueif a source is still producing sound. -
void queueBuffer(std::
uint32_t sourceId, std:: uint32_t bufferId) override - Appends a buffer to the streaming queue of a source.
-
auto numProcessedBuffers(std::
uint32_t sourceId) -> std:: int32_t override - Returns the number of queued buffers a source has finished playing.
-
void unqueueBuffers(std::
uint32_t sourceId, std:: int32_t count, std:: uint32_t* bufferIds) override - Removes the specified number of played buffers from the front of the queue.
- void suspendDevice() override
- Suspends the audio device.
- void resumeDevice() override
- Resumes the audio device.
Protected functions
- void onBlockingOperationBegan() override
- Called when the outermost blocking operation begins, for a backend that has to react.
- void onBlockingOperationEnded() override
- Called when the last outstanding blocking operation ends (see onBlockingOperationBegan()).
Function documentation
void nCine:: AicaAudioDevice:: unqueueBuffers(std:: uint32_t sourceId,
std:: int32_t count,
std:: uint32_t* bufferIds) override
Removes the specified number of played buffers from the front of the queue.
| Parameters | |
|---|---|
| sourceId | |
| count | |
| bufferIds | Receives the ids of the removed buffers, must hold count entries |
void nCine:: AicaAudioDevice:: onBlockingOperationBegan() override protected
Called when the outermost blocking operation begins, for a backend that has to react.
The counting half of beginBlockingOperation() is done here so that no backend has to: two independent owners already open these windows (a level load and the episode scan), and a backend whose "stopped" state is a flag rather than a count would have the inner end reopen its stream in the middle of the outer block. Overridden instead of beginBlockingOperation() itself.