2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
7 #include "MusePackReader.h"
9 #include <InterfaceDefs.h>
14 //#define TRACE_MUSEPACK_READER
15 #ifdef TRACE_MUSEPACK_READER
22 MusePackReader::MusePackReader()
27 MusePackReader::~MusePackReader()
33 MusePackReader::Copyright()
35 return "MusePack reader, " B_UTF8_COPYRIGHT
" by Axel Dörfler";
40 MusePackReader::Sniff(int32
*_streamCount
)
42 BPositionIO
*file
= dynamic_cast<BPositionIO
*>(Source());
44 // we cannot handle non seekable files for now
47 file
->Seek(0, SEEK_SET
);
48 int error
= fInfo
.ReadStreamInfo(file
);
50 // error came from engine
51 TRACE("MusePackReader: ReadStreamInfo() engine error %d\n", error
);
53 } else if (error
< B_OK
)
56 TRACE("MusePackReader: recognized MPC file\n");
63 MusePackReader::GetFileFormatInfo(media_file_format
*mff
)
66 mff
->capabilities
= media_file_format::B_READABLE
67 | media_file_format::B_KNOWS_ENCODED_AUDIO
68 | media_file_format::B_IMPERFECTLY_SEEKABLE
;
69 mff
->family
= B_MISC_FORMAT_FAMILY
;
71 strcpy(mff
->mime_type
, "audio/x-mpc");
72 strcpy(mff
->file_extension
, "mpc");
73 strcpy(mff
->short_name
, "MusePack");
74 strcpy(mff
->pretty_name
, "MusePack");
79 MusePackReader::AllocateCookie(int32 streamNumber
, void **_cookie
)
81 // we don't need a cookie - we only know one single stream
84 media_format_description description
;
85 description
.family
= B_MISC_FORMAT_FAMILY
;
86 description
.u
.misc
.file_format
= 'mpc ';
87 description
.u
.misc
.codec
= 'MPC7';
88 // 7 is the most recent stream version
90 status_t status
= BMediaFormats().GetFormatFor(description
, &fFormat
);
94 // allocate and initialize internal decoder
95 fDecoder
= new MPC_decoder(static_cast<BPositionIO
*>(Source()));
96 fDecoder
->RESET_Globals();
97 fDecoder
->RESET_Synthesis();
98 fDecoder
->SetStreamInfo(&fInfo
);
99 if (!fDecoder
->FileInit()) {
105 #if 0 // not required to report
106 fFormat
.u
.encoded_audio
.output
.frame_rate
= fInfo
.simple
.SampleFreq
;
107 fFormat
.u
.encoded_audio
.output
.channel_count
= fInfo
.simple
.Channels
;
108 fFormat
.u
.encoded_audio
.output
.format
= media_raw_audio_format::B_AUDIO_FLOAT
;
109 fFormat
.u
.encoded_audio
.output
.byte_order
= B_MEDIA_HOST_ENDIAN
;
110 fFormat
.u
.encoded_audio
.output
.buffer_size
= sizeof(MPC_SAMPLE_FORMAT
) * FRAMELEN
* 2;
118 MusePackReader::FreeCookie(void *cookie
)
120 // nothing to do here
126 MusePackReader::GetStreamInfo(void *cookie
, int64
*_frameCount
, bigtime_t
*_duration
,
127 media_format
*format
, const void **_infoBuffer
, size_t *_infoSize
)
132 *_frameCount
= FRAMELEN
* (int64
)fInfo
.simple
.Frames
;
133 *_duration
= bigtime_t(1000.0 * fInfo
.simple
.Frames
* FRAMELEN
134 / (fInfo
.simple
.SampleFreq
/ 1000.0) + 0.5);
138 // we provide the stream info in this place
139 *_infoBuffer
= (void *)fDecoder
;
140 *_infoSize
= sizeof(MPC_decoder
);
147 MusePackReader::Seek(void *cookie
, uint32 seekTo
, int64
*frame
, bigtime_t
*time
)
149 // we don't care, let the decoder do the work...
150 // (MPC not really differentiates between decoder and container)
156 MusePackReader::GetNextChunk(void *cookie
, const void **chunkBuffer
, size_t *chunkSize
,
157 media_header
*mediaHeader
)
159 // this one will never be called by our decoder