refactor: decoder utilizing ffmpeg and ma decoders#1050
Conversation
closetcaiman
left a comment
There was a problem hiding this comment.
lgtm,
nice job deduplicating this!
closetcaiman
left a comment
There was a problem hiding this comment.
Nice job including the decoder-specific errors. I also like the namespace usage instead of a class with static methods, it feels a lot more cpp-like and modern. I left a few nitpicks.
| const ma_uint32 outRate = | ||
| outputSampleRate > 0 ? static_cast<ma_uint32>(outputSampleRate) : 0; | ||
| ma_decoder_config config = ma_decoder_config_init(ma_format_f32, 0, outRate); | ||
| static ma_decoding_backend_vtable *customBackends[] = { |
There was a problem hiding this comment.
from clang-tidy: Do not declare C-style arrays, use 'std::array' instead
either resolve or ignore if it's ma-specific, but add a comment.
There was a problem hiding this comment.
miniaudio is basically c library, so I think in this case we would like to leave it as it is
| ma_decoding_backend_libvorbis, | ||
| ma_decoding_backend_libopus, | ||
| }; | ||
| config.ppCustomBackendVTables = customBackends; |
There was a problem hiding this comment.
from clang-tidy: Do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead
either resolve or ignore if it's ma-specific, but add a comment.
There was a problem hiding this comment.
miniaudio is basically c library, so I think in this case we would like to leave it as it is
| AudioFormat detectAudioFormat(const void *data, size_t size); | ||
|
|
||
| static constexpr int CHUNK_SIZE = 4096; | ||
| bool pathHasExtension(const std::string &path, const std::vector<std::string> &extensions); | ||
|
|
||
| class AudioDecoder { | ||
| public: | ||
| AudioDecoder() = delete; | ||
| inline bool needsFFmpeg(AudioFormat format) { | ||
| return format == AudioFormat::MP4 || format == AudioFormat::M4A || format == AudioFormat::AAC; | ||
| } | ||
|
|
||
| [[nodiscard]] static AudioBufferResult decodeWithFilePath( | ||
| const std::string &path, | ||
| float sampleRate); | ||
| [[nodiscard]] static AudioBufferResult | ||
| decodeWithMemoryBlock(const void *data, size_t size, float sampleRate); | ||
| [[nodiscard]] static AudioBufferResult decodeWithPCMInBase64( | ||
| const std::string &data, | ||
| float inputSampleRate, | ||
| int inputChannelCount, | ||
| bool interleaved); | ||
| inline bool needsFFmpegByPath(const std::string &path) { |
There was a problem hiding this comment.
Aren't those [[nodiscard]] too?
Closes #
Introduced changes
Checklist