annotate libmpcodecs/ae_toolame.c @ 15258:c2979462805a

fixed wrong function pointers definitions
author nicodvb
date Mon, 25 Apr 2005 06:46:30 +0000
parents 6d6792c02b6f
children 92772475ed8d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
1 #include <stdio.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
2 #include <stdlib.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
3 #include <inttypes.h>
15238
2cc48c37a7eb FreeBSD fix
nexus
parents: 15234
diff changeset
4 #include <unistd.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
5 #include <string.h>
15240
6d6792c02b6f macosx compilation fix
nicodvb
parents: 15238
diff changeset
6 #include <sys/types.h>
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
7 #include "m_option.h"
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
8 #include "../mp_msg.h"
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
9 #include "aviheader.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
10 #include "../libaf/af_format.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
11 #include "ms_hdr.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
12 #include "muxer.h"
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
13 #include "ae_toolame.h"
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
14 #include "../libmpdemux/mp3_hdr.h"
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
15
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
16
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
17 static int
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
18 param_bitrate = 192,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
19 param_psy = 3,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
20 param_maxvbr = 192,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
21 param_errprot = 0,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
22 param_debug = 0;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
23
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
24 float param_vbr = 0;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
25 static char *param_mode = "stereo";
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
26
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
27 m_option_t toolameopts_conf[] = {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
28 {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
29 {"mode", &param_mode, CONF_TYPE_STRING, 0, 0, 0, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
30 {"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
31 {"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, 0, 50, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
32 {"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
33 {"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
34 {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
35 {NULL, NULL, 0, 0, 0, 0, NULL}
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
36 };
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
37
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
38
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
39 static int bind_toolame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
40 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
41 mux_a->wf = malloc(sizeof(WAVEFORMATEX)+256);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
42 mux_a->wf->wFormatTag = 0x50;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
43 mux_a->wf->nChannels = encoder->params.channels;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
44 mux_a->wf->nSamplesPerSec = encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
45 mux_a->wf->nAvgBytesPerSec = 125 * encoder->params.bitrate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
46 mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
47 mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
48
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
49 if((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
50 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
51 mux_a->h.dwScale = encoder->params.samples_per_frame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
52 mux_a->h.dwRate = encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
53 mux_a->h.dwSampleSize = 0; // Blocksize not constant
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
54 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
55 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
56 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
57 mux_a->h.dwSampleSize = mux_a->h.dwScale;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
58 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
59 mux_a->wf->nBlockAlign = mux_a->h.dwScale;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
60 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
61 mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
62
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
63 mux_a->wf->cbSize = 12;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
64 mux_a->wf->wBitsPerSample = 0; /* does not apply */
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
65 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
66 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
67 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
68 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
69 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
70
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
71 // Fix allocation
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
72 mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
73
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
74 encoder->input_format = AF_FORMAT_S16_NE;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
75 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
76 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
77
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
78 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
79 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
80
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
81 static int encode_toolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
82 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
83 mpae_toolame_ctx *ctx = (mpae_toolame_ctx *)encoder->priv;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
84 int ret_size = 0, i, nsamples;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
85 int16_t *buffer;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
86
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
87 nsamples = len / (2*encoder->params.channels);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
88 buffer = (uint16_t *) src;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
89 for(i = 0; i < nsamples; i++)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
90 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
91 ctx->left_pcm[i] = buffer[ctx->channels * i];
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
92 ctx->right_pcm[i] = buffer[(ctx->channels * i) + (ctx->channels - 1)];
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
93 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
94
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
95 toolame_encode_buffer(ctx->toolame_ctx, ctx->left_pcm, ctx->right_pcm, nsamples, dest, max_size, &ret_size);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
96 return ret_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
97 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
98
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
99 int close_toolame(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
100 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
101 free(encoder->priv);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
102 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
103 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
104
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
105 static int get_frame_size(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
106 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
107 int sz;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
108 if(encoder->stream->buffer_len < 4)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
109 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
110 sz = mp_decode_mp3_header(encoder->stream->buffer);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
111 if(sz <= 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
112 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
113 return sz;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
114 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
115
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
116
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
117 int mpae_init_toolame(audio_encoder_t *encoder)
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
118 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
119 int mode;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
120 mpae_toolame_ctx *ctx = NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
121
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
122 if(encoder->params.channels == 1)
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
123 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
124 mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_toolame, 1 audio channel, forcing mono mode\n");
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
125 mode = MPG_MD_MONO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
126 }
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
127 else if(encoder->params.channels == 2)
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
128 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
129 if(! strcasecmp(param_mode, "dual"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
130 mode = MPG_MD_DUAL_CHANNEL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
131 else if(! strcasecmp(param_mode, "jstereo"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
132 mode = MPG_MD_JOINT_STEREO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
133 else if(! strcasecmp(param_mode, "stereo"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
134 mode = MPG_MD_STEREO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
135 else
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
136 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
137 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, unknown mode %s, exiting\n", param_mode);
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
138 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
139 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
140 else
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
141 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, Toolame can't encode > 2 channels, exiting\n");
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
142
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
143 ctx = (mpae_toolame_ctx *) calloc(1, sizeof(mpae_toolame_ctx));
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
144 if(ctx == NULL)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
145 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
146 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_toolame_ctx));
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
147 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
148 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
149
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
150 ctx->toolame_ctx = toolame_init();
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
151 if(ctx->toolame_ctx == NULL)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
152 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
153 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't initial parameters from libtoolame, exiting\n");
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
154 free(ctx);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
155 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
156 }
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
157 ctx->channels = encoder->params.channels;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
158 ctx->srate = encoder->params.sample_rate;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
159
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
160 if(toolame_setMode(ctx->toolame_ctx, mode) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
161 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
162
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
163 if(toolame_setPsymodel(ctx->toolame_ctx, param_psy) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
164 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
165
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
166 if(toolame_setSampleFreq(ctx->toolame_ctx, encoder->params.sample_rate) != 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
167 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
168
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
169 if(toolame_setBitrate(ctx->toolame_ctx, param_bitrate) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
170 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
171
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
172 if(param_errprot)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
173 if(toolame_setErrorProtection(ctx->toolame_ctx, TRUE) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
174 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
175
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
176 if(param_vbr > 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
177 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
178 if(toolame_setVBR(ctx->toolame_ctx, TRUE) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
179 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
180 if(toolame_setVBRLevel(ctx->toolame_ctx, param_maxvbr) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
181 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
182 if(toolame_setPadding(ctx->toolame_ctx, FALSE) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
183 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
184 if(toolame_setVBRUpperBitrate(ctx->toolame_ctx, param_maxvbr) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
185 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
186 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
187
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
188 if(toolame_setVerbosity(ctx->toolame_ctx, param_debug) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
189 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
190
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
191 if(toolame_init_params(ctx->toolame_ctx) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
192 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
193
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
194 ctx->bitrate = param_bitrate;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
195 encoder->params.bitrate = ctx->bitrate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
196 encoder->params.samples_per_frame = 1152;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
197 encoder->priv = ctx;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
198 encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
199
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
200 encoder->bind = bind_toolame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
201 encoder->get_frame_size = get_frame_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
202 encoder->encode = encode_toolame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
203 encoder->close = close_toolame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
204
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
205 return 1;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
206 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
207