Fix small problem with uninitialized data fed to sndfile
[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 {
10         memset(&sf_info, 0 , sizeof(sf_info));
11         in.reset( sf_open(path.c_str(), SFM_READ, &sf_info), sf_close);
12         if (!in) throw failed_constructor();
13 }
14
15 SndFileImportableSource::~SndFileImportableSource ()
16 {
17 }
18
19 nframes_t
20 SndFileImportableSource::read (Sample* buffer, nframes_t nframes) 
21 {
22         nframes_t per_channel = nframes / sf_info.channels;
23         per_channel = sf_readf_float (in.get(), buffer, per_channel);
24         return per_channel * sf_info.channels;
25 }
26
27 uint
28 SndFileImportableSource::channels () const 
29 {
30         return sf_info.channels;
31 }
32
33 nframes_t
34 SndFileImportableSource::length () const 
35 {
36         return sf_info.frames;
37 }
38
39 nframes_t
40 SndFileImportableSource::samplerate() const
41 {
42         return sf_info.samplerate;
43 }
44
45 void
46 SndFileImportableSource::seek (nframes_t pos)
47 {
48         sf_seek (in.get(), 0, SEEK_SET);
49 }