diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2007-11-15 02:31:58 +0000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2007-11-15 02:31:58 +0000 |
commit | 27b022bdebcf324373c01f6aa4dc666630a2d5bf (patch) | |
tree | cd91767c542eb58bc5960980da454141c8bd80d0 /libs/ardour/ardour/importable_source.h | |
parent | 4076f7714aff134ae06859f16a7c4e9b88193afc (diff) |
Pass a path argument to ImportableSource rather than SNDFILE handle so resource management is contained
git-svn-id: svn://localhost/ardour2/trunk@2667 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/importable_source.h')
-rw-r--r-- | libs/ardour/ardour/importable_source.h | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/libs/ardour/ardour/importable_source.h b/libs/ardour/ardour/importable_source.h index 4f08498fce..5845d841b6 100644 --- a/libs/ardour/ardour/importable_source.h +++ b/libs/ardour/ardour/importable_source.h @@ -21,30 +21,39 @@ #define __ardour_importable_source_h__ #include <sndfile.h> +#include <pbd/failed_constructor.h> #include <ardour/types.h> namespace ARDOUR { class ImportableSource { public: - ImportableSource (SNDFILE* sf, SF_INFO* info) : in (sf), sf_info (info) {} + ImportableSource (const std::string& path) + : in (sf_open (path.c_str(), SFM_READ, &sf_info), sf_close) + { + if (!in) throw failed_constructor(); + + } + virtual ~ImportableSource() {} virtual nframes_t read (Sample* buffer, nframes_t nframes) { - nframes_t per_channel = nframes / sf_info->channels; - per_channel = sf_readf_float (in, buffer, per_channel); - return per_channel * sf_info->channels; + nframes_t per_channel = nframes / sf_info.channels; + per_channel = sf_readf_float (in.get(), buffer, per_channel); + return per_channel * sf_info.channels; } virtual float ratio() const { return 1.0f; } - uint channels() const { return sf_info->channels; } + uint channels() const { return sf_info.channels; } + + nframes_t length() const { return sf_info.frames; } - nframes_t length() const { return sf_info->frames; } + nframes_t samplerate() const { return sf_info.samplerate; } protected: - SNDFILE* in; - SF_INFO* sf_info; + SF_INFO sf_info; + boost::shared_ptr<SNDFILE> in; }; } |