1 #include "ardour/caimportable.h"
7 using namespace ARDOUR
;
11 CAImportableSource::CAImportableSource (const string
& path
)
14 af
.Open (path
.c_str());
16 CAStreamBasicDescription
file_format (af
.GetFileDataFormat());
17 CAStreamBasicDescription
client_format (file_format
);
19 /* set canonial form (PCM, native float packed, 32 bit, with the correct number of channels
20 and interleaved (since we plan to deinterleave ourselves)
23 client_format
.SetCanonical(client_format
.NumberChannels(), true);
24 af
.SetClientFormat (client_format
);
26 } catch (CAXException
& cax
) {
27 //Don't report an error here since there is one higher up in import.
28 //Since libsndfile gets tried second, any failures here may show as
29 //invalid errors in the Error log.
30 throw failed_constructor ();
35 CAImportableSource::~CAImportableSource ()
40 CAImportableSource::read (Sample
* buffer
, framecnt_t nframes
)
44 framecnt_t per_channel
;
47 abl
.mNumberBuffers
= 1;
48 abl
.mBuffers
[0].mNumberChannels
= channels();
50 per_channel
= nframes
/ abl
.mBuffers
[0].mNumberChannels
;
52 while (nread
< per_channel
) {
54 UInt32 new_cnt
= per_channel
- nread
;
56 abl
.mBuffers
[0].mDataByteSize
= new_cnt
* abl
.mBuffers
[0].mNumberChannels
* sizeof(Sample
);
57 abl
.mBuffers
[0].mData
= buffer
+ nread
;
60 af
.Read (new_cnt
, &abl
);
61 } catch (CAXException
& cax
) {
62 error
<< string_compose("CAImportable: %1", cax
.mOperation
);
75 if (!at_end
&& nread
< per_channel
) {
78 return nread
* abl
.mBuffers
[0].mNumberChannels
;
83 CAImportableSource::channels () const
85 return af
.GetFileDataFormat().NumberChannels();
89 CAImportableSource::length () const
91 return af
.GetNumberFrames();
95 CAImportableSource::samplerate () const
97 CAStreamBasicDescription client_asbd
;
100 client_asbd
= af
.GetClientDataFormat ();
101 } catch (CAXException
& cax
) {
102 error
<< string_compose ("CAImportable: %1", cax
.mOperation
) << endmsg
;
106 return client_asbd
.mSampleRate
;
110 CAImportableSource::seek (framepos_t pos
)
114 } catch (CAXException
& cax
) {
115 error
<< string_compose ("CAImportable: %1 to %2", cax
.mOperation
, pos
) << endmsg
;