nCine::Ps3AudioDevice class

PlayStation 3 implementation of IAudioDevice on top of PSL1GHT's libaudio.

The console has no mixer to talk to. Where the Dreamcast's AICA is a 64-voice wavetable part with its own sound RAM and the Wii's DSP runs libogc's ASND, lv2 hands a title exactly one thing: a ring of 256-sample blocks of interleaved 32-bit float samples, which the audio hardware scans out verbatim. Everything above that - mixing, resampling, panning, looping, stream queues - is this class, on the PPE.

Two consequences shape the whole design.**

Everything is mixed by hand into one output.* There is no per-source volume or pitch register to program, so setSourceGain() and friends only record a value that MixInto() applies while it walks the sources. That also means a source costs CPU only while it is audible, which is why MaxSources can be generous.

There is no mixer thread.* PSL1GHT ships no pthreads (see the NCINE_WITH_THREADS arm in ncine_options.cmake), so the ring cannot be topped up from a callback the way every other backend does it - it is filled from updatePlayers(), once per frame, on the main thread. That works because the ring is deliberately long: BlockCount blocks of 256 samples at 48 kHz is about 85 ms of audio, so a frame may take five times its 16.6 ms budget before the ring runs dry. What it costs is latency, which for this game is not a meaningful trade.

Resampling is linear interpolation from the buffer's own rate to the port's 48 kHz. The PPE has the headroom for it at these voice counts, and the alternative - resampling every asset offline to one rate - would trade quality for memory the console does not need to save.

Base classes

class AudioDeviceBase
Backend-independent part of an audio device.

Constructors, destructors, conversion operators

Ps3AudioDevice()
~Ps3AudioDevice() override

Public functions

auto isValid() const -> bool override
Returns true if 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 0 on 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, 0 detaches 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.0f disables 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 true if 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::Ps3AudioDevice::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