13
0
livetrax/libs/audiographer/audiographer/sndfile/sndfile_reader.h
Carl Hetherington 73192bc1a7 Remove all use of nframes_t.
git-svn-id: svn://localhost/ardour2/branches/3.0@8166 d708f5d6-7413-0410-9779-e7cbd77b26cf
2010-12-03 22:26:29 +00:00

58 lines
1.6 KiB
C++

#ifndef AUDIOGRAPHER_SNDFILE_READER_H
#define AUDIOGRAPHER_SNDFILE_READER_H
#include "audiographer/utils/listed_source.h"
#include "audiographer/process_context.h"
#include "audiographer/sndfile/sndfile_base.h"
namespace AudioGrapher
{
/** Reader for audio files using libsndfile.
* Only short, int and float are valid template parameters
*/
template<typename T = DefaultSampleType>
class SndfileReader
: public virtual SndfileBase
, public ListedSource<T>
, public Throwing<>
{
public:
SndfileReader (std::string const & path) : SndfileHandle (path) {}
virtual ~SndfileReader () {}
SndfileReader (SndfileReader const & other) : SndfileHandle (other) {}
using SndfileHandle::operator=;
/** Read data into buffer in \a context, only the data is modified (not frame count)
* Note that the data read is output to the outputs, as well as read into the context
* \return number of frames read
*/
framecnt_t read (ProcessContext<T> & context)
{
if (throw_level (ThrowStrict) && context.channels() != channels() ) {
throw Exception (*this, boost::str (boost::format
("Wrong number of channels given to process(), %1% instead of %2%")
% context.channels() % channels()));
}
framecnt_t const frames_read = SndfileHandle::read (context.data(), context.frames());
ProcessContext<T> c_out = context.beginning (frames_read);
if (frames_read < context.frames()) {
c_out.set_flag (ProcessContext<T>::EndOfInput);
}
output (c_out);
return frames_read;
}
protected:
/// SndfileHandle has to be constructed directly by deriving classes
SndfileReader () {}
};
} // namespace
#endif // AUDIOGRAPHER_SNDFILE_READER_H