Пример #1
0
/*
 * Input	:	Filename
 * Output	: 	1 if succesful 0 if not
 */
int openFile(const char * name)
{
	readOff = readBuf;
	if((fp = fopen(name, "rb"))) {
		if(strstr(name, ".aac") || strstr(name, ".AAC")) {
			dec_state  = DEC_AAC;
			if((decoder = AACInitDecoder())) {
				if(fill_readBuffer(readBuf, &readOff, READ_BUF_SIZE, &dataLeft) == READ_BUF_SIZE) {
					int ret = 0;
					int bitOffset = 0, bitsAvail = dataLeft << 3;
					if(IS_ADIF(readBuf))
						ret = UnpackADIFHeader((AACDecInfo*)decoder, &readOff, &bitOffset, &bitsAvail);
					else
						ret = UnpackADTSHeader((AACDecInfo*)decoder, &readOff, &bitOffset, &bitsAvail);
					if(!ret) {
						AACGetLastFrameInfo(decoder, &inf);
						readOff = readBuf;
						dataLeft = READ_BUF_SIZE;
						return 1;
					}
				}
			}
		} else {
			dec_state = DEC_MP4;
			mp4cb.user_data = fp;
			if((infile = mp4ff_open_read(&mp4cb))) {
				if ((track = findAudioTrack(infile)) >= 0) {
					/* Decoder failed to initialize */
					if((decoder = AACInitDecoder())) {
						/* Decoder should be updated to decode raw blocks in the mp4
						 * IMPORTANT:
						 * mp4ff_get_channel_count will return the wrong value for mono in this state
						 */
						inf.sampRateCore = mp4ff_get_sample_rate(infile, track);
						samples = mp4ff_num_samples(infile, track);
						/*
						DECODER CONFIG:
						[AAAA ABBB] [BCCC CDEF]

						A)object type
						B)frequency index
						C)channel configuration
						D)bit: frame length flag
						E)bit: dependsOnCoreCoder
						F)bit: extensionFlag
						*/

						unsigned char * config_buf;
						unsigned int config_bufSize;
						mp4ff_get_decoder_config(infile, track, &config_buf, &config_bufSize);
						inf.profile =  AAC_PROFILE_LC;
						inf.nChans 	= (config_buf[1] >> 3) & 0xF;
						free(config_buf);
						if(!AACSetRawBlockParams(decoder, 0, &inf))
							return 1;
					}
				}
			}
		}
	}
Пример #2
0
/**************************************************************************************
 * Function:    AACDecode
 *
 * Description: decode AAC frame
 *
 * Inputs:      valid AAC decoder instance pointer (HAACDecoder)
 *              double pointer to buffer of AAC data
 *              pointer to number of valid bytes remaining in inbuf
 *              pointer to outbuf, big enough to hold one frame of decoded PCM samples
 *                (outbuf must be double-sized if SBR enabled)
 *
 * Outputs:     PCM data in outbuf, interleaved LRLRLR... if stereo
 *                number of output samples = 1024 per channel (2048 if SBR enabled)
 *              updated inbuf pointer
 *              updated bytesLeft
 *
 * Return:      0 if successful, error code (< 0) if error
 *
 * Notes:       inbuf pointer and bytesLeft are not updated until whole frame is
 *                successfully decoded, so if ERR_AAC_INDATA_UNDERFLOW is returned
 *                just call AACDecode again with more data in inbuf
 **************************************************************************************/
int AACDecode(HAACDecoder hAACDecoder, unsigned char **inbuf, int *bytesLeft, short *outbuf)
{
	int err, offset, bitOffset, bitsAvail;
	int ch, baseChan, baseChanSBR, elementChans;
	unsigned char *inptr;
	AACDecInfo *aacDecInfo = (AACDecInfo *)hAACDecoder;
#ifdef AAC_ENABLE_SBR
	int elementChansSBR;
#endif

	if (!aacDecInfo)
		return ERR_AAC_NULL_POINTER;

	/* make local copies (see "Notes" above) */
	inptr = *inbuf;
	bitOffset = 0;
	bitsAvail = (*bytesLeft) << 3;

	/* first time through figure out what the file format is */
	if (aacDecInfo->format == AAC_FF_Unknown) {
		if (bitsAvail < 32)
			return ERR_AAC_INDATA_UNDERFLOW;
		
		if (IS_ADIF(inptr)) {
			/* unpack ADIF header */
			aacDecInfo->format = AAC_FF_ADIF;
			err = UnpackADIFHeader(aacDecInfo, &inptr, &bitOffset, &bitsAvail);
			if (err)
				return err;
		} else {
			/* assume ADTS by default */
			aacDecInfo->format = AAC_FF_ADTS;
		}
	} 
	
	/* if ADTS, search for start of next frame */
	if (aacDecInfo->format == AAC_FF_ADTS) {
		/* can have 1-4 raw data blocks per ADTS frame (header only present for first one) */
		if (aacDecInfo->adtsBlocksLeft == 0) {
			offset = AACFindSyncWord(inptr, bitsAvail >> 3);
			if (offset < 0)
				return ERR_AAC_INDATA_UNDERFLOW;
			inptr += offset;
			bitsAvail -= (offset << 3);

			err = UnpackADTSHeader(aacDecInfo, &inptr, &bitOffset, &bitsAvail);
			if (err)
				return err;

			if (aacDecInfo->nChans == -1) {
				/* figure out implicit channel mapping if necessary */
				err = GetADTSChannelMapping(aacDecInfo, inptr, bitOffset, bitsAvail);
				if (err)
					return err;
			}
		}
		aacDecInfo->adtsBlocksLeft--;
	} else if (aacDecInfo->format == AAC_FF_RAW) {
Пример #3
0
int aac_openFile(char * name) {
	readOff = readBuffer;
	if((sndFile = fopen(name, "rb"))) {
		if((decoder = AACInitDecoder())) {
			if(fill_readBuffer(readBuffer, &readOff, READ_BUF_SIZE, &dataLeft) == READ_BUF_SIZE) {
				int ret = 0;
				int bitOffset = 0, bitsAvail = dataLeft << 3;
				if(IS_ADIF(readBuffer))
					ret = UnpackADIFHeader((AACDecInfo*)decoder, &readOff, &bitOffset, &bitsAvail);
				else
					ret = UnpackADTSHeader((AACDecInfo*)decoder, &readOff, &bitOffset, &bitsAvail);
				if(!ret) {
					AACGetLastFrameInfo(decoder, &inf);
					readOff = readBuffer;
					dataLeft = READ_BUF_SIZE;
					return 0;
				}
			}
		}
	}
	return -1;	/* sndFile == NULL */
}