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