From 43c4584a3264cf52c929114dca0c0f25ce97d356 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 4 Oct 2016 10:04:38 -0700 Subject: [PATCH] Move WAV structs outside of writer. --- firmware/application/io_wave.hpp | 98 ++++++++++++++++---------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/firmware/application/io_wave.hpp b/firmware/application/io_wave.hpp index d315aadc..186b2fb2 100644 --- a/firmware/application/io_wave.hpp +++ b/firmware/application/io_wave.hpp @@ -29,6 +29,55 @@ #include #include +struct fmt_pcm_t { + constexpr fmt_pcm_t( + const uint32_t sampling_rate + ) : nSamplesPerSec { sampling_rate }, + nAvgBytesPerSec { nSamplesPerSec * nBlockAlign } + { + } + +private: + uint8_t ckID[4] { 'f', 'm', 't', ' ' }; + uint32_t cksize { 16 }; + uint16_t wFormatTag { 0x0001 }; + uint16_t nChannels { 1 }; + uint32_t nSamplesPerSec; + uint32_t nAvgBytesPerSec; + uint16_t nBlockAlign { 2 }; + uint16_t wBitsPerSample { 16 }; +}; + +struct data_t { + constexpr data_t( + const uint32_t size + ) : cksize { size } + { + } + +private: + uint8_t ckID[4] { 'd', 'a', 't', 'a' }; + uint32_t cksize { 0 }; +}; + +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 }, + fmt { sampling_rate }, + data { data_chunk_size } + { + } + +private: + uint8_t riff_id[4] { 'R', 'I', 'F', 'F' }; + uint32_t cksize { 0 }; + uint8_t wave_id[4] { 'W', 'A', 'V', 'E' }; + fmt_pcm_t fmt; + data_t data; +}; + class WAVFileWriter : public FileWriter { public: WAVFileWriter() = default; @@ -56,55 +105,6 @@ public: } private: - struct fmt_pcm_t { - constexpr fmt_pcm_t( - const uint32_t sampling_rate - ) : nSamplesPerSec { sampling_rate }, - nAvgBytesPerSec { nSamplesPerSec * nBlockAlign } - { - } - - private: - uint8_t ckID[4] { 'f', 'm', 't', ' ' }; - uint32_t cksize { 16 }; - uint16_t wFormatTag { 0x0001 }; - uint16_t nChannels { 1 }; - uint32_t nSamplesPerSec; - uint32_t nAvgBytesPerSec; - uint16_t nBlockAlign { 2 }; - uint16_t wBitsPerSample { 16 }; - }; - - struct data_t { - constexpr data_t( - const uint32_t size - ) : cksize { size } - { - } - - private: - uint8_t ckID[4] { 'd', 'a', 't', 'a' }; - uint32_t cksize { 0 }; - }; - - 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 }, - fmt { sampling_rate }, - data { data_chunk_size } - { - } - - private: - uint8_t riff_id[4] { 'R', 'I', 'F', 'F' }; - uint32_t cksize { 0 }; - uint8_t wave_id[4] { 'W', 'A', 'V', 'E' }; - fmt_pcm_t fmt; - data_t data; - }; - uint32_t sampling_rate; uint32_t bytes_written;