minor refactor
This commit is contained in:
+7
-4
@@ -10,6 +10,7 @@
|
||||
|
||||
static debug::Logger logger("ogg");
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using namespace audio;
|
||||
|
||||
static inline std::string vorbis_error_message(int code) {
|
||||
@@ -33,7 +34,7 @@ static inline std::string vorbis_error_message(int code) {
|
||||
}
|
||||
}
|
||||
|
||||
audio::PCM* ogg::load_pcm(const std::filesystem::path& file, bool headerOnly) {
|
||||
std::unique_ptr<audio::PCM> ogg::load_pcm(const fs::path& file, bool headerOnly) {
|
||||
OggVorbis_File vf;
|
||||
int code;
|
||||
if ((code = ov_fopen(file.u8string().c_str(), &vf))) {
|
||||
@@ -66,7 +67,9 @@ audio::PCM* ogg::load_pcm(const std::filesystem::path& file, bool headerOnly) {
|
||||
totalSamples = data.size() / channels / 2;
|
||||
}
|
||||
ov_clear(&vf);
|
||||
return new PCM(std::move(data), totalSamples, channels, 16, sampleRate, seekable);
|
||||
return std::make_unique<PCM>(
|
||||
std::move(data), totalSamples, channels, 16, sampleRate, seekable
|
||||
);
|
||||
}
|
||||
|
||||
class OggStream : public PCMStream {
|
||||
@@ -149,11 +152,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
PCMStream* ogg::create_stream(const std::filesystem::path& file) {
|
||||
std::unique_ptr<PCMStream> ogg::create_stream(const fs::path& file) {
|
||||
OggVorbis_File vf;
|
||||
int code;
|
||||
if ((code = ov_fopen(file.u8string().c_str(), &vf))) {
|
||||
throw std::runtime_error("vorbis: "+vorbis_error_message(code));
|
||||
}
|
||||
return new OggStream(std::move(vf));
|
||||
return std::make_unique<OggStream>(std::move(vf));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user