1 #include "ardour/sndfileimportable.h"
6 using namespace ARDOUR
;
9 /* FIXME: this was copied from sndfilesource.cc, at some point these should be merged */
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
) {
19 int64_t ret
= (uint32_t) binfo
->time_reference_high
;
21 ret
|= (uint32_t) binfo
->time_reference_low
;
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
;
34 memset (&binfo
, 0, sizeof (binfo
));
35 timecode
= get_timecode_info (in
.get(), &binfo
, timecode_exists
);
37 if (!timecode_exists
) {
42 SndFileImportableSource::~SndFileImportableSource ()
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
;
55 SndFileImportableSource::channels () const
57 return sf_info
.channels
;
61 SndFileImportableSource::length () const
63 return (framecnt_t
) sf_info
.frames
;
67 SndFileImportableSource::samplerate () const
69 return sf_info
.samplerate
;
73 SndFileImportableSource::seek (framepos_t
/*pos*/)
75 sf_seek (in
.get(), 0, SEEK_SET
);
79 SndFileImportableSource::natural_position () const
81 return (framepos_t
) timecode
;
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
);