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 error
<< string_compose ("CAImportable: %1", cax
.mOperation
) << endmsg
;
28 throw failed_constructor ();
33 CAImportableSource::~CAImportableSource ()
38 CAImportableSource::read (Sample
* buffer
, nframes_t nframes
)
42 nframes_t per_channel
;
45 abl
.mNumberBuffers
= 1;
46 abl
.mBuffers
[0].mNumberChannels
= channels();
48 per_channel
= nframes
/ abl
.mBuffers
[0].mNumberChannels
;
50 while (nread
< per_channel
) {
52 UInt32 new_cnt
= per_channel
- nread
;
54 abl
.mBuffers
[0].mDataByteSize
= new_cnt
* abl
.mBuffers
[0].mNumberChannels
* sizeof(Sample
);
55 abl
.mBuffers
[0].mData
= buffer
+ nread
;
58 af
.Read (new_cnt
, &abl
);
59 } catch (CAXException
& cax
) {
60 error
<< string_compose("CAImportable: %1", cax
.mOperation
);
73 if (!at_end
&& nread
< per_channel
) {
76 return nread
* abl
.mBuffers
[0].mNumberChannels
;
81 CAImportableSource::channels () const
83 return af
.GetFileDataFormat().NumberChannels();
87 CAImportableSource::length () const
89 return af
.GetNumberFrames();
93 CAImportableSource::samplerate() const
95 CAStreamBasicDescription client_asbd
;
98 client_asbd
= af
.GetClientDataFormat ();
99 } catch (CAXException
& cax
) {
100 error
<< string_compose ("CAImportable: %1", cax
.mOperation
) << endmsg
;
104 return client_asbd
.mSampleRate
;
108 CAImportableSource::seek (nframes_t pos
)
112 } catch (CAXException
& cax
) {
113 error
<< string_compose ("CAImportable: %1 to %2", cax
.mOperation
, pos
) << endmsg
;