Apple ALAC decoder not working -- magic cookie contents are faulty.

This commit is contained in:
Mike Brady
2016-08-30 23:33:08 +01:00
parent d4c247cdd0
commit 0479994c4c
4 changed files with 18 additions and 20 deletions
+14 -16
View File
@@ -16,25 +16,23 @@ typedef struct magicCookie {
magicCookie cookie;
ALACDecoder * theDecoder;
extern "C" int apple_alac_init(int frame_size,int sample_size,int sample_rate) {
extern "C" int apple_alac_init(int32_t fmtp[12]) {
memset(&cookie,0,sizeof(magicCookie));
#define CHANNELS_PER_FRAME 2
//create a magic cookie for the decoder
//create a magic cookie for the decoder from the fmtp information. It seems to be in the same format as a simple magic cookie
cookie.config.frameLength = Swap32NtoB(frame_size);
cookie.config.compatibleVersion = 0;
cookie.config.bitDepth = sample_size;
cookie.config.pb = 40;
cookie.config.mb = 10;
cookie.config.kb = 14;
cookie.config.numChannels = CHANNELS_PER_FRAME;
cookie.config.maxRun = Swap16NtoB(255);
cookie.config.maxFrameBytes = 0;
cookie.config.avgBitRate = 0;
cookie.config.sampleRate = Swap32NtoB(sample_rate);
cookie.config.frameLength = Swap32NtoB(352);
cookie.config.compatibleVersion = fmtp[2]; // should be zero, uint8_t
cookie.config.bitDepth = fmtp[3]; // uint8_t expected to be 16
cookie.config.pb = fmtp[4]; // uint8_t should be 40;
cookie.config.mb = fmtp[5]; // uint8_t should be 10;
cookie.config.kb = fmtp[6]; // uint8_t should be 14;
cookie.config.numChannels = fmtp[7]; // uint8_t expected to be 2
cookie.config.maxRun = Swap16NtoB(fmtp[8]); // uint16_t expected to be 255
cookie.config.maxFrameBytes = Swap32NtoB(fmtp[9]); // uint32_t should be 0;
cookie.config.avgBitRate = Swap32NtoB(fmtp[10]); // uint32_t should be 0;;
cookie.config.sampleRate = Swap32NtoB(fmtp[11]); // uint32_t expected to be 44100;
theDecoder = new ALACDecoder;
theDecoder->Init(&cookie, sizeof(magicCookie));
@@ -47,7 +45,7 @@ extern "C" int apple_alac_decode_frame(unsigned char *sampleBuffer, uint32_t buf
uint32_t numFrames = 0;
BitBuffer theInputBuffer;
BitBufferInit(&theInputBuffer, sampleBuffer, bufferLength);
theDecoder->Decode(&theInputBuffer, dest, Swap32BtoN(cookie.config.frameLength), CHANNELS_PER_FRAME, &numFrames);
theDecoder->Decode(&theInputBuffer, dest, Swap32BtoN(cookie.config.frameLength), cookie.config.numChannels, &numFrames);
*outsize = numFrames;
return 0;
}
+1 -1
View File
@@ -11,7 +11,7 @@
#endif
EXTERNC int apple_alac_init(int frame_size,int sample_size,int sample_rate);
EXTERNC int apple_alac_init(int32_t fmtp[12]);
EXTERNC int apple_alac_terminate();
EXTERNC int apple_alac_decode_frame(unsigned char *sampleBuffer, uint32_t bufferLength, unsigned char *dest, int *outsize);
+2 -2
View File
@@ -365,7 +365,7 @@ static int init_decoder(int32_t fmtp[12]) {
input_num_channels = fmtp[7];
input_bit_depth = fmtp[3];
input_bytes_per_frame = input_num_channels*(input_bit_depth+7)/8;
input_bytes_per_frame = input_num_channels*((input_bit_depth+7)/8);
alac = alac_create(input_bit_depth, input_num_channels);
if (!alac)
@@ -386,7 +386,7 @@ static int init_decoder(int32_t fmtp[12]) {
alac_allocate_buffers(alac);
#ifdef HAVE_APPLE_ALAC
apple_alac_init(max_frames_per_packet,input_bit_depth,input_sample_rate);
apple_alac_init(fmtp);
#endif
return 0;
+1 -1
View File
@@ -442,7 +442,7 @@ int parse_options(int argc, char **argv) {
}
/* Get the alac_decoder setting. */
if (config_lookup_string(config.cfg, "alac_decoder", &str)) {
if (config_lookup_string(config.cfg, "general.alac_decoder", &str)) {
if (strcasecmp(str, "hammerton") == 0)
config.use_apple_decoder = 0;
else if (strcasecmp(str, "apple") == 0) {