Added "artist" and "title" (=frequency) info chunks to WAV files

This commit is contained in:
furrtek 2017-08-12 14:29:54 +01:00
parent 7f97a090e4
commit 96880d2fc6
5 changed files with 53 additions and 17 deletions

View File

@ -124,9 +124,11 @@ uint16_t WAVFileReader::bits_per_sample() {
Optional<File::Error> WAVFileWriter::create( Optional<File::Error> WAVFileWriter::create(
const std::filesystem::path& filename, const std::filesystem::path& filename,
size_t sampling_rate_set size_t sampling_rate_set,
std::string title_set
) { ) {
sampling_rate = sampling_rate_set; sampling_rate = sampling_rate_set;
title = title_set;
const auto create_error = FileWriter::create(filename); const auto create_error = FileWriter::create(filename);
if( create_error.is_valid() ) { if( create_error.is_valid() ) {
return create_error; return create_error;
@ -136,7 +138,7 @@ Optional<File::Error> WAVFileWriter::create(
} }
Optional<File::Error> WAVFileWriter::update_header() { 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); const auto seek_0_result = file.seek(0);
if( seek_0_result.is_error() ) { if( seek_0_result.is_error() ) {
return seek_0_result.error(); return seek_0_result.error();
@ -152,3 +154,16 @@ Optional<File::Error> WAVFileWriter::update_header() {
} }
return { }; 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 { };
}

View File

@ -27,8 +27,7 @@
#include "file.hpp" #include "file.hpp"
#include "optional.hpp" #include "optional.hpp"
#include <cstddef> #include <string.h>
#include <cstdint>
struct fmt_pcm_t { struct fmt_pcm_t {
constexpr fmt_pcm_t( constexpr fmt_pcm_t(
@ -64,8 +63,9 @@ private:
struct header_t { struct header_t {
constexpr header_t( constexpr header_t(
const uint32_t sampling_rate, const uint32_t sampling_rate,
const uint32_t data_chunk_size const uint32_t data_chunk_size,
) : cksize { sizeof(header_t) + data_chunk_size - 8 }, const uint32_t info_chunk_size
) : cksize { sizeof(header_t) + data_chunk_size + info_chunk_size - 8 },
fmt { sampling_rate }, fmt { sampling_rate },
data { data_chunk_size } data { data_chunk_size }
{ {
@ -79,6 +79,27 @@ private:
data_t data; 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 { class WAVFileReader : public FileReader {
public: public:
WAVFileReader() = default; WAVFileReader() = default;
@ -145,16 +166,21 @@ public:
WAVFileWriter& operator=(WAVFileWriter&&) = delete; WAVFileWriter& operator=(WAVFileWriter&&) = delete;
~WAVFileWriter() { ~WAVFileWriter() {
write_tags();
update_header(); update_header();
} }
Optional<File::Error> create( Optional<File::Error> create(
const std::filesystem::path& filename, const std::filesystem::path& filename,
size_t sampling_rate size_t sampling_rate,
std::string title_set
); );
private: private:
uint32_t sampling_rate { 0 }; uint32_t sampling_rate { 0 };
uint32_t info_chunk_size { 0 };
std::string title { };
Optional<File::Error> update_header(); Optional<File::Error> update_header();
Optional<File::Error> write_tags();
}; };

View File

@ -145,7 +145,11 @@ void RecordView::start() {
case FileType::WAV: case FileType::WAV:
{ {
auto p = std::make_unique<WAVFileWriter>(); 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() ) { if( create_error.is_valid() ) {
handle_error(create_error.value()); handle_error(create_error.value());
} else { } else {

View File

@ -25,14 +25,8 @@
#include "ui_soundboard.hpp" #include "ui_soundboard.hpp"
#include "lfsr_random.hpp" #include "lfsr_random.hpp"
#include "portapack.hpp"
#include "string_format.hpp" #include "string_format.hpp"
#include "portapack_shared_memory.hpp"
#include <cstring>
#include <vector>
using namespace ctcss; using namespace ctcss;
using namespace portapack; using namespace portapack;

View File

@ -27,10 +27,7 @@
#include "ui_widget.hpp" #include "ui_widget.hpp"
#include "ui_font_fixed_8x16.hpp" #include "ui_font_fixed_8x16.hpp"
#include "baseband_api.hpp" #include "baseband_api.hpp"
#include "ui_navigation.hpp"
#include "ui_receiver.hpp" #include "ui_receiver.hpp"
#include "utility.hpp"
#include "message.hpp"
#include "io_wave.hpp" #include "io_wave.hpp"
#include "ctcss.hpp" #include "ctcss.hpp"