diff --git a/firmware/application/io_wave.cpp b/firmware/application/io_wave.cpp index 37830ec0..f8249205 100644 --- a/firmware/application/io_wave.cpp +++ b/firmware/application/io_wave.cpp @@ -124,9 +124,11 @@ uint16_t WAVFileReader::bits_per_sample() { Optional 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 WAVFileWriter::create( } Optional 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 WAVFileWriter::update_header() { } return { }; } + +Optional 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 { }; +} diff --git a/firmware/application/io_wave.hpp b/firmware/application/io_wave.hpp index 4898fb46..6bebc020 100644 --- a/firmware/application/io_wave.hpp +++ b/firmware/application/io_wave.hpp @@ -27,8 +27,7 @@ #include "file.hpp" #include "optional.hpp" -#include -#include +#include 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 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 update_header(); + Optional write_tags(); }; diff --git a/firmware/application/ui_record_view.cpp b/firmware/application/ui_record_view.cpp index 41d78313..640661a5 100644 --- a/firmware/application/ui_record_view.cpp +++ b/firmware/application/ui_record_view.cpp @@ -145,7 +145,11 @@ void RecordView::start() { case FileType::WAV: { auto p = std::make_unique(); - 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 { diff --git a/firmware/application/ui_soundboard.cpp b/firmware/application/ui_soundboard.cpp index 4fce6379..18077c9b 100644 --- a/firmware/application/ui_soundboard.cpp +++ b/firmware/application/ui_soundboard.cpp @@ -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 -#include - using namespace ctcss; using namespace portapack; diff --git a/firmware/application/ui_soundboard.hpp b/firmware/application/ui_soundboard.hpp index d1ceb5f5..828fbaf8 100644 --- a/firmware/application/ui_soundboard.hpp +++ b/firmware/application/ui_soundboard.hpp @@ -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"