AmigaAudioDevice class
Classic Amiga implementation of IAudioDevice on top of ahi.device.
The mixer is the N64 backend's, transplanted: everything is software-mixed by hand into one 16-bit stereo stream on the main thread (32-bit integer accumulator, 32.32 fixed-point cursors, Q15 gains), topped up once per frame from updatePlayers(). What differs is only where the stream goes: blocks are handed to ahi.device as overlapping CMD_WRITE requests, which is the OS's retargetable audio - Paula's 14-bit trick on a stock machine, Pamela on a Vampire, HDMI on a PiStorm, a sound card where one exists - with AHI doing the final rate conversion, so the game mixes at the rate the performance preset can afford rather than whatever the user's AHI mode runs at. Where the device supports it, the block being filled is linked (ahir_Link) to the one still playing so playback is gapless - whether it does is measured rather than assumed, see ProbeLinkSupport() - and the queue is long enough to survive a late frame, see _maxInFlight.
Unlike the N64 there is no decimation-on-upload here: the machines this port targets have tens of megabytes of fast RAM, so sounds are stored as they arrive (8-bit stays 8-bit, the mixer widens on read - that half of the N64 design is kept, because it halves the resident bytes for the game's mostly 8-bit content at one shift per sample).
Base classes
- class AudioDeviceBase
- Backend-independent part of an audio device.
Constructors, destructors, conversion operators
- AmigaAudioDevice()
- ~AmigaAudioDevice() 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.
-
void setMixingFrequency(std::
int32_t frequency) override - Changes the rate the device mixes at, if the backend has one to change.
-
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.
Function documentation
void nCine:: AmigaAudioDevice:: setMixingFrequency(std:: int32_t frequency) override
Changes the rate the device mixes at, if the backend has one to change.
Only the software-mixing backends whose cost is linear in this rate honour it (the PSP's, where the mix is upsampled to the hardware's fixed rate, and the Amiga's, where AHI resamples the output); nativeFrequency() then reports the new rate, so the module music decoders that size themselves by it follow on the next stream they open. A rate the backend cannot run at, or 0, is ignored. Everywhere else this is a no-op.
void nCine:: AmigaAudioDevice:: 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 |