annotate libmpcodecs/ae_lame.c @ 15234:e84a6ae9d51e

audio encoding reworked
author nicodvb
date Fri, 22 Apr 2005 06:59:59 +0000
parents
children 2cc48c37a7eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
1 #include <stdio.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
2 #include <stdlib.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
3 #include <inttypes.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
4 #include <string.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
5 #include "m_option.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
6 #include "../mp_msg.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
7 #include "aviheader.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
8 #include "ms_hdr.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
9 #include "muxer.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
10 #include "../help_mp.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
11 #include "ae_pcm.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
12 #include "../libaf/af_format.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
13 #include "../libmpdemux/mp3_hdr.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
14
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
15 #undef CDECL
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
16 #include <lame/lame.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
17
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
18 lame_global_flags *lame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
19 static int lame_param_quality=0; // best
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
20 static int lame_param_algqual=5; // same as old default
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
21 static int lame_param_vbr=vbr_default;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
22 static int lame_param_mode=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
23 static int lame_param_padding=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
24 static int lame_param_br=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
25 static int lame_param_ratio=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
26 static float lame_param_scale=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
27 static int lame_param_lowpassfreq = 0; //auto
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
28 static int lame_param_highpassfreq = 0; //auto
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
29 static int lame_param_free_format = 0; //disabled
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
30 static int lame_param_br_min = 0; //not specified
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
31 static int lame_param_br_max = 0; //not specified
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
32
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
33 #if HAVE_MP3LAME >= 392
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
34 int lame_param_fast=0; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
35 static char* lame_param_preset=NULL; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
36 static int lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name );
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
37 static void lame_presets_longinfo_dm ( FILE* msgfp );
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
38 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
39
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
40
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
41 m_option_t lameopts_conf[]={
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
42 {"q", &lame_param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
43 {"aq", &lame_param_algqual, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
44 {"vbr", &lame_param_vbr, CONF_TYPE_INT, CONF_RANGE, 0, vbr_max_indicator, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
45 {"cbr", &lame_param_vbr, CONF_TYPE_FLAG, 0, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
46 {"abr", &lame_param_vbr, CONF_TYPE_FLAG, 0, 0, vbr_abr, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
47 {"mode", &lame_param_mode, CONF_TYPE_INT, CONF_RANGE, 0, MAX_INDICATOR, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
48 {"padding", &lame_param_padding, CONF_TYPE_INT, CONF_RANGE, 0, PAD_MAX_INDICATOR, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
49 {"br", &lame_param_br, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
50 {"ratio", &lame_param_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
51 {"vol", &lame_param_scale, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
52 {"lowpassfreq",&lame_param_lowpassfreq, CONF_TYPE_INT, CONF_RANGE, -1, 48000,0},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
53 {"highpassfreq",&lame_param_highpassfreq, CONF_TYPE_INT, CONF_RANGE, -1, 48000,0},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
54 {"nofree", &lame_param_free_format, CONF_TYPE_FLAG, 0, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
55 {"free", &lame_param_free_format, CONF_TYPE_FLAG, 0, 0, 1, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
56 {"br_min", &lame_param_br_min, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
57 {"br_max", &lame_param_br_max, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
58 #if HAVE_MP3LAME >= 392
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
59 {"fast", &lame_param_fast, CONF_TYPE_FLAG, 0, 0, 1, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
60 {"preset", &lame_param_preset, CONF_TYPE_STRING, 0, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
61 #else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
62 {"fast", "MPlayer was built without -lameopts fast support (requires libmp3lame >=3.92).\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
63 {"preset", "MPlayer was built without -lameopts preset support (requires libmp3lame >=3.92).\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
64 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
65 {"help", MSGTR_MEncoderMP3LameHelp, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
66 {NULL, NULL, 0, 0, 0, 0, NULL}
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
67 };
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
68
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
69
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
70 static int pass;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
71 extern int verbose;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
72
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
73 static int bind_lame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
74 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
75 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_MP3AudioSelected);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
76 mux_a->h.dwSampleSize=0; // VBR
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
77 mux_a->h.dwRate=encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
78 mux_a->h.dwScale=encoder->params.samples_per_frame; // samples/frame
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
79 if(sizeof(MPEGLAYER3WAVEFORMAT)!=30) mp_msg(MSGT_MENCODER,MSGL_WARN,MSGTR_MP3WaveFormatSizeNot30,sizeof(MPEGLAYER3WAVEFORMAT));
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
80 mux_a->wf=malloc(sizeof(MPEGLAYER3WAVEFORMAT)); // should be 30
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
81 mux_a->wf->wFormatTag=0x55; // MP3
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
82 mux_a->wf->nChannels= (lame_param_mode<0) ? encoder->params.channels : ((lame_param_mode==3) ? 1 : 2);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
83 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
84 if(! lame_param_vbr)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
85 mux_a->wf->nAvgBytesPerSec=lame_param_br * 125;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
86 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
87 mux_a->wf->nAvgBytesPerSec=192000/8; // FIXME!
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
88 mux_a->wf->nBlockAlign=encoder->params.samples_per_frame; // required for l3codeca.acm + WMP 6.4
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
89 mux_a->wf->wBitsPerSample=0; //16;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
90 // from NaNdub: (requires for l3codeca.acm)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
91 mux_a->wf->cbSize=12;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
92 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->wID=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
93 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->fdwFlags=2;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
94 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nBlockSize=encoder->params.samples_per_frame; // ???
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
95 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nFramesPerBlock=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
96 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nCodecDelay=0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
97
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
98 encoder->input_format = AF_FORMAT_S16_LE;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
99 encoder->min_buffer_size = 4608;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
100 encoder->max_buffer_size = mux_a->h.dwRate * mux_a->wf->nChannels * 2;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
101
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
102 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
103 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
104
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
105 #define min(a, b) ((a) <= (b) ? (a) : (b))
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
106
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
107 static int get_frame_size(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
108 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
109 int sz;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
110 if(encoder->stream->buffer_len < 4)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
111 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
112 sz = mp_decode_mp3_header(encoder->stream->buffer);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
113 if(sz <= 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
114 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
115 return sz;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
116 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
117
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
118 static int encode_lame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
119 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
120 int n = 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
121 if(encoder->params.channels == 1)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
122 n = lame_encode_buffer(lame, (short *)src, (short *)src, len/2, dest, max_size);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
123 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
124 n = lame_encode_buffer_interleaved(lame,(short *)src, len/4, dest, max_size);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
125
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
126 return (n < 0 ? 0 : n);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
127 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
128
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
129
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
130 static int close_lame(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
131 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
132 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
133 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
134
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
135 static void fixup(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
136 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
137 // fixup CBR mp3 audio header:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
138 if(!lame_param_vbr) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
139 encoder->stream->h.dwSampleSize=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
140 ((MPEGLAYER3WAVEFORMAT*)(encoder->stream->wf))->nBlockSize=
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
141 (encoder->stream->size+(encoder->stream->h.dwLength>>1))/encoder->stream->h.dwLength;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
142 encoder->stream->h.dwLength=encoder->stream->size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
143 encoder->stream->h.dwRate=encoder->stream->wf->nAvgBytesPerSec;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
144 encoder->stream->h.dwScale=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
145 encoder->stream->wf->nBlockAlign=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
146 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_CBRAudioByterate,
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
147 encoder->stream->h.dwRate,((MPEGLAYER3WAVEFORMAT*)(encoder->stream->wf))->nBlockSize);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
148 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
149 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
150
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
151 int mpae_init_lame(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
152 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
153 encoder->params.bitrate = lame_param_br * 125;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
154 encoder->params.samples_per_frame = encoder->params.sample_rate < 32000 ? 576 : 1152;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
155 encoder->decode_buffer_size = 2304;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
156
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
157 lame=lame_init();
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
158 lame_set_bWriteVbrTag(lame,0);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
159 lame_set_in_samplerate(lame,encoder->params.sample_rate);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
160 //lame_set_in_samplerate(lame,sh_audio->samplerate); // if resampling done by lame
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
161 lame_set_num_channels(lame,encoder->params.channels);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
162 lame_set_out_samplerate(lame,encoder->params.sample_rate);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
163 lame_set_quality(lame,lame_param_algqual); // 0 = best q
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
164 if(lame_param_free_format) lame_set_free_format(lame,1);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
165 if(lame_param_vbr){ // VBR:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
166 lame_set_VBR(lame,lame_param_vbr); // vbr mode
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
167 lame_set_VBR_q(lame,lame_param_quality); // 0 = best vbr q 5=~128k
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
168 if(lame_param_br>0) lame_set_VBR_mean_bitrate_kbps(lame,lame_param_br);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
169 if(lame_param_br_min>0) lame_set_VBR_min_bitrate_kbps(lame,lame_param_br_min);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
170 if(lame_param_br_max>0) lame_set_VBR_max_bitrate_kbps(lame,lame_param_br_max);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
171 } else { // CBR:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
172 if(lame_param_br>0) lame_set_brate(lame,lame_param_br);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
173 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
174 if(lame_param_mode>=0) lame_set_mode(lame,lame_param_mode); // j-st
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
175 if(lame_param_ratio>0) lame_set_compression_ratio(lame,lame_param_ratio);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
176 if(lame_param_scale>0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
177 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_SettingAudioInputGain, lame_param_scale);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
178 lame_set_scale(lame,lame_param_scale);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
179 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
180 if(lame_param_lowpassfreq>=-1) lame_set_lowpassfreq(lame,lame_param_lowpassfreq);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
181 if(lame_param_highpassfreq>=-1) lame_set_highpassfreq(lame,lame_param_highpassfreq);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
182 #if HAVE_MP3LAME >= 392
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
183 if(lame_param_preset != NULL) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
184 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_LamePresetEquals,lame_param_preset);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
185 if(lame_presets_set(lame,lame_param_fast, (lame_param_vbr==0), lame_param_preset) < 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
186 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
187 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
188 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
189 if(lame_init_params(lame) == -1) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
190 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_LameCantInit);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
191 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
192 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
193 if(verbose>0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
194 lame_print_config(lame);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
195 lame_print_internals(lame);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
196 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
197
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
198 encoder->bind = bind_lame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
199 encoder->get_frame_size = get_frame_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
200 encoder->encode = encode_lame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
201 encoder->fixup = fixup;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
202 encoder->close = close_lame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
203 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
204 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
205
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
206 #if HAVE_MP3LAME >= 392
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
207 /* lame_presets_set
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
208 taken out of presets_set in lame-3.93.1/frontend/parse.c and modified */
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
209 static int lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name )
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
210 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
211 int mono = 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
212
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
213 if (strcmp(preset_name, "help") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
214 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_LameVersion, get_lame_version(), get_lame_url());
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
215 lame_presets_longinfo_dm(stderr);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
216 return -1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
217 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
218
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
219 //aliases for compatibility with old presets
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
220
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
221 if (strcmp(preset_name, "phone") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
222 preset_name = "16";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
223 mono = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
224 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
225 if ( (strcmp(preset_name, "phon+") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
226 (strcmp(preset_name, "lw") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
227 (strcmp(preset_name, "mw-eu") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
228 (strcmp(preset_name, "sw") == 0)) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
229 preset_name = "24";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
230 mono = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
231 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
232 if (strcmp(preset_name, "mw-us") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
233 preset_name = "40";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
234 mono = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
235 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
236 if (strcmp(preset_name, "voice") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
237 preset_name = "56";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
238 mono = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
239 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
240 if (strcmp(preset_name, "fm") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
241 preset_name = "112";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
242 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
243 if ( (strcmp(preset_name, "radio") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
244 (strcmp(preset_name, "tape") == 0)) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
245 preset_name = "112";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
246 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
247 if (strcmp(preset_name, "hifi") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
248 preset_name = "160";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
249 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
250 if (strcmp(preset_name, "cd") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
251 preset_name = "192";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
252 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
253 if (strcmp(preset_name, "studio") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
254 preset_name = "256";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
255 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
256
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
257 #if HAVE_MP3LAME >= 393
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
258 if (strcmp(preset_name, "medium") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
259 if (fast > 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
260 lame_set_preset(gfp, MEDIUM_FAST);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
261 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
262 lame_set_preset(gfp, MEDIUM);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
263
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
264 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
265 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
266 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
267
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
268 if (strcmp(preset_name, "standard") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
269 if (fast > 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
270 lame_set_preset(gfp, STANDARD_FAST);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
271 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
272 lame_set_preset(gfp, STANDARD);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
273
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
274 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
275 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
276
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
277 else if (strcmp(preset_name, "extreme") == 0){
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
278 if (fast > 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
279 lame_set_preset(gfp, EXTREME_FAST);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
280 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
281 lame_set_preset(gfp, EXTREME);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
282
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
283 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
284 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
285
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
286 else if (((strcmp(preset_name, "insane") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
287 (strcmp(preset_name, "320" ) == 0)) && (fast < 1)) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
288
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
289 lame_set_preset(gfp, INSANE);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
290
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
291 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
292 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
293
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
294 // Generic ABR Preset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
295 if (((atoi(preset_name)) > 0) && (fast < 1)) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
296 if ((atoi(preset_name)) >= 8 && (atoi(preset_name)) <= 320){
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
297 lame_set_preset(gfp, atoi(preset_name));
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
298
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
299 if (cbr == 1 )
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
300 lame_set_VBR(gfp, vbr_off);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
301
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
302 if (mono == 1 ) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
303 lame_set_mode(gfp, MONO);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
304 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
305
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
306 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
307
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
308 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
309 else {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
310 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_LameVersion, get_lame_version(), get_lame_url());
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
311 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_InvalidBitrateForLamePreset);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
312 return -1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
313 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
314 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
315
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
316 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_LameVersion, get_lame_version(), get_lame_url());
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
317 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_InvalidLamePresetOptions);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
318 return -1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
319 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
320 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
321
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
322 #if HAVE_MP3LAME >= 392
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
323 /* lame_presets_longinfo_dm
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
324 taken out of presets_longinfo_dm in lame-3.93.1/frontend/parse.c and modified */
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
325 static void lame_presets_longinfo_dm ( FILE* msgfp )
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
326 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
327 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_LamePresetsLongInfo);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
328 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
329 #endif