new files from sakari, missed last time
[ardour.git] / libs / ardour / sndfileimportable.cc
1 #include <ardour/sndfileimportable.h>
2 #include <sndfile.h>
3
4 using namespace ARDOUR;
5 using namespace std;
6
7 SndFileImportableSource::SndFileImportableSource (const string& path)
8         : in (sf_open (path.c_str(), SFM_READ, &sf_info), sf_close)
9 {
10         if (!in) throw failed_constructor();
11 }
12
13 SndFileImportableSource::~SndFileImportableSource ()
14 {
15 }
16
17 nframes_t
18 SndFileImportableSource::read (Sample* buffer, nframes_t nframes) 
19 {
20         nframes_t per_channel = nframes / sf_info.channels;
21         per_channel = sf_readf_float (in.get(), buffer, per_channel);
22         return per_channel * sf_info.channels;
23 }
24
25 uint
26 SndFileImportableSource::channels () const 
27 {
28         return sf_info.channels;
29 }
30
31 nframes_t
32 SndFileImportableSource::length () const 
33 {
34         return sf_info.frames;
35 }
36
37 nframes_t
38 SndFileImportableSource::samplerate() const
39 {
40         return sf_info.samplerate;
41 }
42
43 void
44 SndFileImportableSource::seek (nframes_t pos)
45 {
46         sf_seek (in.get(), 0, SEEK_SET);
47 }