// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md #include "Encoder.hpp" #include "EncoderWAV.hpp" #include #include #include #include #include namespace audio { Encoder::Encoder(const std::string &filePath, const Format &frmt) : format(frmt), filePath(filePath) { fd = std::fopen(filePath.c_str(), "w"); if (fd == nullptr) { return; } constexpr size_t streamBufferSize = 6; streamBuffer = std::make_unique(streamBufferSize); setvbuf(fd, streamBuffer.get(), _IOFBF, streamBufferSize); isInitialized = true; } Encoder::~Encoder() { if (fd != nullptr) { std::fclose(fd); } } std::unique_ptr Encoder::Create(const std::string &filePath, const Format &frmt) { const auto extension = std::filesystem::path(filePath).extension(); const auto extensionLowercase = utils::stringToLowercase(extension); std::unique_ptr enc; if (extensionLowercase == ".wav") { enc = std::make_unique(filePath, frmt); } else { return nullptr; } if (enc->isInitialized) { return enc; } return nullptr; } } // namespace audio