22#include "utility/sound/decoder/wav_decoder.hpp"
24#define DR_WAV_IMPLEMENTATION
29namespace utility::sound
36 wavDecoderLogger.
debug() <<
"WAV decoder initialized";
41 wavDecoderLogger.
debug() <<
"WAV decoder destroyed";
47 auto extension = filePath.substr(filePath.find_last_of(
".") + 1);
48 return extension ==
"wav";
53 return type == AudioDecoderType::WAV;
56std::shared_ptr<utility::sound::AudioBuffer>
59 auto audioBuffer = std::make_shared<AudioBuffer>();
63 if (!drwav_init_memory(&wav, file->data().data(), file->size(),
nullptr)) {
68 decodedAudio.
channels = wav.channels;
72 static_cast<size_t>(wav.totalPCMFrameCount * wav.channels));
74 size_t framesRead = drwav_read_pcm_frames(&wav, wav.totalPCMFrameCount,
76 if (framesRead != wav.totalPCMFrameCount) {
85 audioBuffer->upload(decodedAudio);
LogMessage debug(std::source_location loc=std::source_location::current())
Begin a debug-level log message.
Standard output/error logger implementation.
bool canDecode(const std::string &filePath) const override
Determines whether the specified file can be decoded.
WAVDecoder()
Creates a WAV decoder instance.
std::shared_ptr< AudioBuffer > decode(std::shared_ptr< utility::File > file) override
Decodes a WAV file into an AudioBuffer.
~WAVDecoder() override
Destroys the WAV decoder instance.
Platform-specific default logger alias.
Contains decoded Pulse-Code Modulation (PCM) audio data.
uint16_t bitsPerSample
Number of bits used to represent each sample.
uint16_t channels
Number of audio channels.
std::vector< std::byte > samples
Raw PCM sample data.
ALenum format
OpenAL format corresponding to the decoded audio data.
uint32_t sampleRate
Audio sample rate in hertz.