portapack-mayhem/firmware/application/io_convert.hpp
Mark Thompson d6b0173e7a
C8 capture support (#1286)
* C8 conversion

* C8 conversion

* C8 support

* C8 support

* C8 support

* C8 support

* Don't auto-convert GPS C8 files

* C8 support

* C8 support

* C8 support

* Remove hang workaround (different PR)

* Comment change

* Clang

* Clang

* Clang

* Merged change from PR #1287

* C8 support

* C8 support

* Improve bandwidth display

* Merged minor optimization from PR 1289

* Merge change from PR 1289

* Use complex types for C8/C16 conversion

* C8 support

* C8 support

* C8 support

* C8 support

* Roll back changes

* Roll back C8 changes

* C8 support

* C8 support

* C8 support

* C8 support

* C8 support

* Don't transmit samples past EOF

* Don't transmit samples past EOF

* Clang

* Clang attempt

* Clang attempt

* C8 support

* Clang
2023-07-22 02:20:56 -05:00

82 lines
2.4 KiB
C++

/*
* Copyright (C) 2023 Mark Thompson
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include "io_file.hpp"
#include "io.hpp"
#include "file.hpp"
#include "optional.hpp"
#include <cstdint>
namespace file_convert {
void c8_to_c16(const void* buffer, File::Size bytes);
void c32_to_c16(const void* buffer, File::Size bytes);
void c16_to_c8(const void* buffer, File::Size bytes);
} /* namespace file_convert */
class FileConvertReader : public stream::Reader {
public:
FileConvertReader() = default;
FileConvertReader(const FileConvertReader&) = delete;
FileConvertReader& operator=(const FileConvertReader&) = delete;
FileConvertReader(FileConvertReader&& file) = delete;
FileConvertReader& operator=(FileConvertReader&&) = delete;
Optional<File::Error> open(const std::filesystem::path& filename);
File::Result<File::Size> read(void* const buffer, const File::Size bytes) override;
const File& file() const& { return file_; }
bool convert_c8_to_c16{};
bool convert_c32_to_c16{};
protected:
File file_{};
uint64_t bytes_read_{0};
};
class FileConvertWriter : public stream::Writer {
public:
FileConvertWriter() = default;
FileConvertWriter(const FileConvertWriter&) = delete;
FileConvertWriter& operator=(const FileConvertWriter&) = delete;
FileConvertWriter(FileConvertWriter&& file) = delete;
FileConvertWriter& operator=(FileConvertWriter&&) = delete;
Optional<File::Error> create(const std::filesystem::path& filename);
File::Result<File::Size> write(const void* const buffer, const File::Size bytes) override;
const File& file() const& { return file_; }
bool convert_c16_to_c8{};
protected:
File file_{};
uint64_t bytes_written_{0};
};