process 32-bit input if possible (i.e. respect aac:INT_PCM type)

switch AAC-FDK from pcm16 to pcm32:
    typedef LONG INT_PCM;
    #define SAMPLE_BITS 32
This commit is contained in:
Dima 2019-09-19 13:07:22 +03:00
parent 130e249ebf
commit 353e4fcd7a
4 changed files with 24 additions and 10 deletions

View File

@ -247,7 +247,7 @@ FAIL:
int aac_encode_frame(HANDLE_AACENCODER encoder,
const pcm_sample_description_t *format,
const int16_t *input, unsigned iframes,
const INT_PCM *input, unsigned iframes,
aacenc_frame_t *output)
{
uint32_t ilen = iframes * format->channels_per_frame;
@ -258,9 +258,9 @@ int aac_encode_frame(HANDLE_AACENCODER encoder,
void *obufs[1];
INT ibuf_ids[] = { IN_AUDIO_DATA };
INT obuf_ids[] = { OUT_BITSTREAM_DATA };
INT ibuf_sizes[] = { ilen * sizeof(int16_t) };
INT ibuf_sizes[] = { ilen * sizeof(INT_PCM) };
INT obuf_sizes[1];
INT ibuf_el_sizes[] = { sizeof(int16_t) };
INT ibuf_el_sizes[] = { sizeof(INT_PCM) };
INT obuf_el_sizes[] = { 1 };
AACENC_ERROR err;
unsigned channel_mode, obytes;

View File

@ -50,7 +50,7 @@ int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
int aac_encode_frame(HANDLE_AACENCODER encoder,
const pcm_sample_description_t *format,
const int16_t *input, unsigned iframes,
const INT_PCM *input, unsigned iframes,
aacenc_frame_t *output);
#endif

View File

@ -521,7 +521,7 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
HANDLE_AACENCODER encoder, uint32_t frame_length,
m4af_ctx_t *m4af)
{
int16_t *ibuf = 0, *ip;
INT_PCM *ibuf = 0, *ip;
aacenc_frame_t obuf[2] = {{ 0 }}, *obp;
unsigned flip = 0;
int nread = 1;

View File

@ -10,6 +10,8 @@
#if HAVE_STDINT_H
# include <stdint.h>
#endif
#include <assert.h>
#include <fdk-aac/aacenc_lib.h>
#include "pcm_reader.h"
typedef struct pcm_sint16_converter_t {
@ -57,12 +59,18 @@ static int read_frames(pcm_reader_t *reader, void *buffer, unsigned nframes)
count = nframes * sfmt->channels_per_frame;
if (PCM_IS_FLOAT(sfmt)) {
float *ip = self->pivot;
int16_t *op = buffer;
INT_PCM *op = buffer;
#if SAMPLE_BITS == 16
for (i = 0; i < count; ++i)
op[i] = pcm_clip(ip[i] * 32768.0, -32768.0, 32767.0);
op[i] = (int16_t)pcm_clip(ip[i] * 32768.0, -32768.0, 32767.0);
#else
for (i = 0; i < count; ++i)
op[i] = (int32_t)pcm_clip(ip[i] * 2147483648.0, -2147483648.0, 2147483647.0);
#endif
} else {
int32_t *ip = self->pivot;
int16_t *op = buffer;
INT_PCM *op = buffer;
#if SAMPLE_BITS == 16
if (sfmt->bits_per_channel <= 16) {
for (i = 0; i < count; ++i)
op[i] = ip[i] >> 16;
@ -72,6 +80,10 @@ static int read_frames(pcm_reader_t *reader, void *buffer, unsigned nframes)
op[i] = (n == 0x8000) ? 0x7fff : n;
}
}
#else
for (i = 0; i < count; ++i)
op[i] = ip[i];
#endif
}
return nframes;
}
@ -94,14 +106,16 @@ pcm_reader_t *pcm_open_sint16_converter(pcm_reader_t *reader)
pcm_sint16_converter_t *self = 0;
pcm_sample_description_t *fmt;
assert((SAMPLE_BITS>>3) == sizeof(INT_PCM));
if ((self = calloc(1, sizeof(pcm_sint16_converter_t))) == 0)
return 0;
self->src = reader;
self->vtbl = &my_vtable;
memcpy(&self->format, pcm_get_format(reader), sizeof(self->format));
fmt = &self->format;
fmt->bits_per_channel = 16;
fmt->bits_per_channel = SAMPLE_BITS;
fmt->sample_type = PCM_TYPE_SINT;
fmt->bytes_per_frame = 2 * fmt->channels_per_frame;
fmt->bytes_per_frame = sizeof(INT_PCM) * fmt->channels_per_frame;
return (pcm_reader_t *)self;
}