Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour2.git] / libs / ardour / sndfileimportable.cc
blobc9f6c4014f272f75e54b99610c2a70f7d3eebf63
1 #include "ardour/sndfileimportable.h"
2 #include <sndfile.h>
3 #include <iostream>
4 #include <cstring>
6 using namespace ARDOUR;
7 using namespace std;
9 /* FIXME: this was copied from sndfilesource.cc, at some point these should be merged */
10 int64_t
11 SndFileImportableSource::get_timecode_info (SNDFILE* sf, SF_BROADCAST_INFO* binfo, bool& exists)
13 if (sf_command (sf, SFC_GET_BROADCAST_INFO, binfo, sizeof (*binfo)) != SF_TRUE) {
14 exists = false;
15 return 0;
18 exists = true;
19 int64_t ret = (uint32_t) binfo->time_reference_high;
20 ret <<= 32;
21 ret |= (uint32_t) binfo->time_reference_low;
22 return ret;
25 SndFileImportableSource::SndFileImportableSource (const string& path)
27 memset(&sf_info, 0 , sizeof(sf_info));
28 in.reset( sf_open(path.c_str(), SFM_READ, &sf_info), sf_close);
29 if (!in) throw failed_constructor();
31 SF_BROADCAST_INFO binfo;
32 bool timecode_exists;
34 memset (&binfo, 0, sizeof (binfo));
35 timecode = get_timecode_info (in.get(), &binfo, timecode_exists);
37 if (!timecode_exists) {
38 timecode = 0;
42 SndFileImportableSource::~SndFileImportableSource ()
46 framecnt_t
47 SndFileImportableSource::read (Sample* buffer, framecnt_t nframes)
49 framecnt_t per_channel = nframes / sf_info.channels;
50 per_channel = sf_readf_float (in.get(), buffer, per_channel);
51 return per_channel * sf_info.channels;
54 uint
55 SndFileImportableSource::channels () const
57 return sf_info.channels;
60 framecnt_t
61 SndFileImportableSource::length () const
63 return (framecnt_t) sf_info.frames;
66 framecnt_t
67 SndFileImportableSource::samplerate () const
69 return sf_info.samplerate;
72 void
73 SndFileImportableSource::seek (framepos_t /*pos*/)
75 sf_seek (in.get(), 0, SEEK_SET);
78 framepos_t
79 SndFileImportableSource::natural_position () const
81 return (framepos_t) timecode;
84 bool
85 SndFileImportableSource::clamped_at_unity () const
87 int const type = sf_info.format & SF_FORMAT_TYPEMASK;
88 int const sub = sf_info.format & SF_FORMAT_SUBMASK;
89 /* XXX: this may not be the full list of formats that are unclamped */
90 return (sub != SF_FORMAT_FLOAT && sub != SF_FORMAT_DOUBLE && type != SF_FORMAT_OGG);