fix to use libFDKAAC signaling mode 1

It turned out that mode 1 is explicit, backward compatible signaling.
We don't have to implement it on our side.
This commit is contained in:
nu774 2013-11-08 12:23:52 +09:00
parent a26e3cf3e8
commit 71e4764062
3 changed files with 5 additions and 83 deletions

View File

@ -64,70 +64,6 @@ void aacenc_get_lib_info(LIB_INFO *info)
free(lib_info);
}
static const unsigned aacenc_sampling_freq_tab[] = {
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
16000, 12000, 11025, 8000, 7350, 0, 0, 0
};
static
unsigned sampling_freq_index(unsigned rate)
{
unsigned i;
for (i = 0; aacenc_sampling_freq_tab[i]; ++i)
if (aacenc_sampling_freq_tab[i] == rate)
return i;
return 0xf;
}
/*
* Append backward compatible SBR/PS signaling to implicit signaling ASC,
* if SBR/PS is present.
*/
int aacenc_mp4asc(const aacenc_param_t *params,
const uint8_t *asc, uint32_t ascsize,
uint8_t *outasc, uint32_t *outsize)
{
unsigned asc_sfreq = aacenc_sampling_freq_tab[(asc[0]&0x7)<<1 |asc[1]>>7];
unsigned shift = aacenc_is_dual_rate_sbr(params);
switch (params->profile) {
case AOT_SBR:
case AOT_PS:
if (!shift)
break;
if (*outsize < ascsize + 3)
return -1;
memcpy(outasc, asc, ascsize);
/* syncExtensionType:11 (value:0x2b7) */
outasc[ascsize+0] = 0x2b << 1;
outasc[ascsize+1] = 0x7 << 5;
/* extensionAudioObjectType:5 (value:5)*/
outasc[ascsize+1] |= 5;
/* sbrPresentFlag:1 (value:1) */
outasc[ascsize+2] = 0x80;
/* extensionSamplingFrequencyIndex:4 */
outasc[ascsize+2] |= sampling_freq_index(asc_sfreq << shift) << 3;
if (params->profile == AOT_SBR) {
*outsize = ascsize + 3;
return 0;
}
if (*outsize < ascsize + 5)
return -1;
/* syncExtensionType:11 (value:0x548) */
outasc[ascsize+2] |= 0x5;
outasc[ascsize+3] = 0x48;
/* psPresentFlag:1 (value:1) */
outasc[ascsize+4] = 0x80;
*outsize = ascsize + 5;
return 0;
}
if (*outsize < ascsize)
return -1;
memcpy(outasc, asc, ascsize);
*outsize = ascsize;
return 0;
}
static
int aacenc_channel_mode(const pcm_sample_description_t *format)
{

View File

@ -38,10 +38,6 @@ int aacenc_is_dual_rate_sbr(const aacenc_param_t *params);
void aacenc_get_lib_info(LIB_INFO *info);
int aacenc_mp4asc(const aacenc_param_t *params,
const uint8_t *asc, uint32_t ascsize,
uint8_t *outasc, uint32_t *outsize);
int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
const pcm_sample_description_t *format,
AACENC_InfoStruct *info);

View File

@ -785,15 +785,6 @@ int main(int argc, char **argv)
sample_format = pcm_get_format(reader);
/*
* We use explicit/hierarchical signaling for LOAS.
* Other than that, we request implicit signaling to FDK library, then
* append explicit/backward-compatible signaling to ASC in case of MP4FF.
*
* Explicit/backward-compatible signaling of SBR is the most recommended
* way in MPEG4 part3 spec, and seems the only way supported by iTunes.
* Since FDK library does not support it, we have to do it on our side.
*/
sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)&params);
if (sbr_mode && !aacenc_is_sbr_ratio_available()) {
fprintf(stderr, "WARNING: Only dual-rate SBR is available "
@ -801,7 +792,9 @@ int main(int argc, char **argv)
params.sbr_ratio = 2;
}
scale_shift = aacenc_is_dual_rate_sbr((aacenc_param_t*)&params);
params.sbr_signaling = (params.transport_format == TT_MP4_LOAS) ? 2 : 0;
params.sbr_signaling =
(params.transport_format == TT_MP4_LOAS) ? 2 :
(params.transport_format == TT_MP4_RAW) ? 1 : 0;
if (sbr_mode && !scale_shift)
params.sbr_signaling = 2;
@ -824,16 +817,13 @@ int main(int argc, char **argv)
if (!params.transport_format) {
uint32_t scale;
uint8_t mp4asc[32];
uint32_t ascsize = sizeof(mp4asc);
unsigned framelen = aacinfo.frameLength;
scale = sample_format->sample_rate >> scale_shift;
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
params.output_fp)) < 0)
goto END;
aacenc_mp4asc((aacenc_param_t*)&params, aacinfo.confBuf,
aacinfo.confSize, mp4asc, &ascsize);
m4af_set_decoder_specific_info(m4af, 0, mp4asc, ascsize);
m4af_set_decoder_specific_info(m4af, 0,
aacinfo.confBuf, aacinfo.confSize);
m4af_set_fixed_frame_duration(m4af, 0,
framelen >> scale_shift);
m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);