mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-14 20:18:13 +00:00
Added "artist" and "title" (=frequency) info chunks to WAV files
This commit is contained in:
parent
7f97a090e4
commit
96880d2fc6
@ -124,9 +124,11 @@ uint16_t WAVFileReader::bits_per_sample() {
|
||||
|
||||
Optional<File::Error> WAVFileWriter::create(
|
||||
const std::filesystem::path& filename,
|
||||
size_t sampling_rate_set
|
||||
size_t sampling_rate_set,
|
||||
std::string title_set
|
||||
) {
|
||||
sampling_rate = sampling_rate_set;
|
||||
title = title_set;
|
||||
const auto create_error = FileWriter::create(filename);
|
||||
if( create_error.is_valid() ) {
|
||||
return create_error;
|
||||
@ -136,7 +138,7 @@ Optional<File::Error> WAVFileWriter::create(
|
||||
}
|
||||
|
||||
Optional<File::Error> WAVFileWriter::update_header() {
|
||||
header_t header { sampling_rate, (uint32_t)bytes_written };
|
||||
header_t header { sampling_rate, (uint32_t)bytes_written - sizeof(header_t), info_chunk_size };
|
||||
const auto seek_0_result = file.seek(0);
|
||||
if( seek_0_result.is_error() ) {
|
||||
return seek_0_result.error();
|
||||
@ -152,3 +154,16 @@ Optional<File::Error> WAVFileWriter::update_header() {
|
||||
}
|
||||
return { };
|
||||
}
|
||||
|
||||
Optional<File::Error> WAVFileWriter::write_tags() {
|
||||
tags_t tags { title };
|
||||
|
||||
const auto write_result = file.write(&tags, sizeof(tags));
|
||||
if( write_result.is_error() ) {
|
||||
return write_result.error();
|
||||
}
|
||||
|
||||
info_chunk_size = sizeof(tags);
|
||||
|
||||
return { };
|
||||
}
|
||||
|
@ -27,8 +27,7 @@
|
||||
#include "file.hpp"
|
||||
#include "optional.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string.h>
|
||||
|
||||
struct fmt_pcm_t {
|
||||
constexpr fmt_pcm_t(
|
||||
@ -64,8 +63,9 @@ private:
|
||||
struct header_t {
|
||||
constexpr header_t(
|
||||
const uint32_t sampling_rate,
|
||||
const uint32_t data_chunk_size
|
||||
) : cksize { sizeof(header_t) + data_chunk_size - 8 },
|
||||
const uint32_t data_chunk_size,
|
||||
const uint32_t info_chunk_size
|
||||
) : cksize { sizeof(header_t) + data_chunk_size + info_chunk_size - 8 },
|
||||
fmt { sampling_rate },
|
||||
data { data_chunk_size }
|
||||
{
|
||||
@ -79,6 +79,27 @@ private:
|
||||
data_t data;
|
||||
};
|
||||
|
||||
struct tags_t {
|
||||
constexpr tags_t(
|
||||
const std::string& title_str
|
||||
)
|
||||
{
|
||||
strcpy(title, title_str.c_str());
|
||||
cksize = sizeof(tags_t) - 8;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t list_id[4] { 'L', 'I', 'S', 'T' };
|
||||
uint32_t cksize { 0 };
|
||||
uint8_t info_id[4] { 'I', 'N', 'F', 'O' };
|
||||
uint8_t iart_id[4] { 'I', 'A', 'R', 'T' };
|
||||
uint32_t sckiart_size { 12 };
|
||||
char artist[12] { "PortaPack\0\0" };
|
||||
uint8_t inam_id[4] { 'I', 'N', 'A', 'M' };
|
||||
uint32_t sckinam_size { 64 };
|
||||
char title[64] { 0 };
|
||||
};
|
||||
|
||||
class WAVFileReader : public FileReader {
|
||||
public:
|
||||
WAVFileReader() = default;
|
||||
@ -145,16 +166,21 @@ public:
|
||||
WAVFileWriter& operator=(WAVFileWriter&&) = delete;
|
||||
|
||||
~WAVFileWriter() {
|
||||
write_tags();
|
||||
update_header();
|
||||
}
|
||||
|
||||
Optional<File::Error> create(
|
||||
const std::filesystem::path& filename,
|
||||
size_t sampling_rate
|
||||
size_t sampling_rate,
|
||||
std::string title_set
|
||||
);
|
||||
|
||||
private:
|
||||
uint32_t sampling_rate { 0 };
|
||||
uint32_t info_chunk_size { 0 };
|
||||
std::string title { };
|
||||
|
||||
Optional<File::Error> update_header();
|
||||
Optional<File::Error> write_tags();
|
||||
};
|
||||
|
@ -145,7 +145,11 @@ void RecordView::start() {
|
||||
case FileType::WAV:
|
||||
{
|
||||
auto p = std::make_unique<WAVFileWriter>();
|
||||
auto create_error = p->create(base_path.replace_extension(u".WAV"), sampling_rate);
|
||||
auto create_error = p->create(
|
||||
base_path.replace_extension(u".WAV"),
|
||||
sampling_rate,
|
||||
to_string_dec_uint(receiver_model.tuning_frequency()) + "Hz"
|
||||
);
|
||||
if( create_error.is_valid() ) {
|
||||
handle_error(create_error.value());
|
||||
} else {
|
||||
|
@ -25,14 +25,8 @@
|
||||
#include "ui_soundboard.hpp"
|
||||
|
||||
#include "lfsr_random.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
using namespace ctcss;
|
||||
using namespace portapack;
|
||||
|
||||
|
@ -27,10 +27,7 @@
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "message.hpp"
|
||||
#include "io_wave.hpp"
|
||||
#include "ctcss.hpp"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user