kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit a58ba61f6867c6ae088dff891459753e6025cef8
parent 35b4b1a0c19d010e28a7e62c5e2bc17b2bae1861
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date:   Mon,  1 Apr 2019 17:14:04 +0000

Audio file IO: read_channels/write_channels

Diffstat:
Minclude/kfr/io/audiofile.hpp | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/kfr/io/audiofile.hpp b/include/kfr/io/audiofile.hpp @@ -76,6 +76,17 @@ struct audio_reader : public abstract_reader<T> /// @brief Reads interleaved audio using abstract_reader<T>::read; + univector2d<T> read_channels() { return read_channels(format().length); } + + univector2d<T> read_channels(size_t size) + { + univector<T> interleaved = read(size * format().channels); + univector2d<T> input_channels(format().channels, + univector<T>(interleaved.size() / format().channels)); + deinterleave(input_channels, interleaved); + return input_channels; + } + /// @brief Returns audio format description virtual const audio_format_and_length& format() const = 0; }; @@ -86,6 +97,13 @@ struct audio_writer : public abstract_writer<T> /// @brief Writes interleaved audio using abstract_writer<T>::write; + template <univector_tag Tag1, univector_tag Tag2> + size_t write_channels(const univector2d<T, Tag1, Tag2>& data) + { + const univector<T> interleaved = interleave(data); + return write(interleaved) / format().channels; + } + /// @brief Returns audio format description virtual const audio_format_and_length& format() const = 0; @@ -200,6 +218,8 @@ private: template <typename T> struct audio_reader_wav : audio_reader<T> { + using audio_reader<T>::read; + /// @brief Constructs WAV reader audio_reader_wav(std::shared_ptr<abstract_reader<>>&& reader) : reader(std::move(reader)) {