1 /***********************************************************************
2 * AUTHOR: Marcus Overhagen
5 ***********************************************************************/
7 #include <MediaTrack.h>
11 /*************************************************************
13 *************************************************************/
15 BSoundFile::BSoundFile()
21 BSoundFile::BSoundFile(const entry_ref
*ref
,
29 BSoundFile::~BSoundFile()
33 // fMediaTrack will be deleted by the BMediaFile destructor
38 BSoundFile::InitCheck() const
43 return fSoundFile
->InitCheck();
48 BSoundFile::SetTo(const entry_ref
*ref
,
52 BMediaTrack
* track
= fMediaTrack
;
54 fMediaFile
->ReleaseTrack(track
);
57 BMediaFile
* file
= fMediaFile
;
62 BFile
* file
= fSoundFile
;
66 if (open_mode
== B_READ_ONLY
) {
67 return _ref_to_file(ref
);
76 BSoundFile::FileFormat() const
83 BSoundFile::SamplingRate() const
90 BSoundFile::CountChannels() const
97 BSoundFile::SampleSize() const
104 BSoundFile::ByteOrder() const
111 BSoundFile::SampleFormat() const
113 return fSampleFormat
;
118 BSoundFile::FrameSize() const
120 return fSampleSize
* fChannelCount
;
125 BSoundFile::CountFrames() const
132 BSoundFile::IsCompressed() const
134 return fIsCompressed
;
139 BSoundFile::CompressionType() const
141 return fCompressionType
;
146 BSoundFile::CompressionName() const
148 return fCompressionName
;
153 BSoundFile::SetFileFormat(int32 format
)
155 fFileFormat
= format
;
161 BSoundFile::SetSamplingRate(int32 fps
)
164 return fSamplingRate
;
169 BSoundFile::SetChannelCount(int32 spf
)
172 return fChannelCount
;
177 BSoundFile::SetSampleSize(int32 bps
)
185 BSoundFile::SetByteOrder(int32 bord
)
193 BSoundFile::SetSampleFormat(int32 fmt
)
196 return fSampleFormat
;
201 BSoundFile::SetCompressionType(int32 type
)
208 BSoundFile::SetCompressionName(char *name
)
215 BSoundFile::SetIsCompressed(bool tf
)
222 BSoundFile::SetDataLocation(off_t offset
)
231 BSoundFile::SetFrameCount(off_t count
)
239 BSoundFile::ReadFrames(char *buf
,
249 BSoundFile::WriteFrames(char *buf
,
259 BSoundFile::SeekToFrame(off_t n
)
268 BSoundFile::FrameIndex() const
275 BSoundFile::FramesRemaining() const
277 return fFrameCount
- FrameIndex();
280 /*************************************************************
282 *************************************************************/
285 void BSoundFile::_ReservedSoundFile1() {}
286 void BSoundFile::_ReservedSoundFile2() {}
287 void BSoundFile::_ReservedSoundFile3() {}
290 BSoundFile::_init_raw_stats()
295 fFileFormat
= B_UNKNOWN_FILE
;
296 fSamplingRate
= 44100;
299 fByteOrder
= B_BIG_ENDIAN
;
300 fSampleFormat
= B_LINEAR_SAMPLES
;
303 fIsCompressed
= false;
304 fCompressionType
= -1;
305 fCompressionName
= NULL
;
310 BSoundFile::_ref_to_file(const entry_ref
*ref
)
313 BFile
* file
= new BFile(ref
, B_READ_ONLY
);
314 status
= file
->InitCheck();
315 if (status
!= B_OK
) {
319 BMediaFile
* media
= new BMediaFile(file
);
320 status
= media
->InitCheck();
321 if (status
!= B_OK
) {
326 media_file_format mfi
;
327 media
->GetFileFormatInfo(&mfi
);
328 switch (mfi
.family
) {
329 case B_AIFF_FORMAT_FAMILY
: fFileFormat
= B_AIFF_FILE
; break;
330 case B_WAV_FORMAT_FAMILY
: fFileFormat
= B_WAVE_FILE
; break;
331 default: fFileFormat
= B_UNKNOWN_FILE
; break;
334 BMediaTrack
* track
= 0;
336 while (trackNum
< media
->CountTracks()) {
337 track
= media
->TrackAt(trackNum
);
338 status
= track
->EncodedFormat(&mf
);
339 if (status
!= B_OK
) {
340 media
->ReleaseTrack(track
);
348 media
->ReleaseTrack(track
);
356 media_raw_audio_format
* raw
= 0;
357 if (mf
.type
== B_MEDIA_ENCODED_AUDIO
) {
358 raw
= &mf
.u
.encoded_audio
.output
;
360 if (mf
.type
== B_MEDIA_RAW_AUDIO
) {
361 raw
= &mf
.u
.raw_audio
;
370 fSamplingRate
= (int)raw
->frame_rate
;
371 fChannelCount
= raw
->channel_count
;
372 fSampleSize
= raw
->format
& 0xf;
373 fByteOrder
= raw
->byte_order
;
374 switch (raw
->format
) {
375 case media_raw_audio_format::B_AUDIO_FLOAT
:
376 fSampleFormat
= B_FLOAT_SAMPLES
;
378 case media_raw_audio_format::B_AUDIO_INT
:
379 case media_raw_audio_format::B_AUDIO_SHORT
:
380 case media_raw_audio_format::B_AUDIO_UCHAR
:
381 case media_raw_audio_format::B_AUDIO_CHAR
:
382 fSampleFormat
= B_LINEAR_SAMPLES
;
385 fSampleFormat
= B_UNDEFINED_SAMPLES
;
388 fFrameCount
= track
->CountFrames();
390 if (mf
.type
== B_MEDIA_ENCODED_AUDIO
) {
391 fIsCompressed
= true;
392 fCompressionType
= mf
.u
.encoded_audio
.encoding
;