OpenTTD Source 20260304-master-g1baaa74679
SoundLoader_Opus Class Reference

Opus sound loader. More...

Inheritance diagram for SoundLoader_Opus:
SoundLoader PriorityBaseProvider< SoundLoader > BaseProvider< SoundLoader >

Public Member Functions

bool Load (SoundEntry &sound, bool new_format, std::vector< std::byte > &data) const override
 Load a sound from the file and offset in the given sound entry.
Public Member Functions inherited from SoundLoader
 SoundLoader (std::string_view name, std::string_view description, int priority)
 ~SoundLoader () override
 Unregister this sound loader.
Public Member Functions inherited from PriorityBaseProvider< SoundLoader >
constexpr PriorityBaseProvider (std::string_view name, std::string_view description, int priority)
int GetPriority () const
Public Member Functions inherited from BaseProvider< SoundLoader >
constexpr BaseProvider (std::string_view name, std::string_view description)
virtual ~BaseProvider ()=default
 Ensure the destructor of the sub classes are called as well.
std::string_view GetName () const
std::string_view GetDescription () const

Static Public Attributes

static constexpr uint16_t OPUS_SAMPLE_RATE = 48000
 OpusFile always decodes at 48kHz.
static constexpr uint8_t OPUS_SAMPLE_BITS = 16
 OpusFile op_read() uses 16 bits per sample.
static constexpr size_t MIN_OPUS_FILE_SIZE = 57U
 For good results, you will need at least 57 bytes (for a pure Opus-only stream).
static constexpr size_t DECODE_BUFFER_SAMPLES = 5760 * 2
 It is recommended that this be large enough for at least 120 ms of data at 48 kHz per channel (5760 values per channel).
static constexpr size_t DECODE_BUFFER_BYTES = DECODE_BUFFER_SAMPLES * sizeof(opus_int16)

Static Private Attributes

static SoundLoader_Opus instance {}

Additional Inherited Members

Protected Attributes inherited from PriorityBaseProvider< SoundLoader >
const int priority
Protected Attributes inherited from BaseProvider< SoundLoader >
const std::string_view name
const std::string_view description

Detailed Description

Opus sound loader.

Definition at line 23 of file soundloader_opus.cpp.

Constructor & Destructor Documentation

◆ SoundLoader_Opus()

SoundLoader_Opus::SoundLoader_Opus ( )
inline

Definition at line 25 of file soundloader_opus.cpp.

Member Function Documentation

◆ Load()

bool SoundLoader_Opus::Load ( SoundEntry & sound,
bool new_format,
std::vector< std::byte > & data ) const
inlineoverridevirtual

Load a sound from the file and offset in the given sound entry.

It is up to the implementations to update the sound's channels, bits_per_sample and rate.

Parameters
soundThe entry to load.
new_formatWhether this is an old format soundset (with some buggy data), or the new format.
[out]dataThe vector to write the decoded sound data into.
Returns
true iff the entry was loaded correctly.

Implements SoundLoader.

Definition at line 40 of file soundloader_opus.cpp.

References Debug, RandomAccessFile::GetPos(), MIN_OPUS_FILE_SIZE, OPUS_SAMPLE_BITS, OPUS_SAMPLE_RATE, RandomAccessFile::ReadBlock(), and RandomAccessFile::SeekTo().

Field Documentation

◆ DECODE_BUFFER_BYTES

size_t SoundLoader_Opus::DECODE_BUFFER_BYTES = DECODE_BUFFER_SAMPLES * sizeof(opus_int16)
staticconstexpr

Definition at line 38 of file soundloader_opus.cpp.

◆ DECODE_BUFFER_SAMPLES

size_t SoundLoader_Opus::DECODE_BUFFER_SAMPLES = 5760 * 2
staticconstexpr

It is recommended that this be large enough for at least 120 ms of data at 48 kHz per channel (5760 values per channel).

Smaller buffers will simply return less data, possibly consuming more memory to buffer the data internally.

Definition at line 37 of file soundloader_opus.cpp.

◆ instance

SoundLoader_Opus SoundLoader_Opus::instance {}
staticprivate

Definition at line 104 of file soundloader_opus.cpp.

◆ MIN_OPUS_FILE_SIZE

size_t SoundLoader_Opus::MIN_OPUS_FILE_SIZE = 57U
staticconstexpr

For good results, you will need at least 57 bytes (for a pure Opus-only stream).

Definition at line 31 of file soundloader_opus.cpp.

Referenced by Load().

◆ OPUS_SAMPLE_BITS

uint8_t SoundLoader_Opus::OPUS_SAMPLE_BITS = 16
staticconstexpr

OpusFile op_read() uses 16 bits per sample.

Definition at line 28 of file soundloader_opus.cpp.

Referenced by Load().

◆ OPUS_SAMPLE_RATE

uint16_t SoundLoader_Opus::OPUS_SAMPLE_RATE = 48000
staticconstexpr

OpusFile always decodes at 48kHz.

Definition at line 27 of file soundloader_opus.cpp.

Referenced by Load().


The documentation for this class was generated from the following file: