mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
2c116b15d5 | |||
e1adc17835 | |||
3c0f152d39 | |||
5732f1f6c5 | |||
a3271927b8 | |||
3de0e22dcc | |||
d533c8e002 | |||
c5eec15549 | |||
3b518efd31 | |||
556a3db11b | |||
4d48b091d4 | |||
d11b044131 | |||
6709cf694c | |||
7259767b09 | |||
3aa2787e34 |
50
ChangeLog
50
ChangeLog
@ -1,7 +1,55 @@
|
|||||||
2013-10-25 nu774 <honeycomb77@gmail.com>
|
2013-10-30 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
* update ChangeLog [HEAD]
|
* update ChangeLog [HEAD]
|
||||||
|
|
||||||
|
* bump version [v0.4.2]
|
||||||
|
|
||||||
|
* use tell() to obtain data chunk offset
|
||||||
|
|
||||||
|
* rename aacenc_result_t -> aacenc_frame_t, simplify write_sample()
|
||||||
|
|
||||||
|
* prepend 1 sample zero padding in case of SBR and enc_delay is odd
|
||||||
|
|
||||||
|
* cleanup interface of aac_encode_frame()
|
||||||
|
|
||||||
|
* add some copyright notice
|
||||||
|
|
||||||
|
2013-10-29 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* smart padding for better gapless playback
|
||||||
|
|
||||||
|
* fix unused variable warning
|
||||||
|
|
||||||
|
* fix warning: cast size_t as sprintf() arg to int
|
||||||
|
|
||||||
|
* fix vcxproj
|
||||||
|
|
||||||
|
* fix pcm_seek() to inline
|
||||||
|
|
||||||
|
2013-10-27 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.4.1]
|
||||||
|
|
||||||
|
* add --include-sbr-delay
|
||||||
|
|
||||||
|
* fix help message: show -I as shorthand for --ignorelength
|
||||||
|
|
||||||
|
* remove --sbr-signaling
|
||||||
|
|
||||||
|
2013-10-26 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* re-fix #ifdef cond for lrint()
|
||||||
|
|
||||||
|
* tag mapping: add recorded date and tempo, remove performer->artist
|
||||||
|
|
||||||
|
2013-10-25 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* fix MSVC12 build issue
|
||||||
|
|
||||||
|
* fix build issue on platform where fileno is a naive macro
|
||||||
|
|
||||||
|
* update ChangeLog
|
||||||
|
|
||||||
* bump version [v0.4.0]
|
* bump version [v0.4.0]
|
||||||
|
|
||||||
* update README
|
* update README
|
||||||
|
@ -98,6 +98,8 @@ copy ..\fdk-aac\libSYS\include\machine_type.h include\fdk-aac\ </Command>
|
|||||||
<ClCompile Include="..\src\aacenc.c" />
|
<ClCompile Include="..\src\aacenc.c" />
|
||||||
<ClCompile Include="..\src\caf_reader.c" />
|
<ClCompile Include="..\src\caf_reader.c" />
|
||||||
<ClCompile Include="..\src\compat_win32.c" />
|
<ClCompile Include="..\src\compat_win32.c" />
|
||||||
|
<ClCompile Include="..\src\extrapolater.c" />
|
||||||
|
<ClCompile Include="..\src\lpc.c" />
|
||||||
<ClCompile Include="..\src\lpcm.c" />
|
<ClCompile Include="..\src\lpcm.c" />
|
||||||
<ClCompile Include="..\src\m4af.c" />
|
<ClCompile Include="..\src\m4af.c" />
|
||||||
<ClCompile Include="..\src\main.c" />
|
<ClCompile Include="..\src\main.c" />
|
||||||
@ -111,7 +113,10 @@ copy ..\fdk-aac\libSYS\include\machine_type.h include\fdk-aac\ </Command>
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\missings\getopt.h" />
|
<ClInclude Include="..\missings\getopt.h" />
|
||||||
<ClInclude Include="..\src\aacenc.h" />
|
<ClInclude Include="..\src\aacenc.h" />
|
||||||
|
<ClInclude Include="..\src\caf_reader.h" />
|
||||||
|
<ClInclude Include="..\src\catypes.h" />
|
||||||
<ClInclude Include="..\src\compat.h" />
|
<ClInclude Include="..\src\compat.h" />
|
||||||
|
<ClInclude Include="..\src\lpc.h" />
|
||||||
<ClInclude Include="..\src\lpcm.h" />
|
<ClInclude Include="..\src\lpcm.h" />
|
||||||
<ClInclude Include="..\src\m4af.h" />
|
<ClInclude Include="..\src\m4af.h" />
|
||||||
<ClInclude Include="..\src\m4af_endian.h" />
|
<ClInclude Include="..\src\m4af_endian.h" />
|
||||||
|
@ -24,6 +24,12 @@
|
|||||||
<ClCompile Include="..\src\compat_win32.c">
|
<ClCompile Include="..\src\compat_win32.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\extrapolater.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\lpc.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\src\lpcm.c">
|
<ClCompile Include="..\src\lpcm.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -62,6 +68,9 @@
|
|||||||
<ClInclude Include="..\src\compat.h">
|
<ClInclude Include="..\src\compat.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\lpc.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\src\lpcm.h">
|
<ClInclude Include="..\src\lpcm.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -6,6 +6,8 @@ bin_PROGRAMS = fdkaac
|
|||||||
fdkaac_SOURCES = \
|
fdkaac_SOURCES = \
|
||||||
src/aacenc.c \
|
src/aacenc.c \
|
||||||
src/caf_reader.c \
|
src/caf_reader.c \
|
||||||
|
src/extrapolater.c \
|
||||||
|
src/lpc.c \
|
||||||
src/lpcm.c \
|
src/lpcm.c \
|
||||||
src/m4af.c \
|
src/m4af.c \
|
||||||
src/main.c \
|
src/main.c \
|
||||||
|
93
src/aacenc.c
93
src/aacenc.c
@ -13,6 +13,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "aacenc.h"
|
#include "aacenc.h"
|
||||||
|
|
||||||
|
int aacenc_is_sbr_ratio_available()
|
||||||
|
{
|
||||||
|
#if AACENCODER_LIB_VL0 < 3 || (AACENCODER_LIB_VL0==3 && AACENCODER_LIB_VL1<4)
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
LIB_INFO lib_info;
|
||||||
|
aacenc_get_lib_info(&lib_info);
|
||||||
|
return lib_info.version > 0x03040000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int aacenc_is_sbr_active(const aacenc_param_t *params)
|
int aacenc_is_sbr_active(const aacenc_param_t *params)
|
||||||
{
|
{
|
||||||
switch (params->profile) {
|
switch (params->profile) {
|
||||||
@ -26,6 +37,33 @@ int aacenc_is_sbr_active(const aacenc_param_t *params)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int aacenc_is_dual_rate_sbr(const aacenc_param_t *params)
|
||||||
|
{
|
||||||
|
if (params->profile == AOT_PS || params->profile == AOT_MP2_PS)
|
||||||
|
return 1;
|
||||||
|
else if (params->profile == AOT_SBR || params->profile == AOT_MP2_SBR)
|
||||||
|
return params->sbr_ratio == 0 || params->sbr_ratio == 2;
|
||||||
|
else if (params->profile == AOT_ER_AAC_ELD && params->lowdelay_sbr)
|
||||||
|
return params->sbr_ratio == 2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void aacenc_get_lib_info(LIB_INFO *info)
|
||||||
|
{
|
||||||
|
LIB_INFO *lib_info = 0;
|
||||||
|
lib_info = calloc(FDK_MODULE_LAST, sizeof(LIB_INFO));
|
||||||
|
if (aacEncGetLibInfo(lib_info) == AACENC_OK) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < FDK_MODULE_LAST; ++i) {
|
||||||
|
if (lib_info[i].module_id == FDK_AACENC) {
|
||||||
|
memcpy(info, &lib_info[i], sizeof(LIB_INFO));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(lib_info);
|
||||||
|
}
|
||||||
|
|
||||||
static const unsigned aacenc_sampling_freq_tab[] = {
|
static const unsigned aacenc_sampling_freq_tab[] = {
|
||||||
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
|
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
|
||||||
16000, 12000, 11025, 8000, 7350, 0, 0, 0
|
16000, 12000, 11025, 8000, 7350, 0, 0, 0
|
||||||
@ -50,10 +88,13 @@ int aacenc_mp4asc(const aacenc_param_t *params,
|
|||||||
uint8_t *outasc, uint32_t *outsize)
|
uint8_t *outasc, uint32_t *outsize)
|
||||||
{
|
{
|
||||||
unsigned asc_sfreq = aacenc_sampling_freq_tab[(asc[0]&0x7)<<1 |asc[1]>>7];
|
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) {
|
switch (params->profile) {
|
||||||
case AOT_SBR:
|
case AOT_SBR:
|
||||||
case AOT_PS:
|
case AOT_PS:
|
||||||
|
if (!shift)
|
||||||
|
break;
|
||||||
if (*outsize < ascsize + 3)
|
if (*outsize < ascsize + 3)
|
||||||
return -1;
|
return -1;
|
||||||
memcpy(outasc, asc, ascsize);
|
memcpy(outasc, asc, ascsize);
|
||||||
@ -65,10 +106,10 @@ int aacenc_mp4asc(const aacenc_param_t *params,
|
|||||||
/* sbrPresentFlag:1 (value:1) */
|
/* sbrPresentFlag:1 (value:1) */
|
||||||
outasc[ascsize+2] = 0x80;
|
outasc[ascsize+2] = 0x80;
|
||||||
/* extensionSamplingFrequencyIndex:4 */
|
/* extensionSamplingFrequencyIndex:4 */
|
||||||
outasc[ascsize+2] |= sampling_freq_index(asc_sfreq << 1) << 3;
|
outasc[ascsize+2] |= sampling_freq_index(asc_sfreq << shift) << 3;
|
||||||
if (params->profile == AOT_SBR) {
|
if (params->profile == AOT_SBR) {
|
||||||
*outsize = ascsize + 3;
|
*outsize = ascsize + 3;
|
||||||
break;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*outsize < ascsize + 5)
|
if (*outsize < ascsize + 5)
|
||||||
return -1;
|
return -1;
|
||||||
@ -78,13 +119,12 @@ int aacenc_mp4asc(const aacenc_param_t *params,
|
|||||||
/* psPresentFlag:1 (value:1) */
|
/* psPresentFlag:1 (value:1) */
|
||||||
outasc[ascsize+4] = 0x80;
|
outasc[ascsize+4] = 0x80;
|
||||||
*outsize = ascsize + 5;
|
*outsize = ascsize + 5;
|
||||||
break;
|
return 0;
|
||||||
default:
|
}
|
||||||
if (*outsize < ascsize)
|
if (*outsize < ascsize)
|
||||||
return -1;
|
return -1;
|
||||||
memcpy(outasc, asc, ascsize);
|
memcpy(outasc, asc, ascsize);
|
||||||
*outsize = ascsize;
|
*outsize = ascsize;
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +133,10 @@ int aacenc_channel_mode(const pcm_sample_description_t *format)
|
|||||||
{
|
{
|
||||||
uint32_t chanmask = format->channel_mask;
|
uint32_t chanmask = format->channel_mask;
|
||||||
|
|
||||||
if (format->channels_per_frame > 6)
|
if (format->channels_per_frame > 8)
|
||||||
return 0;
|
return 0;
|
||||||
if (!chanmask) {
|
if (!chanmask) {
|
||||||
static uint32_t defaults[] = { 0x4, 0x3, 0x7, 0, 0x37, 0x3f };
|
static uint32_t defaults[] = { 0x4, 0x3, 0x7, 0, 0x37, 0x3f, 0, 0x63f };
|
||||||
chanmask = defaults[format->channels_per_frame - 1];
|
chanmask = defaults[format->channels_per_frame - 1];
|
||||||
}
|
}
|
||||||
switch (chanmask) {
|
switch (chanmask) {
|
||||||
@ -108,6 +148,10 @@ int aacenc_channel_mode(const pcm_sample_description_t *format)
|
|||||||
case 0x107: return MODE_1_2_1;
|
case 0x107: return MODE_1_2_1;
|
||||||
case 0x607: return MODE_1_2_2;
|
case 0x607: return MODE_1_2_2;
|
||||||
case 0x60f: return MODE_1_2_2_1;
|
case 0x60f: return MODE_1_2_2_1;
|
||||||
|
#if AACENCODER_LIB_VL0 > 3 || (AACENCODER_LIB_VL0==3 && AACENCODER_LIB_VL1>=4)
|
||||||
|
case 0xff: return MODE_1_2_2_2_1;
|
||||||
|
case 0x63f: return MODE_7_1_REAR_SURROUND;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -118,8 +162,11 @@ int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
|
|||||||
{
|
{
|
||||||
int channel_mode;
|
int channel_mode;
|
||||||
int aot;
|
int aot;
|
||||||
|
LIB_INFO lib_info;
|
||||||
|
|
||||||
*encoder = 0;
|
*encoder = 0;
|
||||||
|
aacenc_get_lib_info(&lib_info);
|
||||||
|
|
||||||
if ((channel_mode = aacenc_channel_mode(format)) == 0) {
|
if ((channel_mode = aacenc_channel_mode(format)) == 0) {
|
||||||
fprintf(stderr, "ERROR: unsupported channel layout\n");
|
fprintf(stderr, "ERROR: unsupported channel layout\n");
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
@ -145,13 +192,21 @@ int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
|
|||||||
fprintf(stderr, "ERROR: unsupported sample rate\n");
|
fprintf(stderr, "ERROR: unsupported sample rate\n");
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
aacEncoder_SetParam(*encoder, AACENC_CHANNELMODE, channel_mode);
|
if (aacEncoder_SetParam(*encoder, AACENC_CHANNELMODE,
|
||||||
|
channel_mode) != AACENC_OK) {
|
||||||
|
fprintf(stderr, "ERROR: unsupported channel mode\n");
|
||||||
|
goto FAIL;
|
||||||
|
}
|
||||||
aacEncoder_SetParam(*encoder, AACENC_BANDWIDTH, params->bandwidth);
|
aacEncoder_SetParam(*encoder, AACENC_BANDWIDTH, params->bandwidth);
|
||||||
aacEncoder_SetParam(*encoder, AACENC_CHANNELORDER, 1);
|
aacEncoder_SetParam(*encoder, AACENC_CHANNELORDER, 1);
|
||||||
aacEncoder_SetParam(*encoder, AACENC_AFTERBURNER, !!params->afterburner);
|
aacEncoder_SetParam(*encoder, AACENC_AFTERBURNER, !!params->afterburner);
|
||||||
|
|
||||||
if (aot == AOT_ER_AAC_ELD && params->lowdelay_sbr)
|
aacEncoder_SetParam(*encoder, AACENC_SBR_MODE, params->lowdelay_sbr);
|
||||||
aacEncoder_SetParam(*encoder, AACENC_SBR_MODE, 1);
|
|
||||||
|
#if AACENCODER_LIB_VL0 > 3 || (AACENCODER_LIB_VL0==3 && AACENCODER_LIB_VL1>=4)
|
||||||
|
if (lib_info.version > 0x03040000)
|
||||||
|
aacEncoder_SetParam(*encoder, AACENC_SBR_RATIO, params->sbr_ratio);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (aacEncoder_SetParam(*encoder, AACENC_TRANSMUX,
|
if (aacEncoder_SetParam(*encoder, AACENC_TRANSMUX,
|
||||||
params->transport_format) != AACENC_OK) {
|
params->transport_format) != AACENC_OK) {
|
||||||
@ -187,7 +242,7 @@ FAIL:
|
|||||||
int aac_encode_frame(HANDLE_AACENCODER encoder,
|
int aac_encode_frame(HANDLE_AACENCODER encoder,
|
||||||
const pcm_sample_description_t *format,
|
const pcm_sample_description_t *format,
|
||||||
const int16_t *input, unsigned iframes,
|
const int16_t *input, unsigned iframes,
|
||||||
uint8_t **output, uint32_t *olen, uint32_t *osize)
|
aacenc_frame_t *output)
|
||||||
{
|
{
|
||||||
uint32_t ilen = iframes * format->channels_per_frame;
|
uint32_t ilen = iframes * format->channels_per_frame;
|
||||||
AACENC_BufDesc ibdesc = { 0 }, obdesc = { 0 };
|
AACENC_BufDesc ibdesc = { 0 }, obdesc = { 0 };
|
||||||
@ -205,12 +260,14 @@ int aac_encode_frame(HANDLE_AACENCODER encoder,
|
|||||||
unsigned channel_mode, obytes;
|
unsigned channel_mode, obytes;
|
||||||
|
|
||||||
channel_mode = aacEncoder_GetParam(encoder, AACENC_CHANNELMODE);
|
channel_mode = aacEncoder_GetParam(encoder, AACENC_CHANNELMODE);
|
||||||
obytes = 6144 / 8 * channel_mode + 7;
|
obytes = 6144 / 8 * channel_mode;
|
||||||
if (!*output || *osize < obytes) {
|
if (!output->data || output->capacity < obytes) {
|
||||||
*osize = obytes;
|
uint8_t *p = realloc(output->data, obytes);
|
||||||
*output = realloc(*output, obytes);
|
if (!p) return -1;
|
||||||
|
output->capacity = obytes;
|
||||||
|
output->data = p;
|
||||||
}
|
}
|
||||||
obufs[0] = *output;
|
obufs[0] = output->data;
|
||||||
obuf_sizes[0] = obytes;
|
obuf_sizes[0] = obytes;
|
||||||
|
|
||||||
iargs.numInSamples = ilen ? ilen : -1; /* -1 for signaling EOF */
|
iargs.numInSamples = ilen ? ilen : -1; /* -1 for signaling EOF */
|
||||||
@ -230,6 +287,6 @@ int aac_encode_frame(HANDLE_AACENCODER encoder,
|
|||||||
fprintf(stderr, "ERROR: aacEncEncode() failed\n");
|
fprintf(stderr, "ERROR: aacEncEncode() failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*olen = oargs.numOutBytes;
|
output->size = oargs.numOutBytes;
|
||||||
return oargs.numInSamples;
|
return oargs.numInSamples / format->channels_per_frame;
|
||||||
}
|
}
|
||||||
|
14
src/aacenc.h
14
src/aacenc.h
@ -15,6 +15,7 @@
|
|||||||
unsigned bandwidth; \
|
unsigned bandwidth; \
|
||||||
unsigned afterburner; \
|
unsigned afterburner; \
|
||||||
unsigned lowdelay_sbr; \
|
unsigned lowdelay_sbr; \
|
||||||
|
unsigned sbr_ratio; \
|
||||||
unsigned sbr_signaling; \
|
unsigned sbr_signaling; \
|
||||||
unsigned transport_format; \
|
unsigned transport_format; \
|
||||||
unsigned adts_crc_check; \
|
unsigned adts_crc_check; \
|
||||||
@ -24,8 +25,19 @@ typedef struct aacenc_param_t {
|
|||||||
AACENC_PARAMS
|
AACENC_PARAMS
|
||||||
} aacenc_param_t;
|
} aacenc_param_t;
|
||||||
|
|
||||||
|
typedef struct aacenc_frame_t {
|
||||||
|
uint8_t *data;
|
||||||
|
uint32_t size, capacity;
|
||||||
|
} aacenc_frame_t;
|
||||||
|
|
||||||
|
int aacenc_is_sbr_ratio_available();
|
||||||
|
|
||||||
int aacenc_is_sbr_active(const aacenc_param_t *params);
|
int aacenc_is_sbr_active(const aacenc_param_t *params);
|
||||||
|
|
||||||
|
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,
|
int aacenc_mp4asc(const aacenc_param_t *params,
|
||||||
const uint8_t *asc, uint32_t ascsize,
|
const uint8_t *asc, uint32_t ascsize,
|
||||||
uint8_t *outasc, uint32_t *outsize);
|
uint8_t *outasc, uint32_t *outsize);
|
||||||
@ -37,6 +49,6 @@ int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
|
|||||||
int aac_encode_frame(HANDLE_AACENCODER encoder,
|
int aac_encode_frame(HANDLE_AACENCODER encoder,
|
||||||
const pcm_sample_description_t *format,
|
const pcm_sample_description_t *format,
|
||||||
const int16_t *input, unsigned iframes,
|
const int16_t *input, unsigned iframes,
|
||||||
uint8_t **output, uint32_t *olen, uint32_t *osize);
|
aacenc_frame_t *output);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -193,12 +193,10 @@ int caf_parse(caf_reader_t *reader, int64_t *data_length)
|
|||||||
} else if (fcc == M4AF_FOURCC('d','a','t','a')) {
|
} else if (fcc == M4AF_FOURCC('d','a','t','a')) {
|
||||||
TRY_IO(pcm_skip(&reader->io, 4)); /* mEditCount */
|
TRY_IO(pcm_skip(&reader->io, 4)); /* mEditCount */
|
||||||
*data_length = (chunk_size == ~0ULL) ? chunk_size : chunk_size - 4;
|
*data_length = (chunk_size == ~0ULL) ? chunk_size : chunk_size - 4;
|
||||||
reader->data_offset += 12;
|
reader->data_offset = pcm_tell(&reader->io);
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
TRY_IO(pcm_skip(&reader->io, chunk_size));
|
TRY_IO(pcm_skip(&reader->io, chunk_size));
|
||||||
|
|
||||||
reader->data_offset += (chunk_size + 8);
|
|
||||||
}
|
}
|
||||||
ENSURE(reader->sample_format.channels_per_frame);
|
ENSURE(reader->sample_format.channels_per_frame);
|
||||||
ENSURE(fcc == M4AF_FOURCC('d','a','t','a'));
|
ENSURE(fcc == M4AF_FOURCC('d','a','t','a'));
|
||||||
|
208
src/extrapolater.c
Normal file
208
src/extrapolater.c
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 nu774
|
||||||
|
* For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
*/
|
||||||
|
#if HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
#if HAVE_STDINT_H
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "pcm_reader.h"
|
||||||
|
#include "lpc.h"
|
||||||
|
|
||||||
|
typedef int16_t sample_t;
|
||||||
|
|
||||||
|
typedef struct buffer_t {
|
||||||
|
sample_t *data;
|
||||||
|
unsigned count; /* count in frames */
|
||||||
|
unsigned capacity; /* size in bytes */
|
||||||
|
} buffer_t;
|
||||||
|
|
||||||
|
typedef struct extrapolater_t {
|
||||||
|
pcm_reader_vtbl_t *vtbl;
|
||||||
|
pcm_reader_t *src;
|
||||||
|
pcm_sample_description_t format;
|
||||||
|
buffer_t buffer[2];
|
||||||
|
unsigned nbuffer;
|
||||||
|
int (*process)(struct extrapolater_t *, void *, unsigned);
|
||||||
|
} extrapolater_t;
|
||||||
|
|
||||||
|
#define LPC_ORDER 32
|
||||||
|
|
||||||
|
static inline pcm_reader_t *get_source(pcm_reader_t *reader)
|
||||||
|
{
|
||||||
|
return ((extrapolater_t *)reader)->src;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const
|
||||||
|
pcm_sample_description_t *get_format(pcm_reader_t *reader)
|
||||||
|
{
|
||||||
|
return pcm_get_format(get_source(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int64_t get_length(pcm_reader_t *reader)
|
||||||
|
{
|
||||||
|
return pcm_get_length(get_source(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int64_t get_position(pcm_reader_t *reader)
|
||||||
|
{
|
||||||
|
return pcm_get_position(get_source(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int realloc_buffer(buffer_t *bp, size_t size)
|
||||||
|
{
|
||||||
|
if (bp->capacity < size) {
|
||||||
|
void *p = realloc(bp->data, size);
|
||||||
|
if (!p) return -1;
|
||||||
|
bp->data = p;
|
||||||
|
bp->capacity = size;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void reverse_buffer(sample_t *data, unsigned nframes, unsigned nchannels)
|
||||||
|
{
|
||||||
|
unsigned i = 0, j = nchannels * (nframes - 1), n;
|
||||||
|
|
||||||
|
for (; i < j; i += nchannels, j -= nchannels) {
|
||||||
|
for (n = 0; n < nchannels; ++n) {
|
||||||
|
sample_t tmp = data[i + n];
|
||||||
|
data[i + n] = data[j + n];
|
||||||
|
data[j + n] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fetch(extrapolater_t *self, unsigned nframes)
|
||||||
|
{
|
||||||
|
const pcm_sample_description_t *sfmt = pcm_get_format(self->src);
|
||||||
|
buffer_t *bp = &self->buffer[self->nbuffer];
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (realloc_buffer(bp, nframes * sfmt->bytes_per_frame) == 0) {
|
||||||
|
rc = pcm_read_frames(self->src, bp->data, nframes);
|
||||||
|
bp->count = rc > 0 ? rc : 0;
|
||||||
|
}
|
||||||
|
if (rc > 0)
|
||||||
|
self->nbuffer ^= 1;
|
||||||
|
return bp->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int extrapolate(extrapolater_t *self, const buffer_t *bp,
|
||||||
|
void *dst, unsigned nframes)
|
||||||
|
{
|
||||||
|
const pcm_sample_description_t *sfmt = pcm_get_format(self->src);
|
||||||
|
unsigned i, n = sfmt->channels_per_frame;
|
||||||
|
float lpc[LPC_ORDER];
|
||||||
|
|
||||||
|
for (i = 0; i < n; ++i) {
|
||||||
|
vorbis_lpc_from_data(bp->data + i, lpc, bp->count, LPC_ORDER, n);
|
||||||
|
vorbis_lpc_predict(lpc, &bp->data[i + n * (bp->count - LPC_ORDER)],
|
||||||
|
LPC_ORDER, (sample_t*)dst + i, nframes, n);
|
||||||
|
}
|
||||||
|
return nframes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int process1(extrapolater_t *self, void *buffer, unsigned nframes);
|
||||||
|
static int process2(extrapolater_t *self, void *buffer, unsigned nframes);
|
||||||
|
static int process3(extrapolater_t *self, void *buffer, unsigned nframes);
|
||||||
|
|
||||||
|
static int process0(extrapolater_t *self, void *buffer, unsigned nframes)
|
||||||
|
{
|
||||||
|
const pcm_sample_description_t *sfmt = pcm_get_format(self->src);
|
||||||
|
unsigned nchannels = sfmt->channels_per_frame;
|
||||||
|
buffer_t *bp = &self->buffer[self->nbuffer];
|
||||||
|
|
||||||
|
if (fetch(self, nframes) < 2 * LPC_ORDER)
|
||||||
|
memset(buffer, 0, nframes * sfmt->bytes_per_frame);
|
||||||
|
else {
|
||||||
|
reverse_buffer(bp->data, bp->count, nchannels);
|
||||||
|
extrapolate(self, bp, buffer, nframes);
|
||||||
|
reverse_buffer(buffer, nframes, nchannels);
|
||||||
|
reverse_buffer(bp->data, bp->count, nchannels);
|
||||||
|
}
|
||||||
|
self->process = bp->count ? process1 : process2;
|
||||||
|
return nframes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int process1(extrapolater_t *self, void *buffer, unsigned nframes)
|
||||||
|
{
|
||||||
|
const pcm_sample_description_t *sfmt = pcm_get_format(self->src);
|
||||||
|
buffer_t *bp = &self->buffer[self->nbuffer ^ 1];
|
||||||
|
|
||||||
|
assert(bp->count <= nframes);
|
||||||
|
memcpy(buffer, bp->data, bp->count * sfmt->bytes_per_frame);
|
||||||
|
if (!fetch(self, nframes))
|
||||||
|
self->process = process2;
|
||||||
|
return bp->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int process2(extrapolater_t *self, void *buffer, unsigned nframes)
|
||||||
|
{
|
||||||
|
const pcm_sample_description_t *sfmt = pcm_get_format(self->src);
|
||||||
|
buffer_t *bp = &self->buffer[self->nbuffer];
|
||||||
|
buffer_t *bbp = &self->buffer[self->nbuffer ^ 1];
|
||||||
|
|
||||||
|
if (bp->count < 2 * LPC_ORDER) {
|
||||||
|
size_t total = bp->count + bbp->count;
|
||||||
|
if (bbp->count &&
|
||||||
|
realloc_buffer(bbp, total * sfmt->bytes_per_frame) == 0)
|
||||||
|
{
|
||||||
|
memcpy(bbp->data + bbp->count * sfmt->channels_per_frame,
|
||||||
|
bp->data, bp->count * sfmt->bytes_per_frame);
|
||||||
|
bbp->count = total;
|
||||||
|
bp->count = 0;
|
||||||
|
bp = bbp;
|
||||||
|
self->nbuffer ^= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self->process = process3;
|
||||||
|
|
||||||
|
if (bp->count >= 2 * LPC_ORDER)
|
||||||
|
extrapolate(self, bp, buffer, nframes);
|
||||||
|
else
|
||||||
|
memset(buffer, 0, nframes * sfmt->bytes_per_frame);
|
||||||
|
return nframes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int process3(extrapolater_t *self, void *buffer, unsigned nframes)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_frames(pcm_reader_t *reader, void *buffer, unsigned nframes)
|
||||||
|
{
|
||||||
|
extrapolater_t *self = (extrapolater_t *)reader;
|
||||||
|
return self->process(self, buffer, nframes);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void teardown(pcm_reader_t **reader)
|
||||||
|
{
|
||||||
|
extrapolater_t *self = (extrapolater_t *)*reader;
|
||||||
|
pcm_teardown(&self->src);
|
||||||
|
free(self->buffer[0].data);
|
||||||
|
free(self->buffer[1].data);
|
||||||
|
free(self);
|
||||||
|
*reader = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static pcm_reader_vtbl_t my_vtable = {
|
||||||
|
get_format, get_length, get_position, read_frames, teardown
|
||||||
|
};
|
||||||
|
|
||||||
|
pcm_reader_t *extrapolater_open(pcm_reader_t *reader)
|
||||||
|
{
|
||||||
|
extrapolater_t *self = 0;
|
||||||
|
|
||||||
|
if ((self = calloc(1, sizeof(extrapolater_t))) == 0)
|
||||||
|
return 0;
|
||||||
|
self->src = reader;
|
||||||
|
self->vtbl = &my_vtable;
|
||||||
|
self->process = process0;
|
||||||
|
return (pcm_reader_t *)self;
|
||||||
|
}
|
169
src/lpc.c
Normal file
169
src/lpc.c
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/********************************************************************
|
||||||
|
* *
|
||||||
|
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
||||||
|
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
||||||
|
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||||
|
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||||
|
* *
|
||||||
|
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
|
||||||
|
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||||
|
* *
|
||||||
|
********************************************************************
|
||||||
|
|
||||||
|
function: LPC low level routines
|
||||||
|
last mod: $Id: lpc.c 16227 2009-07-08 06:58:46Z xiphmont $
|
||||||
|
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/* Some of these routines (autocorrelator, LPC coefficient estimator)
|
||||||
|
are derived from code written by Jutta Degener and Carsten Bormann;
|
||||||
|
thus we include their copyright below. The entirety of this file
|
||||||
|
is freely redistributable on the condition that both of these
|
||||||
|
copyright notices are preserved without modification. */
|
||||||
|
|
||||||
|
/* Preserved Copyright: *********************************************/
|
||||||
|
|
||||||
|
/* Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann,
|
||||||
|
Technische Universita"t Berlin
|
||||||
|
|
||||||
|
Any use of this software is permitted provided that this notice is not
|
||||||
|
removed and that neither the authors nor the Technische Universita"t
|
||||||
|
Berlin are deemed to have made any representations as to the
|
||||||
|
suitability of this software for any purpose nor are held responsible
|
||||||
|
for any defects of this software. THERE IS ABSOLUTELY NO WARRANTY FOR
|
||||||
|
THIS SOFTWARE.
|
||||||
|
|
||||||
|
As a matter of courtesy, the authors request to be informed about uses
|
||||||
|
this software has found, about bugs in this software, and about any
|
||||||
|
improvements that may be of general interest.
|
||||||
|
|
||||||
|
Berlin, 28.11.1994
|
||||||
|
Jutta Degener
|
||||||
|
Carsten Bormann
|
||||||
|
|
||||||
|
*********************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_STDINT_H
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "lpc.h"
|
||||||
|
#include "lpcm.h"
|
||||||
|
|
||||||
|
/* Autocorrelation LPC coeff generation algorithm invented by
|
||||||
|
N. Levinson in 1947, modified by J. Durbin in 1959. */
|
||||||
|
|
||||||
|
/* Input : n elements of time doamin data
|
||||||
|
Output: m lpc coefficients, excitation energy */
|
||||||
|
|
||||||
|
float vorbis_lpc_from_data(short *data,float *lpci,int n,int m,int stride){
|
||||||
|
double *aut=malloc(sizeof(*aut)*(m+1));
|
||||||
|
double *lpc=malloc(sizeof(*lpc)*(m));
|
||||||
|
double error;
|
||||||
|
double epsilon;
|
||||||
|
int i,j;
|
||||||
|
|
||||||
|
/* autocorrelation, p+1 lag coefficients */
|
||||||
|
j=m+1;
|
||||||
|
while(j--){
|
||||||
|
double d=0; /* double needed for accumulator depth */
|
||||||
|
for(i=j;i<n;i++)d+=(double)data[i*stride]*data[(i-j)*stride]/1073741824.0;
|
||||||
|
aut[j]=d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generate lpc coefficients from autocorr values */
|
||||||
|
|
||||||
|
/* set our noise floor to about -100dB */
|
||||||
|
error=aut[0] * (1. + 1e-10);
|
||||||
|
epsilon=1e-9*aut[0]+1e-10;
|
||||||
|
|
||||||
|
for(i=0;i<m;i++){
|
||||||
|
double r= -aut[i+1];
|
||||||
|
|
||||||
|
if(error<epsilon){
|
||||||
|
memset(lpc+i,0,(m-i)*sizeof(*lpc));
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sum up this iteration's reflection coefficient; note that in
|
||||||
|
Vorbis we don't save it. If anyone wants to recycle this code
|
||||||
|
and needs reflection coefficients, save the results of 'r' from
|
||||||
|
each iteration. */
|
||||||
|
|
||||||
|
for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
|
||||||
|
r/=error;
|
||||||
|
|
||||||
|
/* Update LPC coefficients and total error */
|
||||||
|
|
||||||
|
lpc[i]=r;
|
||||||
|
for(j=0;j<i/2;j++){
|
||||||
|
double tmp=lpc[j];
|
||||||
|
|
||||||
|
lpc[j]+=r*lpc[i-1-j];
|
||||||
|
lpc[i-1-j]+=r*tmp;
|
||||||
|
}
|
||||||
|
if(i&1)lpc[j]+=lpc[j]*r;
|
||||||
|
|
||||||
|
error*=1.-r*r;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
|
||||||
|
/* slightly damp the filter */
|
||||||
|
{
|
||||||
|
double g = .99;
|
||||||
|
double damp = g;
|
||||||
|
for(j=0;j<m;j++){
|
||||||
|
lpc[j]*=damp;
|
||||||
|
damp*=g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
|
||||||
|
|
||||||
|
/* we need the error value to know how big an impulse to hit the
|
||||||
|
filter with later */
|
||||||
|
|
||||||
|
free(aut);
|
||||||
|
free(lpc);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vorbis_lpc_predict(float *coeff,short *prime,int m,
|
||||||
|
short *data,long n,int stride){
|
||||||
|
|
||||||
|
/* in: coeff[0...m-1] LPC coefficients
|
||||||
|
prime[0...m-1] initial values (allocated size of n+m-1)
|
||||||
|
out: data[0...n-1] data samples */
|
||||||
|
|
||||||
|
long i,j,o,p;
|
||||||
|
float y;
|
||||||
|
float *work=malloc(sizeof(*work)*(m+n));
|
||||||
|
|
||||||
|
if(!prime)
|
||||||
|
for(i=0;i<m;i++)
|
||||||
|
work[i]=0.f;
|
||||||
|
else
|
||||||
|
for(i=0;i<m;i++)
|
||||||
|
work[i]=prime[i*stride]/32768.0f;
|
||||||
|
|
||||||
|
for(i=0;i<n;i++){
|
||||||
|
y=0;
|
||||||
|
o=i;
|
||||||
|
p=m;
|
||||||
|
for(j=0;j<m;j++)
|
||||||
|
y-=work[o++]*coeff[--p];
|
||||||
|
|
||||||
|
work[o]=y;
|
||||||
|
data[i*stride]=lrint(pcm_clip(y*32768.0,-32768.0,32767.0));
|
||||||
|
}
|
||||||
|
free(work);
|
||||||
|
}
|
27
src/lpc.h
Normal file
27
src/lpc.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/********************************************************************
|
||||||
|
* *
|
||||||
|
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
||||||
|
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
||||||
|
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||||
|
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||||
|
* *
|
||||||
|
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
|
||||||
|
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||||
|
* *
|
||||||
|
********************************************************************
|
||||||
|
|
||||||
|
function: LPC low level routines
|
||||||
|
last mod: $Id: lpc.h 16037 2009-05-26 21:10:58Z xiphmont $
|
||||||
|
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
#ifndef _V_LPC_H_
|
||||||
|
#define _V_LPC_H_
|
||||||
|
|
||||||
|
/* simple linear scale LPC code */
|
||||||
|
extern float vorbis_lpc_from_data(short *data,float *lpc,int n,int m,int stride);
|
||||||
|
|
||||||
|
extern void vorbis_lpc_predict(float *coeff,short *prime,int m,
|
||||||
|
short *data,long n,int stride);
|
||||||
|
|
||||||
|
#endif
|
29
src/lpcm.c
29
src/lpcm.c
@ -13,35 +13,6 @@
|
|||||||
#include "lpcm.h"
|
#include "lpcm.h"
|
||||||
#include "m4af_endian.h"
|
#include "m4af_endian.h"
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1800
|
|
||||||
# ifdef _M_IX86
|
|
||||||
inline int lrint(double x)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
_asm {
|
|
||||||
fld x
|
|
||||||
fistp n
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
# else
|
|
||||||
# include <emmintrin.h>
|
|
||||||
inline int lrint(double x)
|
|
||||||
{
|
|
||||||
return _mm_cvtsd_si32(_mm_load_sd(&x));
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static
|
|
||||||
inline double pcm_clip(double n, double min_value, double max_value)
|
|
||||||
{
|
|
||||||
if (n < min_value)
|
|
||||||
return min_value;
|
|
||||||
else if (n > max_value)
|
|
||||||
return max_value;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
static
|
static
|
||||||
inline float pcm_i2f(int32_t n)
|
inline float pcm_i2f(int32_t n)
|
||||||
{
|
{
|
||||||
|
30
src/lpcm.h
30
src/lpcm.h
@ -31,6 +31,36 @@ typedef struct pcm_sample_description_t {
|
|||||||
#define PCM_BYTES_PER_CHANNEL(desc) \
|
#define PCM_BYTES_PER_CHANNEL(desc) \
|
||||||
((desc)->bytes_per_frame / (desc)->channels_per_frame)
|
((desc)->bytes_per_frame / (desc)->channels_per_frame)
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER < 1800
|
||||||
|
# ifdef _M_IX86
|
||||||
|
static inline int lrint(double x)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
_asm {
|
||||||
|
fld x
|
||||||
|
fistp n
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
# else
|
||||||
|
# include <emmintrin.h>
|
||||||
|
static inline int lrint(double x)
|
||||||
|
{
|
||||||
|
return _mm_cvtsd_si32(_mm_load_sd(&x));
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static
|
||||||
|
inline double pcm_clip(double n, double min_value, double max_value)
|
||||||
|
{
|
||||||
|
if (n < min_value)
|
||||||
|
return min_value;
|
||||||
|
else if (n > max_value)
|
||||||
|
return max_value;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
int pcm_convert_to_native_sint16(const pcm_sample_description_t *format,
|
int pcm_convert_to_native_sint16(const pcm_sample_description_t *format,
|
||||||
const void *input, uint32_t nframes,
|
const void *input, uint32_t nframes,
|
||||||
int16_t *result);
|
int16_t *result);
|
||||||
|
@ -864,7 +864,6 @@ void m4af_write_sbgp_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
|||||||
static
|
static
|
||||||
void m4af_write_sgpd_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
void m4af_write_sgpd_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
{
|
{
|
||||||
m4af_track_t *track = &ctx->track[track_idx];
|
|
||||||
m4af_write(ctx,
|
m4af_write(ctx,
|
||||||
"\0\0\0\026" /* size: 22 */
|
"\0\0\0\026" /* size: 22 */
|
||||||
"sgpd" /* type */
|
"sgpd" /* type */
|
||||||
@ -1050,7 +1049,6 @@ void m4af_write_elst_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
|||||||
static
|
static
|
||||||
void m4af_write_edts_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
void m4af_write_edts_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
{
|
{
|
||||||
m4af_track_t *track = &ctx->track[track_idx];
|
|
||||||
int64_t pos = m4af_tell(ctx);
|
int64_t pos = m4af_tell(ctx);
|
||||||
m4af_write(ctx, "\0\0\0\0edts", 8);
|
m4af_write(ctx, "\0\0\0\0edts", 8);
|
||||||
m4af_write_elst_box(ctx, track_idx);
|
m4af_write_elst_box(ctx, track_idx);
|
||||||
|
163
src/main.c
163
src/main.c
@ -132,7 +132,14 @@ PROGNAME " %s\n"
|
|||||||
" -a, --afterburner <n> Afterburner\n"
|
" -a, --afterburner <n> Afterburner\n"
|
||||||
" 0: Off\n"
|
" 0: Off\n"
|
||||||
" 1: On(default)\n"
|
" 1: On(default)\n"
|
||||||
" -L, --lowdelay-sbr Enable ELD-SBR (AAC ELD only)\n"
|
" -L, --lowdelay-sbr <-1|0|1> Configure SBR activity on AAC ELD\n"
|
||||||
|
" -1: Use ELD SBR auto configurator\n"
|
||||||
|
" 0: Disable SBR on ELD (default)\n"
|
||||||
|
" 1: Enable SBR on ELD\n"
|
||||||
|
" -s, --sbr-ratio <0|1|2> Controls activation of downsampled SBR\n"
|
||||||
|
" 0: Use lib default (default)\n"
|
||||||
|
" 1: downsampled SBR (default for ELD+SBR)\n"
|
||||||
|
" 2: dual-rate SBR (default for HE-AAC)\n"
|
||||||
" -f, --transport-format <n> Transport format\n"
|
" -f, --transport-format <n> Transport format\n"
|
||||||
" 0: RAW (default, muxed into M4A)\n"
|
" 0: RAW (default, muxed into M4A)\n"
|
||||||
" 1: ADIF\n"
|
" 1: ADIF\n"
|
||||||
@ -228,7 +235,7 @@ static
|
|||||||
int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
unsigned n;
|
int n;
|
||||||
|
|
||||||
#define OPT_INCLUDE_SBR_DELAY M4AF_FOURCC('s','d','l','y')
|
#define OPT_INCLUDE_SBR_DELAY M4AF_FOURCC('s','d','l','y')
|
||||||
#define OPT_MOOV_BEFORE_MDAT M4AF_FOURCC('m','o','o','v')
|
#define OPT_MOOV_BEFORE_MDAT M4AF_FOURCC('m','o','o','v')
|
||||||
@ -247,7 +254,8 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
{ "bitrate-mode", required_argument, 0, 'm' },
|
{ "bitrate-mode", required_argument, 0, 'm' },
|
||||||
{ "bandwidth", required_argument, 0, 'w' },
|
{ "bandwidth", required_argument, 0, 'w' },
|
||||||
{ "afterburner", required_argument, 0, 'a' },
|
{ "afterburner", required_argument, 0, 'a' },
|
||||||
{ "lowdelay-sbr", no_argument, 0, 'L' },
|
{ "lowdelay-sbr", required_argument, 0, 'L' },
|
||||||
|
{ "sbr-ratio", required_argument, 0, 's' },
|
||||||
{ "transport-format", required_argument, 0, 'f' },
|
{ "transport-format", required_argument, 0, 'f' },
|
||||||
{ "adts-crc-check", no_argument, 0, 'C' },
|
{ "adts-crc-check", no_argument, 0, 'C' },
|
||||||
{ "header-period", required_argument, 0, 'P' },
|
{ "header-period", required_argument, 0, 'P' },
|
||||||
@ -325,7 +333,18 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
params->afterburner = n;
|
params->afterburner = n;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
params->lowdelay_sbr = 1;
|
if (sscanf(optarg, "%d", &n) != 1 || n < -1 || n > 1) {
|
||||||
|
fprintf(stderr, "invalid arg for lowdelay-sbr\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
params->lowdelay_sbr = n;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (sscanf(optarg, "%u", &n) != 1 || n > 2) {
|
||||||
|
fprintf(stderr, "invalid arg for sbr-ratio\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
params->sbr_ratio = n;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
if (sscanf(optarg, "%u", &n) != 1) {
|
if (sscanf(optarg, "%u", &n) != 1) {
|
||||||
@ -472,16 +491,15 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
};
|
};
|
||||||
|
|
||||||
static
|
static
|
||||||
int write_sample(FILE *ofp, m4af_ctx_t *m4af,
|
int write_sample(FILE *ofp, m4af_ctx_t *m4af, aacenc_frame_t *frame)
|
||||||
const void *data, uint32_t size, uint32_t duration)
|
|
||||||
{
|
{
|
||||||
if (!m4af) {
|
if (!m4af) {
|
||||||
fwrite(data, 1, size, ofp);
|
fwrite(frame->data, 1, frame->size, ofp);
|
||||||
if (ferror(ofp)) {
|
if (ferror(ofp)) {
|
||||||
fprintf(stderr, "ERROR: fwrite(): %s\n", strerror(errno));
|
fprintf(stderr, "ERROR: fwrite(): %s\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (m4af_write_sample(m4af, 0, data, size, duration) < 0) {
|
} else if (m4af_write_sample(m4af, 0, frame->data, frame->size, 0) < 0) {
|
||||||
fprintf(stderr, "ERROR: failed to write m4a sample\n");
|
fprintf(stderr, "ERROR: failed to write m4a sample\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -489,51 +507,76 @@ int write_sample(FILE *ofp, m4af_ctx_t *m4af,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int encode(pcm_reader_t *reader, HANDLE_AACENCODER encoder,
|
int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
|
||||||
uint32_t frame_length, FILE *ofp, m4af_ctx_t *m4af,
|
HANDLE_AACENCODER encoder, uint32_t frame_length,
|
||||||
int show_progress)
|
m4af_ctx_t *m4af)
|
||||||
{
|
{
|
||||||
int16_t *ibuf = 0;
|
int16_t *ibuf = 0, *ip;
|
||||||
uint8_t *obuf = 0;
|
aacenc_frame_t obuf[2] = {{ 0 }}, *obp;
|
||||||
uint32_t olen;
|
unsigned flip = 0;
|
||||||
uint32_t osize = 0;
|
|
||||||
int nread = 1;
|
int nread = 1;
|
||||||
int consumed;
|
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
int frames_written = 0;
|
int remaining, consumed;
|
||||||
|
int frames_written = 0, encoded = 0;
|
||||||
aacenc_progress_t progress = { 0 };
|
aacenc_progress_t progress = { 0 };
|
||||||
const pcm_sample_description_t *fmt = pcm_get_format(reader);
|
const pcm_sample_description_t *fmt = pcm_get_format(reader);
|
||||||
|
|
||||||
ibuf = malloc(frame_length * fmt->bytes_per_frame);
|
ibuf = malloc(frame_length * fmt->bytes_per_frame);
|
||||||
aacenc_progress_init(&progress, pcm_get_length(reader), fmt->sample_rate);
|
aacenc_progress_init(&progress, pcm_get_length(reader), fmt->sample_rate);
|
||||||
do {
|
|
||||||
|
for (;;) {
|
||||||
|
/*
|
||||||
|
* Since we delay the write, we cannot just exit loop when interrupted.
|
||||||
|
* Instead, we regard it as EOF.
|
||||||
|
*/
|
||||||
if (g_interrupted)
|
if (g_interrupted)
|
||||||
nread = 0;
|
nread = 0;
|
||||||
else if (nread) {
|
if (nread > 0) {
|
||||||
if ((nread = pcm_read_frames(reader, ibuf, frame_length)) < 0) {
|
if ((nread = pcm_read_frames(reader, ibuf, frame_length)) < 0) {
|
||||||
fprintf(stderr, "ERROR: read failed\n");
|
fprintf(stderr, "ERROR: read failed\n");
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
if (show_progress)
|
if (!params->silent)
|
||||||
aacenc_progress_update(&progress, pcm_get_position(reader),
|
aacenc_progress_update(&progress, pcm_get_position(reader),
|
||||||
fmt->sample_rate * 2);
|
fmt->sample_rate * 2);
|
||||||
}
|
}
|
||||||
if ((consumed = aac_encode_frame(encoder, fmt, ibuf, nread,
|
ip = ibuf;
|
||||||
&obuf, &olen, &osize)) < 0)
|
remaining = nread;
|
||||||
goto END;
|
do {
|
||||||
if (olen > 0) {
|
obp = &obuf[flip];
|
||||||
if (write_sample(ofp, m4af, obuf, olen, frame_length) < 0)
|
consumed = aac_encode_frame(encoder, fmt, ip, remaining, obp);
|
||||||
|
if (consumed < 0) goto END;
|
||||||
|
if (consumed == 0 && obp->size == 0) goto DONE;
|
||||||
|
if (obp->size == 0) break;
|
||||||
|
|
||||||
|
remaining -= consumed;
|
||||||
|
ip += consumed * fmt->channels_per_frame;
|
||||||
|
flip ^= 1;
|
||||||
|
/*
|
||||||
|
* As we pad 1 frame at beginning and ending by our extrapolator,
|
||||||
|
* we want to drop them.
|
||||||
|
* We delay output by 1 frame by double buffering, and discard
|
||||||
|
* second frame and final frame from the encoder.
|
||||||
|
* Since sbr_header is included in the first frame (in case of
|
||||||
|
* SBR), we cannot discard first frame. So we pick second instead.
|
||||||
|
*/
|
||||||
|
++encoded;
|
||||||
|
if (encoded == 1 || encoded == 3)
|
||||||
|
continue;
|
||||||
|
obp = &obuf[flip];
|
||||||
|
if (write_sample(params->output_fp, m4af, obp) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
++frames_written;
|
++frames_written;
|
||||||
|
} while (remaining > 0);
|
||||||
}
|
}
|
||||||
} while (nread > 0 || olen > 0);
|
DONE:
|
||||||
|
if (!params->silent)
|
||||||
if (show_progress)
|
|
||||||
aacenc_progress_finish(&progress, pcm_get_position(reader));
|
aacenc_progress_finish(&progress, pcm_get_position(reader));
|
||||||
rc = frames_written;
|
rc = frames_written;
|
||||||
END:
|
END:
|
||||||
if (ibuf) free(ibuf);
|
if (ibuf) free(ibuf);
|
||||||
if (obuf) free(obuf);
|
if (obuf[0].data) free(obuf[0].data);
|
||||||
|
if (obuf[1].data) free(obuf[1].data);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,19 +586,11 @@ void put_tool_tag(m4af_ctx_t *m4af, const aacenc_param_ex_t *params,
|
|||||||
{
|
{
|
||||||
char tool_info[256];
|
char tool_info[256];
|
||||||
char *p = tool_info;
|
char *p = tool_info;
|
||||||
LIB_INFO *lib_info = 0;
|
LIB_INFO lib_info;
|
||||||
|
|
||||||
p += sprintf(p, PROGNAME " %s, ", fdkaac_version);
|
p += sprintf(p, PROGNAME " %s, ", fdkaac_version);
|
||||||
|
aacenc_get_lib_info(&lib_info);
|
||||||
lib_info = calloc(FDK_MODULE_LAST, sizeof(LIB_INFO));
|
p += sprintf(p, "libfdk-aac %s, ", lib_info.versionStr);
|
||||||
if (aacEncGetLibInfo(lib_info) == AACENC_OK) {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < FDK_MODULE_LAST; ++i)
|
|
||||||
if (lib_info[i].module_id == FDK_AACENC)
|
|
||||||
break;
|
|
||||||
p += sprintf(p, "libfdk-aac %s, ", lib_info[i].versionStr);
|
|
||||||
}
|
|
||||||
free(lib_info);
|
|
||||||
if (params->bitrate_mode)
|
if (params->bitrate_mode)
|
||||||
sprintf(p, "VBR mode %d", params->bitrate_mode);
|
sprintf(p, "VBR mode %d", params->bitrate_mode);
|
||||||
else
|
else
|
||||||
@ -607,7 +642,7 @@ char *generate_output_filename(const char *filename, const char *ext)
|
|||||||
const char *ext_org = strrchr(base, '.');
|
const char *ext_org = strrchr(base, '.');
|
||||||
if (ext_org) ilen = ext_org - base;
|
if (ext_org) ilen = ext_org - base;
|
||||||
p = malloc(ilen + ext_len + 1);
|
p = malloc(ilen + ext_len + 1);
|
||||||
sprintf(p, "%.*s%s", ilen, base, ext);
|
sprintf(p, "%.*s%s", (int)ilen, base, ext);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -651,7 +686,7 @@ int parse_raw_spec(const char *spec, pcm_sample_description_t *desc)
|
|||||||
static pcm_io_vtbl_t pcm_io_vtbl = {
|
static pcm_io_vtbl_t pcm_io_vtbl = {
|
||||||
read_callback, seek_callback, tell_callback
|
read_callback, seek_callback, tell_callback
|
||||||
};
|
};
|
||||||
static pcm_io_vtbl_t pcm_io_vtbl_noseek = { read_callback, 0, 0 };
|
static pcm_io_vtbl_t pcm_io_vtbl_noseek = { read_callback, 0, tell_callback };
|
||||||
|
|
||||||
static
|
static
|
||||||
pcm_reader_t *open_input(aacenc_param_ex_t *params)
|
pcm_reader_t *open_input(aacenc_param_ex_t *params)
|
||||||
@ -709,10 +744,13 @@ pcm_reader_t *open_input(aacenc_param_ex_t *params)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
fprintf(stderr, "ERROR: unsupported input file\n");
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pcm_open_sint16_converter(reader);
|
if ((reader = pcm_open_sint16_converter(reader)) != 0)
|
||||||
|
reader = extrapolater_open(reader);
|
||||||
|
return reader;
|
||||||
END:
|
END:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -729,11 +767,13 @@ int main(int argc, char **argv)
|
|||||||
pcm_reader_t *reader = 0;
|
pcm_reader_t *reader = 0;
|
||||||
HANDLE_AACENCODER encoder = 0;
|
HANDLE_AACENCODER encoder = 0;
|
||||||
AACENC_InfoStruct aacinfo = { 0 };
|
AACENC_InfoStruct aacinfo = { 0 };
|
||||||
|
LIB_INFO lib_info = { 0 };
|
||||||
m4af_ctx_t *m4af = 0;
|
m4af_ctx_t *m4af = 0;
|
||||||
const pcm_sample_description_t *sample_format;
|
const pcm_sample_description_t *sample_format;
|
||||||
int downsampled_timescale = 0;
|
int downsampled_timescale = 0;
|
||||||
int frame_count = 0;
|
int frame_count = 0;
|
||||||
int sbr_mode = 0;
|
int sbr_mode = 0;
|
||||||
|
unsigned scale_shift = 0;
|
||||||
|
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
setbuf(stderr, 0);
|
setbuf(stderr, 0);
|
||||||
@ -755,7 +795,16 @@ int main(int argc, char **argv)
|
|||||||
* way in MPEG4 part3 spec, and seems the only way supported by iTunes.
|
* 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.
|
* Since FDK library does not support it, we have to do it on our side.
|
||||||
*/
|
*/
|
||||||
|
sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
|
||||||
|
if (sbr_mode && !aacenc_is_sbr_ratio_available()) {
|
||||||
|
fprintf(stderr, "WARNING: Only dual-rate SBR is available "
|
||||||
|
"for this version\n");
|
||||||
|
params.sbr_ratio = 2;
|
||||||
|
}
|
||||||
|
scale_shift = aacenc_is_dual_rate_sbr((aacenc_param_t*)¶ms);
|
||||||
params.sbr_signaling = (params.transport_format == TT_MP4_LOAS) ? 2 : 0;
|
params.sbr_signaling = (params.transport_format == TT_MP4_LOAS) ? 2 : 0;
|
||||||
|
if (sbr_mode && !scale_shift)
|
||||||
|
params.sbr_signaling = 2;
|
||||||
|
|
||||||
if (aacenc_init(&encoder, (aacenc_param_t*)¶ms, sample_format,
|
if (aacenc_init(&encoder, (aacenc_param_t*)¶ms, sample_format,
|
||||||
&aacinfo) < 0)
|
&aacinfo) < 0)
|
||||||
@ -773,15 +822,13 @@ int main(int argc, char **argv)
|
|||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
handle_signals();
|
handle_signals();
|
||||||
sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
|
|
||||||
if (!params.transport_format) {
|
if (!params.transport_format) {
|
||||||
uint32_t scale;
|
uint32_t scale;
|
||||||
uint8_t mp4asc[32];
|
uint8_t mp4asc[32];
|
||||||
uint32_t ascsize = sizeof(mp4asc);
|
uint32_t ascsize = sizeof(mp4asc);
|
||||||
unsigned framelen = aacinfo.frameLength;
|
unsigned framelen = aacinfo.frameLength;
|
||||||
if (sbr_mode)
|
scale = sample_format->sample_rate >> scale_shift;
|
||||||
downsampled_timescale = 1;
|
|
||||||
scale = sample_format->sample_rate >> downsampled_timescale;
|
|
||||||
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
|
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
|
||||||
params.output_fp)) < 0)
|
params.output_fp)) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
@ -789,13 +836,22 @@ int main(int argc, char **argv)
|
|||||||
aacinfo.confSize, mp4asc, &ascsize);
|
aacinfo.confSize, mp4asc, &ascsize);
|
||||||
m4af_set_decoder_specific_info(m4af, 0, mp4asc, ascsize);
|
m4af_set_decoder_specific_info(m4af, 0, mp4asc, ascsize);
|
||||||
m4af_set_fixed_frame_duration(m4af, 0,
|
m4af_set_fixed_frame_duration(m4af, 0,
|
||||||
framelen >> downsampled_timescale);
|
framelen >> scale_shift);
|
||||||
m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
|
m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
|
||||||
m4af_set_priming_mode(m4af, params.gapless_mode + 1);
|
m4af_set_priming_mode(m4af, params.gapless_mode + 1);
|
||||||
m4af_begin_write(m4af);
|
m4af_begin_write(m4af);
|
||||||
}
|
}
|
||||||
frame_count = encode(reader, encoder, aacinfo.frameLength,
|
if (scale_shift && (aacinfo.encoderDelay & 1)) {
|
||||||
params.output_fp, m4af, !params.silent);
|
/*
|
||||||
|
* Since odd delay cannot be exactly expressed in downsampled scale,
|
||||||
|
* we push one zero frame to the encoder here, to make delay even
|
||||||
|
*/
|
||||||
|
int16_t zero[8] = { 0 };
|
||||||
|
aacenc_frame_t frame = { 0 };
|
||||||
|
aac_encode_frame(encoder, sample_format, zero, 1, &frame);
|
||||||
|
free(frame.data);
|
||||||
|
}
|
||||||
|
frame_count = encode(¶ms, reader, encoder, aacinfo.frameLength, m4af);
|
||||||
if (frame_count < 0)
|
if (frame_count < 0)
|
||||||
goto END;
|
goto END;
|
||||||
if (m4af) {
|
if (m4af) {
|
||||||
@ -805,12 +861,11 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (sbr_mode && params.profile != AOT_ER_AAC_ELD &&
|
if (sbr_mode && params.profile != AOT_ER_AAC_ELD &&
|
||||||
!params.include_sbr_delay)
|
!params.include_sbr_delay)
|
||||||
delay -= 481 << 1;
|
delay -= 481 << scale_shift;
|
||||||
if (sbr_mode && (delay & 1))
|
if (scale_shift && (delay & 1))
|
||||||
++delay;
|
++delay;
|
||||||
padding = frame_count * aacinfo.frameLength - frames_read - delay;
|
padding = frame_count * aacinfo.frameLength - frames_read - delay;
|
||||||
m4af_set_priming(m4af, 0, delay >> downsampled_timescale,
|
m4af_set_priming(m4af, 0, delay >> scale_shift, padding >> scale_shift);
|
||||||
padding >> downsampled_timescale);
|
|
||||||
if (finalize_m4a(m4af, ¶ms, encoder) < 0)
|
if (finalize_m4a(m4af, ¶ms, encoder) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 nu774
|
||||||
|
* For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
*/
|
||||||
#if HAVE_CONFIG_H
|
#if HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 nu774
|
||||||
|
* For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
*/
|
||||||
#ifndef METADATA_H
|
#ifndef METADATA_H
|
||||||
#define METADATA_H
|
#define METADATA_H
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 nu774
|
||||||
|
* For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
*/
|
||||||
#ifndef PCM_READER_H
|
#ifndef PCM_READER_H
|
||||||
#define PCM_READER_H
|
#define PCM_READER_H
|
||||||
|
|
||||||
@ -85,7 +89,7 @@ uint32_t bitcount(uint32_t bits)
|
|||||||
int pcm_read(pcm_io_context_t *io, void *buffer, uint32_t size);
|
int pcm_read(pcm_io_context_t *io, void *buffer, uint32_t size);
|
||||||
int pcm_skip(pcm_io_context_t *io, int64_t count);
|
int pcm_skip(pcm_io_context_t *io, int64_t count);
|
||||||
|
|
||||||
static int pcm_seek(pcm_io_context_t *io, int64_t off, int whence)
|
static inline int pcm_seek(pcm_io_context_t *io, int64_t off, int whence)
|
||||||
{
|
{
|
||||||
return io->vtbl->seek ? io->vtbl->seek(io->cookie, off, whence) : -1;
|
return io->vtbl->seek ? io->vtbl->seek(io->cookie, off, whence) : -1;
|
||||||
}
|
}
|
||||||
@ -109,4 +113,6 @@ int apple_chan_chunk(pcm_io_context_t *io, uint32_t chunk_size,
|
|||||||
|
|
||||||
pcm_reader_t *pcm_open_sint16_converter(pcm_reader_t *reader);
|
pcm_reader_t *pcm_open_sint16_converter(pcm_reader_t *reader);
|
||||||
|
|
||||||
|
pcm_reader_t *extrapolater_open(pcm_reader_t *reader);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 nu774
|
||||||
|
* For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
*/
|
||||||
#if HAVE_CONFIG_H
|
#if HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -93,7 +93,6 @@ int riff_ds64(wav_reader_t *reader, int64_t *length)
|
|||||||
TRY_IO(pcm_scanl(&reader->io, "QQQL",
|
TRY_IO(pcm_scanl(&reader->io, "QQQL",
|
||||||
&riff_size, length, &sample_count, &table_size) != 4);
|
&riff_size, length, &sample_count, &table_size) != 4);
|
||||||
TRY_IO(pcm_skip(&reader->io, (chunk_size - 27) & ~1));
|
TRY_IO(pcm_skip(&reader->io, (chunk_size - 27) & ~1));
|
||||||
reader->data_offset += (chunk_size + 9) & ~1;
|
|
||||||
FAIL:
|
FAIL:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -163,7 +162,6 @@ int wav_parse(wav_reader_t *reader, int64_t *data_length)
|
|||||||
container == RIFF_FOURCC('R','F','6','4'));
|
container == RIFF_FOURCC('R','F','6','4'));
|
||||||
TRY_IO(pcm_read32le(&reader->io, &fcc));
|
TRY_IO(pcm_read32le(&reader->io, &fcc));
|
||||||
ENSURE(fcc == RIFF_FOURCC('W','A','V','E'));
|
ENSURE(fcc == RIFF_FOURCC('W','A','V','E'));
|
||||||
reader->data_offset = 12;
|
|
||||||
|
|
||||||
if (container == RIFF_FOURCC('R','F','6','4'))
|
if (container == RIFF_FOURCC('R','F','6','4'))
|
||||||
riff_ds64(reader, data_length);
|
riff_ds64(reader, data_length);
|
||||||
@ -174,12 +172,11 @@ int wav_parse(wav_reader_t *reader, int64_t *data_length)
|
|||||||
} else if (fcc == RIFF_FOURCC('d','a','t','a')) {
|
} else if (fcc == RIFF_FOURCC('d','a','t','a')) {
|
||||||
if (container == RIFF_FOURCC('R','I','F','F'))
|
if (container == RIFF_FOURCC('R','I','F','F'))
|
||||||
*data_length = chunk_size;
|
*data_length = chunk_size;
|
||||||
reader->data_offset += 8;
|
reader->data_offset = pcm_tell(&reader->io);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
TRY_IO(pcm_skip(&reader->io, (chunk_size + 1) & ~1));
|
TRY_IO(pcm_skip(&reader->io, (chunk_size + 1) & ~1));
|
||||||
}
|
}
|
||||||
reader->data_offset += (chunk_size + 9) & ~1;
|
|
||||||
}
|
}
|
||||||
if (fcc == RIFF_FOURCC('d','a','t','a'))
|
if (fcc == RIFF_FOURCC('d','a','t','a'))
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user