2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
8 #include "MusePackDecoder.h"
9 #include "mpc/in_mpc.h"
12 MusePackDecoder::MusePackDecoder()
19 MusePackDecoder::~MusePackDecoder()
26 MusePackDecoder::GetCodecInfo(media_codec_info
*info
)
28 strcpy(info
->short_name
, "musepack");
29 strcpy(info
->pretty_name
, "MusePack audio codec based on mpcdec by Andree Buschmann");
34 MusePackDecoder::Setup(media_format
*ioEncodedFormat
, const void *infoBuffer
, size_t infoSize
)
36 if (infoBuffer
== NULL
|| infoSize
!= sizeof(MPC_decoder
))
39 fDecoder
= (MPC_decoder
*)infoBuffer
;
40 fFrameRate
= fDecoder
->fInfo
->simple
.SampleFreq
;
47 MusePackDecoder::NegotiateOutputFormat(media_format
*format
)
49 // ToDo: rework the underlying MPC engine to be more flexible
51 format
->type
= B_MEDIA_RAW_AUDIO
;
52 format
->u
.raw_audio
.frame_rate
= fFrameRate
;
53 format
->u
.raw_audio
.channel_count
= fDecoder
->fInfo
->simple
.Channels
;
54 format
->u
.raw_audio
.format
= media_raw_audio_format::B_AUDIO_FLOAT
;
55 format
->u
.raw_audio
.byte_order
= B_MEDIA_HOST_ENDIAN
;
56 format
->u
.raw_audio
.buffer_size
= sizeof(MPC_SAMPLE_FORMAT
) * FRAMELEN
* 2;
57 // the buffer size is hardcoded in the MPC engine...
59 if (format
->u
.raw_audio
.channel_mask
== 0) {
60 format
->u
.raw_audio
.channel_mask
= (format
->u
.raw_audio
.channel_count
== 1) ?
61 B_CHANNEL_LEFT
: B_CHANNEL_LEFT
| B_CHANNEL_RIGHT
;
69 MusePackDecoder::SeekedTo(int64 frame
, bigtime_t time
)
77 MusePackDecoder::Decode(void *buffer
, int64
*_frameCount
, media_header
*mediaHeader
, media_decode_info
*info
)
79 // ToDo: add error checking (check for broken frames)
81 mediaHeader
->start_time
= (bigtime_t
) ((1000 * fFramePosition
) / (fFrameRate
/ 1000.0));
83 // printf("MusePackDecoder::Decode, start-time %.3f, played-frames %Ld\n", mediaHeader->start_time / 1000000.0, fFramePosition);
85 uint32 ring
= fDecoder
->Zaehler
;
86 int frameCount
= fDecoder
->DECODE((MPC_SAMPLE_FORMAT
*)buffer
);
88 fDecoder
->UpdateBuffer(ring
);
90 fFramePosition
+= frameCount
;
91 *_frameCount
= frameCount
;
93 return frameCount
> 0 ? B_OK
: B_LAST_BUFFER_ERROR
;