mstorsjo / fdk-aac

A standalone library of the Fraunhofer FDK AAC code from Android.

Home Page:https://sourceforge.net/projects/opencore-amr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why frame size reported is 1/4 the actual number of decoded bytes for AAC?

prashantrar opened this issue · comments

#define I2S_DMA_PAGE_SIZE_M4A 4096

err = aacDecoder_DecodeFrame(handle, decode_buf, I2S_DMA_PAGE_SIZE_M4A, 0);
		av_free_packet(&pkt);
		if (err == AAC_DEC_NOT_ENOUGH_BITS)
			continue;
		if (err != AAC_DEC_OK) {
			printf("Decode failed: %x\n", err);
			continue;
		}
		if(!info){
			info = aacDecoder_GetStreamInfo(handle);
			if (!info || info->sampleRate <= 0) {
				printf("No stream info\n");
				break;
			}
			printf("sampleRate: %d, frameSize: %d, numChannels: %d\n", info->sampleRate, info->frameSize, info->numChannels);
			frame_size = info->frameSize * info->numChannels;
		}
#if WRITE_RAW_DATA_SD
		do{
			res = f_write(&m_file, decode_buf, frame_size*2, (u32*)&bw);
			if(res){
				f_lseek(&m_file, 0); 
				printf("Write error.\n");
			}
			//printf("Write %d bytes.\n", bw);
		}while(bw < frame_size*2);
		bw = 0;
#endif

Above is my rough code example for decoding an m4a file and writing the RAW pcm data as a file into SDCARD.

My question here is that for AAC-LC the frame_size obtained from aacDecoder_GetStreamInfo is 1024, we multiply this by number of channels but unless I supply a decode buffer of size 4096 and write 4096 bytes of decoded data into SDCARD I am unable to get the correct PCM data.

Why is aacDecoder_GetStreamInfo returning a frame size of 1024 when the actual number of decoded bytes is 4096 for AAC-LC.

Because the frame size returned by aacDecoder_GetStreamInfo is the number of samples per frame. You need to multiply this by the number of channels and by 2 (for 16 bits per sample).