mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
Originally committed as revision 2129 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
b928ec649c
commit
743739d2c5
10
ffmpeg.c
10
ffmpeg.c
@ -936,6 +936,11 @@ static int av_encode(AVFormatContext **output_files,
|
|||||||
ost->resample = audio_resample_init(codec->channels, icodec->channels,
|
ost->resample = audio_resample_init(codec->channels, icodec->channels,
|
||||||
codec->sample_rate,
|
codec->sample_rate,
|
||||||
icodec->sample_rate);
|
icodec->sample_rate);
|
||||||
|
if(!ost->resample)
|
||||||
|
{
|
||||||
|
printf("Can't resample. Aborting.\n");
|
||||||
|
av_abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Request specific number of channels */
|
/* Request specific number of channels */
|
||||||
icodec->channels = codec->channels;
|
icodec->channels = codec->channels;
|
||||||
@ -944,6 +949,11 @@ static int av_encode(AVFormatContext **output_files,
|
|||||||
ost->resample = audio_resample_init(codec->channels, icodec->channels,
|
ost->resample = audio_resample_init(codec->channels, icodec->channels,
|
||||||
codec->sample_rate,
|
codec->sample_rate,
|
||||||
icodec->sample_rate);
|
icodec->sample_rate);
|
||||||
|
if(!ost->resample)
|
||||||
|
{
|
||||||
|
printf("Can't resample. Aborting.\n");
|
||||||
|
av_abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ist->decoding_needed = 1;
|
ist->decoding_needed = 1;
|
||||||
|
@ -978,7 +978,7 @@ static void output_audio_block(AC3EncodeContext *s,
|
|||||||
int8_t global_exp[AC3_MAX_CHANNELS],
|
int8_t global_exp[AC3_MAX_CHANNELS],
|
||||||
int block_num)
|
int block_num)
|
||||||
{
|
{
|
||||||
int ch, nb_groups, group_size, i, baie;
|
int ch, nb_groups, group_size, i, baie, rbnd;
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
uint16_t qmant[AC3_MAX_CHANNELS][N/2];
|
uint16_t qmant[AC3_MAX_CHANNELS][N/2];
|
||||||
int exp0, exp1;
|
int exp0, exp1;
|
||||||
@ -1000,14 +1000,28 @@ static void output_audio_block(AC3EncodeContext *s,
|
|||||||
put_bits(&s->pb, 1, 0); /* no new coupling strategy */
|
put_bits(&s->pb, 1, 0); /* no new coupling strategy */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->acmod == 2) {
|
if (s->acmod == 2)
|
||||||
put_bits(&s->pb, 1, 0); /* no matrixing (but should be used in the future) */
|
{
|
||||||
}
|
if(block_num==0)
|
||||||
|
{
|
||||||
|
/* first block must define rematrixing (rematstr) */
|
||||||
|
put_bits(&s->pb, 1, 1);
|
||||||
|
|
||||||
|
/* dummy rematrixing rematflg(1:4)=0 */
|
||||||
|
for (rbnd=0;rbnd<4;rbnd++)
|
||||||
|
put_bits(&s->pb, 1, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* no matrixing (but should be used in the future) */
|
||||||
|
put_bits(&s->pb, 1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
{
|
{
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
printf("Block #%d (%d)\n", block_num, count++);
|
printf("Block #%d (%d)\n", block_num, count++);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* exponent strategy */
|
/* exponent strategy */
|
||||||
@ -1329,7 +1343,8 @@ static int output_frame_end(AC3EncodeContext *s)
|
|||||||
frame = s->pb.buf;
|
frame = s->pb.buf;
|
||||||
n = 2 * s->frame_size - (pbBufPtr(&s->pb) - frame) - 2;
|
n = 2 * s->frame_size - (pbBufPtr(&s->pb) - frame) - 2;
|
||||||
assert(n >= 0);
|
assert(n >= 0);
|
||||||
memset(pbBufPtr(&s->pb), 0, n);
|
if(n>0)
|
||||||
|
memset(pbBufPtr(&s->pb), 0, n);
|
||||||
|
|
||||||
/* Now we must compute both crcs : this is not so easy for crc1
|
/* Now we must compute both crcs : this is not so easy for crc1
|
||||||
because it is at the beginning of the data... */
|
because it is at the beginning of the data... */
|
||||||
|
@ -194,6 +194,23 @@ static void stereo_mux(short *output, short *input1, short *input2, int n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ac3_5p1_mux(short *output, short *input1, short *input2, int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
short l,r;
|
||||||
|
|
||||||
|
for(i=0;i<n;i++) {
|
||||||
|
l=*input1++;
|
||||||
|
r=*input2++;
|
||||||
|
*output++ = l; /* left */
|
||||||
|
*output++ = (l/2)+(r/2); /* center */
|
||||||
|
*output++ = r; /* right */
|
||||||
|
*output++ = 0; /* left surround */
|
||||||
|
*output++ = 0; /* right surroud */
|
||||||
|
*output++ = 0; /* low freq */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples)
|
static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples)
|
||||||
{
|
{
|
||||||
short *buf1;
|
short *buf1;
|
||||||
@ -225,12 +242,18 @@ ReSampleContext *audio_resample_init(int output_channels, int input_channels,
|
|||||||
ReSampleContext *s;
|
ReSampleContext *s;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (output_channels > 2 || input_channels > 2)
|
if ( input_channels > 2)
|
||||||
return NULL;
|
{
|
||||||
|
printf("Resampling with input channels greater than 2 unsupported.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
s = av_mallocz(sizeof(ReSampleContext));
|
s = av_mallocz(sizeof(ReSampleContext));
|
||||||
if (!s)
|
if (!s)
|
||||||
return NULL;
|
{
|
||||||
|
printf("Can't allocate memory for resample context.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
s->ratio = (float)output_rate / (float)input_rate;
|
s->ratio = (float)output_rate / (float)input_rate;
|
||||||
|
|
||||||
@ -241,6 +264,14 @@ ReSampleContext *audio_resample_init(int output_channels, int input_channels,
|
|||||||
if (s->output_channels < s->filter_channels)
|
if (s->output_channels < s->filter_channels)
|
||||||
s->filter_channels = s->output_channels;
|
s->filter_channels = s->output_channels;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ac3 output is the only case where filter_channels could be greater than 2.
|
||||||
|
* input channels can't be greater than 2, so resample the 2 channels and then
|
||||||
|
* expand to 6 channels after the resampling.
|
||||||
|
*/
|
||||||
|
if(s->filter_channels>2)
|
||||||
|
s->filter_channels = 2;
|
||||||
|
|
||||||
for(i=0;i<s->filter_channels;i++) {
|
for(i=0;i<s->filter_channels;i++) {
|
||||||
init_mono_resample(&s->channel_ctx[i], s->ratio);
|
init_mono_resample(&s->channel_ctx[i], s->ratio);
|
||||||
}
|
}
|
||||||
@ -279,10 +310,10 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
|
|||||||
buftmp2[0] = bufin[0];
|
buftmp2[0] = bufin[0];
|
||||||
buftmp3[0] = output;
|
buftmp3[0] = output;
|
||||||
stereo_to_mono(buftmp2[0], input, nb_samples);
|
stereo_to_mono(buftmp2[0], input, nb_samples);
|
||||||
} else if (s->output_channels == 2 && s->input_channels == 1) {
|
} else if (s->output_channels >= 2 && s->input_channels == 1) {
|
||||||
buftmp2[0] = input;
|
buftmp2[0] = input;
|
||||||
buftmp3[0] = bufout[0];
|
buftmp3[0] = bufout[0];
|
||||||
} else if (s->output_channels == 2) {
|
} else if (s->output_channels >= 2) {
|
||||||
buftmp2[0] = bufin[0];
|
buftmp2[0] = bufin[0];
|
||||||
buftmp2[1] = bufin[1];
|
buftmp2[1] = bufin[1];
|
||||||
buftmp3[0] = bufout[0];
|
buftmp3[0] = bufout[0];
|
||||||
@ -303,6 +334,8 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
|
|||||||
mono_to_stereo(output, buftmp3[0], nb_samples1);
|
mono_to_stereo(output, buftmp3[0], nb_samples1);
|
||||||
} else if (s->output_channels == 2) {
|
} else if (s->output_channels == 2) {
|
||||||
stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
|
stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
|
||||||
|
} else if (s->output_channels == 6) {
|
||||||
|
ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
|
||||||
}
|
}
|
||||||
|
|
||||||
av_free(bufin[0]);
|
av_free(bufin[0]);
|
||||||
|
@ -52,4 +52,4 @@ stddev: 19.19 bytes:7602176
|
|||||||
stddev: 8.19 bytes:7602176
|
stddev: 8.19 bytes:7602176
|
||||||
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
|
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
|
||||||
116d1290ba1b4eb98fdee52e423417b1 *./data/out.wav
|
116d1290ba1b4eb98fdee52e423417b1 *./data/out.wav
|
||||||
048b9c3444c788bac6ce5cc3a8f4db00 *./data/a-ac3.rm
|
d056da679e6d6682812fffb28a7f0db6 *./data/a-ac3.rm
|
||||||
|
@ -52,4 +52,4 @@ bee27a404ab6a1b7ab1d3551eb4f1877 *./data/a-flv.flv
|
|||||||
stddev: 5.29 bytes:7602176
|
stddev: 5.29 bytes:7602176
|
||||||
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
|
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
|
||||||
116d1290ba1b4eb98fdee52e423417b1 *./data/out.wav
|
116d1290ba1b4eb98fdee52e423417b1 *./data/out.wav
|
||||||
048b9c3444c788bac6ce5cc3a8f4db00 *./data/a-ac3.rm
|
d056da679e6d6682812fffb28a7f0db6 *./data/a-ac3.rm
|
||||||
|
Loading…
Reference in New Issue
Block a user