30#ifndef APF_SNDFILETOOLS_H
31#define APF_SNDFILETOOLS_H
46inline SndfileHandle
load_sndfile(
const std::string& name,
size_t sample_rate
53 throw std::logic_error(
"apf::load_sndfile(): Empty file name!");
56 auto handle = SndfileHandle(name, SFM_READ);
60 if (!handle.rawHandle())
62 if (!handle.channels())
65 throw std::logic_error(
66 "apf::load_sndfile(): \"" + name +
"\" couldn't be loaded!");
71 const size_t true_sample_rate = handle.samplerate();
72 if (sample_rate != true_sample_rate)
74 throw std::logic_error(
"apf::load_sndfile(): \"" + name
75 +
"\" has sample rate " +
str::A2S(true_sample_rate) +
" instead of "
82 const size_t true_channels = handle.channels();
84 if (channels != true_channels)
86 throw std::logic_error(
"apf::load_sndfile(): \"" + name +
"\" has "
87 +
str::A2S(true_channels) +
" channels instead of "
std::string A2S(const T &input)
Converter "Anything to String".
Audio Processing Framework.
SndfileHandle load_sndfile(const std::string &name, size_t sample_rate, size_t channels)
Load sound file, throw exception if something's wrong.