Skip to content

Commit

Permalink
Remove experimental support for Replaying C32 files (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotherNgineer committed Jul 23, 2023
1 parent c4df2e6 commit 828eb67
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 32 deletions.
3 changes: 0 additions & 3 deletions firmware/application/apps/ui_fileman.cpp
Expand Up @@ -41,7 +41,6 @@ static const fs::path txt_ext{u".TXT"};
static const fs::path ppl_ext{u".PPL"};
static const fs::path c8_ext{u".C8"};
static const fs::path c16_ext{u".C16"};
static const fs::path c32_ext{u".C32"};
static const fs::path cxx_ext{u".C*"};
static const fs::path png_ext{u".PNG"};
static const fs::path bmp_ext{u".BMP"};
Expand Down Expand Up @@ -87,8 +86,6 @@ fs::path get_partner_file(fs::path path) {
path.replace_extension(c8_ext);
if (!fs::file_exists(path))
path.replace_extension(c16_ext);
if (!fs::file_exists(path))
path.replace_extension(c32_ext);
} else
return {};

Expand Down
1 change: 0 additions & 1 deletion firmware/application/apps/ui_fileman.hpp
Expand Up @@ -76,7 +76,6 @@ class FileManBaseView : public View {
{u".BMP", &bitmap_icon_file_image, ui::Color::green()},
{u".C8", &bitmap_icon_file_iq, ui::Color::dark_cyan()},
{u".C16", &bitmap_icon_file_iq, ui::Color::dark_cyan()},
{u".C32", &bitmap_icon_file_iq, ui::Color::dark_cyan()},
{u".WAV", &bitmap_icon_file_wav, ui::Color::dark_magenta()},
{u".PPL", &bitmap_icon_file_iq, ui::Color::white()}, // PPL is the file extension for playlist app
{u"", &bitmap_icon_file, ui::Color::light_grey()} // NB: Must be last.
Expand Down
5 changes: 1 addition & 4 deletions firmware/application/file.cpp
Expand Up @@ -31,7 +31,6 @@
namespace fs = std::filesystem;
static const fs::path c8_ext{u".C8"};
static const fs::path c16_ext{u".C16"};
static const fs::path c32_ext{u".C32"};

Optional<File::Error> File::open_fatfs(const std::filesystem::path& filename, BYTE mode) {
auto result = f_open(&f, reinterpret_cast<const TCHAR*>(filename.c_str()), mode);
Expand Down Expand Up @@ -515,16 +514,14 @@ bool path_iequal(

bool is_cxx_capture_file(const path& filename) {
auto ext = filename.extension();
return path_iequal(c8_ext, ext) || path_iequal(c16_ext, ext) || path_iequal(c32_ext, ext);
return path_iequal(c8_ext, ext) || path_iequal(c16_ext, ext);
}

uint8_t capture_file_sample_size(const path& filename) {
if (path_iequal(filename.extension(), c8_ext))
return sizeof(complex8_t);
if (path_iequal(filename.extension(), c16_ext))
return sizeof(complex16_t);
if (path_iequal(filename.extension(), c32_ext))
return sizeof(complex32_t);
return 0;
}

Expand Down
23 changes: 1 addition & 22 deletions firmware/application/io_convert.cpp
Expand Up @@ -24,7 +24,6 @@

namespace fs = std::filesystem;
static const fs::path c8_ext = u".C8";
static const fs::path c32_ext = u".C32";

namespace file_convert {

Expand Down Expand Up @@ -60,41 +59,21 @@ void c8_to_c16(const void* buffer, File::Size bytes) {
}
}

// Convert c32 buffer to c16 buffer.
// Same buffer used for input & output; input size is bytes; output size is bytes/2.
void c32_to_c16(const void* buffer, File::Size bytes) {
complex32_t* src = (complex32_t*)buffer;
complex16_t* dest = (complex16_t*)buffer;

// Shift isn't used here because it would amplify noise at center freq since it's a signed number
// i.e. ((-1 >> 16) << 16) = -65536, whereas (-1 / 65536) * 65536 = 0
for (File::Size i = 0; i < bytes / sizeof(complex32_t); i++) {
auto re_out = src[i].real() / 65536;
auto im_out = src[i].imag() / 65536;
dest[i] = {(int8_t)re_out, (int8_t)im_out};
}
}

} /* namespace file_convert */

// Automatically enables C8/C16 or C32/C16 conversion based on file extension
// Automatically enables C8/C16 conversion based on file extension
Optional<File::Error> FileConvertReader::open(const std::filesystem::path& filename) {
convert_c8_to_c16 = path_iequal(filename.extension(), c8_ext);
convert_c32_to_c16 = path_iequal(filename.extension(), c32_ext);
return file_.open(filename);
}

// If C8 conversion enabled, half the number of bytes are read from the file & expanded to fill the whole buffer.
// If C32 conversion enabled, the full byte count is read from the file, and compressed to half the buffer size.
File::Result<File::Size> FileConvertReader::read(void* const buffer, const File::Size bytes) {
auto read_result = file_.read(buffer, convert_c8_to_c16 ? bytes / 2 : bytes);
if (read_result.is_ok()) {
if (convert_c8_to_c16) {
file_convert::c8_to_c16(buffer, read_result.value());
read_result = read_result.value() * 2;
} else if (convert_c32_to_c16) {
file_convert::c32_to_c16(buffer, read_result.value());
read_result = read_result.value() / 2;
}
bytes_read_ += read_result.value();
}
Expand Down
2 changes: 0 additions & 2 deletions firmware/application/io_convert.hpp
Expand Up @@ -32,7 +32,6 @@
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 */
Expand All @@ -52,7 +51,6 @@ class FileConvertReader : public stream::Reader {
const File& file() const& { return file_; }

bool convert_c8_to_c16{};
bool convert_c32_to_c16{};

protected:
File file_{};
Expand Down

0 comments on commit 828eb67

Please sign in to comment.