annotate libmpcodecs/ae_lame.c @ 33585:1f6ff1848bd3

Remove left-over code from icon/cursor handling that is now done by w32_common.c
author reimar
date Sun, 19 Jun 2011 18:43:07 +0000
parents 4e59a7aebadb
children 277ec491a8a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
18
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
19 #include <stdio.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
20 #include <stdlib.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
21 #include <inttypes.h>
15238
2cc48c37a7eb FreeBSD fix
nexus
parents: 15234
diff changeset
22 #include <unistd.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
23 #include <string.h>
15240
6d6792c02b6f macosx compilation fix
nicodvb
parents: 15238
diff changeset
24 #include <sys/types.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
25 #include "m_option.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16802
diff changeset
26 #include "mp_msg.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
27 #include "libmpdemux/aviheader.h"
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
28 #include "libmpdemux/ms_hdr.h"
22600
3c2b4a866c6a Add explicit location for headers from the stream/ directory.
diego
parents: 21660
diff changeset
29 #include "stream/stream.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
30 #include "libmpdemux/muxer.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16802
diff changeset
31 #include "help_mp.h"
30554
321e9ea69b9f #include corresponding .h files in .c files.
diego
parents: 30421
diff changeset
32 #include "ae_lame.h"
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
33 #include "ae_pcm.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16802
diff changeset
34 #include "libaf/af_format.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16802
diff changeset
35 #include "libmpdemux/mp3_hdr.h"
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
36
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
37 #undef CDECL
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
38 #include <lame/lame.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
39
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
40 lame_global_flags *lame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
41 static int lame_param_quality=0; // best
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
42 static int lame_param_algqual=5; // same as old default
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
43 static int lame_param_vbr=vbr_default;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
44 static int lame_param_mode=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
45 static int lame_param_padding=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
46 static int lame_param_br=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
47 static int lame_param_ratio=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
48 static float lame_param_scale=-1; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
49 static int lame_param_lowpassfreq = 0; //auto
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
50 static int lame_param_highpassfreq = 0; //auto
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
51 static int lame_param_free_format = 0; //disabled
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
52 static int lame_param_br_min = 0; //not specified
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
53 static int lame_param_br_max = 0; //not specified
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
54
27363
40057010b1fa Change a bunch of codec-specific preprocessor directives from a HAVE_
diego
parents: 26754
diff changeset
55 #ifdef CONFIG_MP3LAME_PRESET
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
56 int lame_param_fast=0; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
57 static char* lame_param_preset=NULL; // unset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
58 static int lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name );
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
59 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
60
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
61
30955
4e59a7aebadb Mark encoder-related m_option_t struct arrays as const.
diego
parents: 30554
diff changeset
62 const m_option_t lameopts_conf[] = {
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
63 {"q", &lame_param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
64 {"aq", &lame_param_algqual, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
65 {"vbr", &lame_param_vbr, CONF_TYPE_INT, CONF_RANGE, 0, vbr_max_indicator, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
66 {"cbr", &lame_param_vbr, CONF_TYPE_FLAG, 0, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
67 {"abr", &lame_param_vbr, CONF_TYPE_FLAG, 0, 0, vbr_abr, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
68 {"mode", &lame_param_mode, CONF_TYPE_INT, CONF_RANGE, 0, MAX_INDICATOR, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
69 {"padding", &lame_param_padding, CONF_TYPE_INT, CONF_RANGE, 0, PAD_MAX_INDICATOR, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
70 {"br", &lame_param_br, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
71 {"ratio", &lame_param_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
72 {"vol", &lame_param_scale, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
73 {"lowpassfreq",&lame_param_lowpassfreq, CONF_TYPE_INT, CONF_RANGE, -1, 48000,0},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
74 {"highpassfreq",&lame_param_highpassfreq, CONF_TYPE_INT, CONF_RANGE, -1, 48000,0},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
75 {"nofree", &lame_param_free_format, CONF_TYPE_FLAG, 0, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
76 {"free", &lame_param_free_format, CONF_TYPE_FLAG, 0, 0, 1, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
77 {"br_min", &lame_param_br_min, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
78 {"br_max", &lame_param_br_max, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
27363
40057010b1fa Change a bunch of codec-specific preprocessor directives from a HAVE_
diego
parents: 26754
diff changeset
79 #ifdef CONFIG_MP3LAME_PRESET
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
80 {"fast", &lame_param_fast, CONF_TYPE_FLAG, 0, 0, 1, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
81 {"preset", &lame_param_preset, CONF_TYPE_STRING, 0, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
82 #else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
83 {"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
84 {"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
85 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
86 {"help", MSGTR_MEncoderMP3LameHelp, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
87 {NULL, NULL, 0, 0, 0, 0, NULL}
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
88 };
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
89
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
90
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
91 static int bind_lame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
92 {
21621
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
93 mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_MP3AudioSelected);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
94 mux_a->h.dwSampleSize=0; // VBR
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
95 mux_a->h.dwRate=encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
96 mux_a->h.dwScale=encoder->params.samples_per_frame; // samples/frame
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
97 if(sizeof(MPEGLAYER3WAVEFORMAT)!=30) mp_msg(MSGT_MENCODER,MSGL_WARN,MSGTR_MP3WaveFormatSizeNot30,sizeof(MPEGLAYER3WAVEFORMAT));
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
98 mux_a->wf=malloc(sizeof(MPEGLAYER3WAVEFORMAT)); // should be 30
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
99 mux_a->wf->wFormatTag=0x55; // MP3
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
100 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
101 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
102 if(! lame_param_vbr)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
103 mux_a->wf->nAvgBytesPerSec=lame_param_br * 125;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
104 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
105 mux_a->wf->nAvgBytesPerSec=192000/8; // FIXME!
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
106 mux_a->wf->nBlockAlign=encoder->params.samples_per_frame; // required for l3codeca.acm + WMP 6.4
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
107 mux_a->wf->wBitsPerSample=0; //16;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
108 // from NaNdub: (requires for l3codeca.acm)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
109 mux_a->wf->cbSize=12;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
110 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->wID=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
111 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->fdwFlags=2;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
112 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nBlockSize=encoder->params.samples_per_frame; // ???
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
113 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nFramesPerBlock=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
114 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nCodecDelay=0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
115
19397
0074c9c77a0e Set encoder's input format to "native endiannes", instead of little endian.
gpoirier
parents: 17932
diff changeset
116 encoder->input_format = AF_FORMAT_S16_NE;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
117 encoder->min_buffer_size = 4608;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
118 encoder->max_buffer_size = mux_a->h.dwRate * mux_a->wf->nChannels * 2;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
119
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
120 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
121 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
122
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
123 #define min(a, b) ((a) <= (b) ? (a) : (b))
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
124
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
125 static int get_frame_size(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
126 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
127 int sz;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
128 if(encoder->stream->buffer_len < 4)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
129 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
130 sz = mp_decode_mp3_header(encoder->stream->buffer);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
131 if(sz <= 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
132 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
133 return sz;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
134 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
135
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
136 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
137 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
138 int n = 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
139 if(encoder->params.channels == 1)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
140 n = lame_encode_buffer(lame, (short *)src, (short *)src, len/2, dest, max_size);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
141 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
142 n = lame_encode_buffer_interleaved(lame,(short *)src, len/4, dest, max_size);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
143
26754
63630c09e237 cosmetics: Remove pointless parentheses from return calls.
diego
parents: 25503
diff changeset
144 return n < 0 ? 0 : n;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
145 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
146
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
147
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
148 static int close_lame(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
149 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
150 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
151 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
152
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
153 static void fixup(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
154 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
155 // fixup CBR mp3 audio header:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
156 if(!lame_param_vbr) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
157 encoder->stream->h.dwSampleSize=1;
28347
1f4b3aaefcd8 Avoid a division by 0 when using -oac mp3lame but no audio data actually is encoded.
reimar
parents: 27363
diff changeset
158 if (encoder->stream->h.dwLength)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
159 ((MPEGLAYER3WAVEFORMAT*)(encoder->stream->wf))->nBlockSize=
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
160 (encoder->stream->size+(encoder->stream->h.dwLength>>1))/encoder->stream->h.dwLength;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
161 encoder->stream->h.dwLength=encoder->stream->size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
162 encoder->stream->h.dwRate=encoder->stream->wf->nAvgBytesPerSec;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
163 encoder->stream->h.dwScale=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
164 encoder->stream->wf->nBlockAlign=1;
21621
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
165 mp_msg(MSGT_MENCODER, MSGL_V, MSGTR_CBRAudioByterate,
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
166 encoder->stream->h.dwRate,((MPEGLAYER3WAVEFORMAT*)(encoder->stream->wf))->nBlockSize);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
167 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
168 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
169
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
170 int mpae_init_lame(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
171 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
172 encoder->params.bitrate = lame_param_br * 125;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
173 encoder->params.samples_per_frame = encoder->params.sample_rate < 32000 ? 576 : 1152;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
174 encoder->decode_buffer_size = 2304;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
175
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
176 lame=lame_init();
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
177 lame_set_bWriteVbrTag(lame,0);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
178 lame_set_in_samplerate(lame,encoder->params.sample_rate);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
179 //lame_set_in_samplerate(lame,sh_audio->samplerate); // if resampling done by lame
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
180 lame_set_num_channels(lame,encoder->params.channels);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
181 lame_set_out_samplerate(lame,encoder->params.sample_rate);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
182 lame_set_quality(lame,lame_param_algqual); // 0 = best q
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
183 if(lame_param_free_format) lame_set_free_format(lame,1);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
184 if(lame_param_vbr){ // VBR:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
185 lame_set_VBR(lame,lame_param_vbr); // vbr mode
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
186 lame_set_VBR_q(lame,lame_param_quality); // 0 = best vbr q 5=~128k
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
187 if(lame_param_br>0) lame_set_VBR_mean_bitrate_kbps(lame,lame_param_br);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
188 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
189 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
190 } else { // CBR:
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
191 if(lame_param_br>0) lame_set_brate(lame,lame_param_br);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
192 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
193 if(lame_param_mode>=0) lame_set_mode(lame,lame_param_mode); // j-st
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
194 if(lame_param_ratio>0) lame_set_compression_ratio(lame,lame_param_ratio);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
195 if(lame_param_scale>0) {
21621
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
196 mp_msg(MSGT_MENCODER, MSGL_V, MSGTR_SettingAudioInputGain, lame_param_scale);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
197 lame_set_scale(lame,lame_param_scale);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
198 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
199 if(lame_param_lowpassfreq>=-1) lame_set_lowpassfreq(lame,lame_param_lowpassfreq);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
200 if(lame_param_highpassfreq>=-1) lame_set_highpassfreq(lame,lame_param_highpassfreq);
27363
40057010b1fa Change a bunch of codec-specific preprocessor directives from a HAVE_
diego
parents: 26754
diff changeset
201 #ifdef CONFIG_MP3LAME_PRESET
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
202 if(lame_param_preset != NULL) {
21621
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
203 mp_msg(MSGT_MENCODER, MSGL_V, MSGTR_LamePresetEquals,lame_param_preset);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
204 if(lame_presets_set(lame,lame_param_fast, (lame_param_vbr==0), lame_param_preset) < 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
205 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
206 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
207 #endif
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
208 if(lame_init_params(lame) == -1) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
209 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_LameCantInit);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
210 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
211 }
17932
3fe3b2b3a6ce Convert all if(verbose>X) to mp_msg_test calls.
diego
parents: 17012
diff changeset
212 if( mp_msg_test(MSGT_MENCODER,MSGL_V) ) {
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
213 lame_print_config(lame);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
214 lame_print_internals(lame);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
215 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
216
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
217 encoder->bind = bind_lame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
218 encoder->get_frame_size = get_frame_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
219 encoder->encode = encode_lame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
220 encoder->fixup = fixup;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
221 encoder->close = close_lame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
222 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
223 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
224
27363
40057010b1fa Change a bunch of codec-specific preprocessor directives from a HAVE_
diego
parents: 26754
diff changeset
225 #ifdef CONFIG_MP3LAME_PRESET
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
226 /* lame_presets_set
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
227 taken out of presets_set in lame-3.93.1/frontend/parse.c and modified */
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
228 static int lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name )
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
229 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
230 int mono = 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
231
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
232 if (strcmp(preset_name, "help") == 0) {
21621
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
233 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_LameVersion, get_lame_version(), get_lame_url());
21622
5cd2a0041019 Simplify: get rid of useless lame_presets_longinfo_dm function.
reimar
parents: 21621
diff changeset
234 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_LamePresetsLongInfo);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
235 return -1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
236 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
237
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
238 //aliases for compatibility with old presets
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
239
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
240 if (strcmp(preset_name, "phone") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
241 preset_name = "16";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
242 mono = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
243 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
244 if ( (strcmp(preset_name, "phon+") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
245 (strcmp(preset_name, "lw") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
246 (strcmp(preset_name, "mw-eu") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
247 (strcmp(preset_name, "sw") == 0)) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
248 preset_name = "24";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
249 mono = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
250 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
251 if (strcmp(preset_name, "mw-us") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
252 preset_name = "40";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
253 mono = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
254 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
255 if (strcmp(preset_name, "voice") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
256 preset_name = "56";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
257 mono = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
258 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
259 if (strcmp(preset_name, "fm") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
260 preset_name = "112";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
261 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
262 if ( (strcmp(preset_name, "radio") == 0) ||
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
263 (strcmp(preset_name, "tape") == 0)) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
264 preset_name = "112";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
265 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
266 if (strcmp(preset_name, "hifi") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
267 preset_name = "160";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
268 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
269 if (strcmp(preset_name, "cd") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
270 preset_name = "192";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
271 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
272 if (strcmp(preset_name, "studio") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
273 preset_name = "256";
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
274 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
275
27363
40057010b1fa Change a bunch of codec-specific preprocessor directives from a HAVE_
diego
parents: 26754
diff changeset
276 #ifdef CONFIG_MP3LAME_PRESET_MEDIUM
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
277 if (strcmp(preset_name, "medium") == 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, MEDIUM_FAST);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
280 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
281 lame_set_preset(gfp, MEDIUM);
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 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
286
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
287 if (strcmp(preset_name, "standard") == 0) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
288 if (fast > 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
289 lame_set_preset(gfp, STANDARD_FAST);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
290 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
291 lame_set_preset(gfp, STANDARD);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
292
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
293 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
294 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
295
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
296 else if (strcmp(preset_name, "extreme") == 0){
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
297 if (fast > 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
298 lame_set_preset(gfp, EXTREME_FAST);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
299 else
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
300 lame_set_preset(gfp, EXTREME);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
301
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
302 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
303 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
304
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
305 else if (((strcmp(preset_name, "insane") == 0) ||
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
306 (strcmp(preset_name, "320" ) == 0)) && (fast < 1)) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
307
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
308 lame_set_preset(gfp, INSANE);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28347
diff changeset
309
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
310 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
311 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
312
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
313 // Generic ABR Preset
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
314 if (((atoi(preset_name)) > 0) && (fast < 1)) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
315 if ((atoi(preset_name)) >= 8 && (atoi(preset_name)) <= 320){
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
316 lame_set_preset(gfp, atoi(preset_name));
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
317
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
318 if (cbr == 1 )
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
319 lame_set_VBR(gfp, vbr_off);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
320
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
321 if (mono == 1 ) {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
322 lame_set_mode(gfp, MONO);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
323 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
324
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
325 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
326
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
327 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
328 else {
21621
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
329 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_LameVersion, get_lame_version(), get_lame_url());
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
330 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_InvalidBitrateForLamePreset);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
331 return -1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
332 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
333 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
334
21621
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
335 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_LameVersion, get_lame_version(), get_lame_url());
28ade900407d Fix FIXME mp_msg levels and targets
reimar
parents: 19397
diff changeset
336 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_InvalidLamePresetOptions);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
337 return -1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
338 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
339 #endif