annotate libmpcodecs/ae_twolame.c @ 17725:d7dd016cb97a

update activity every 30 sec
author nplourde
date Sat, 04 Mar 2006 12:37:44 +0000
parents 6ff3379a0862
children ca9da45d13e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15359
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
1 #include <stdio.h>
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
2 #include <stdlib.h>
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
3 #include <inttypes.h>
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
4 #include <unistd.h>
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
5 #include <string.h>
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
6 #include <sys/types.h>
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
7 #include "m_option.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16482
diff changeset
8 #include "mp_msg.h"
15359
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
9 #include "aviheader.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16482
diff changeset
10 #include "libaf/af_format.h"
15359
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
11 #include "ms_hdr.h"
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
12 #include "muxer.h"
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
13 #include "ae_twolame.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16482
diff changeset
14 #include "libmpdemux/mp3_hdr.h"
15359
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
15
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
16
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
17 static int
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
18 param_bitrate = 192,
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
19 param_psy = 3,
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
20 param_maxvbr = 0,
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
21 param_errprot = 0,
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
22 param_debug = 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
23
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
24 static float param_vbr = 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
25 static char *param_mode = "stereo";
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
26
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
27 m_option_t twolameopts_conf[] = {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
28 {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
29 {"mode", &param_mode, CONF_TYPE_STRING, 0, 0, 0, NULL},
15362
4ff00aa141ef updated psycho model range; made a parameter file-static in ae_toolame.c
nicodvb
parents: 15359
diff changeset
30 {"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, -1, 4, NULL},
15359
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
31 {"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, -50, 50, NULL},
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
32 {"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
33 {"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
34 {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
35 {NULL, NULL, 0, 0, 0, 0, NULL}
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
36 };
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
37
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
38
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
39 static int bind_twolame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
40 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
41 mpae_twolame_ctx *ctx = (mpae_twolame_ctx *) encoder->priv;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
42
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
43 mux_a->wf = malloc(sizeof(WAVEFORMATEX)+256);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
44 mux_a->wf->wFormatTag = 0x50;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
45 mux_a->wf->nChannels = encoder->params.channels;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
46 mux_a->wf->nSamplesPerSec = encoder->params.sample_rate;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
47 mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
48
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
49 if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec))
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
50 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
51 mux_a->h.dwScale = encoder->params.samples_per_frame;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
52 mux_a->h.dwRate = encoder->params.sample_rate;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
53 mux_a->h.dwSampleSize = 0; // Blocksize not constant
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
54 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
55 else
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
56 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
57 mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
58 mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
59 mux_a->h.dwSampleSize = mux_a->h.dwScale;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
60 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
61 mux_a->wf->nBlockAlign = mux_a->h.dwScale;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
62 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
63 mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
64
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
65 mux_a->wf->cbSize = 0; //12;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
66 mux_a->wf->wBitsPerSample = 0; /* does not apply */
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
67 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
68 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
69 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
70 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
71 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
72
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
73 // Fix allocation
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
74 mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
75
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
76 encoder->input_format = AF_FORMAT_S16_NE;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
77 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
78 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
79
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
80 return 1;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
81 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
82
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
83 static int encode_twolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
84 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
85 mpae_twolame_ctx *ctx = (mpae_twolame_ctx *)encoder->priv;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
86 int ret_size = 0, r2;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
87
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
88 len /= (2*encoder->params.channels);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
89 ret_size = twolame_encode_buffer_interleaved(ctx->twolame_ctx, src, len, dest, max_size);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
90 r2 = mp_decode_mp3_header(dest);
16482
82698fb46c73 reduced verbosity
nicodvb
parents: 15362
diff changeset
91 mp_msg(MSGT_MENCODER, MSGL_DBG2, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2);
15359
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
92 if(r2 > 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
93 ret_size = r2;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
94 return ret_size;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
95 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
96
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
97 int close_twolame(audio_encoder_t *encoder)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
98 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
99 free(encoder->priv);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
100 return 1;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
101 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
102
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
103 static int get_frame_size(audio_encoder_t *encoder)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
104 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
105 int sz;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
106 if(encoder->stream->buffer_len < 4)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
107 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
108 sz = mp_decode_mp3_header(encoder->stream->buffer);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
109 if(sz <= 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
110 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
111 return sz;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
112 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
113
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
114
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
115 int mpae_init_twolame(audio_encoder_t *encoder)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
116 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
117 int mode;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
118 mpae_twolame_ctx *ctx = NULL;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
119
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
120 if(encoder->params.channels == 1)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
121 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
122 mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_twolame, 1 audio channel, forcing mono mode\n");
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
123 mode = TWOLAME_MONO;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
124 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
125 else if(encoder->params.channels == 2)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
126 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
127 if(! strcasecmp(param_mode, "dual"))
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
128 mode = TWOLAME_DUAL_CHANNEL;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
129 else if(! strcasecmp(param_mode, "jstereo"))
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
130 mode = TWOLAME_JOINT_STEREO;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
131 else if(! strcasecmp(param_mode, "stereo"))
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
132 mode = TWOLAME_STEREO;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
133 else
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
134 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
135 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, unknown mode %s, exiting\n", param_mode);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
136 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
137 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
138 else
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
139 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, Twolame can't encode > 2 channels, exiting\n");
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
140
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
141 ctx = (mpae_twolame_ctx *) calloc(1, sizeof(mpae_twolame_ctx));
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
142 if(ctx == NULL)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
143 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
144 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_twolame_ctx));
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
145 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
146 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
147
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
148 ctx->twolame_ctx = twolame_init();
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
149 if(ctx->twolame_ctx == NULL)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
150 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
151 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't initial parameters from libtwolame, exiting\n");
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
152 free(ctx);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
153 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
154 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
155 ctx->vbr = 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
156
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
157 if(twolame_set_num_channels(ctx->twolame_ctx, encoder->params.channels) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
158 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
159 if(twolame_set_mode(ctx->twolame_ctx, mode) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
160 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
161
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
162 if(twolame_set_in_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
163 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
164
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
165 if(twolame_set_out_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
166 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
167
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
168 if(encoder->params.sample_rate < 32000)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
169 twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG2);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
170 else
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
171 twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG1);
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
172
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
173 if(twolame_set_psymodel(ctx->twolame_ctx, param_psy) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
174 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
175
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
176 if(twolame_set_bitrate(ctx->twolame_ctx, param_bitrate) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
177 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
178
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
179 if(param_errprot)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
180 if(twolame_set_error_protection(ctx->twolame_ctx, TRUE) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
181 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
182
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
183 if(param_vbr != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
184 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
185 if(twolame_set_VBR(ctx->twolame_ctx, TRUE) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
186 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
187 if(twolame_set_VBR_q(ctx->twolame_ctx, param_vbr) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
188 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
189 if(twolame_set_padding(ctx->twolame_ctx, FALSE) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
190 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
191 if(param_maxvbr)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
192 {
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
193 if(twolame_set_VBR_max_bitrate_kbps(ctx->twolame_ctx, param_maxvbr) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
194 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
195 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
196 ctx->vbr = 1;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
197 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
198
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
199 if(twolame_set_verbosity(ctx->twolame_ctx, param_debug) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
200 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
201
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
202 if(twolame_init_params(ctx->twolame_ctx) != 0)
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
203 return 0;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
204
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
205 encoder->params.bitrate = param_bitrate * 1000;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
206 encoder->params.samples_per_frame = 1152;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
207 encoder->priv = ctx;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
208 encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
209
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
210 encoder->bind = bind_twolame;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
211 encoder->get_frame_size = get_frame_size;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
212 encoder->encode = encode_twolame;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
213 encoder->close = close_twolame;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
214
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
215 return 1;
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
216 }
af245d15f502 added twolame mp2 audio encoder
nicodvb
parents:
diff changeset
217