├── .gitignore
├── .swiftpm
    └── xcode
    │   └── package.xcworkspace
    │       └── xcshareddata
    │           └── IDEWorkspaceChecks.plist
├── LICENSE
├── Package.swift
├── README.md
├── Sources
    ├── LAME
    │   ├── COPYING
    │   ├── LICENSE
    │   ├── README
    │   ├── include
    │   │   ├── config.h
    │   │   └── lame.h
    │   ├── libmp3lame
    │   │   ├── VbrTag.c
    │   │   ├── VbrTag.h
    │   │   ├── bitstream.c
    │   │   ├── bitstream.h
    │   │   ├── encoder.c
    │   │   ├── encoder.h
    │   │   ├── fft.c
    │   │   ├── fft.h
    │   │   ├── gain_analysis.c
    │   │   ├── gain_analysis.h
    │   │   ├── id3tag.c
    │   │   ├── id3tag.h
    │   │   ├── l3side.h
    │   │   ├── lame-analysis.h
    │   │   ├── lame.c
    │   │   ├── lame_global_flags.h
    │   │   ├── machine.h
    │   │   ├── mpglib_interface.c
    │   │   ├── newmdct.c
    │   │   ├── newmdct.h
    │   │   ├── presets.c
    │   │   ├── psymodel.c
    │   │   ├── psymodel.h
    │   │   ├── quantize.c
    │   │   ├── quantize.h
    │   │   ├── quantize_pvt.c
    │   │   ├── quantize_pvt.h
    │   │   ├── reservoir.c
    │   │   ├── reservoir.h
    │   │   ├── set_get.c
    │   │   ├── set_get.h
    │   │   ├── tables.c
    │   │   ├── tables.h
    │   │   ├── takehiro.c
    │   │   ├── util.c
    │   │   ├── util.h
    │   │   ├── vbrquantize.c
    │   │   ├── vbrquantize.h
    │   │   ├── vector
    │   │   │   ├── .deps
    │   │   │   │   └── xmm_quantize_sub.Plo
    │   │   │   ├── lame_intrin.h
    │   │   │   └── xmm_quantize_sub.c
    │   │   ├── version.c
    │   │   └── version.h
    │   └── mpglib
    │   │   ├── common.c
    │   │   ├── common.h
    │   │   ├── dct64_i386.c
    │   │   ├── dct64_i386.h
    │   │   ├── decode_i386.c
    │   │   ├── decode_i386.h
    │   │   ├── huffman.h
    │   │   ├── interface.c
    │   │   ├── interface.h
    │   │   ├── l2tables.h
    │   │   ├── layer1.c
    │   │   ├── layer1.h
    │   │   ├── layer2.c
    │   │   ├── layer2.h
    │   │   ├── layer3.c
    │   │   ├── layer3.h
    │   │   ├── mpg123.h
    │   │   ├── mpglib.h
    │   │   ├── tabinit.c
    │   │   └── tabinit.h
    └── SwiftLAME
    │   ├── Models
    │       ├── AVAudioBufferData.swift
    │       └── SwiftLameError.swift
    │   ├── SwiftLameEncoder.swift
    │   └── Wrappers
    │       ├── Lame.swift
    │       ├── LameBitrateMode.swift
    │       ├── LameConfiguration.swift
    │       ├── LameQuality.swift
    │       └── LameSampleRate.swift
└── Tests
    └── SwiftLAMETests
        └── SwiftLAMETests.swift
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /.build
3 | /Packages
4 | xcuserdata/
5 | DerivedData/
6 | .swiftpm/configuration/registries.json
7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8 | .netrc
9 | 
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 | 
2 | 
3 | 
4 | 
5 | 	IDEDidComputeMac32BitWarning
6 | 	
7 | 
8 | 
9 | 
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
 1 | // swift-tools-version: 5.9
 2 | 
 3 | import PackageDescription
 4 | 
 5 | 
 6 | let package = Package(
 7 |     name: "SwiftLAME",
 8 |     platforms: [.macOS(.v12), .iOS(.v15)],
 9 |     products: [
10 |         .library(
11 |             name: "SwiftLAME",
12 |             targets: [
13 |                 "SwiftLAME"
14 |             ]
15 |         )
16 |     ],
17 |     targets: [
18 |         
19 |         // Targets
20 |         
21 |         .target(
22 |             name: "SwiftLAME",
23 |             dependencies: ["LAME"]
24 |         ),
25 |         .target(
26 |             name: "LAME",
27 |             publicHeadersPath: "include",
28 |             cSettings: [
29 |                 .define("HAVE_CONFIG_H"),
30 |                 .unsafeFlags(["-w", "-Xanalyzer", "-analyzer-disable-all-checks"])
31 |             ]
32 |         ),
33 |         
34 |         // Tests
35 |         
36 |         .testTarget(
37 |             name: "SwiftLAMETests",
38 |             dependencies: ["SwiftLAME"]
39 |         )
40 |     ]
41 | )
42 | 
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
 4 | SwiftLAME is a lightweight Swift wrapper around the [open-source LAME project](https://lame.sourceforge.io) for encoding audio files to MP3 format. This project was created to support the MP3 conversion feature of our [Producer Toolkit macOS App](https://hiddenspectrum.io/producer-toolkit).
 5 | 
 6 | 
 7 | ## Requirements
 8 | SwiftLAME has been tested on macOS 12+, and iOS 15+, although older versions are likely supported. Consider contributing a change to Package.swift if you find this to be the case.
 9 | 
10 | ## Installation
11 | 
12 | Add the dependency to your `Package.swift` file:
13 | 
14 | ```swift
15 | dependencies: [
16 |     .package(url: "https://github.com/hidden-spectrum/swiftlame", .upToNextMajor(from: "0.1.0")),
17 | ]
18 | ```
19 | 
20 | ## Usage
21 | 
22 | ```swift
23 | import SwiftLAME
24 | 
25 | let progress = Progress()
26 | let lameEncoder = try SwiftLameEncoder(
27 |     sourceUrl: URL("file:///path/to/source/file.wav"), 
28 |     configuration: .init(
29 |         sampleRate: .constant(44100)
30 |         bitrateMode: .constant(320)
31 |         quality: .mp3Best
32 |     ),
33 |     destinationUrl: URL("file:///path/to/destination/file.wav"),
34 |     progress: progress // optional
35 | )
36 | try await lameEncoder.encode(priority: .userInitiated)
37 | ```
38 | 
39 | ## Source Codec Support
40 | SwiftLAME supports converting from the following codecs:
41 | - WAV
42 | - AIFF
43 | - Raw PCM
44 | 
45 | 
46 | ## Notes
47 | - SwiftLAME is still in early alpha. There may be bugs or missing features.
48 | 
49 | ## License
50 | SwiftLAME, like the [LAME project](https://lame.sourceforge.io/license.txt), is distributed under the LGPL License.
51 | 
--------------------------------------------------------------------------------
/Sources/LAME/LICENSE:
--------------------------------------------------------------------------------
 1 | Can I use LAME in my commercial program?  
 2 | 
 3 | Yes, you can, under the restrictions of the LGPL (see COPYING
 4 | in this folder). The easiest way to do this is to:
 5 | 
 6 | 1. Link to LAME as separate library (libmp3lame.a on unix or 
 7 |    lame_enc.dll or libmp3lame.dll on windows)
 8 | 
 9 | 2. Fully acknowledge that you are using LAME, and give a link
10 |    to our web site, www.mp3dev.org
11 | 
12 | 3. If you make modifications to LAME, you *must* release these
13 |    modifications back to the LAME project, under the LGPL.
14 | 
--------------------------------------------------------------------------------
/Sources/LAME/README:
--------------------------------------------------------------------------------
 1 |                       LAME 3.xx
 2 |                LAME Ain't an MP3 Encoder
 3 |                   http://lame.sf.net
 4 | 	                  May 2011
 5 | 
 6 | Originally developed by Mike Cheng (www.uq.net.au/~zzmcheng) and was
 7 | latter developed by Mark Taylor (www.mp3dev.org). Currently maintained
 8 | by The LAME Project.
 9 | 
10 | This code is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
11 | (LGPL, see www.gnu.org), version 2.
12 | 
13 | As LAME may contain software for which some companies may claim software
14 | patents, if you are in a location where software patents are recognized, it is
15 | suggested that you seek legal advice before deploying and/or redistributing
16 | LAME.
17 | 
18 | In particular, it is suggested to visit
19 | 
20 |     http://www.mp3licensing.com/
21 | 
22 | if it applies to your jurisdiction.
23 | 
24 | ============================================================================
25 | 
26 | see the file "INSTALL" for installation (compiling) instructions.
27 | see the file "USAGE" for the most up-to-date guide to the command line options.
28 | see the file "LICENSE" for details on how to use LAME in non-GPL programs.
29 | see the file "HACKING" if you are interested in working on LAME
30 | see the file "API" for details of the LAME encoding library API
31 | 
32 | There is HTML documentation and a man page in the doc directory.
33 | 
34 | ============================================================================
35 | 
36 | LAME uses the MPGLIB decoding engine, from the mpg123 package, written
37 | by: Michael Hipp (www.mpg123.de) MPGLIB is released under the GPL.
38 | 
39 | Copyrights (c) 1999-2011 by The LAME Project
40 | Copyrights (c) 1999,2000,2001 by Mark Taylor
41 | Copyrights (c) 1998 by Michael Cheng
42 | Copyrights (c) 1995,1996,1997 by Michael Hipp: mpglib
43 | 
44 | As well as additional copyrights as documented in the source code.
45 | 
--------------------------------------------------------------------------------
/Sources/LAME/include/config.h:
--------------------------------------------------------------------------------
  1 | /* config.h.  Generated from config.h.in by configure.  */
  2 | /* config.h.in.  Generated from configure.in by autoheader.  */
  3 | 
  4 | 
  5 | #ifndef LAME_CONFIG_H
  6 | #define LAME_CONFIG_H
  7 | 
  8 | 
  9 | /* debug define */
 10 | /* #undef ABORTFP */
 11 | 
 12 | /* Define if building universal (internal helper macro) */
 13 | /* #undef AC_APPLE_UNIVERSAL_BUILD */
 14 | 
 15 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
 16 |    systems. This function is required for `alloca.c' support on those systems.
 17 |    */
 18 | /* #undef CRAY_STACKSEG_END */
 19 | 
 20 | /* Define to 1 if using `alloca.c'. */
 21 | /* #undef C_ALLOCA */
 22 | 
 23 | /* alot of debug output */
 24 | #undef DEBUG
 25 | 
 26 | /* allow to compute a more accurate replaygain value */
 27 | #define DECODE_ON_THE_FLY 1
 28 | 
 29 | /* double is faster than float on Alpha */
 30 | /* #undef FLOAT */
 31 | 
 32 | /* Define to 1 if you have `alloca', as a function or macro. */
 33 | #define HAVE_ALLOCA 1
 34 | 
 35 | /* Define to 1 if you have  and it should be used (not on Ultrix).
 36 |    */
 37 | #define HAVE_ALLOCA_H 1
 38 | 
 39 | /* Define to 1 if you have the  header file. */
 40 | #define HAVE_DLFCN_H 1
 41 | 
 42 | /* we link against libefence */
 43 | /* #undef HAVE_EFENCE */
 44 | 
 45 | /* Define to 1 if you have the  header file. */
 46 | #define HAVE_ERRNO_H 1
 47 | 
 48 | /* Define to 1 if you have the  header file. */
 49 | #define HAVE_FCNTL_H 1
 50 | 
 51 | /* Define to 1 if you have the `gettimeofday' function. */
 52 | #define HAVE_GETTIMEOFDAY 1
 53 | 
 54 | /* Define if you have the iconv() function and it works. */
 55 | /* #undef HAVE_ICONV */
 56 | 
 57 | /* add ieee754_float32_t type */
 58 | /* #undef HAVE_IEEE754_FLOAT32_T */
 59 | #ifndef HAVE_IEEE754_FLOAT32_T
 60 | 	typedef float ieee754_float32_t;
 61 | #endif
 62 | 
 63 | /* add ieee754_float64_t type */
 64 | /* #undef HAVE_IEEE754_FLOAT64_T */
 65 | #ifndef HAVE_IEEE754_FLOAT64_T
 66 | 	typedef double ieee754_float64_t;
 67 | #endif
 68 | 
 69 | /* system has 80 bit floats */
 70 | /* #undef HAVE_IEEE854_FLOAT80 */
 71 | 
 72 | /* add ieee854_float80_t type */
 73 | /* #undef HAVE_IEEE854_FLOAT80_T */
 74 | #ifndef HAVE_IEEE854_FLOAT80_T
 75 | 	typedef long double ieee854_float80_t;
 76 | #endif
 77 | 
 78 | /* add int16_t type */
 79 | #define HAVE_INT16_T 1
 80 | #ifndef HAVE_INT16_T
 81 | 	typedef short int16_t;
 82 | #endif
 83 | 
 84 | /* add int32_t type */
 85 | #define HAVE_INT32_T 1
 86 | #ifndef HAVE_INT32_T
 87 | #define A_INT32_T int
 88 | 	typedef A_INT32_T int32_t;
 89 | #endif
 90 | 
 91 | /* add int64_t type */
 92 | #define HAVE_INT64_T 1
 93 | #ifndef HAVE_INT64_T
 94 | #define A_INT64_T long
 95 | 	typedef A_INT64_T int64_t;
 96 | #endif
 97 | 
 98 | /* add int8_t type */
 99 | #define HAVE_INT8_T 1
100 | #ifndef HAVE_INT8_T
101 | 	typedef char int8_t;
102 | #endif
103 | 
104 | /* Define to 1 if you have the  header file. */
105 | #define HAVE_INTTYPES_H 1
106 | 
107 | /* Define to 1 if you have the  header file. */
108 | #define HAVE_LIMITS_H 1
109 | 
110 | /* Define to 1 if you have the  header file. */
111 | /* #undef HAVE_LINUX_SOUNDCARD_H */
112 | 
113 | /* Define to 1 if the type `long double' works and has more range or precision
114 |    than `double'. */
115 | /* #undef HAVE_LONG_DOUBLE */
116 | 
117 | /* Define to 1 if the type `long double' works and has more range or precision
118 |    than `double'. */
119 | /* #undef HAVE_LONG_DOUBLE_WIDER */
120 | 
121 | /* Define to 1 if you have the  header file. */
122 | #define HAVE_MEMORY_H 1
123 | 
124 | /* build with mpglib support */
125 | #define HAVE_MPGLIB 1
126 | 
127 | /* have nasm */
128 | /* #undef HAVE_NASM */
129 | 
130 | /* Define to 1 if you have the  header file. */
131 | /* #undef HAVE_NCURSES_TERMCAP_H */
132 | 
133 | /* Define to 1 if you have the `socket' function. */
134 | #define HAVE_SOCKET 1
135 | 
136 | /* Define to 1 if you have the  header file. */
137 | #define HAVE_STDINT_H 1
138 | 
139 | /* Define to 1 if you have the  header file. */
140 | #define HAVE_STDLIB_H 1
141 | 
142 | /* Define to 1 if you have the  header file. */
143 | #define HAVE_STRINGS_H 1
144 | 
145 | /* Define to 1 if you have the  header file. */
146 | #define HAVE_STRING_H 1
147 | 
148 | /* Define to 1 if you have the `strtol' function. */
149 | #define HAVE_STRTOL 1
150 | 
151 | /* Define to 1 if you have the  header file. */
152 | /* #undef HAVE_SYS_SOUNDCARD_H */
153 | 
154 | /* Define to 1 if you have the  header file. */
155 | #define HAVE_SYS_STAT_H 1
156 | 
157 | /* Define to 1 if you have the  header file. */
158 | #define HAVE_SYS_TIME_H 1
159 | 
160 | /* Define to 1 if you have the  header file. */
161 | #define HAVE_SYS_TYPES_H 1
162 | 
163 | /* have termcap */
164 | #define HAVE_TERMCAP 1
165 | 
166 | /* Define to 1 if you have the  header file. */
167 | #define HAVE_TERMCAP_H 1
168 | 
169 | /* add uint16_t type */
170 | #define HAVE_UINT16_T 1
171 | #ifndef HAVE_UINT16_T
172 | 	typedef unsigned short uint16_t;
173 | #endif
174 | 
175 | /* add uint32_t type */
176 | #define HAVE_UINT32_T 1
177 | #ifndef HAVE_UINT32_T
178 | #define A_UINT32_T unsigned int
179 | 	typedef A_UINT32_T uint32_t;
180 | #endif
181 | 
182 | /* add uint64_t type */
183 | #define HAVE_UINT64_T 1
184 | #ifndef HAVE_UINT64_T
185 | #define A_UINT64_T unsigned long
186 | 	typedef A_UINT64_T uint64_t;
187 | #endif
188 | 
189 | /* add uint8_t type */
190 | #define HAVE_UINT8_T 1
191 | #ifndef HAVE_UINT8_T
192 | 	typedef unsigned char uint8_t;
193 | #endif
194 | 
195 | /* Define to 1 if you have the  header file. */
196 | #define HAVE_UNISTD_H 1
197 | 
198 | /* Define if SSE intrinsics work. */
199 | /* #undef HAVE_XMMINTRIN_H */
200 | 
201 | /* Define as const if the declaration of iconv() needs const. */
202 | #define ICONV_CONST 
203 | 
204 | /* requested by Frank, seems to be temporary needed for a smooth transition */
205 | #define LAME_LIBRARY_BUILD 1
206 | 
207 | /* set to 1 if you have libsndfile */
208 | /* #undef LIBSNDFILE */
209 | 
210 | /* Define to the sub-directory where libtool stores uninstalled libraries. */
211 | #define LT_OBJDIR ".libs/"
212 | 
213 | /* use MMX version of choose_table */
214 | /* #undef MMX_choose_table */
215 | 
216 | /* build without hooks for analyzer */
217 | /* #undef NOANALYSIS */
218 | 
219 | /* Name of package */
220 | #define PACKAGE "lame"
221 | 
222 | /* Define to the address where bug reports for this package should be sent. */
223 | #define PACKAGE_BUGREPORT "lame-dev@lists.sf.net"
224 | 
225 | /* Define to the full name of this package. */
226 | #define PACKAGE_NAME "lame"
227 | 
228 | /* Define to the full name and version of this package. */
229 | #define PACKAGE_STRING "lame 3.100"
230 | 
231 | /* Define to the one symbol short name of this package. */
232 | #define PACKAGE_TARNAME "lame"
233 | 
234 | /* Define to the home page for this package. */
235 | #define PACKAGE_URL ""
236 | 
237 | /* Define to the version of this package. */
238 | #define PACKAGE_VERSION "3.100"
239 | 
240 | /* The size of `double', as computed by sizeof. */
241 | #define SIZEOF_DOUBLE 8
242 | 
243 | /* The size of `float', as computed by sizeof. */
244 | #define SIZEOF_FLOAT 4
245 | 
246 | /* The size of `int', as computed by sizeof. */
247 | #define SIZEOF_INT 4
248 | 
249 | /* The size of `long', as computed by sizeof. */
250 | #define SIZEOF_LONG 8
251 | 
252 | /* The size of `long double', as computed by sizeof. */
253 | /* #undef SIZEOF_LONG_DOUBLE */
254 | 
255 | /* The size of `long long', as computed by sizeof. */
256 | #define SIZEOF_LONG_LONG 8
257 | 
258 | /* The size of `short', as computed by sizeof. */
259 | #define SIZEOF_SHORT 2
260 | 
261 | /* The size of `unsigned int', as computed by sizeof. */
262 | #define SIZEOF_UNSIGNED_INT 4
263 | 
264 | /* The size of `unsigned long', as computed by sizeof. */
265 | #define SIZEOF_UNSIGNED_LONG 8
266 | 
267 | /* The size of `unsigned long long', as computed by sizeof. */
268 | #define SIZEOF_UNSIGNED_LONG_LONG 8
269 | 
270 | /* The size of `unsigned short', as computed by sizeof. */
271 | #define SIZEOF_UNSIGNED_SHORT 2
272 | 
273 | /* If using the C implementation of alloca, define if you know the
274 |    direction of stack growth for your system; otherwise it will be
275 |    automatically deduced at runtime.
276 | 	STACK_DIRECTION > 0 => grows toward higher addresses
277 | 	STACK_DIRECTION < 0 => grows toward lower addresses
278 | 	STACK_DIRECTION = 0 => direction of growth unknown */
279 | /* #undef STACK_DIRECTION */
280 | 
281 | /* Define to 1 if you have the ANSI C header files. */
282 | #define STDC_HEADERS 1
283 | 
284 | /* IEEE754 compatible machine */
285 | /* #undef TAKEHIRO_IEEE754_HACK */
286 | 
287 | /* Define to 1 if you can safely include both  and . */
288 | #define TIME_WITH_SYS_TIME 1
289 | 
290 | /* faster log implementation with less but enough precission */
291 | /* #undef USE_FAST_LOG */
292 | 
293 | /* Enable extensions on AIX 3, Interix.  */
294 | #ifndef _ALL_SOURCE
295 | # define _ALL_SOURCE 1
296 | #endif
297 | /* Enable GNU extensions on systems that have them.  */
298 | #ifndef _GNU_SOURCE
299 | # define _GNU_SOURCE 1
300 | #endif
301 | /* Enable threading extensions on Solaris.  */
302 | #ifndef _POSIX_PTHREAD_SEMANTICS
303 | # define _POSIX_PTHREAD_SEMANTICS 1
304 | #endif
305 | /* Enable extensions on HP NonStop.  */
306 | #ifndef _TANDEM_SOURCE
307 | # define _TANDEM_SOURCE 1
308 | #endif
309 | /* Enable general extensions on Solaris.  */
310 | #ifndef __EXTENSIONS__
311 | # define __EXTENSIONS__ 1
312 | #endif
313 | 
314 | 
315 | /* Version number of package */
316 | #define VERSION "3.100"
317 | 
318 | /* Define if using the dmalloc debugging malloc package */
319 | /* #undef WITH_DMALLOC */
320 | 
321 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
322 |    significant byte first (like Motorola and SPARC, unlike Intel). */
323 | #if defined AC_APPLE_UNIVERSAL_BUILD
324 | # if defined __BIG_ENDIAN__
325 | #  define WORDS_BIGENDIAN 1
326 | # endif
327 | #else
328 | # ifndef WORDS_BIGENDIAN
329 | /* #  undef WORDS_BIGENDIAN */
330 | # endif
331 | #endif
332 | 
333 | /* Enable large inode numbers on Mac OS X 10.5.  */
334 | #ifndef _DARWIN_USE_64_BIT_INODE
335 | # define _DARWIN_USE_64_BIT_INODE 1
336 | #endif
337 | 
338 | /* Number of bits in a file offset, on hosts where this is settable. */
339 | /* #undef _FILE_OFFSET_BITS */
340 | 
341 | /* Define for large files, on AIX-style hosts. */
342 | /* #undef _LARGE_FILES */
343 | 
344 | /* Define to 1 if on MINIX. */
345 | /* #undef _MINIX */
346 | 
347 | /* Define to 2 if the system does not provide POSIX.1 features except with
348 |    this defined. */
349 | /* #undef _POSIX_1_SOURCE */
350 | 
351 | /* Define to 1 if you need to in order for `stat' and other things to work. */
352 | /* #undef _POSIX_SOURCE */
353 | 
354 | /* we're on DEC Alpha */
355 | /* #undef __DECALPHA__ */
356 | 
357 | /* work around a glibc bug */
358 | /* #undef __NO_MATH_INLINES */
359 | 
360 | /* Define to empty if `const' does not conform to ANSI C. */
361 | /* #undef const */
362 | 
363 | /* Define to `__inline__' or `__inline' if that's what the C compiler
364 |    calls it, or to nothing if 'inline' is not supported under any name.  */
365 | #ifndef __cplusplus
366 | /* #undef inline */
367 | #endif
368 | 
369 | /* Define to `unsigned int' if  does not define. */
370 | /* #undef size_t */
371 | 
372 | #endif /* LAME_CONFIG_H */
373 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/VbrTag.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *      Xing VBR tagging for LAME.
 3 |  *
 4 |  *      Copyright (c) 1999 A.L. Faber
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_VRBTAG_H
23 | #define LAME_VRBTAG_H
24 | 
25 | 
26 | /* -----------------------------------------------------------
27 |  * A Vbr header may be present in the ancillary
28 |  * data field of the first frame of an mp3 bitstream
29 |  * The Vbr header (optionally) contains
30 |  *      frames      total number of audio frames in the bitstream
31 |  *      bytes       total number of bytes in the bitstream
32 |  *      toc         table of contents
33 | 
34 |  * toc (table of contents) gives seek points
35 |  * for random access
36 |  * the ith entry determines the seek point for
37 |  * i-percent duration
38 |  * seek point in bytes = (toc[i]/256.0) * total_bitstream_bytes
39 |  * e.g. half duration seek point = (toc[50]/256.0) * total_bitstream_bytes
40 |  */
41 | 
42 | 
43 | #define FRAMES_FLAG     0x0001
44 | #define BYTES_FLAG      0x0002
45 | #define TOC_FLAG        0x0004
46 | #define VBR_SCALE_FLAG  0x0008
47 | 
48 | #define NUMTOCENTRIES 100
49 | 
50 | #ifndef lame_internal_flags_defined
51 | #define lame_internal_flags_defined
52 | struct lame_internal_flags;
53 | typedef struct lame_internal_flags lame_internal_flags;
54 | #endif
55 | 
56 | 
57 | /*structure to receive extracted header */
58 | /* toc may be NULL*/
59 | typedef struct {
60 |     int     h_id;            /* from MPEG header, 0=MPEG2, 1=MPEG1 */
61 |     int     samprate;        /* determined from MPEG header */
62 |     int     flags;           /* from Vbr header data */
63 |     int     frames;          /* total bit stream frames from Vbr header data */
64 |     int     bytes;           /* total bit stream bytes from Vbr header data */
65 |     int     vbr_scale;       /* encoded vbr scale from Vbr header data */
66 |     unsigned char toc[NUMTOCENTRIES]; /* may be NULL if toc not desired */
67 |     int     headersize;      /* size of VBR header, in bytes */
68 |     int     enc_delay;       /* encoder delay */
69 |     int     enc_padding;     /* encoder paddign added at end of stream */
70 | } VBRTAGDATA;
71 | 
72 | int     GetVbrTag(VBRTAGDATA * pTagData, const unsigned char *buf);
73 | 
74 | int     InitVbrTag(lame_global_flags * gfp);
75 | int     PutVbrTag(lame_global_flags const *gfp, FILE * fid);
76 | void    AddVbrFrame(lame_internal_flags * gfc);
77 | void    UpdateMusicCRC(uint16_t * crc, const unsigned char *buffer, int size);
78 | 
79 | #endif
80 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/bitstream.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *	MP3 bitstream Output interface for LAME
 3 |  *
 4 |  *	Copyright (c) 1999 Takehiro TOMINAGA
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_BITSTREAM_H
23 | #define LAME_BITSTREAM_H
24 | 
25 | int     getframebits(const lame_internal_flags * gfc);
26 | 
27 | int     format_bitstream(lame_internal_flags * gfc);
28 | 
29 | void    flush_bitstream(lame_internal_flags * gfc);
30 | void    add_dummy_byte(lame_internal_flags * gfc, unsigned char val, unsigned int n);
31 | 
32 | int     copy_buffer(lame_internal_flags * gfc, unsigned char *buffer, int buffer_size,
33 |                     int update_crc);
34 | void    init_bit_stream_w(lame_internal_flags * gfc);
35 | void    CRC_writeheader(lame_internal_flags const *gfc, char *buffer);
36 | int     compute_flushbits(const lame_internal_flags * gfp, int *nbytes);
37 | 
38 | int     get_max_frame_buffer_size_by_constraint(SessionConfig_t const * cfg, int constraint);
39 | 
40 | #endif
41 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/encoder.h:
--------------------------------------------------------------------------------
  1 | /*
  2 |  *      encoder.h include file
  3 |  *
  4 |  *      Copyright (c) 2000 Mark Taylor
  5 |  *
  6 |  * This library is free software; you can redistribute it and/or
  7 |  * modify it under the terms of the GNU Library General Public
  8 |  * License as published by the Free Software Foundation; either
  9 |  * version 2 of the License, or (at your option) any later version.
 10 |  *
 11 |  * This library is distributed in the hope that it will be useful,
 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14 |  * Library General Public License for more details.
 15 |  *
 16 |  * You should have received a copy of the GNU Library General Public
 17 |  * License along with this library; if not, write to the
 18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 19 |  * Boston, MA 02111-1307, USA.
 20 |  */
 21 | 
 22 | 
 23 | #ifndef LAME_ENCODER_H
 24 | #define LAME_ENCODER_H
 25 | 
 26 | /***********************************************************************
 27 | *
 28 | *  encoder and decoder delays
 29 | *
 30 | ***********************************************************************/
 31 | 
 32 | /* 
 33 |  * layer III enc->dec delay:  1056 (1057?)   (observed)
 34 |  * layer  II enc->dec delay:   480  (481?)   (observed)
 35 |  *
 36 |  * polyphase 256-16             (dec or enc)        = 240
 37 |  * mdct      256+32  (9*32)     (dec or enc)        = 288
 38 |  * total:    512+16
 39 |  *
 40 |  * My guess is that delay of polyphase filterbank is actualy 240.5
 41 |  * (there are technical reasons for this, see postings in mp3encoder).
 42 |  * So total Encode+Decode delay = ENCDELAY + 528 + 1
 43 |  */
 44 | 
 45 | /* 
 46 |  * ENCDELAY  The encoder delay.  
 47 |  *
 48 |  * Minimum allowed is MDCTDELAY (see below)
 49 |  *  
 50 |  * The first 96 samples will be attenuated, so using a value less than 96
 51 |  * will result in corrupt data for the first 96-ENCDELAY samples.
 52 |  *
 53 |  * suggested: 576
 54 |  * set to 1160 to sync with FhG.
 55 |  */
 56 | 
 57 | #define ENCDELAY      576
 58 | 
 59 | 
 60 | 
 61 | /*
 62 |  * make sure there is at least one complete frame after the
 63 |  * last frame containing real data
 64 |  *
 65 |  * Using a value of 288 would be sufficient for a 
 66 |  * a very sophisticated decoder that can decode granule-by-granule instead
 67 |  * of frame by frame.  But lets not assume this, and assume the decoder  
 68 |  * will not decode frame N unless it also has data for frame N+1
 69 |  *
 70 |  */
 71 | /*#define POSTDELAY   288*/
 72 | #define POSTDELAY   1152
 73 | 
 74 | 
 75 | 
 76 | /* 
 77 |  * delay of the MDCT used in mdct.c
 78 |  * original ISO routines had a delay of 528!  
 79 |  * Takehiro's routines: 
 80 |  */
 81 | 
 82 | #define MDCTDELAY     48
 83 | #define FFTOFFSET     (224+MDCTDELAY)
 84 | 
 85 | /*
 86 |  * Most decoders, including the one we use, have a delay of 528 samples.  
 87 |  */
 88 | 
 89 | #define DECDELAY      528
 90 | 
 91 | 
 92 | /* number of subbands */
 93 | #define SBLIMIT       32
 94 | 
 95 | /* parition bands bands */
 96 | #define CBANDS        64
 97 | 
 98 | /* number of critical bands/scale factor bands where masking is computed*/
 99 | #define SBPSY_l       21
100 | #define SBPSY_s       12
101 | 
102 | /* total number of scalefactor bands encoded */
103 | #define SBMAX_l       22
104 | #define SBMAX_s       13
105 | #define PSFB21         6
106 | #define PSFB12         6
107 | 
108 | 
109 | 
110 | /* FFT sizes */
111 | #define BLKSIZE       1024
112 | #define HBLKSIZE      (BLKSIZE/2 + 1)
113 | #define BLKSIZE_s     256
114 | #define HBLKSIZE_s    (BLKSIZE_s/2 + 1)
115 | 
116 | 
117 | /* #define switch_pe        1800 */
118 | #define NORM_TYPE     0
119 | #define START_TYPE    1
120 | #define SHORT_TYPE    2
121 | #define STOP_TYPE     3
122 | 
123 | /* 
124 |  * Mode Extention:
125 |  * When we are in stereo mode, there are 4 possible methods to store these
126 |  * two channels. The stereo modes -m? are using a subset of them.
127 |  *
128 |  *  -ms: MPG_MD_LR_LR
129 |  *  -mj: MPG_MD_LR_LR and MPG_MD_MS_LR
130 |  *  -mf: MPG_MD_MS_LR
131 |  *  -mi: all
132 |  */
133 | #if 0
134 | #define MPG_MD_LR_LR  0
135 | #define MPG_MD_LR_I   1
136 | #define MPG_MD_MS_LR  2
137 | #define MPG_MD_MS_I   3
138 | #endif
139 | enum MPEGChannelMode
140 | {   MPG_MD_LR_LR = 0
141 | ,   MPG_MD_LR_I  = 1
142 | ,   MPG_MD_MS_LR = 2
143 | ,   MPG_MD_MS_I  = 3
144 | };
145 | 
146 | #ifndef lame_internal_flags_defined
147 | #define lame_internal_flags_defined
148 | struct lame_internal_flags;
149 | typedef struct lame_internal_flags lame_internal_flags;
150 | #endif
151 | 
152 | int     lame_encode_mp3_frame(lame_internal_flags * gfc,
153 |                               sample_t const *inbuf_l,
154 |                               sample_t const *inbuf_r, unsigned char *mp3buf, int mp3buf_size);
155 | 
156 | #endif /* LAME_ENCODER_H */
157 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/fft.c:
--------------------------------------------------------------------------------
  1 | /*
  2 | ** FFT and FHT routines
  3 | **  Copyright 1988, 1993; Ron Mayer
  4 | **      Copyright (c) 1999-2000 Takehiro Tominaga
  5 | **
  6 | **  fht(fz,n);
  7 | **      Does a hartley transform of "n" points in the array "fz".
  8 | **
  9 | ** NOTE: This routine uses at least 2 patented algorithms, and may be
 10 | **       under the restrictions of a bunch of different organizations.
 11 | **       Although I wrote it completely myself; it is kind of a derivative
 12 | **       of a routine I once authored and released under the GPL, so it
 13 | **       may fall under the free software foundation's restrictions;
 14 | **       it was worked on as a Stanford Univ project, so they claim
 15 | **       some rights to it; it was further optimized at work here, so
 16 | **       I think this company claims parts of it.  The patents are
 17 | **       held by R. Bracewell (the FHT algorithm) and O. Buneman (the
 18 | **       trig generator), both at Stanford Univ.
 19 | **       If it were up to me, I'd say go do whatever you want with it;
 20 | **       but it would be polite to give credit to the following people
 21 | **       if you use this anywhere:
 22 | **           Euler     - probable inventor of the fourier transform.
 23 | **           Gauss     - probable inventor of the FFT.
 24 | **           Hartley   - probable inventor of the hartley transform.
 25 | **           Buneman   - for a really cool trig generator
 26 | **           Mayer(me) - for authoring this particular version and
 27 | **                       including all the optimizations in one package.
 28 | **       Thanks,
 29 | **       Ron Mayer; mayer@acuson.com
 30 | ** and added some optimization by
 31 | **           Mather    - idea of using lookup table
 32 | **           Takehiro  - some dirty hack for speed up
 33 | */
 34 | 
 35 | /* $Id: fft.c,v 1.39 2017/09/06 15:07:29 robert Exp $ */
 36 | 
 37 | #ifdef HAVE_CONFIG_H
 38 | # include 
 39 | #endif
 40 | 
 41 | #include "lame.h"
 42 | #include "machine.h"
 43 | #include "encoder.h"
 44 | #include "util.h"
 45 | #include "fft.h"
 46 | 
 47 | #include "vector/lame_intrin.h"
 48 | 
 49 | 
 50 | 
 51 | #define TRI_SIZE (5-1)  /* 1024 =  4**5 */
 52 | 
 53 | /* fft.c    */
 54 | 
 55 | static const FLOAT costab[TRI_SIZE * 2] = {
 56 |     9.238795325112867e-01, 3.826834323650898e-01,
 57 |     9.951847266721969e-01, 9.801714032956060e-02,
 58 |     9.996988186962042e-01, 2.454122852291229e-02,
 59 |     9.999811752826011e-01, 6.135884649154475e-03
 60 | };
 61 | 
 62 | static void
 63 | fht(FLOAT * fz, int n)
 64 | {
 65 |     const FLOAT *tri = costab;
 66 |     int     k4;
 67 |     FLOAT  *fi, *gi;
 68 |     FLOAT const *fn;
 69 | 
 70 |     n <<= 1;            /* to get BLKSIZE, because of 3DNow! ASM routine */
 71 |     fn = fz + n;
 72 |     k4 = 4;
 73 |     do {
 74 |         FLOAT   s1, c1;
 75 |         int     i, k1, k2, k3, kx;
 76 |         kx = k4 >> 1;
 77 |         k1 = k4;
 78 |         k2 = k4 << 1;
 79 |         k3 = k2 + k1;
 80 |         k4 = k2 << 1;
 81 |         fi = fz;
 82 |         gi = fi + kx;
 83 |         do {
 84 |             FLOAT   f0, f1, f2, f3;
 85 |             f1 = fi[0] - fi[k1];
 86 |             f0 = fi[0] + fi[k1];
 87 |             f3 = fi[k2] - fi[k3];
 88 |             f2 = fi[k2] + fi[k3];
 89 |             fi[k2] = f0 - f2;
 90 |             fi[0] = f0 + f2;
 91 |             fi[k3] = f1 - f3;
 92 |             fi[k1] = f1 + f3;
 93 |             f1 = gi[0] - gi[k1];
 94 |             f0 = gi[0] + gi[k1];
 95 |             f3 = SQRT2 * gi[k3];
 96 |             f2 = SQRT2 * gi[k2];
 97 |             gi[k2] = f0 - f2;
 98 |             gi[0] = f0 + f2;
 99 |             gi[k3] = f1 - f3;
100 |             gi[k1] = f1 + f3;
101 |             gi += k4;
102 |             fi += k4;
103 |         } while (fi < fn);
104 |         c1 = tri[0];
105 |         s1 = tri[1];
106 |         for (i = 1; i < kx; i++) {
107 |             FLOAT   c2, s2;
108 |             c2 = 1 - (2 * s1) * s1;
109 |             s2 = (2 * s1) * c1;
110 |             fi = fz + i;
111 |             gi = fz + k1 - i;
112 |             do {
113 |                 FLOAT   a, b, g0, f0, f1, g1, f2, g2, f3, g3;
114 |                 b = s2 * fi[k1] - c2 * gi[k1];
115 |                 a = c2 * fi[k1] + s2 * gi[k1];
116 |                 f1 = fi[0] - a;
117 |                 f0 = fi[0] + a;
118 |                 g1 = gi[0] - b;
119 |                 g0 = gi[0] + b;
120 |                 b = s2 * fi[k3] - c2 * gi[k3];
121 |                 a = c2 * fi[k3] + s2 * gi[k3];
122 |                 f3 = fi[k2] - a;
123 |                 f2 = fi[k2] + a;
124 |                 g3 = gi[k2] - b;
125 |                 g2 = gi[k2] + b;
126 |                 b = s1 * f2 - c1 * g3;
127 |                 a = c1 * f2 + s1 * g3;
128 |                 fi[k2] = f0 - a;
129 |                 fi[0] = f0 + a;
130 |                 gi[k3] = g1 - b;
131 |                 gi[k1] = g1 + b;
132 |                 b = c1 * g2 - s1 * f3;
133 |                 a = s1 * g2 + c1 * f3;
134 |                 gi[k2] = g0 - a;
135 |                 gi[0] = g0 + a;
136 |                 fi[k3] = f1 - b;
137 |                 fi[k1] = f1 + b;
138 |                 gi += k4;
139 |                 fi += k4;
140 |             } while (fi < fn);
141 |             c2 = c1;
142 |             c1 = c2 * tri[0] - s1 * tri[1];
143 |             s1 = c2 * tri[1] + s1 * tri[0];
144 |         }
145 |         tri += 2;
146 |     } while (k4 < n);
147 | }
148 | 
149 | 
150 | static const unsigned char rv_tbl[] = {
151 |     0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
152 |     0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
153 |     0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
154 |     0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
155 |     0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
156 |     0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
157 |     0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
158 |     0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
159 |     0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
160 |     0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
161 |     0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
162 |     0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
163 |     0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
164 |     0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
165 |     0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
166 |     0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe
167 | };
168 | 
169 | #define ch01(index)  (buffer[chn][index])
170 | 
171 | #define ml00(f) (window[i        ] * f(i))
172 | #define ml10(f) (window[i + 0x200] * f(i + 0x200))
173 | #define ml20(f) (window[i + 0x100] * f(i + 0x100))
174 | #define ml30(f) (window[i + 0x300] * f(i + 0x300))
175 | 
176 | #define ml01(f) (window[i + 0x001] * f(i + 0x001))
177 | #define ml11(f) (window[i + 0x201] * f(i + 0x201))
178 | #define ml21(f) (window[i + 0x101] * f(i + 0x101))
179 | #define ml31(f) (window[i + 0x301] * f(i + 0x301))
180 | 
181 | #define ms00(f) (window_s[i       ] * f(i + k))
182 | #define ms10(f) (window_s[0x7f - i] * f(i + k + 0x80))
183 | #define ms20(f) (window_s[i + 0x40] * f(i + k + 0x40))
184 | #define ms30(f) (window_s[0x3f - i] * f(i + k + 0xc0))
185 | 
186 | #define ms01(f) (window_s[i + 0x01] * f(i + k + 0x01))
187 | #define ms11(f) (window_s[0x7e - i] * f(i + k + 0x81))
188 | #define ms21(f) (window_s[i + 0x41] * f(i + k + 0x41))
189 | #define ms31(f) (window_s[0x3e - i] * f(i + k + 0xc1))
190 | 
191 | void
192 | fft_short(lame_internal_flags const *const gfc,
193 |           FLOAT x_real[3][BLKSIZE_s], int chn, const sample_t *const buffer[2])
194 | {
195 |     int     i;
196 |     int     j;
197 |     int     b;
198 | 
199 | #define window_s gfc->cd_psy->window_s
200 | #define window gfc->cd_psy->window
201 | 
202 |     for (b = 0; b < 3; b++) {
203 |         FLOAT  *x = &x_real[b][BLKSIZE_s / 2];
204 |         short const k = (576 / 3) * (b + 1);
205 |         j = BLKSIZE_s / 8 - 1;
206 |         do {
207 |             FLOAT   f0, f1, f2, f3, w;
208 | 
209 |             i = rv_tbl[j << 2];
210 | 
211 |             f0 = ms00(ch01);
212 |             w = ms10(ch01);
213 |             f1 = f0 - w;
214 |             f0 = f0 + w;
215 |             f2 = ms20(ch01);
216 |             w = ms30(ch01);
217 |             f3 = f2 - w;
218 |             f2 = f2 + w;
219 | 
220 |             x -= 4;
221 |             x[0] = f0 + f2;
222 |             x[2] = f0 - f2;
223 |             x[1] = f1 + f3;
224 |             x[3] = f1 - f3;
225 | 
226 |             f0 = ms01(ch01);
227 |             w = ms11(ch01);
228 |             f1 = f0 - w;
229 |             f0 = f0 + w;
230 |             f2 = ms21(ch01);
231 |             w = ms31(ch01);
232 |             f3 = f2 - w;
233 |             f2 = f2 + w;
234 | 
235 |             x[BLKSIZE_s / 2 + 0] = f0 + f2;
236 |             x[BLKSIZE_s / 2 + 2] = f0 - f2;
237 |             x[BLKSIZE_s / 2 + 1] = f1 + f3;
238 |             x[BLKSIZE_s / 2 + 3] = f1 - f3;
239 |         } while (--j >= 0);
240 | 
241 | #undef window
242 | #undef window_s
243 | 
244 |         gfc->fft_fht(x, BLKSIZE_s / 2);
245 |         /* BLKSIZE_s/2 because of 3DNow! ASM routine */
246 |     }
247 | }
248 | 
249 | void
250 | fft_long(lame_internal_flags const *const gfc,
251 |          FLOAT x[BLKSIZE], int chn, const sample_t *const buffer[2])
252 | {
253 |     int     i;
254 |     int     jj = BLKSIZE / 8 - 1;
255 |     x += BLKSIZE / 2;
256 | 
257 | #define window_s gfc->cd_psy->window_s
258 | #define window gfc->cd_psy->window
259 | 
260 |     do {
261 |         FLOAT   f0, f1, f2, f3, w;
262 | 
263 |         i = rv_tbl[jj];
264 |         f0 = ml00(ch01);
265 |         w = ml10(ch01);
266 |         f1 = f0 - w;
267 |         f0 = f0 + w;
268 |         f2 = ml20(ch01);
269 |         w = ml30(ch01);
270 |         f3 = f2 - w;
271 |         f2 = f2 + w;
272 | 
273 |         x -= 4;
274 |         x[0] = f0 + f2;
275 |         x[2] = f0 - f2;
276 |         x[1] = f1 + f3;
277 |         x[3] = f1 - f3;
278 | 
279 |         f0 = ml01(ch01);
280 |         w = ml11(ch01);
281 |         f1 = f0 - w;
282 |         f0 = f0 + w;
283 |         f2 = ml21(ch01);
284 |         w = ml31(ch01);
285 |         f3 = f2 - w;
286 |         f2 = f2 + w;
287 | 
288 |         x[BLKSIZE / 2 + 0] = f0 + f2;
289 |         x[BLKSIZE / 2 + 2] = f0 - f2;
290 |         x[BLKSIZE / 2 + 1] = f1 + f3;
291 |         x[BLKSIZE / 2 + 3] = f1 - f3;
292 |     } while (--jj >= 0);
293 | 
294 | #undef window
295 | #undef window_s
296 | 
297 |     gfc->fft_fht(x, BLKSIZE / 2);
298 |     /* BLKSIZE/2 because of 3DNow! ASM routine */
299 | }
300 | 
301 | #ifdef HAVE_NASM
302 | extern void fht_3DN(FLOAT * fz, int n);
303 | extern void fht_SSE(FLOAT * fz, int n);
304 | #endif
305 | 
306 | void
307 | init_fft(lame_internal_flags * const gfc)
308 | {
309 |     int     i;
310 | 
311 |     /* The type of window used here will make no real difference, but */
312 |     /* in the interest of merging nspsytune stuff - switch to blackman window */
313 |     for (i = 0; i < BLKSIZE; i++)
314 |         /* blackman window */
315 |         gfc->cd_psy->window[i] = 0.42 - 0.5 * cos(2 * PI * (i + .5) / BLKSIZE) +
316 |             0.08 * cos(4 * PI * (i + .5) / BLKSIZE);
317 | 
318 |     for (i = 0; i < BLKSIZE_s / 2; i++)
319 |         gfc->cd_psy->window_s[i] = 0.5 * (1.0 - cos(2.0 * PI * (i + 0.5) / BLKSIZE_s));
320 | 
321 |     gfc->fft_fht = fht;
322 | #ifdef HAVE_NASM
323 |     if (gfc->CPU_features.AMD_3DNow) {
324 |         gfc->fft_fht = fht_3DN;
325 |     }
326 |     else if (gfc->CPU_features.SSE) {
327 |         gfc->fft_fht = fht_SSE;
328 |     }
329 |     else {
330 |         gfc->fft_fht = fht;
331 |     }
332 | #else
333 | #ifdef HAVE_XMMINTRIN_H
334 | #ifdef MIN_ARCH_SSE
335 |     gfc->fft_fht = fht_SSE2;
336 | #endif
337 | #endif
338 | #endif
339 | }
340 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/fft.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *	Fast Fourier Transform include file
 3 |  *
 4 |  *	Copyright (c) 2000 Mark Taylor
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_FFT_H
23 | #define LAME_FFT_H
24 | 
25 | void    fft_long(lame_internal_flags const *const gfc, FLOAT x_real[BLKSIZE],
26 |                  int chn, const sample_t *const data[2]);
27 | 
28 | void    fft_short(lame_internal_flags const *const gfc, FLOAT x_real[3][BLKSIZE_s],
29 |                   int chn, const sample_t *const data[2]);
30 | 
31 | void    init_fft(lame_internal_flags * const gfc);
32 | 
33 | #endif
34 | 
35 | /* End of fft.h */
36 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/gain_analysis.h:
--------------------------------------------------------------------------------
  1 | /*
  2 |  *  ReplayGainAnalysis - analyzes input samples and give the recommended dB change
  3 |  *  Copyright (C) 2001 David Robinson and Glen Sawyer
  4 |  *
  5 |  *  This library is free software; you can redistribute it and/or
  6 |  *  modify it under the terms of the GNU Lesser General Public
  7 |  *  License as published by the Free Software Foundation; either
  8 |  *  version 2.1 of the License, or (at your option) any later version.
  9 |  *
 10 |  *  This library is distributed in the hope that it will be useful,
 11 |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13 |  *  Lesser General Public License for more details.
 14 |  *
 15 |  *  You should have received a copy of the GNU Lesser General Public
 16 |  *  License along with this library; if not, write to the Free Software
 17 |  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18 |  *
 19 |  *  concept and filter values by David Robinson (David@Robinson.org)
 20 |  *    -- blame him if you think the idea is flawed
 21 |  *  coding by Glen Sawyer (mp3gain@hotmail.com) 735 W 255 N, Orem, UT 84057-4505 USA
 22 |  *    -- blame him if you think this runs too slowly, or the coding is otherwise flawed
 23 |  *
 24 |  *  For an explanation of the concepts and the basic algorithms involved, go to:
 25 |  *    http://www.replaygain.org/
 26 |  */
 27 | 
 28 | #ifndef GAIN_ANALYSIS_H
 29 | #define GAIN_ANALYSIS_H
 30 | 
 31 | #ifdef HAVE_INTTYPES_H
 32 | # include 
 33 | #else
 34 | # ifdef HAVE_STDINT_H
 35 | #  include 
 36 | # endif
 37 | #endif
 38 | 
 39 | #ifdef __cplusplus
 40 | extern  "C" {
 41 | #endif
 42 | 
 43 | 
 44 |     typedef sample_t Float_t; /* Type used for filtering */
 45 | 
 46 | 
 47 | #define PINK_REF                64.82       /* 298640883795 */ /* calibration value for 89dB */
 48 | 
 49 | 
 50 | #define YULE_ORDER         10
 51 | #define BUTTER_ORDER        2
 52 | #define YULE_FILTER     filterYule
 53 | #define BUTTER_FILTER   filterButter
 54 | #define RMS_PERCENTILE      0.95 /* percentile which is louder than the proposed level */
 55 | #define MAX_SAMP_FREQ   48000L /* maximum allowed sample frequency [Hz] */
 56 | #define RMS_WINDOW_TIME_NUMERATOR    1L
 57 | #define RMS_WINDOW_TIME_DENOMINATOR 20L /* numerator / denominator = time slice size [s] */
 58 | #define STEPS_per_dB      100 /* Table entries per dB */
 59 | #define MAX_dB            120 /* Table entries for 0...MAX_dB (normal max. values are 70...80 dB) */
 60 | 
 61 |     enum { GAIN_NOT_ENOUGH_SAMPLES = -24601, GAIN_ANALYSIS_ERROR = 0, GAIN_ANALYSIS_OK =
 62 |             1, INIT_GAIN_ANALYSIS_ERROR = 0, INIT_GAIN_ANALYSIS_OK = 1
 63 |     };
 64 | 
 65 |     enum { MAX_ORDER = (BUTTER_ORDER > YULE_ORDER ? BUTTER_ORDER : YULE_ORDER)
 66 |             , MAX_SAMPLES_PER_WINDOW = ((MAX_SAMP_FREQ * RMS_WINDOW_TIME_NUMERATOR) / RMS_WINDOW_TIME_DENOMINATOR + 1) /* max. Samples per Time slice */
 67 |     };
 68 | 
 69 |     struct replaygain_data {
 70 |         Float_t linprebuf[MAX_ORDER * 2];
 71 |         Float_t *linpre;     /* left input samples, with pre-buffer */
 72 |         Float_t lstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
 73 |         Float_t *lstep;      /* left "first step" (i.e. post first filter) samples */
 74 |         Float_t loutbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
 75 |         Float_t *lout;       /* left "out" (i.e. post second filter) samples */
 76 |         Float_t rinprebuf[MAX_ORDER * 2];
 77 |         Float_t *rinpre;     /* right input samples ... */
 78 |         Float_t rstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
 79 |         Float_t *rstep;
 80 |         Float_t routbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
 81 |         Float_t *rout;
 82 |         long    sampleWindow; /* number of samples required to reach number of milliseconds required for RMS window */
 83 |         long    totsamp;
 84 |         double  lsum;
 85 |         double  rsum;
 86 |         int     freqindex;
 87 |         int     first;
 88 |         uint32_t A[STEPS_per_dB * MAX_dB];
 89 |         uint32_t B[STEPS_per_dB * MAX_dB];
 90 | 
 91 |     };
 92 | #ifndef replaygain_data_defined
 93 | #define replaygain_data_defined
 94 |     typedef struct replaygain_data replaygain_t;
 95 | #endif
 96 | 
 97 | 
 98 | 
 99 | 
100 |     int     InitGainAnalysis(replaygain_t * rgData, long samplefreq);
101 |     int     AnalyzeSamples(replaygain_t * rgData, const Float_t * left_samples,
102 |                            const Float_t * right_samples, size_t num_samples, int num_channels);
103 |     Float_t GetTitleGain(replaygain_t * rgData);
104 | 
105 | 
106 | #ifdef __cplusplus
107 | }
108 | #endif
109 | #endif                       /* GAIN_ANALYSIS_H */
110 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/id3tag.h:
--------------------------------------------------------------------------------
 1 | 
 2 | #ifndef LAME_ID3_H
 3 | #define LAME_ID3_H
 4 | 
 5 | 
 6 | #define CHANGED_FLAG    (1U << 0)
 7 | #define ADD_V2_FLAG     (1U << 1)
 8 | #define V1_ONLY_FLAG    (1U << 2)
 9 | #define V2_ONLY_FLAG    (1U << 3)
10 | #define SPACE_V1_FLAG   (1U << 4)
11 | #define PAD_V2_FLAG     (1U << 5)
12 | 
13 | enum {
14 |     MIMETYPE_NONE = 0,
15 |     MIMETYPE_JPEG,
16 |     MIMETYPE_PNG,
17 |     MIMETYPE_GIF
18 | };
19 | 
20 | typedef struct FrameDataNode {
21 |     struct FrameDataNode *nxt;
22 |     uint32_t fid;             /* Frame Identifier                 */
23 |     char    lng[4];          /* 3-character language descriptor  */
24 |     struct {
25 |         union {
26 |             char   *l;       /* ptr to Latin-1 chars             */
27 |             unsigned short *u; /* ptr to UCS-2 text                */
28 |             unsigned char *b; /* ptr to raw bytes                 */
29 |         } ptr;
30 |         size_t  dim;
31 |         int     enc;         /* 0:Latin-1, 1:UCS-2, 2:RAW        */
32 |     } dsc  , txt;
33 | } FrameDataNode;
34 | 
35 | 
36 | typedef struct id3tag_spec {
37 |     /* private data members */
38 |     unsigned int flags;
39 |     int     year;
40 |     char   *title;
41 |     char   *artist;
42 |     char   *album;
43 |     char   *comment;
44 |     int     track_id3v1;
45 |     int     genre_id3v1;
46 |     unsigned char *albumart;
47 |     unsigned int albumart_size;
48 |     unsigned int padding_size;
49 |     int     albumart_mimetype;
50 |     char    language[4]; /* the language of the frame's content, according to ISO-639-2 */
51 |     FrameDataNode *v2_head, *v2_tail;
52 | } id3tag_spec;
53 | 
54 | 
55 | /* write tag into stream at current position */
56 | extern int id3tag_write_v2(lame_global_flags * gfp);
57 | extern int id3tag_write_v1(lame_global_flags * gfp);
58 | /*
59 |  * NOTE: A version 2 tag will NOT be added unless one of the text fields won't
60 |  * fit in a version 1 tag (e.g. the title string is longer than 30 characters),
61 |  * or the "id3tag_add_v2" or "id3tag_v2_only" functions are used.
62 |  */
63 | 
64 | #endif
65 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/l3side.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *	Layer 3 side include file
 3 |  *
 4 |  *	Copyright (c) 1999 Mark Taylor
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_L3SIDE_H
23 | #define LAME_L3SIDE_H
24 | 
25 | /* max scalefactor band, max(SBMAX_l, SBMAX_s*3, (SBMAX_s-3)*3+8) */
26 | #define SFBMAX (SBMAX_s*3)
27 | 
28 | /* Layer III side information. */
29 | typedef struct {
30 |     int     l[1 + SBMAX_l];
31 |     int     s[1 + SBMAX_s];
32 |     int     psfb21[1 + PSFB21];
33 |     int     psfb12[1 + PSFB12];
34 | } scalefac_struct;
35 | 
36 | 
37 | typedef struct {
38 |     FLOAT   l[SBMAX_l];
39 |     FLOAT   s[SBMAX_s][3];
40 | } III_psy_xmin;
41 | 
42 | typedef struct {
43 |     III_psy_xmin thm;
44 |     III_psy_xmin en;
45 | } III_psy_ratio;
46 | 
47 | typedef struct {
48 |     FLOAT   xr[576];
49 |     int     l3_enc[576];
50 |     int     scalefac[SFBMAX];
51 |     FLOAT   xrpow_max;
52 | 
53 |     int     part2_3_length;
54 |     int     big_values;
55 |     int     count1;
56 |     int     global_gain;
57 |     int     scalefac_compress;
58 |     int     block_type;
59 |     int     mixed_block_flag;
60 |     int     table_select[3];
61 |     int     subblock_gain[3 + 1];
62 |     int     region0_count;
63 |     int     region1_count;
64 |     int     preflag;
65 |     int     scalefac_scale;
66 |     int     count1table_select;
67 | 
68 |     int     part2_length;
69 |     int     sfb_lmax;
70 |     int     sfb_smin;
71 |     int     psy_lmax;
72 |     int     sfbmax;
73 |     int     psymax;
74 |     int     sfbdivide;
75 |     int     width[SFBMAX];
76 |     int     window[SFBMAX];
77 |     int     count1bits;
78 |     /* added for LSF */
79 |     const int *sfb_partition_table;
80 |     int     slen[4];
81 | 
82 |     int     max_nonzero_coeff;
83 |     char    energy_above_cutoff[SFBMAX];
84 | } gr_info;
85 | 
86 | typedef struct {
87 |     gr_info tt[2][2];
88 |     int     main_data_begin;
89 |     int     private_bits;
90 |     int     resvDrain_pre;
91 |     int     resvDrain_post;
92 |     int     scfsi[2][4];
93 | } III_side_info_t;
94 | 
95 | #endif
96 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/lame-analysis.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *      GTK plotting routines source file
 3 |  *
 4 |  *      Copyright (c) 1999 Mark Taylor
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_GTKANAL_H
23 | #define LAME_GTKANAL_H
24 | 
25 | 
26 | #define READ_AHEAD 40   /* number of frames to read ahead */
27 | #define MAXMPGLAG READ_AHEAD /* if the mpg123 lag becomes bigger than this
28 |                                 we have to stop */
29 | #define NUMBACK 6       /* number of frames we can back up */
30 | #define NUMPINFO (NUMBACK+READ_AHEAD+1)
31 | 
32 | 
33 | 
34 | struct plotting_data {
35 |     int     frameNum;        /* current frame number */
36 |     int     frameNum123;
37 |     int     num_samples;     /* number of pcm samples read for this frame */
38 |     double  frametime;       /* starting time of frame, in seconds */
39 |     double  pcmdata[2][1600];
40 |     double  pcmdata2[2][1152 + 1152 - DECDELAY];
41 |     double  xr[2][2][576];
42 |     double  mpg123xr[2][2][576];
43 |     double  ms_ratio[2];
44 |     double  ms_ener_ratio[2];
45 | 
46 |     /* L,R, M and S values */
47 |     double  energy_save[4][BLKSIZE]; /* psymodel is one ahead */
48 |     double  energy[2][4][BLKSIZE];
49 |     double  pe[2][4];
50 |     double  thr[2][4][SBMAX_l];
51 |     double  en[2][4][SBMAX_l];
52 |     double  thr_s[2][4][3 * SBMAX_s];
53 |     double  en_s[2][4][3 * SBMAX_s];
54 |     double  ers_save[4];     /* psymodel is one ahead */
55 |     double  ers[2][4];
56 | 
57 |     double  sfb[2][2][SBMAX_l];
58 |     double  sfb_s[2][2][3 * SBMAX_s];
59 |     double  LAMEsfb[2][2][SBMAX_l];
60 |     double  LAMEsfb_s[2][2][3 * SBMAX_s];
61 | 
62 |     int     LAMEqss[2][2];
63 |     int     qss[2][2];
64 |     int     big_values[2][2];
65 |     int     sub_gain[2][2][3];
66 | 
67 |     double  xfsf[2][2][SBMAX_l];
68 |     double  xfsf_s[2][2][3 * SBMAX_s];
69 | 
70 |     int     over[2][2];
71 |     double  tot_noise[2][2];
72 |     double  max_noise[2][2];
73 |     double  over_noise[2][2];
74 |     int     over_SSD[2][2];
75 |     int     blocktype[2][2];
76 |     int     scalefac_scale[2][2];
77 |     int     preflag[2][2];
78 |     int     mpg123blocktype[2][2];
79 |     int     mixed[2][2];
80 |     int     mainbits[2][2];
81 |     int     sfbits[2][2];
82 |     int     LAMEmainbits[2][2];
83 |     int     LAMEsfbits[2][2];
84 |     int     framesize, stereo, js, ms_stereo, i_stereo, emph, bitrate, sampfreq, maindata;
85 |     int     crc, padding;
86 |     int     scfsi[2], mean_bits, resvsize;
87 |     int     totbits;
88 | };
89 | #ifndef plotting_data_defined
90 | #define plotting_data_defined
91 | typedef struct plotting_data plotting_data;
92 | #endif
93 | #if 0
94 | extern plotting_data *pinfo;
95 | #endif
96 | #endif
97 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/lame_global_flags.h:
--------------------------------------------------------------------------------
  1 | #ifndef LAME_GLOBAL_FLAGS_H
  2 | #define LAME_GLOBAL_FLAGS_H
  3 | 
  4 | #ifndef lame_internal_flags_defined
  5 | #define lame_internal_flags_defined
  6 | struct lame_internal_flags;
  7 | typedef struct lame_internal_flags lame_internal_flags;
  8 | #endif
  9 | 
 10 | 
 11 | typedef enum short_block_e {
 12 |     short_block_not_set = -1, /* allow LAME to decide */
 13 |     short_block_allowed = 0, /* LAME may use them, even different block types for L/R */
 14 |     short_block_coupled, /* LAME may use them, but always same block types in L/R */
 15 |     short_block_dispensed, /* LAME will not use short blocks, long blocks only */
 16 |     short_block_forced  /* LAME will not use long blocks, short blocks only */
 17 | } short_block_t;
 18 | 
 19 | /***********************************************************************
 20 | *
 21 | *  Control Parameters set by User.  These parameters are here for
 22 | *  backwards compatibility with the old, non-shared lib API.
 23 | *  Please use the lame_set_variablename() functions below
 24 | *
 25 | *
 26 | ***********************************************************************/
 27 | struct lame_global_struct {
 28 |     unsigned int class_id;
 29 | 
 30 |     /* input description */
 31 |     unsigned long num_samples; /* number of samples. default=2^32-1           */
 32 |     int     num_channels;    /* input number of channels. default=2         */
 33 |     int     samplerate_in;   /* input_samp_rate in Hz. default=44.1 kHz     */
 34 |     int     samplerate_out;  /* output_samp_rate.
 35 |                                 default: LAME picks best value
 36 |                                 at least not used for MP3 decoding:
 37 |                                 Remember 44.1 kHz MP3s and AC97           */
 38 |     float   scale;           /* scale input by this amount before encoding
 39 |                                 at least not used for MP3 decoding          */
 40 |     float   scale_left;      /* scale input of channel 0 (left) by this
 41 |                                 amount before encoding                      */
 42 |     float   scale_right;     /* scale input of channel 1 (right) by this
 43 |                                 amount before encoding                      */
 44 | 
 45 |     /* general control params */
 46 |     int     analysis;        /* collect data for a MP3 frame analyzer?      */
 47 |     int     write_lame_tag;  /* add Xing VBR tag?                           */
 48 |     int     decode_only;     /* use lame/mpglib to convert mp3 to wav       */
 49 |     int     quality;         /* quality setting 0=best,  9=worst  default=5 */
 50 |     MPEG_mode mode;          /* see enum in lame.h
 51 |                                 default = LAME picks best value             */
 52 |     int     force_ms;        /* force M/S mode.  requires mode=1            */
 53 |     int     free_format;     /* use free format? default=0                  */
 54 |     int     findReplayGain;  /* find the RG value? default=0       */
 55 |     int     decode_on_the_fly; /* decode on the fly? default=0                */
 56 |     int     write_id3tag_automatic; /* 1 (default) writes ID3 tags, 0 not */
 57 | 
 58 |     int     nogap_total;
 59 |     int     nogap_current;
 60 | 
 61 |     int     substep_shaping;
 62 |     int     noise_shaping;
 63 |     int     subblock_gain;   /*  0 = no, 1 = yes */
 64 |     int     use_best_huffman; /* 0 = no.  1=outside loop  2=inside loop(slow) */
 65 | 
 66 |     /*
 67 |      * set either brate>0  or compression_ratio>0, LAME will compute
 68 |      * the value of the variable not set.
 69 |      * Default is compression_ratio = 11.025
 70 |      */
 71 |     int     brate;           /* bitrate                                    */
 72 |     float   compression_ratio; /* sizeof(wav file)/sizeof(mp3 file)          */
 73 | 
 74 | 
 75 |     /* frame params */
 76 |     int     copyright;       /* mark as copyright. default=0           */
 77 |     int     original;        /* mark as original. default=1            */
 78 |     int     extension;       /* the MP3 'private extension' bit.
 79 |                                 Meaningless                            */
 80 |     int     emphasis;        /* Input PCM is emphased PCM (for
 81 |                                 instance from one of the rarely
 82 |                                 emphased CDs), it is STRONGLY not
 83 |                                 recommended to use this, because
 84 |                                 psycho does not take it into account,
 85 |                                 and last but not least many decoders
 86 |                                 don't care about these bits          */
 87 |     int     error_protection; /* use 2 bytes per frame for a CRC
 88 |                                  checksum. default=0                    */
 89 |     int     strict_ISO;      /* enforce ISO spec as much as possible   */
 90 | 
 91 |     int     disable_reservoir; /* use bit reservoir?                     */
 92 | 
 93 |     /* quantization/noise shaping */
 94 |     int     quant_comp;
 95 |     int     quant_comp_short;
 96 |     int     experimentalY;
 97 |     int     experimentalZ;
 98 |     int     exp_nspsytune;
 99 | 
100 |     int     preset;
101 | 
102 |     /* VBR control */
103 |     vbr_mode VBR;
104 |     float   VBR_q_frac;      /* Range [0,...,1[ */
105 |     int     VBR_q;           /* Range [0,...,9] */
106 |     int     VBR_mean_bitrate_kbps;
107 |     int     VBR_min_bitrate_kbps;
108 |     int     VBR_max_bitrate_kbps;
109 |     int     VBR_hard_min;    /* strictly enforce VBR_min_bitrate
110 |                                 normaly, it will be violated for analog
111 |                                 silence                                 */
112 | 
113 | 
114 |     /* resampling and filtering */
115 |     int     lowpassfreq;     /* freq in Hz. 0=lame choses.
116 |                                 -1=no filter                          */
117 |     int     highpassfreq;    /* freq in Hz. 0=lame choses.
118 |                                 -1=no filter                          */
119 |     int     lowpasswidth;    /* freq width of filter, in Hz
120 |                                 (default=15%)                         */
121 |     int     highpasswidth;   /* freq width of filter, in Hz
122 |                                 (default=15%)                         */
123 | 
124 | 
125 | 
126 |     /*
127 |      * psycho acoustics and other arguments which you should not change
128 |      * unless you know what you are doing
129 |      */
130 |     float   maskingadjust;
131 |     float   maskingadjust_short;
132 |     int     ATHonly;         /* only use ATH                         */
133 |     int     ATHshort;        /* only use ATH for short blocks        */
134 |     int     noATH;           /* disable ATH                          */
135 |     int     ATHtype;         /* select ATH formula                   */
136 |     float   ATHcurve;        /* change ATH formula 4 shape           */
137 |     float   ATH_lower_db;    /* lower ATH by this many db            */
138 |     int     athaa_type;      /* select ATH auto-adjust scheme        */
139 |     float   athaa_sensitivity; /* dB, tune active region of auto-level */
140 |     short_block_t short_blocks;
141 |     int     useTemporal;     /* use temporal masking effect          */
142 |     float   interChRatio;
143 |     float   msfix;           /* Naoki's adjustment of Mid/Side maskings */
144 | 
145 |     int     tune;            /* 0 off, 1 on */
146 |     float   tune_value_a;    /* used to pass values for debugging and stuff */
147 | 
148 |     float   attackthre;      /* attack threshold for L/R/M channel */
149 |     float   attackthre_s;    /* attack threshold for S channel */
150 | 
151 | 
152 |     struct {
153 |         void    (*msgf) (const char *format, va_list ap);
154 |         void    (*debugf) (const char *format, va_list ap);
155 |         void    (*errorf) (const char *format, va_list ap);
156 |     } report;
157 | 
158 |   /************************************************************************/
159 |     /* internal variables, do not set...                                    */
160 |     /* provided because they may be of use to calling application           */
161 |   /************************************************************************/
162 | 
163 |     int     lame_allocated_gfp; /* is this struct owned by calling
164 |                                    program or lame?                     */
165 | 
166 | 
167 | 
168 |   /**************************************************************************/
169 |     /* more internal variables are stored in this structure:                  */
170 |   /**************************************************************************/
171 |     lame_internal_flags *internal_flags;
172 | 
173 | 
174 |     struct {
175 |         int     mmx;
176 |         int     amd3dnow;
177 |         int     sse;
178 | 
179 |     } asm_optimizations;
180 | };
181 | 
182 | int     is_lame_global_flags_valid(const lame_global_flags * gfp);
183 | 
184 | #endif /* LAME_GLOBAL_FLAGS_H */
185 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/machine.h:
--------------------------------------------------------------------------------
  1 | /*
  2 |  *      Machine dependent defines/includes for LAME.
  3 |  *
  4 |  *      Copyright (c) 1999 A.L. Faber
  5 |  *
  6 |  * This library is free software; you can redistribute it and/or
  7 |  * modify it under the terms of the GNU Library General Public
  8 |  * License as published by the Free Software Foundation; either
  9 |  * version 2 of the License, or (at your option) any later version.
 10 |  *
 11 |  * This library is distributed in the hope that it will be useful,
 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14 |  * Library General Public License for more details.
 15 |  *
 16 |  * You should have received a copy of the GNU Library General Public
 17 |  * License along with this library; if not, write to the
 18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 19 |  * Boston, MA 02111-1307, USA.
 20 |  */
 21 | 
 22 | #ifndef LAME_MACHINE_H
 23 | #define LAME_MACHINE_H
 24 | 
 25 | #include "version.h"
 26 | 
 27 | #include 
 28 | #include 
 29 | 
 30 | #ifdef STDC_HEADERS
 31 | # include 
 32 | # include 
 33 | #else
 34 | # ifndef HAVE_STRCHR
 35 | #  define strchr index
 36 | #  define strrchr rindex
 37 | # endif
 38 | char   *strchr(), *strrchr();
 39 | # ifndef HAVE_MEMCPY
 40 | #  define memcpy(d, s, n) bcopy ((s), (d), (n))
 41 | #  define memmove(d, s, n) bcopy ((s), (d), (n))
 42 | # endif
 43 | #endif
 44 | 
 45 | #if  defined(__riscos__)  &&  defined(FPA10)
 46 | # include "ymath.h"
 47 | #else
 48 | # include 
 49 | #endif
 50 | #include 
 51 | 
 52 | #include 
 53 | 
 54 | #ifdef HAVE_ERRNO_H
 55 | # include 
 56 | #endif
 57 | #ifdef HAVE_FCNTL_H
 58 | # include 
 59 | #endif
 60 | 
 61 | #if defined(macintosh)
 62 | # include 
 63 | # include 
 64 | #else
 65 | # include 
 66 | # include 
 67 | #endif
 68 | 
 69 | #ifdef HAVE_INTTYPES_H
 70 | # include 
 71 | #else
 72 | # ifdef HAVE_STDINT_H
 73 | #  include 
 74 | # endif
 75 | #endif
 76 | 
 77 | #ifdef WITH_DMALLOC
 78 | #include 
 79 | #endif
 80 | 
 81 | /*
 82 |  * 3 different types of pow() functions:
 83 |  *   - table lookup
 84 |  *   - pow()
 85 |  *   - exp()   on some machines this is claimed to be faster than pow()
 86 |  */
 87 | 
 88 | #define POW20(x) (assert(0 <= (x+Q_MAX2) && x < Q_MAX), pow20[x+Q_MAX2])
 89 | /*#define POW20(x)  pow(2.0,((double)(x)-210)*.25) */
 90 | /*#define POW20(x)  exp( ((double)(x)-210)*(.25*LOG2) ) */
 91 | 
 92 | #define IPOW20(x)  (assert(0 <= x && x < Q_MAX), ipow20[x])
 93 | /*#define IPOW20(x)  exp( -((double)(x)-210)*.1875*LOG2 ) */
 94 | /*#define IPOW20(x)  pow(2.0,-((double)(x)-210)*.1875) */
 95 | 
 96 | /* in case this is used without configure */
 97 | #ifndef inline
 98 | # define inline
 99 | #endif
100 | 
101 | #if defined(_MSC_VER)
102 | # undef inline
103 | # define inline _inline
104 | #elif defined(__SASC) || defined(__GNUC__) || defined(__ICC) || defined(__ECC)
105 | /* if __GNUC__ we always want to inline, not only if the user requests it */
106 | # undef inline
107 | # define inline __inline
108 | #endif
109 | 
110 | #if    defined(_MSC_VER)
111 | # pragma warning( disable : 4244 )
112 | /*# pragma warning( disable : 4305 ) */
113 | #endif
114 | 
115 | /*
116 |  * FLOAT    for variables which require at least 32 bits
117 |  * FLOAT8   for variables which require at least 64 bits
118 |  *
119 |  * On some machines, 64 bit will be faster than 32 bit.  Also, some math
120 |  * routines require 64 bit float, so setting FLOAT=float will result in a
121 |  * lot of conversions.
122 |  */
123 | 
124 | #if ( defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) )
125 | # define WIN32_LEAN_AND_MEAN
126 | # include 
127 | # include 
128 | # define FLOAT_MAX FLT_MAX
129 | #else
130 | # ifndef FLOAT
131 | typedef float FLOAT;
132 | #  ifdef FLT_MAX
133 | #   define FLOAT_MAX FLT_MAX
134 | #  else
135 | #   define FLOAT_MAX 1e37 /* approx */
136 | #  endif
137 | # endif
138 | #endif
139 | 
140 | #ifndef FLOAT8
141 | typedef double FLOAT8;
142 | # ifdef DBL_MAX
143 | #  define FLOAT8_MAX DBL_MAX
144 | # else
145 | #  define FLOAT8_MAX 1e99 /* approx */
146 | # endif
147 | #else
148 | # ifdef FLT_MAX
149 | #  define FLOAT8_MAX FLT_MAX
150 | # else
151 | #  define FLOAT8_MAX 1e37 /* approx */
152 | # endif
153 | #endif
154 | 
155 | /* sample_t must be floating point, at least 32 bits */
156 | typedef FLOAT sample_t;
157 | 
158 | #define dimension_of(array) (sizeof(array)/sizeof(array[0]))
159 | #define beyond(array) (array+dimension_of(array))
160 | #define compiletime_assert(expression) enum{static_assert_##FILE##_##LINE = 1/((expression)?1:0)}
161 | #define lame_calloc(TYPE, COUNT) ((TYPE*)calloc(COUNT, sizeof(TYPE)))
162 | #define multiple_of(CHUNK, COUNT) (\
163 |   ( (COUNT) < 1 || (CHUNK) < 1 || (COUNT) % (CHUNK) == 0 ) \
164 |   ? (COUNT) \
165 |   : ((COUNT) + (CHUNK) - (COUNT) % (CHUNK)) \
166 |   )
167 | 
168 | #if 1
169 | #define EQ(a,b) (\
170 | (fabs(a) > fabs(b)) \
171 |  ? (fabs((a)-(b)) <= (fabs(a) * 1e-6f)) \
172 |  : (fabs((a)-(b)) <= (fabs(b) * 1e-6f)))
173 | #else
174 | #define EQ(a,b) (fabs((a)-(b))<1E-37)
175 | #endif
176 | 
177 | #define NEQ(a,b) (!EQ(a,b))
178 | 
179 | #ifdef _MSC_VER
180 | #  if _MSC_VER < 1400
181 | #  define fabsf fabs
182 | #  define powf pow
183 | #  define log10f log10
184 | #  endif
185 | #endif
186 | 
187 | #endif
188 | 
189 | /* end of machine.h */
190 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/newmdct.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *	New Modified DCT include file
 3 |  *
 4 |  *	Copyright (c) 1999 Takehiro TOMINAGA
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_NEWMDCT_H
23 | #define LAME_NEWMDCT_H
24 | 
25 | void    mdct_sub48(lame_internal_flags * gfc, const sample_t * w0, const sample_t * w1);
26 | 
27 | #endif /* LAME_NEWMDCT_H */
28 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/psymodel.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *	psymodel.h
 3 |  *
 4 |  *	Copyright (c) 1999 Mark Taylor
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_PSYMODEL_H
23 | #define LAME_PSYMODEL_H
24 | 
25 | 
26 | int     L3psycho_anal_ns(lame_internal_flags * gfc,
27 |                          const sample_t *const buffer[2], int gr,
28 |                          III_psy_ratio ratio[2][2],
29 |                          III_psy_ratio MS_ratio[2][2],
30 |                          FLOAT pe[2], FLOAT pe_MS[2], FLOAT ener[2], int blocktype_d[2]);
31 | 
32 | int     L3psycho_anal_vbr(lame_internal_flags * gfc,
33 |                           const sample_t *const buffer[2], int gr,
34 |                           III_psy_ratio ratio[2][2],
35 |                           III_psy_ratio MS_ratio[2][2],
36 |                           FLOAT pe[2], FLOAT pe_MS[2], FLOAT ener[2], int blocktype_d[2]);
37 | 
38 | 
39 | int     psymodel_init(lame_global_flags const* gfp);
40 | 
41 | 
42 | #define rpelev 2
43 | #define rpelev2 16
44 | #define rpelev_s 2
45 | #define rpelev2_s 16
46 | 
47 | /* size of each partition band, in barks: */
48 | #define DELBARK .34
49 | 
50 | 
51 | /* tuned for output level (sensitive to energy scale) */
52 | #define VO_SCALE (1./( 14752*14752 )/(BLKSIZE/2))
53 | 
54 | #define temporalmask_sustain_sec 0.01
55 | 
56 | #define NS_PREECHO_ATT0 0.8
57 | #define NS_PREECHO_ATT1 0.6
58 | #define NS_PREECHO_ATT2 0.3
59 | 
60 | #define NS_MSFIX 3.5
61 | #define NSATTACKTHRE 4.4
62 | #define NSATTACKTHRE_S 25
63 | 
64 | #endif /* LAME_PSYMODEL_H */
65 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/quantize.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * MP3 quantization
 3 |  *
 4 |  * Copyright (c) 1999 Mark Taylor
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_QUANTIZE_H
23 | #define LAME_QUANTIZE_H
24 | 
25 | void    CBR_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
26 |                            const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]);
27 | 
28 | void    VBR_old_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
29 |                                const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]);
30 | 
31 | void    VBR_new_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
32 |                                const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]);
33 | 
34 | void    ABR_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
35 |                            const FLOAT ms_ratio[2], const III_psy_ratio ratio[2][2]);
36 | 
37 | 
38 | #endif /* LAME_QUANTIZE_H */
39 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/quantize_pvt.h:
--------------------------------------------------------------------------------
  1 | /*
  2 |  *	quantize_pvt include file
  3 |  *
  4 |  *	Copyright (c) 1999 Takehiro TOMINAGA
  5 |  *
  6 |  * This library is free software; you can redistribute it and/or
  7 |  * modify it under the terms of the GNU Library General Public
  8 |  * License as published by the Free Software Foundation; either
  9 |  * version 2 of the License, or (at your option) any later version.
 10 |  *
 11 |  * This library is distributed in the hope that it will be useful,
 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 14 |  * Library General Public License for more details.
 15 |  *
 16 |  * You should have received a copy of the GNU Library General Public
 17 |  * License along with this library; if not, write to the
 18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 19 |  * Boston, MA 02111-1307, USA.
 20 |  */
 21 | 
 22 | #ifndef LAME_QUANTIZE_PVT_H
 23 | #define LAME_QUANTIZE_PVT_H
 24 | 
 25 | #define IXMAX_VAL 8206  /* ix always <= 8191+15.    see count_bits() */
 26 | 
 27 | /* buggy Winamp decoder cannot handle values > 8191 */
 28 | /* #define IXMAX_VAL 8191 */
 29 | 
 30 | #define PRECALC_SIZE (IXMAX_VAL+2)
 31 | 
 32 | 
 33 | extern const int nr_of_sfb_block[6][3][4];
 34 | extern const int pretab[SBMAX_l];
 35 | extern const int slen1_tab[16];
 36 | extern const int slen2_tab[16];
 37 | 
 38 | extern const scalefac_struct sfBandIndex[9];
 39 | 
 40 | extern FLOAT pow43[PRECALC_SIZE];
 41 | #ifdef TAKEHIRO_IEEE754_HACK
 42 | extern FLOAT adj43asm[PRECALC_SIZE];
 43 | #else
 44 | extern FLOAT adj43[PRECALC_SIZE];
 45 | #endif
 46 | 
 47 | #define Q_MAX (256+1)
 48 | #define Q_MAX2 116      /* minimum possible number of
 49 |                            -cod_info->global_gain
 50 |                            + ((scalefac[] + (cod_info->preflag ? pretab[sfb] : 0))
 51 |                            << (cod_info->scalefac_scale + 1))
 52 |                            + cod_info->subblock_gain[cod_info->window[sfb]] * 8;
 53 | 
 54 |                            for long block, 0+((15+3)<<2) = 18*4 = 72
 55 |                            for short block, 0+(15<<2)+7*8 = 15*4+56 = 116
 56 |                          */
 57 | 
 58 | extern FLOAT pow20[Q_MAX + Q_MAX2 + 1];
 59 | extern FLOAT ipow20[Q_MAX];
 60 | 
 61 | typedef struct calc_noise_result_t {
 62 |     FLOAT   over_noise;      /* sum of quantization noise > masking */
 63 |     FLOAT   tot_noise;       /* sum of all quantization noise */
 64 |     FLOAT   max_noise;       /* max quantization noise */
 65 |     int     over_count;      /* number of quantization noise > masking */
 66 |     int     over_SSD;        /* SSD-like cost of distorted bands */
 67 |     int     bits;
 68 | } calc_noise_result;
 69 | 
 70 | 
 71 | /**
 72 | * allows re-use of previously
 73 | * computed noise values
 74 | */
 75 | typedef struct calc_noise_data_t {
 76 |     int     global_gain;
 77 |     int     sfb_count1;
 78 |     int     step[39];
 79 |     FLOAT   noise[39];
 80 |     FLOAT   noise_log[39];
 81 | } calc_noise_data;
 82 | 
 83 | 
 84 | int     on_pe(lame_internal_flags * gfc, const FLOAT pe[2][2],
 85 |               int targ_bits[2], int mean_bits, int gr, int cbr);
 86 | 
 87 | void    reduce_side(int targ_bits[2], FLOAT ms_ener_ratio, int mean_bits, int max_bits);
 88 | 
 89 | 
 90 | void    iteration_init(lame_internal_flags * gfc);
 91 | 
 92 | 
 93 | int     calc_xmin(lame_internal_flags const *gfc,
 94 |                   III_psy_ratio const *const ratio, gr_info * const cod_info, FLOAT * l3_xmin);
 95 | 
 96 | int     calc_noise(const gr_info * const cod_info,
 97 |                    const FLOAT * l3_xmin,
 98 |                    FLOAT * distort, calc_noise_result * const res, calc_noise_data * prev_noise);
 99 | 
100 | void    set_frame_pinfo(lame_internal_flags * gfc, const III_psy_ratio ratio[2][2]);
101 | 
102 | 
103 | 
104 | 
105 | /* takehiro.c */
106 | 
107 | int     count_bits(lame_internal_flags const *const gfc, const FLOAT * const xr,
108 |                    gr_info * const cod_info, calc_noise_data * prev_noise);
109 | int     noquant_count_bits(lame_internal_flags const *const gfc,
110 |                            gr_info * const cod_info, calc_noise_data * prev_noise);
111 | 
112 | 
113 | void    best_huffman_divide(const lame_internal_flags * const gfc, gr_info * const cod_info);
114 | 
115 | void    best_scalefac_store(const lame_internal_flags * gfc, const int gr, const int ch,
116 |                             III_side_info_t * const l3_side);
117 | 
118 | int     scale_bitcount(const lame_internal_flags * gfc, gr_info * cod_info);
119 | 
120 | void    huffman_init(lame_internal_flags * const gfc);
121 | 
122 | void    init_xrpow_core_init(lame_internal_flags * const gfc);
123 | 
124 | FLOAT   athAdjust(FLOAT a, FLOAT x, FLOAT athFloor, float ATHfixpoint);
125 | 
126 | #define LARGE_BITS 100000
127 | 
128 | #endif /* LAME_QUANTIZE_PVT_H */
129 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/reservoir.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |  *      bit reservoir source file
  3 |  *
  4 |  *      Copyright (c) 1999-2000 Mark Taylor
  5 |  *
  6 |  * This library is free software; you can redistribute it and/or
  7 |  * modify it under the terms of the GNU Library General Public
  8 |  * License as published by the Free Software Foundation; either
  9 |  * version 2 of the License, or (at your option) any later version.
 10 |  *
 11 |  * This library is distributed in the hope that it will be useful,
 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14 |  * Library General Public License for more details.
 15 |  *
 16 |  * You should have received a copy of the GNU Library General Public
 17 |  * License along with this library; if not, write to the
 18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 19 |  * Boston, MA 02111-1307, USA.
 20 |  */
 21 | 
 22 | /* $Id: reservoir.c,v 1.45 2011/05/07 16:05:17 rbrito Exp $ */
 23 | 
 24 | #ifdef HAVE_CONFIG_H
 25 | # include 
 26 | #endif
 27 | 
 28 | 
 29 | #include "lame.h"
 30 | #include "machine.h"
 31 | #include "encoder.h"
 32 | #include "util.h"
 33 | #include "reservoir.h"
 34 | 
 35 | #include "bitstream.h"
 36 | #include "lame-analysis.h"
 37 | #include "lame_global_flags.h"
 38 | 
 39 | 
 40 | /*
 41 |   ResvFrameBegin:
 42 |   Called (repeatedly) at the beginning of a frame. Updates the maximum
 43 |   size of the reservoir, and checks to make sure main_data_begin
 44 |   was set properly by the formatter
 45 | */
 46 | 
 47 | /*
 48 |  *  Background information:
 49 |  *
 50 |  *  This is the original text from the ISO standard. Because of
 51 |  *  sooo many bugs and irritations correcting comments are added
 52 |  *  in brackets []. A '^W' means you should remove the last word.
 53 |  *
 54 |  *  1) The following rule can be used to calculate the maximum
 55 |  *     number of bits used for one granule [^W frame]:
 56 |  *     At the highest possible bitrate of Layer III (320 kbps
 57 |  *     per stereo signal [^W^W^W], 48 kHz) the frames must be of
 58 |  *     [^W^W^W are designed to have] constant length, i.e.
 59 |  *     one buffer [^W^W the frame] length is:
 60 |  *
 61 |  *         320 kbps * 1152/48 kHz = 7680 bit = 960 byte
 62 |  *
 63 |  *     This value is used as the maximum buffer per channel [^W^W] at
 64 |  *     lower bitrates [than 320 kbps]. At 64 kbps mono or 128 kbps
 65 |  *     stereo the main granule length is 64 kbps * 576/48 kHz = 768 bit
 66 |  *     [per granule and channel] at 48 kHz sampling frequency.
 67 |  *     This means that there is a maximum deviation (short time buffer
 68 |  *     [= reservoir]) of 7680 - 2*2*768 = 4608 bits is allowed at 64 kbps.
 69 |  *     The actual deviation is equal to the number of bytes [with the
 70 |  *     meaning of octets] denoted by the main_data_end offset pointer.
 71 |  *     The actual maximum deviation is (2^9-1)*8 bit = 4088 bits
 72 |  *     [for MPEG-1 and (2^8-1)*8 bit for MPEG-2, both are hard limits].
 73 |  *     ... The xchange of buffer bits between the left and right channel
 74 |  *     is allowed without restrictions [exception: dual channel].
 75 |  *     Because of the [constructed] constraint on the buffer size
 76 |  *     main_data_end is always set to 0 in the case of bit_rate_index==14,
 77 |  *     i.e. data rate 320 kbps per stereo signal [^W^W^W]. In this case
 78 |  *     all data are allocated between adjacent header [^W sync] words
 79 |  *     [, i.e. there is no buffering at all].
 80 |  */
 81 | 
 82 | int
 83 | ResvFrameBegin(lame_internal_flags * gfc, int *mean_bits)
 84 | {
 85 |     SessionConfig_t const *const cfg = &gfc->cfg;
 86 |     EncStateVar_t *const esv = &gfc->sv_enc;
 87 |     int     fullFrameBits;
 88 |     int     resvLimit;
 89 |     int     maxmp3buf;
 90 |     III_side_info_t *const l3_side = &gfc->l3_side;
 91 |     int     frameLength;
 92 |     int     meanBits;
 93 | 
 94 |     frameLength = getframebits(gfc);
 95 |     meanBits = (frameLength - cfg->sideinfo_len * 8) / cfg->mode_gr;
 96 | 
 97 | /*
 98 |  *  Meaning of the variables:
 99 |  *      resvLimit: (0, 8, ..., 8*255 (MPEG-2), 8*511 (MPEG-1))
100 |  *          Number of bits can be stored in previous frame(s) due to
101 |  *          counter size constaints
102 |  *      maxmp3buf: ( ??? ... 8*1951 (MPEG-1 and 2), 8*2047 (MPEG-2.5))
103 |  *          Number of bits allowed to encode one frame (you can take 8*511 bit
104 |  *          from the bit reservoir and at most 8*1440 bit from the current
105 |  *          frame (320 kbps, 32 kHz), so 8*1951 bit is the largest possible
106 |  *          value for MPEG-1 and -2)
107 |  *
108 |  *          maximum allowed granule/channel size times 4 = 8*2047 bits.,
109 |  *          so this is the absolute maximum supported by the format.
110 |  *
111 |  *
112 |  *      fullFrameBits:  maximum number of bits available for encoding
113 |  *                      the current frame.
114 |  *
115 |  *      mean_bits:      target number of bits per granule.
116 |  *
117 |  *      frameLength:
118 |  *
119 |  *      gfc->ResvMax:   maximum allowed reservoir
120 |  *
121 |  *      gfc->ResvSize:  current reservoir size
122 |  *
123 |  *      l3_side->resvDrain_pre:
124 |  *         ancillary data to be added to previous frame:
125 |  *         (only usefull in VBR modes if it is possible to have
126 |  *         maxmp3buf < fullFrameBits)).  Currently disabled,
127 |  *         see #define NEW_DRAIN
128 |  *         2010-02-13: RH now enabled, it seems to be needed for CBR too,
129 |  *                     as there exists one example, where the FhG decoder
130 |  *                     can't decode a -b320 CBR file anymore.
131 |  *
132 |  *      l3_side->resvDrain_post:
133 |  *         ancillary data to be added to this frame:
134 |  *
135 |  */
136 | 
137 |     /* main_data_begin has 9 bits in MPEG-1, 8 bits MPEG-2 */
138 |     resvLimit = (8 * 256) * cfg->mode_gr - 8;
139 | 
140 |     /* maximum allowed frame size.  dont use more than this number of
141 |        bits, even if the frame has the space for them: */
142 |     maxmp3buf = cfg->buffer_constraint;
143 |     esv->ResvMax = maxmp3buf - frameLength;
144 |     if (esv->ResvMax > resvLimit)
145 |         esv->ResvMax = resvLimit;
146 |     if (esv->ResvMax < 0 || cfg->disable_reservoir)
147 |         esv->ResvMax = 0;
148 |     
149 |     fullFrameBits = meanBits * cfg->mode_gr + Min(esv->ResvSize, esv->ResvMax);
150 | 
151 |     if (fullFrameBits > maxmp3buf)
152 |         fullFrameBits = maxmp3buf;
153 | 
154 |     assert(0 == esv->ResvMax % 8);
155 |     assert(esv->ResvMax >= 0);
156 | 
157 |     l3_side->resvDrain_pre = 0;
158 | 
159 |     if (gfc->pinfo != NULL) {
160 |         gfc->pinfo->mean_bits = meanBits / 2; /* expected bits per channel per granule [is this also right for mono/stereo, MPEG-1/2 ?] */
161 |         gfc->pinfo->resvsize = esv->ResvSize;
162 |     }
163 |     *mean_bits = meanBits;
164 |     return fullFrameBits;
165 | }
166 | 
167 | 
168 | /*
169 |   ResvMaxBits
170 |   returns targ_bits:  target number of bits to use for 1 granule
171 |          extra_bits:  amount extra available from reservoir
172 |   Mark Taylor 4/99
173 | */
174 | void
175 | ResvMaxBits(lame_internal_flags * gfc, int mean_bits, int *targ_bits, int *extra_bits, int cbr)
176 | {
177 |     SessionConfig_t const *const cfg = &gfc->cfg;
178 |     EncStateVar_t *const esv = &gfc->sv_enc;
179 |     int     add_bits, targBits, extraBits;
180 |     int     ResvSize = esv->ResvSize, ResvMax = esv->ResvMax;
181 | 
182 |     /* conpensate the saved bits used in the 1st granule */
183 |     if (cbr)
184 |         ResvSize += mean_bits;
185 | 
186 |     if (gfc->sv_qnt.substep_shaping & 1)
187 |         ResvMax *= 0.9;
188 | 
189 |     targBits = mean_bits;
190 | 
191 |     /* extra bits if the reservoir is almost full */
192 |     if (ResvSize * 10 > ResvMax * 9) {
193 |         add_bits = ResvSize - (ResvMax * 9) / 10;
194 |         targBits += add_bits;
195 |         gfc->sv_qnt.substep_shaping |= 0x80;
196 |     }
197 |     else {
198 |         add_bits = 0;
199 |         gfc->sv_qnt.substep_shaping &= 0x7f;
200 |         /* build up reservoir.  this builds the reservoir a little slower
201 |          * than FhG.  It could simple be mean_bits/15, but this was rigged
202 |          * to always produce 100 (the old value) at 128kbs */
203 |         /*    *targ_bits -= (int) (mean_bits/15.2); */
204 |         if (!cfg->disable_reservoir && !(gfc->sv_qnt.substep_shaping & 1))
205 |             targBits -= .1 * mean_bits;
206 |     }
207 | 
208 | 
209 |     /* amount from the reservoir we are allowed to use. ISO says 6/10 */
210 |     extraBits = (ResvSize < (esv->ResvMax * 6) / 10 ? ResvSize : (esv->ResvMax * 6) / 10);
211 |     extraBits -= add_bits;
212 | 
213 |     if (extraBits < 0)
214 |         extraBits = 0;
215 | 
216 |     *targ_bits = targBits;
217 |     *extra_bits = extraBits;
218 | }
219 | 
220 | /*
221 |   ResvAdjust:
222 |   Called after a granule's bit allocation. Readjusts the size of
223 |   the reservoir to reflect the granule's usage.
224 | */
225 | void
226 | ResvAdjust(lame_internal_flags * gfc, gr_info const *gi)
227 | {
228 |     gfc->sv_enc.ResvSize -= gi->part2_3_length + gi->part2_length;
229 | }
230 | 
231 | 
232 | /*
233 |   ResvFrameEnd:
234 |   Called after all granules in a frame have been allocated. Makes sure
235 |   that the reservoir size is within limits, possibly by adding stuffing
236 |   bits.
237 | */
238 | void
239 | ResvFrameEnd(lame_internal_flags * gfc, int mean_bits)
240 | {
241 |     SessionConfig_t const *const cfg = &gfc->cfg;
242 |     EncStateVar_t *const esv = &gfc->sv_enc;
243 |     III_side_info_t *const l3_side = &gfc->l3_side;
244 |     int     stuffingBits;
245 |     int     over_bits;
246 | 
247 |     esv->ResvSize += mean_bits * cfg->mode_gr;
248 |     stuffingBits = 0;
249 |     l3_side->resvDrain_post = 0;
250 |     l3_side->resvDrain_pre = 0;
251 | 
252 |     /* we must be byte aligned */
253 |     if ((over_bits = esv->ResvSize % 8) != 0)
254 |         stuffingBits += over_bits;
255 | 
256 | 
257 |     over_bits = (esv->ResvSize - stuffingBits) - esv->ResvMax;
258 |     if (over_bits > 0) {
259 |         assert(0 == over_bits % 8);
260 |         assert(over_bits >= 0);
261 |         stuffingBits += over_bits;
262 |     }
263 | 
264 | 
265 |     /* NOTE: enabling the NEW_DRAIN code fixes some problems with FhG decoder
266 |              shipped with MS Windows operating systems. Using this, it is even
267 |              possible to use Gabriel's lax buffer consideration again, which
268 |              assumes, any decoder should have a buffer large enough
269 |              for a 320 kbps frame at 32 kHz sample rate.
270 | 
271 |        old drain code:
272 |              lame -b320 BlackBird.wav ---> does not play with GraphEdit.exe using FhG decoder V1.5 Build 50
273 | 
274 |        new drain code:
275 |              lame -b320 BlackBird.wav ---> plays fine with GraphEdit.exe using FhG decoder V1.5 Build 50
276 | 
277 |              Robert Hegemann, 2010-02-13.
278 |      */
279 |     /* drain as many bits as possible into previous frame ancillary data
280 |      * In particular, in VBR mode ResvMax may have changed, and we have
281 |      * to make sure main_data_begin does not create a reservoir bigger
282 |      * than ResvMax  mt 4/00*/
283 |     {
284 |         int     mdb_bytes = Min(l3_side->main_data_begin * 8, stuffingBits) / 8;
285 |         l3_side->resvDrain_pre += 8 * mdb_bytes;
286 |         stuffingBits -= 8 * mdb_bytes;
287 |         esv->ResvSize -= 8 * mdb_bytes;
288 |         l3_side->main_data_begin -= mdb_bytes;
289 |     }
290 |     /* drain the rest into this frames ancillary data */
291 |     l3_side->resvDrain_post += stuffingBits;
292 |     esv->ResvSize -= stuffingBits;
293 | }
294 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/reservoir.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *	bit reservoir include file
 3 |  *
 4 |  *	Copyright (c) 1999 Mark Taylor
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_RESERVOIR_H
23 | #define LAME_RESERVOIR_H
24 | 
25 | int     ResvFrameBegin(lame_internal_flags * gfc, int *mean_bits);
26 | void    ResvMaxBits(lame_internal_flags * gfc, int mean_bits, int *targ_bits, int *max_bits,
27 |                     int cbr);
28 | void    ResvAdjust(lame_internal_flags * gfc, gr_info const *gi);
29 | void    ResvFrameEnd(lame_internal_flags * gfc, int mean_bits);
30 | 
31 | #endif /* LAME_RESERVOIR_H */
32 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/set_get.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * set_get.h -- Internal set/get definitions
 3 |  *
 4 |  * Copyright (C) 2003 Gabriel Bouvigne / Lame project
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the Free Software
18 |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 |  */
20 | 
21 | #ifndef __SET_GET_H__
22 | #define __SET_GET_H__
23 | 
24 | #include 
25 | 
26 | #if defined(__cplusplus)
27 | extern  "C" {
28 | #endif
29 | 
30 | /* select psychoacoustic model */
31 | 
32 | /* manage short blocks */
33 |     int CDECL lame_set_short_threshold(lame_global_flags *, float, float);
34 |     int CDECL lame_set_short_threshold_lrm(lame_global_flags *, float);
35 |     float CDECL lame_get_short_threshold_lrm(const lame_global_flags *);
36 |     int CDECL lame_set_short_threshold_s(lame_global_flags *, float);
37 |     float CDECL lame_get_short_threshold_s(const lame_global_flags *);
38 | 
39 | 
40 |     int CDECL lame_set_maskingadjust(lame_global_flags *, float);
41 |     float CDECL lame_get_maskingadjust(const lame_global_flags *);
42 | 
43 |     int CDECL lame_set_maskingadjust_short(lame_global_flags *, float);
44 |     float CDECL lame_get_maskingadjust_short(const lame_global_flags *);
45 | 
46 | /* select ATH formula 4 shape */
47 |     int CDECL lame_set_ATHcurve(lame_global_flags *, float);
48 |     float CDECL lame_get_ATHcurve(const lame_global_flags *);
49 | 
50 |     int CDECL lame_set_preset_notune(lame_global_flags *, int);
51 | 
52 | /* substep shaping method */
53 |     int CDECL lame_set_substep(lame_global_flags *, int);
54 |     int CDECL lame_get_substep(const lame_global_flags *);
55 | 
56 | /* scalefactors scale */
57 |     int CDECL lame_set_sfscale(lame_global_flags *, int);
58 |     int CDECL lame_get_sfscale(const lame_global_flags *);
59 | 
60 | /* subblock gain */
61 |     int CDECL lame_set_subblock_gain(lame_global_flags *, int);
62 |     int CDECL lame_get_subblock_gain(const lame_global_flags *);
63 | 
64 | 
65 | 
66 | /*presets*/
67 |     int     apply_preset(lame_global_flags *, int preset, int enforce);
68 | 
69 |     void CDECL lame_set_tune(lame_t, float); /* FOR INTERNAL USE ONLY */
70 |     void CDECL lame_set_msfix(lame_t gfp, double msfix);
71 | 
72 | 
73 | #if defined(__cplusplus)
74 | }
75 | #endif
76 | #endif
77 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/tables.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *	MPEG layer 3 tables include file
 3 |  *
 4 |  *	Copyright (c) 1999 Albert L Faber
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_TABLES_H
23 | #define LAME_TABLES_H
24 | 
25 | #if 0
26 | typedef struct {
27 |     unsigned char no;
28 |     unsigned char width;
29 |     unsigned char minval_2;
30 |     float   quiet_thr;
31 |     float   norm;
32 |     float   bark;
33 | } type1_t;
34 | 
35 | typedef struct {
36 |     unsigned char no;
37 |     unsigned char width;
38 |     float   quiet_thr;
39 |     float   norm;
40 |     float   SNR;
41 |     float   bark;
42 | } type2_t;
43 | 
44 | typedef struct {
45 |     unsigned int no:5;
46 |     unsigned int cbw:3;
47 |     unsigned int bu:6;
48 |     unsigned int bo:6;
49 |     unsigned int w1_576:10;
50 |     unsigned int w2_576:10;
51 | } type34_t;
52 | 
53 | typedef struct {
54 |     size_t  len1;
55 |     const type1_t *const tab1;
56 |     size_t  len2;
57 |     const type2_t *const tab2;
58 |     size_t  len3;
59 |     const type34_t *const tab3;
60 |     size_t  len4;
61 |     const type34_t *const tab4;
62 | } type5_t;
63 | 
64 | extern const type5_t table5[6];
65 | 
66 | #endif
67 | 
68 | #define HTN	34
69 | 
70 | struct huffcodetab {
71 |     const unsigned int xlen;          /* max. x-index+   */
72 |     const unsigned int linmax;        /* max number to be stored in linbits */
73 |     const uint16_t *table;      /* pointer to array[xlen][ylen]  */
74 |     const uint8_t *hlen;        /* pointer to array[xlen][ylen]  */
75 | };
76 | 
77 | extern const struct huffcodetab ht[HTN];
78 |     /* global memory block   */
79 |     /* array of all huffcodtable headers */
80 |     /* 0..31 Huffman code table 0..31  */
81 |     /* 32,33 count1-tables   */
82 | 
83 | extern const uint8_t t32l[];
84 | extern const uint8_t t33l[];
85 | 
86 | extern const uint32_t largetbl[16 * 16];
87 | extern const uint32_t table23[3 * 3];
88 | extern const uint32_t table56[4 * 4];
89 | 
90 | extern const int scfsi_band[5];
91 | 
92 | extern const int bitrate_table    [3][16];
93 | extern const int samplerate_table [3][ 4];
94 | 
95 | #endif /* LAME_TABLES_H */
96 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/vbrquantize.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * MP3 VBR quantization
 3 |  *
 4 |  * Copyright (c) 1999 Mark Taylor
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_VBRQUANTIZE_H
23 | #define LAME_VBRQUANTIZE_H
24 | 
25 | int     VBR_encode_frame(lame_internal_flags * gfc, const FLOAT xr34orig[2][2][576],
26 |                          const FLOAT l3_xmin[2][2][SFBMAX], const int maxbits[2][2]);
27 | 
28 | #endif /* LAME_VBRQUANTIZE_H */
29 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/vector/.deps/xmm_quantize_sub.Plo:
--------------------------------------------------------------------------------
1 | # dummy
2 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/vector/lame_intrin.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *      lame_intrin.h include file
 3 |  *
 4 |  *      Copyright (c) 2006 Gabriel Bouvigne
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | 
23 | #ifndef LAME_INTRIN_H
24 | #define LAME_INTRIN_H
25 | 
26 | #import "../l3side.h"
27 | 
28 | void
29 | init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum);
30 | 
31 | void
32 | fht_SSE2(FLOAT* , int);
33 | 
34 | #endif
35 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/vector/xmm_quantize_sub.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |  * MP3 quantization, intrinsics functions
  3 |  *
  4 |  *      Copyright (c) 2005-2006 Gabriel Bouvigne
  5 |  *
  6 |  * This library is free software; you can redistribute it and/or
  7 |  * modify it under the terms of the GNU Library General Public
  8 |  * License as published by the Free Software Foundation; either
  9 |  * version 2 of the License, or (at your option) any later version.
 10 |  *
 11 |  * This library is distributed in the hope that it will be useful,
 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
 14 |  * Library General Public License for more details.
 15 |  *
 16 |  * You should have received a copy of the GNU Library General Public
 17 |  * License along with this library; if not, write to the
 18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 19 |  * Boston, MA 02111-1307, USA.
 20 |  */
 21 | 
 22 | 
 23 | #ifdef HAVE_CONFIG_H
 24 | # include 
 25 | #endif
 26 | 
 27 | #include "lame.h"
 28 | #include "../machine.h"
 29 | #include "../encoder.h"
 30 | #include "util.h"
 31 | #include "lame_intrin.h"
 32 | 
 33 | 
 34 | 
 35 | #ifdef HAVE_XMMINTRIN_H
 36 | 
 37 | #include 
 38 | 
 39 | typedef union {
 40 |     int32_t _i_32[4]; /* unions are initialized by its first member */
 41 |     float   _float[4];
 42 |     __m128  _m128;
 43 | } vecfloat_union;
 44 | 
 45 | #define TRI_SIZE (5-1)  /* 1024 =  4**5 */
 46 | static const FLOAT costab[TRI_SIZE * 2] = {
 47 |     9.238795325112867e-01, 3.826834323650898e-01,
 48 |     9.951847266721969e-01, 9.801714032956060e-02,
 49 |     9.996988186962042e-01, 2.454122852291229e-02,
 50 |     9.999811752826011e-01, 6.135884649154475e-03
 51 | };
 52 | 
 53 | 
 54 | /* make sure functions with SSE instructions maintain their own properly aligned stack */
 55 | #if defined (__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)))
 56 | #define SSE_FUNCTION __attribute__((force_align_arg_pointer))
 57 | #else
 58 | #define SSE_FUNCTION
 59 | #endif
 60 | 
 61 | 
 62 | SSE_FUNCTION void
 63 | init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum)
 64 | {
 65 |     int     i;
 66 |     float   tmp_max = 0;
 67 |     float   tmp_sum = 0;
 68 |     int     upper4 = (upper / 4) * 4;
 69 |     int     rest = upper-upper4;
 70 | 
 71 |     const vecfloat_union fabs_mask = {{ 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF }};
 72 |     const __m128 vec_fabs_mask = _mm_loadu_ps(&fabs_mask._float[0]);
 73 |     vecfloat_union vec_xrpow_max;
 74 |     vecfloat_union vec_sum;
 75 |     vecfloat_union vec_tmp;
 76 | 
 77 |     _mm_prefetch((char *) cod_info->xr, _MM_HINT_T0);
 78 |     _mm_prefetch((char *) xrpow, _MM_HINT_T0);
 79 | 
 80 |     vec_xrpow_max._m128 = _mm_set_ps1(0);
 81 |     vec_sum._m128 = _mm_set_ps1(0);
 82 | 
 83 |     for (i = 0; i < upper4; i += 4) {
 84 |         vec_tmp._m128 = _mm_loadu_ps(&(cod_info->xr[i])); /* load */
 85 |         vec_tmp._m128 = _mm_and_ps(vec_tmp._m128, vec_fabs_mask); /* fabs */
 86 |         vec_sum._m128 = _mm_add_ps(vec_sum._m128, vec_tmp._m128);
 87 |         vec_tmp._m128 = _mm_sqrt_ps(_mm_mul_ps(vec_tmp._m128, _mm_sqrt_ps(vec_tmp._m128)));
 88 |         vec_xrpow_max._m128 = _mm_max_ps(vec_xrpow_max._m128, vec_tmp._m128); /* retrieve max */
 89 |         _mm_storeu_ps(&(xrpow[i]), vec_tmp._m128); /* store into xrpow[] */
 90 |     }
 91 |     vec_tmp._m128 = _mm_set_ps1(0);
 92 |     switch (rest) {
 93 |         case 3: vec_tmp._float[2] = cod_info->xr[upper4+2];
 94 |         case 2: vec_tmp._float[1] = cod_info->xr[upper4+1];
 95 |         case 1: vec_tmp._float[0] = cod_info->xr[upper4+0];
 96 |             vec_tmp._m128 = _mm_and_ps(vec_tmp._m128, vec_fabs_mask); /* fabs */
 97 |             vec_sum._m128 = _mm_add_ps(vec_sum._m128, vec_tmp._m128);
 98 |             vec_tmp._m128 = _mm_sqrt_ps(_mm_mul_ps(vec_tmp._m128, _mm_sqrt_ps(vec_tmp._m128)));
 99 |             vec_xrpow_max._m128 = _mm_max_ps(vec_xrpow_max._m128, vec_tmp._m128); /* retrieve max */
100 |             switch (rest) {
101 |                 case 3: xrpow[upper4+2] = vec_tmp._float[2];
102 |                 case 2: xrpow[upper4+1] = vec_tmp._float[1];
103 |                 case 1: xrpow[upper4+0] = vec_tmp._float[0];
104 |                 default:
105 |                     break;
106 |             }
107 |         default:
108 |             break;
109 |     }
110 |     tmp_sum = vec_sum._float[0] + vec_sum._float[1] + vec_sum._float[2] + vec_sum._float[3];
111 |     {
112 |         float ma = vec_xrpow_max._float[0] > vec_xrpow_max._float[1]
113 |                 ? vec_xrpow_max._float[0] : vec_xrpow_max._float[1];
114 |         float mb = vec_xrpow_max._float[2] > vec_xrpow_max._float[3]
115 |                 ? vec_xrpow_max._float[2] : vec_xrpow_max._float[3];
116 |         tmp_max = ma > mb ? ma : mb;
117 |     }
118 |     cod_info->xrpow_max = tmp_max;
119 |     *sum = tmp_sum;
120 | }
121 | 
122 | 
123 | SSE_FUNCTION static void
124 | store4(__m128 v, float* f0, float* f1, float* f2, float* f3)
125 | {
126 |     vecfloat_union r;
127 |     r._m128 = v;
128 |     *f0 = r._float[0];
129 |     *f1 = r._float[1];
130 |     *f2 = r._float[2];
131 |     *f3 = r._float[3];
132 | }
133 | 
134 | 
135 | SSE_FUNCTION void
136 | fht_SSE2(FLOAT * fz, int n)
137 | {
138 |     const FLOAT *tri = costab;
139 |     int     k4;
140 |     FLOAT  *fi, *gi;
141 |     FLOAT const *fn;
142 | 
143 |     n <<= 1;            /* to get BLKSIZE, because of 3DNow! ASM routine */
144 |     fn = fz + n;
145 |     k4 = 4;
146 |     do {
147 |         FLOAT   s1, c1;
148 |         int     i, k1, k2, k3, kx;
149 |         kx = k4 >> 1;
150 |         k1 = k4;
151 |         k2 = k4 << 1;
152 |         k3 = k2 + k1;
153 |         k4 = k2 << 1;
154 |         fi = fz;
155 |         gi = fi + kx;
156 |         do {
157 |             FLOAT   f0, f1, f2, f3;
158 |             f1 = fi[0] - fi[k1];
159 |             f0 = fi[0] + fi[k1];
160 |             f3 = fi[k2] - fi[k3];
161 |             f2 = fi[k2] + fi[k3];
162 |             fi[k2] = f0 - f2;
163 |             fi[0] = f0 + f2;
164 |             fi[k3] = f1 - f3;
165 |             fi[k1] = f1 + f3;
166 |             f1 = gi[0] - gi[k1];
167 |             f0 = gi[0] + gi[k1];
168 |             f3 = SQRT2 * gi[k3];
169 |             f2 = SQRT2 * gi[k2];
170 |             gi[k2] = f0 - f2;
171 |             gi[0] = f0 + f2;
172 |             gi[k3] = f1 - f3;
173 |             gi[k1] = f1 + f3;
174 |             gi += k4;
175 |             fi += k4;
176 |         } while (fi < fn);
177 |         c1 = tri[0];
178 |         s1 = tri[1];
179 |         for (i = 1; i < kx; i++) {
180 |             __m128 v_s2;
181 |             __m128 v_c2;
182 |             __m128 v_c1;
183 |             __m128 v_s1;
184 |             FLOAT   c2, s2, s1_2 = s1+s1;
185 |             c2 = 1 - s1_2 * s1;
186 |             s2 = s1_2 * c1;
187 |             fi = fz + i;
188 |             gi = fz + k1 - i;
189 |             v_c1 = _mm_set_ps1(c1);
190 |             v_s1 = _mm_set_ps1(s1);
191 |             v_c2 = _mm_set_ps1(c2);
192 |             v_s2 = _mm_set_ps1(s2);
193 |             {
194 |                 static const vecfloat_union sign_mask = {{0x80000000,0,0,0}};
195 |                 v_c1 = _mm_xor_ps(sign_mask._m128, v_c1); /* v_c1 := {-c1, +c1, +c1, +c1} */
196 |             }
197 |             {
198 |                 static const vecfloat_union sign_mask = {{0,0x80000000,0,0}};
199 |                 v_s1 = _mm_xor_ps(sign_mask._m128, v_s1); /* v_s1 := {+s1, -s1, +s1, +s1} */
200 |             }
201 |             {
202 |                 static const vecfloat_union sign_mask = {{0,0,0x80000000,0x80000000}};
203 |                 v_c2 = _mm_xor_ps(sign_mask._m128, v_c2); /* v_c2 := {+c2, +c2, -c2, -c2} */
204 |             }
205 |             do {
206 |                 __m128 p, q, r;
207 | 
208 |                 q = _mm_setr_ps(fi[k1], fi[k3], gi[k1], gi[k3]); /* Q := {fi_k1,fi_k3,gi_k1,gi_k3}*/
209 |                 p = _mm_mul_ps(_mm_set_ps1(s2), q);              /* P := s2 * Q */
210 |                 q = _mm_mul_ps(v_c2, q);                         /* Q := c2 * Q */
211 |                 q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(1,0,3,2));  /* Q := {-c2*gi_k1,-c2*gi_k3,c2*fi_k1,c2*fi_k3} */
212 |                 p = _mm_add_ps(p, q);
213 |                 
214 |                 r = _mm_setr_ps(gi[0], gi[k2], fi[0], fi[k2]);   /* R := {gi_0,gi_k2,fi_0,fi_k2} */
215 |                 q = _mm_sub_ps(r, p);                            /* Q := {gi_0-p0,gi_k2-p1,fi_0-p2,fi_k2-p3} */
216 |                 r = _mm_add_ps(r, p);                            /* R := {gi_0+p0,gi_k2+p1,fi_0+p2,fi_k2+p3} */
217 |                 p = _mm_shuffle_ps(q, r, _MM_SHUFFLE(2,0,2,0));  /* P := {q0,q2,r0,r2} */
218 |                 p = _mm_shuffle_ps(p, p, _MM_SHUFFLE(3,1,2,0));  /* P := {q0,r0,q2,r2} */
219 |                 q = _mm_shuffle_ps(q, r, _MM_SHUFFLE(3,1,3,1));  /* Q := {q1,q3,r1,r3} */
220 |                 r = _mm_mul_ps(v_c1, q);
221 |                 q = _mm_mul_ps(v_s1, q);
222 |                 q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(0,1,2,3));  /* Q := {q3,q2,q1,q0} */
223 |                 q = _mm_add_ps(q, r);
224 | 
225 |                 store4(_mm_sub_ps(p, q), &gi[k3], &gi[k2], &fi[k3], &fi[k2]);
226 |                 store4(_mm_add_ps(p, q), &gi[k1], &gi[ 0], &fi[k1], &fi[ 0]);
227 | 
228 |                 gi += k4;
229 |                 fi += k4;
230 |             } while (fi < fn);
231 |             c2 = c1;
232 |             c1 = c2 * tri[0] - s1 * tri[1];
233 |             s1 = c2 * tri[1] + s1 * tri[0];
234 |         }
235 |         tri += 2;
236 |     } while (k4 < n);
237 | }
238 | 
239 | #endif	/* HAVE_XMMINTRIN_H */
240 | 
241 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/version.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |  *      Version numbering for LAME.
  3 |  *
  4 |  *      Copyright (c) 1999 A.L. Faber
  5 |  *
  6 |  * This library is free software; you can redistribute it and/or
  7 |  * modify it under the terms of the GNU Library General Public
  8 |  * License as published by the Free Software Foundation; either
  9 |  * version 2 of the License, or (at your option) any later version.
 10 |  *
 11 |  * This library is distributed in the hope that it will be useful,
 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14 |  * Library General Public License for more details.
 15 |  *
 16 |  * You should have received a copy of the GNU Library General Public
 17 |  * License along with this library; if not, write to the
 18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 19 |  * Boston, MA 02111-1307, USA.
 20 |  */
 21 | 
 22 | /*!
 23 |   \file   version.c
 24 |   \brief  Version numbering for LAME.
 25 | 
 26 |   Contains functions which describe the version of LAME.
 27 | 
 28 |   \author A.L. Faber
 29 |   \version \$Id: version.c,v 1.34 2011/11/18 09:51:02 robert Exp $
 30 |   \ingroup libmp3lame
 31 | */
 32 | 
 33 | 
 34 | #ifdef HAVE_CONFIG_H
 35 | # include 
 36 | #endif
 37 | 
 38 | 
 39 | #include "lame.h"
 40 | #include "machine.h"
 41 | 
 42 | #include "version.h"    /* macros of version numbers */
 43 | 
 44 | 
 45 | 
 46 | 
 47 | 
 48 | /*! Get the LAME version string. */
 49 | /*!
 50 |   \param void
 51 |   \return a pointer to a string which describes the version of LAME.
 52 | */
 53 | const char *
 54 | get_lame_version(void)
 55 | {                       /* primary to write screen reports */
 56 |     /* Here we can also add informations about compile time configurations */
 57 | 
 58 | #if   LAME_ALPHA_VERSION
 59 |     static /*@observer@ */ const char *const str =
 60 |         STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " "
 61 |         "(alpha " STR(LAME_PATCH_VERSION) ", " __DATE__ " " __TIME__ ")";
 62 | #elif LAME_BETA_VERSION
 63 |     static /*@observer@ */ const char *const str =
 64 |         STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " "
 65 |         "(beta " STR(LAME_PATCH_VERSION) ", " __DATE__ ")";
 66 | #elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0)
 67 |     static /*@observer@ */ const char *const str =
 68 |         STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) "." STR(LAME_PATCH_VERSION);
 69 | #else
 70 |     static /*@observer@ */ const char *const str =
 71 |         STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION);
 72 | #endif
 73 | 
 74 |     return str;
 75 | }
 76 | 
 77 | 
 78 | /*! Get the short LAME version string. */
 79 | /*!
 80 |   It's mainly for inclusion into the MP3 stream.
 81 | 
 82 |   \param void   
 83 |   \return a pointer to the short version of the LAME version string.
 84 | */
 85 | const char *
 86 | get_lame_short_version(void)
 87 | {
 88 |     /* adding date and time to version string makes it harder for output
 89 |        validation */
 90 | 
 91 | #if   LAME_ALPHA_VERSION
 92 |     static /*@observer@ */ const char *const str =
 93 |         STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " (alpha " STR(LAME_PATCH_VERSION) ")";
 94 | #elif LAME_BETA_VERSION
 95 |     static /*@observer@ */ const char *const str =
 96 |         STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) " (beta " STR(LAME_PATCH_VERSION) ")";
 97 | #elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0)
 98 |     static /*@observer@ */ const char *const str =
 99 |         STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) "." STR(LAME_PATCH_VERSION);
100 | #else
101 |     static /*@observer@ */ const char *const str =
102 |         STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION);
103 | #endif
104 | 
105 |     return str;
106 | }
107 | 
108 | /*! Get the _very_ short LAME version string. */
109 | /*!
110 |   It's used in the LAME VBR tag only.
111 | 
112 |   \param void   
113 |   \return a pointer to the short version of the LAME version string.
114 | */
115 | const char *
116 | get_lame_very_short_version(void)
117 | {
118 |     /* adding date and time to version string makes it harder for output
119 |        validation */
120 | #if   LAME_ALPHA_VERSION
121 | #define P "a"
122 | #elif LAME_BETA_VERSION
123 | #define P "b"
124 | #elif LAME_RELEASE_VERSION && (LAME_PATCH_VERSION > 0)
125 | #define P "r"
126 | #else
127 | #define P " "
128 | #endif
129 |     static /*@observer@ */ const char *const str =
130 | #if (LAME_PATCH_VERSION > 0)
131 |       "LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P STR(LAME_PATCH_VERSION)
132 | #else
133 |       "LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P
134 | #endif
135 |       ;
136 |     return str;
137 | }
138 | 
139 | /*! Get the _very_ short LAME version string. */
140 | /*!
141 |   It's used in the LAME VBR tag only, limited to 9 characters max.
142 |   Due to some 3rd party HW/SW decoders, it has to start with LAME.
143 | 
144 |   \param void   
145 |   \return a pointer to the short version of the LAME version string.
146 |  */
147 | const char*
148 | get_lame_tag_encoder_short_version(void)
149 | {
150 |     static /*@observer@ */ const char *const str =
151 |             /* FIXME: new scheme / new version counting / drop versioning here ? */
152 |     "LAME" STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) P
153 |     ;
154 |     return str;
155 | }
156 | 
157 | /*! Get the version string for GPSYCHO. */
158 | /*!
159 |   \param void
160 |   \return a pointer to a string which describes the version of GPSYCHO.
161 | */
162 | const char *
163 | get_psy_version(void)
164 | {
165 | #if   PSY_ALPHA_VERSION > 0
166 |     static /*@observer@ */ const char *const str =
167 |         STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION)
168 |         " (alpha " STR(PSY_ALPHA_VERSION) ", " __DATE__ " " __TIME__ ")";
169 | #elif PSY_BETA_VERSION > 0
170 |     static /*@observer@ */ const char *const str =
171 |         STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION)
172 |         " (beta " STR(PSY_BETA_VERSION) ", " __DATE__ ")";
173 | #else
174 |     static /*@observer@ */ const char *const str =
175 |         STR(PSY_MAJOR_VERSION) "." STR(PSY_MINOR_VERSION);
176 | #endif
177 | 
178 |     return str;
179 | }
180 | 
181 | 
182 | /*! Get the URL for the LAME website. */
183 | /*!
184 |   \param void
185 |   \return a pointer to a string which is a URL for the LAME website.
186 | */
187 | const char *
188 | get_lame_url(void)
189 | {
190 |     static /*@observer@ */ const char *const str = LAME_URL;
191 | 
192 |     return str;
193 | }
194 | 
195 | 
196 | /*! Get the numerical representation of the version. */
197 | /*!
198 |   Writes the numerical representation of the version of LAME and
199 |   GPSYCHO into lvp.
200 | 
201 |   \param lvp    
202 | */
203 | void
204 | get_lame_version_numerical(lame_version_t * lvp)
205 | {
206 |     static /*@observer@ */ const char *const features = ""; /* obsolete */
207 | 
208 |     /* generic version */
209 |     lvp->major = LAME_MAJOR_VERSION;
210 |     lvp->minor = LAME_MINOR_VERSION;
211 | #if LAME_ALPHA_VERSION
212 |     lvp->alpha = LAME_PATCH_VERSION;
213 |     lvp->beta = 0;
214 | #elif LAME_BETA_VERSION
215 |     lvp->alpha = 0;
216 |     lvp->beta = LAME_PATCH_VERSION;
217 | #else
218 |     lvp->alpha = 0;
219 |     lvp->beta = 0;
220 | #endif
221 | 
222 |     /* psy version */
223 |     lvp->psy_major = PSY_MAJOR_VERSION;
224 |     lvp->psy_minor = PSY_MINOR_VERSION;
225 |     lvp->psy_alpha = PSY_ALPHA_VERSION;
226 |     lvp->psy_beta = PSY_BETA_VERSION;
227 | 
228 |     /* compile time features */
229 |     /*@-mustfree@ */
230 |     lvp->features = features;
231 |     /*@=mustfree@ */
232 | }
233 | 
234 | 
235 | const char *
236 | get_lame_os_bitness(void)
237 | {
238 |     static /*@observer@ */ const char *const strXX = "";
239 |     static /*@observer@ */ const char *const str32 = "32bits";
240 |     static /*@observer@ */ const char *const str64 = "64bits";
241 | 
242 |     switch (sizeof(void *)) {
243 |     case 4:
244 |         return str32;
245 | 
246 |     case 8:
247 |         return str64;
248 | 
249 |     default:
250 |         return strXX;
251 |     }
252 | }
253 | 
254 | /* end of version.c */
255 | 
--------------------------------------------------------------------------------
/Sources/LAME/libmp3lame/version.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *      Version numbering for LAME.
 3 |  *
 4 |  *      Copyright (c) 1999 A.L. Faber
 5 |  *
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAME_VERSION_H
23 | #define LAME_VERSION_H
24 | 
25 | 
26 | /*
27 |  * To make a string from a token, use the # operator:
28 |  */
29 | #ifndef STR
30 | # define __STR(x)  #x
31 | # define STR(x)    __STR(x)
32 | #endif
33 | 
34 | # define LAME_URL              "http://lame.sf.net"
35 | 
36 | 
37 | # define LAME_MAJOR_VERSION      3 /* Major version number */
38 | # define LAME_MINOR_VERSION    100 /* Minor version number */
39 | # define LAME_TYPE_VERSION       2 /* 0:alpha 1:beta 2:release */
40 | # define LAME_PATCH_VERSION      0 /* Patch level */
41 | # define LAME_ALPHA_VERSION     (LAME_TYPE_VERSION==0)
42 | # define LAME_BETA_VERSION      (LAME_TYPE_VERSION==1)
43 | # define LAME_RELEASE_VERSION   (LAME_TYPE_VERSION==2)
44 | 
45 | # define PSY_MAJOR_VERSION       1 /* Major version number */
46 | # define PSY_MINOR_VERSION       0 /* Minor version number */
47 | # define PSY_ALPHA_VERSION       0 /* Set number if this is an alpha version, otherwise zero */
48 | # define PSY_BETA_VERSION        0 /* Set number if this is a beta version, otherwise zero */
49 | 
50 | #if LAME_ALPHA_VERSION
51 | #define LAME_PATCH_LEVEL_STRING " alpha " STR(LAME_PATCH_VERSION)
52 | #endif
53 | #if LAME_BETA_VERSION
54 | #define LAME_PATCH_LEVEL_STRING " beta " STR(LAME_PATCH_VERSION)
55 | #endif
56 | #if LAME_RELEASE_VERSION
57 | #if LAME_PATCH_VERSION
58 | #define LAME_PATCH_LEVEL_STRING " release " STR(LAME_PATCH_VERSION)
59 | #else
60 | #define LAME_PATCH_LEVEL_STRING ""
61 | #endif
62 | #endif
63 | 
64 | # define LAME_VERSION_STRING STR(LAME_MAJOR_VERSION) "." STR(LAME_MINOR_VERSION) LAME_PATCH_LEVEL_STRING
65 | 
66 | #endif /* LAME_VERSION_H */
67 | 
68 | /* End of version.h */
69 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/common.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |  * common.c: some common bitstream operations
  3 |  *
  4 |  * Copyright (C) 1999-2010 The L.A.M.E. project
  5 |  *
  6 |  * Initially written by Michael Hipp, see also AUTHORS and README.
  7 |  *  
  8 |  * This library is free software; you can redistribute it and/or
  9 |  * modify it under the terms of the GNU Library General Public
 10 |  * License as published by the Free Software Foundation; either
 11 |  * version 2 of the License, or (at your option) any later version.
 12 |  *
 13 |  * This library is distributed in the hope that it will be useful,
 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 16 |  * Library General Public License for more details.
 17 |  *
 18 |  * You should have received a copy of the GNU Library General Public
 19 |  * License along with this library; if not, write to the
 20 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 21 |  * Boston, MA 02111-1307, USA.
 22 |  */
 23 | 
 24 | /* $Id: common.c,v 1.42 2017/08/19 14:20:27 robert Exp $ */
 25 | 
 26 | #ifdef HAVE_CONFIG_H
 27 | #include 
 28 | #endif
 29 | 
 30 | #include 
 31 | #include 
 32 | #include 
 33 | 
 34 | #ifdef HAVE_FCNTL_H
 35 | #include 
 36 | #endif
 37 | 
 38 | #ifdef macintosh
 39 | #include   
 40 | #include   
 41 | #else
 42 | #include  
 43 | #include  
 44 | #endif
 45 | 
 46 | #include 
 47 | 
 48 | #include "common.h"
 49 | 
 50 | #ifdef WITH_DMALLOC
 51 | #include 
 52 | #endif
 53 | 
 54 | /* In C++ the array first must be prototyped, why ? */
 55 | 
 56 | 
 57 |     /* *INDENT-OFF* */
 58 | const int tabsel_123 [2] [3] [16] = {
 59 |    { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
 60 |      {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
 61 |      {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} },
 62 | 
 63 |    { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
 64 |      {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
 65 |      {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} }
 66 | };
 67 | 
 68 | const long freqs[9] = { 44100, 48000, 32000,
 69 |                         22050, 24000, 16000,
 70 |                         11025, 12000,  8000 };
 71 | 
 72 |     /* *INDENT-ON* */
 73 | 
 74 | 
 75 | real    muls[27][64];
 76 | 
 77 | #if 0
 78 | static void
 79 | get_II_stuff(struct frame *fr)
 80 | {
 81 |     /* *INDENT-OFF* */
 82 |   static const int translate [3] [2] [16] =   /* char ? */
 83 |    { { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } ,
 84 |        { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } ,
 85 |      { { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } ,
 86 |        { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } ,
 87 |      { { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } ,
 88 |        { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } };
 89 |     /* *INDENT-ON* */
 90 | 
 91 |     int     table, sblim;
 92 |     static const struct al_table2 *tables[5] = { alloc_0, alloc_1, alloc_2, alloc_3, alloc_4 };
 93 |     static int sblims[5] = { 27, 30, 8, 12, 30 };
 94 | 
 95 |     if (fr->lsf)
 96 |         table = 4;
 97 |     else
 98 |         table = translate[fr->sampling_frequency][2 - fr->stereo][fr->bitrate_index];
 99 |     sblim = sblims[table];
100 | 
101 |     fr->alloc = tables[table];
102 |     fr->II_sblimit = sblim;
103 | }
104 | #endif
105 | 
106 | #define HDRCMPMASK 0xfffffd00
107 | 
108 | #define MAX_INPUT_FRAMESIZE 4096
109 | 
110 | int
111 | head_check(unsigned long head, int check_layer)
112 | {
113 |     /*
114 |        look for a valid header.  
115 |        if check_layer > 0, then require that
116 |        nLayer = check_layer.  
117 |      */
118 | 
119 |     /* bits 13-14 = layer 3 */
120 |     int     nLayer = 4 - ((head >> 17) & 3);
121 | 
122 |     if ((head & 0xffe00000) != 0xffe00000) {
123 |         /* syncword */
124 |         return FALSE;
125 |     }
126 | 
127 |     if (nLayer == 4)
128 |         return FALSE;
129 | 
130 |     if (check_layer > 0 && nLayer != check_layer)
131 |         return FALSE;
132 | 
133 |     if (((head >> 12) & 0xf) == 0xf) {
134 |         /* bits 16,17,18,19 = 1111  invalid bitrate */
135 |         return FALSE;
136 |     }
137 |     if (((head >> 10) & 0x3) == 0x3) {
138 |         /* bits 20,21 = 11  invalid sampling freq */
139 |         return FALSE;
140 |     }
141 |     if ((head & 0x3) == 0x2)
142 |         /* invalid emphasis */
143 |         return FALSE;
144 |     return TRUE;
145 | }
146 | 
147 | 
148 | #if 0
149 | static void
150 | print_header(PMPSTR mp, struct frame *fr)
151 | {
152 |     static const char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
153 |     static const char *layers[4] = { "Unknown", "I", "II", "III" };
154 | 
155 |     lame_report_fnc(mp->report_msg, "MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n",
156 |             fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
157 |             layers[fr->lay], freqs[fr->sampling_frequency],
158 |             modes[fr->mode], fr->mode_ext, fr->framesize + 4);
159 |     lame_report_fnc(mp->report_msg, "Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
160 |             fr->stereo, fr->copyright ? "Yes" : "No",
161 |             fr->original ? "Yes" : "No", fr->error_protection ? "Yes" : "No", fr->emphasis);
162 |     lame_report_fnc(mp->report_msg, "Bitrate: %d Kbits/s, Extension value: %d\n",
163 |             tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index], fr->extension);
164 | }
165 | 
166 | static void
167 | print_header_compact(PMPSTR mp, struct frame *fr)
168 | {
169 |     static const char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
170 |     static const char *layers[4] = { "Unknown", "I", "II", "III" };
171 | 
172 |     lame_report_fnc(mp->report_err, "MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
173 |             fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
174 |             layers[fr->lay],
175 |             tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index],
176 |             freqs[fr->sampling_frequency], modes[fr->mode]);
177 | }
178 | 
179 | #endif
180 | 
181 | /*
182 |  * decode a header and write the information
183 |  * into the frame structure
184 |  */
185 | int
186 | decode_header(PMPSTR mp, struct frame *fr, unsigned long newhead)
187 | {
188 | 
189 | 
190 |     if (newhead & (1 << 20)) {
191 |         fr->lsf = (newhead & (1 << 19)) ? 0x0 : 0x1;
192 |         fr->mpeg25 = 0;
193 |     }
194 |     else {
195 |         fr->lsf = 1;
196 |         fr->mpeg25 = 1;
197 |     }
198 | 
199 | 
200 |     fr->lay = 4 - ((newhead >> 17) & 3);
201 | 
202 |     if (fr->lay != 3 && fr->mpeg25) {
203 |         lame_report_fnc(mp->report_err, "MPEG-2.5 is supported by Layer3 only\n");
204 |         return 0;
205 |     }
206 |     if (((newhead >> 10) & 0x3) == 0x3) {
207 |         lame_report_fnc(mp->report_err, "Stream error\n");
208 |         return 0;
209 |     }
210 |     if (fr->mpeg25) {
211 |         fr->sampling_frequency = 6 + ((newhead >> 10) & 0x3);
212 |     }
213 |     else
214 |         fr->sampling_frequency = ((newhead >> 10) & 0x3) + (fr->lsf * 3);
215 | 
216 |     fr->error_protection = ((newhead >> 16) & 0x1) ^ 0x1;
217 | 
218 |     if (fr->mpeg25)     /* allow Bitrate change for 2.5 ... */
219 |         fr->bitrate_index = ((newhead >> 12) & 0xf);
220 | 
221 |     fr->bitrate_index = ((newhead >> 12) & 0xf);
222 |     fr->padding = ((newhead >> 9) & 0x1);
223 |     fr->extension = ((newhead >> 8) & 0x1);
224 |     fr->mode = ((newhead >> 6) & 0x3);
225 |     fr->mode_ext = ((newhead >> 4) & 0x3);
226 |     fr->copyright = ((newhead >> 3) & 0x1);
227 |     fr->original = ((newhead >> 2) & 0x1);
228 |     fr->emphasis = newhead & 0x3;
229 | 
230 |     fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
231 | 
232 |     switch (fr->lay) {
233 |     case 1:
234 |         fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
235 |         fr->framesize /= freqs[fr->sampling_frequency];
236 |         fr->framesize = ((fr->framesize + fr->padding) << 2) - 4;
237 |         fr->down_sample = 0;
238 |         fr->down_sample_sblimit = SBLIMIT >> (fr->down_sample);
239 |         break;
240 | 
241 |     case 2:
242 |         fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
243 |         fr->framesize /= freqs[fr->sampling_frequency];
244 |         fr->framesize += fr->padding - 4;
245 |         fr->down_sample = 0;
246 |         fr->down_sample_sblimit = SBLIMIT >> (fr->down_sample);
247 |         break;
248 | 
249 |     case 3:
250 | #if 0
251 |         fr->do_layer = do_layer3;
252 |         if (fr->lsf)
253 |             ssize = (fr->stereo == 1) ? 9 : 17;
254 |         else
255 |             ssize = (fr->stereo == 1) ? 17 : 32;
256 | #endif
257 | 
258 | #if 0
259 |         if (fr->error_protection)
260 |             ssize += 2;
261 | #endif
262 |         if (fr->framesize > MAX_INPUT_FRAMESIZE) {
263 |             lame_report_fnc(mp->report_err, "Frame size too big.\n");
264 |             fr->framesize = MAX_INPUT_FRAMESIZE;
265 |             return (0);
266 |         }
267 | 
268 | 
269 |         if (fr->bitrate_index == 0)
270 |             fr->framesize = 0;
271 |         else {
272 |             fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
273 |             fr->framesize /= freqs[fr->sampling_frequency] << (fr->lsf);
274 |             fr->framesize = fr->framesize + fr->padding - 4;
275 |         }
276 |         break;
277 |     default:
278 |         lame_report_fnc(mp->report_err, "Sorry, layer %d not supported\n", fr->lay);
279 |         return (0);
280 |     }
281 |     /*    print_header(mp, fr); */
282 | 
283 |     return 1;
284 | }
285 | 
286 | 
287 | unsigned int
288 | getbits(PMPSTR mp, int number_of_bits)
289 | {
290 |     unsigned long rval;
291 | 
292 |     if (number_of_bits <= 0 || !mp->wordpointer)
293 |         return 0;
294 | 
295 |     {
296 |         rval = mp->wordpointer[0];
297 |         rval <<= 8;
298 |         rval |= mp->wordpointer[1];
299 |         rval <<= 8;
300 |         rval |= mp->wordpointer[2];
301 |         rval <<= mp->bitindex;
302 |         rval &= 0xffffff;
303 | 
304 |         mp->bitindex += number_of_bits;
305 | 
306 |         rval >>= (24 - number_of_bits);
307 | 
308 |         mp->wordpointer += (mp->bitindex >> 3);
309 |         mp->bitindex &= 7;
310 |     }
311 |     return rval;
312 | }
313 | 
314 | unsigned int
315 | getbits_fast(PMPSTR mp, int number_of_bits)
316 | {
317 |     unsigned long rval;
318 | 
319 |     {
320 |         rval = mp->wordpointer[0];
321 |         rval <<= 8;
322 |         rval |= mp->wordpointer[1];
323 |         rval <<= mp->bitindex;
324 |         rval &= 0xffff;
325 |         mp->bitindex += number_of_bits;
326 | 
327 |         rval >>= (16 - number_of_bits);
328 | 
329 |         mp->wordpointer += (mp->bitindex >> 3);
330 |         mp->bitindex &= 7;
331 |     }
332 |     return rval;
333 | }
334 | 
335 | unsigned char
336 | get_leq_8_bits(PMPSTR mp, unsigned int number_of_bits)
337 | {
338 |     assert(number_of_bits <= 8);
339 |     return (unsigned char) getbits_fast(mp, number_of_bits);
340 | }
341 | 
342 | unsigned short
343 | get_leq_16_bits(PMPSTR mp, unsigned int number_of_bits)
344 | {
345 |     assert(number_of_bits <= 16);
346 |     return (unsigned short) getbits_fast(mp, number_of_bits);
347 | }
348 | 
349 | int
350 | set_pointer(PMPSTR mp, long backstep)
351 | {
352 |     unsigned char *bsbufold;
353 | 
354 |     if (mp->fsizeold < 0 && backstep > 0) {
355 |         lame_report_fnc(mp->report_err, "hip: Can't step back %ld bytes!\n", backstep);
356 |         return MP3_ERR;
357 |     }
358 |     bsbufold = mp->bsspace[1 - mp->bsnum] + 512;
359 |     mp->wordpointer -= backstep;
360 |     if (backstep)
361 |         memcpy(mp->wordpointer, bsbufold + mp->fsizeold - backstep, (size_t) backstep);
362 |     mp->bitindex = 0;
363 |     return MP3_OK;
364 | }
365 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/common.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | 
23 | #ifndef COMMON_H_INCLUDED
24 | #define COMMON_H_INCLUDED
25 | 
26 | #include "mpg123.h"
27 | #include "mpglib.h"
28 | 
29 | extern const int tabsel_123[2][3][16];
30 | extern const long freqs[9];
31 | 
32 | extern real muls[27][64];
33 | 
34 | 
35 | int     head_check(unsigned long head, int check_layer);
36 | int     decode_header(PMPSTR mp, struct frame *fr, unsigned long newhead);
37 | unsigned int getbits(PMPSTR mp, int number_of_bits);
38 | unsigned int getbits_fast(PMPSTR mp, int number_of_bits);
39 | unsigned char get_leq_8_bits(PMPSTR mp, unsigned int number_of_bits);
40 | unsigned short get_leq_16_bits(PMPSTR mp, unsigned int number_of_bits);
41 | int     set_pointer(PMPSTR mp, long backstep);
42 | 
43 | #endif
44 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/dct64_i386.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |  * dct64_i368.c
  3 |  *
  4 |  * Copyright (C) 1999-2010 The L.A.M.E. project
  5 |  *
  6 |  * Initially written by Michael Hipp, see also AUTHORS and README.
  7 |  *  
  8 |  * This library is free software; you can redistribute it and/or
  9 |  * modify it under the terms of the GNU Library General Public
 10 |  * License as published by the Free Software Foundation; either
 11 |  * version 2 of the License, or (at your option) any later version.
 12 |  *
 13 |  * This library is distributed in the hope that it will be useful,
 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 16 |  * Library General Public License for more details.
 17 |  *
 18 |  * You should have received a copy of the GNU Library General Public
 19 |  * License along with this library; if not, write to the
 20 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 21 |  * Boston, MA 02111-1307, USA.
 22 |  *
 23 |  *
 24 |  * Discrete Cosine Tansform (DCT) for subband synthesis
 25 |  * optimized for machines with no auto-increment. 
 26 |  * The performance is highly compiler dependend. Maybe
 27 |  * the dct64.c version for 'normal' processor may be faster
 28 |  * even for Intel processors.
 29 |  */
 30 | 
 31 | /* $Id: dct64_i386.c,v 1.14 2010/03/22 14:30:19 robert Exp $ */
 32 | 
 33 | #ifdef HAVE_CONFIG_H
 34 | #include 
 35 | #endif
 36 | 
 37 | #include "dct64_i386.h"
 38 | #include "tabinit.h"
 39 | 
 40 | #ifdef WITH_DMALLOC
 41 | #include 
 42 | #endif
 43 | 
 44 | static void
 45 | dct64_1(real * out0, real * out1, real * b1, real * b2, real * samples)
 46 | {
 47 | 
 48 |     {
 49 |         real   *costab = pnts[0];
 50 | 
 51 |         b1[0x00] = samples[0x00] + samples[0x1F];
 52 |         b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
 53 | 
 54 |         b1[0x01] = samples[0x01] + samples[0x1E];
 55 |         b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
 56 | 
 57 |         b1[0x02] = samples[0x02] + samples[0x1D];
 58 |         b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
 59 | 
 60 |         b1[0x03] = samples[0x03] + samples[0x1C];
 61 |         b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
 62 | 
 63 |         b1[0x04] = samples[0x04] + samples[0x1B];
 64 |         b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
 65 | 
 66 |         b1[0x05] = samples[0x05] + samples[0x1A];
 67 |         b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
 68 | 
 69 |         b1[0x06] = samples[0x06] + samples[0x19];
 70 |         b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
 71 | 
 72 |         b1[0x07] = samples[0x07] + samples[0x18];
 73 |         b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
 74 | 
 75 |         b1[0x08] = samples[0x08] + samples[0x17];
 76 |         b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
 77 | 
 78 |         b1[0x09] = samples[0x09] + samples[0x16];
 79 |         b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
 80 | 
 81 |         b1[0x0A] = samples[0x0A] + samples[0x15];
 82 |         b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
 83 | 
 84 |         b1[0x0B] = samples[0x0B] + samples[0x14];
 85 |         b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
 86 | 
 87 |         b1[0x0C] = samples[0x0C] + samples[0x13];
 88 |         b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
 89 | 
 90 |         b1[0x0D] = samples[0x0D] + samples[0x12];
 91 |         b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
 92 | 
 93 |         b1[0x0E] = samples[0x0E] + samples[0x11];
 94 |         b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
 95 | 
 96 |         b1[0x0F] = samples[0x0F] + samples[0x10];
 97 |         b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
 98 |     }
 99 | 
100 | 
101 |     {
102 |         real   *costab = pnts[1];
103 | 
104 |         b2[0x00] = b1[0x00] + b1[0x0F];
105 |         b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
106 |         b2[0x01] = b1[0x01] + b1[0x0E];
107 |         b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
108 |         b2[0x02] = b1[0x02] + b1[0x0D];
109 |         b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
110 |         b2[0x03] = b1[0x03] + b1[0x0C];
111 |         b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
112 |         b2[0x04] = b1[0x04] + b1[0x0B];
113 |         b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
114 |         b2[0x05] = b1[0x05] + b1[0x0A];
115 |         b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
116 |         b2[0x06] = b1[0x06] + b1[0x09];
117 |         b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
118 |         b2[0x07] = b1[0x07] + b1[0x08];
119 |         b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
120 | 
121 |         b2[0x10] = b1[0x10] + b1[0x1F];
122 |         b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
123 |         b2[0x11] = b1[0x11] + b1[0x1E];
124 |         b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
125 |         b2[0x12] = b1[0x12] + b1[0x1D];
126 |         b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
127 |         b2[0x13] = b1[0x13] + b1[0x1C];
128 |         b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
129 |         b2[0x14] = b1[0x14] + b1[0x1B];
130 |         b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
131 |         b2[0x15] = b1[0x15] + b1[0x1A];
132 |         b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
133 |         b2[0x16] = b1[0x16] + b1[0x19];
134 |         b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
135 |         b2[0x17] = b1[0x17] + b1[0x18];
136 |         b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
137 |     }
138 | 
139 |     {
140 |         real   *costab = pnts[2];
141 | 
142 |         b1[0x00] = b2[0x00] + b2[0x07];
143 |         b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
144 |         b1[0x01] = b2[0x01] + b2[0x06];
145 |         b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
146 |         b1[0x02] = b2[0x02] + b2[0x05];
147 |         b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
148 |         b1[0x03] = b2[0x03] + b2[0x04];
149 |         b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
150 | 
151 |         b1[0x08] = b2[0x08] + b2[0x0F];
152 |         b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
153 |         b1[0x09] = b2[0x09] + b2[0x0E];
154 |         b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
155 |         b1[0x0A] = b2[0x0A] + b2[0x0D];
156 |         b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
157 |         b1[0x0B] = b2[0x0B] + b2[0x0C];
158 |         b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
159 | 
160 |         b1[0x10] = b2[0x10] + b2[0x17];
161 |         b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
162 |         b1[0x11] = b2[0x11] + b2[0x16];
163 |         b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
164 |         b1[0x12] = b2[0x12] + b2[0x15];
165 |         b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
166 |         b1[0x13] = b2[0x13] + b2[0x14];
167 |         b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
168 | 
169 |         b1[0x18] = b2[0x18] + b2[0x1F];
170 |         b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
171 |         b1[0x19] = b2[0x19] + b2[0x1E];
172 |         b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
173 |         b1[0x1A] = b2[0x1A] + b2[0x1D];
174 |         b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
175 |         b1[0x1B] = b2[0x1B] + b2[0x1C];
176 |         b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
177 |     }
178 | 
179 |     {
180 |         real const cos0 = pnts[3][0];
181 |         real const cos1 = pnts[3][1];
182 | 
183 |         b2[0x00] = b1[0x00] + b1[0x03];
184 |         b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
185 |         b2[0x01] = b1[0x01] + b1[0x02];
186 |         b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
187 | 
188 |         b2[0x04] = b1[0x04] + b1[0x07];
189 |         b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
190 |         b2[0x05] = b1[0x05] + b1[0x06];
191 |         b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
192 | 
193 |         b2[0x08] = b1[0x08] + b1[0x0B];
194 |         b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
195 |         b2[0x09] = b1[0x09] + b1[0x0A];
196 |         b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
197 | 
198 |         b2[0x0C] = b1[0x0C] + b1[0x0F];
199 |         b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
200 |         b2[0x0D] = b1[0x0D] + b1[0x0E];
201 |         b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
202 | 
203 |         b2[0x10] = b1[0x10] + b1[0x13];
204 |         b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
205 |         b2[0x11] = b1[0x11] + b1[0x12];
206 |         b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
207 | 
208 |         b2[0x14] = b1[0x14] + b1[0x17];
209 |         b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
210 |         b2[0x15] = b1[0x15] + b1[0x16];
211 |         b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
212 | 
213 |         b2[0x18] = b1[0x18] + b1[0x1B];
214 |         b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
215 |         b2[0x19] = b1[0x19] + b1[0x1A];
216 |         b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
217 | 
218 |         b2[0x1C] = b1[0x1C] + b1[0x1F];
219 |         b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
220 |         b2[0x1D] = b1[0x1D] + b1[0x1E];
221 |         b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
222 |     }
223 | 
224 |     {
225 |         real const cos0 = pnts[4][0];
226 | 
227 |         b1[0x00] = b2[0x00] + b2[0x01];
228 |         b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
229 |         b1[0x02] = b2[0x02] + b2[0x03];
230 |         b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
231 |         b1[0x02] += b1[0x03];
232 | 
233 |         b1[0x04] = b2[0x04] + b2[0x05];
234 |         b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
235 |         b1[0x06] = b2[0x06] + b2[0x07];
236 |         b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
237 |         b1[0x06] += b1[0x07];
238 |         b1[0x04] += b1[0x06];
239 |         b1[0x06] += b1[0x05];
240 |         b1[0x05] += b1[0x07];
241 | 
242 |         b1[0x08] = b2[0x08] + b2[0x09];
243 |         b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
244 |         b1[0x0A] = b2[0x0A] + b2[0x0B];
245 |         b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
246 |         b1[0x0A] += b1[0x0B];
247 | 
248 |         b1[0x0C] = b2[0x0C] + b2[0x0D];
249 |         b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
250 |         b1[0x0E] = b2[0x0E] + b2[0x0F];
251 |         b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
252 |         b1[0x0E] += b1[0x0F];
253 |         b1[0x0C] += b1[0x0E];
254 |         b1[0x0E] += b1[0x0D];
255 |         b1[0x0D] += b1[0x0F];
256 | 
257 |         b1[0x10] = b2[0x10] + b2[0x11];
258 |         b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
259 |         b1[0x12] = b2[0x12] + b2[0x13];
260 |         b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
261 |         b1[0x12] += b1[0x13];
262 | 
263 |         b1[0x14] = b2[0x14] + b2[0x15];
264 |         b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
265 |         b1[0x16] = b2[0x16] + b2[0x17];
266 |         b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
267 |         b1[0x16] += b1[0x17];
268 |         b1[0x14] += b1[0x16];
269 |         b1[0x16] += b1[0x15];
270 |         b1[0x15] += b1[0x17];
271 | 
272 |         b1[0x18] = b2[0x18] + b2[0x19];
273 |         b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
274 |         b1[0x1A] = b2[0x1A] + b2[0x1B];
275 |         b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
276 |         b1[0x1A] += b1[0x1B];
277 | 
278 |         b1[0x1C] = b2[0x1C] + b2[0x1D];
279 |         b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
280 |         b1[0x1E] = b2[0x1E] + b2[0x1F];
281 |         b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
282 |         b1[0x1E] += b1[0x1F];
283 |         b1[0x1C] += b1[0x1E];
284 |         b1[0x1E] += b1[0x1D];
285 |         b1[0x1D] += b1[0x1F];
286 |     }
287 | 
288 |     out0[0x10 * 16] = b1[0x00];
289 |     out0[0x10 * 12] = b1[0x04];
290 |     out0[0x10 * 8] = b1[0x02];
291 |     out0[0x10 * 4] = b1[0x06];
292 |     out0[0x10 * 0] = b1[0x01];
293 |     out1[0x10 * 0] = b1[0x01];
294 |     out1[0x10 * 4] = b1[0x05];
295 |     out1[0x10 * 8] = b1[0x03];
296 |     out1[0x10 * 12] = b1[0x07];
297 | 
298 |     b1[0x08] += b1[0x0C];
299 |     out0[0x10 * 14] = b1[0x08];
300 |     b1[0x0C] += b1[0x0a];
301 |     out0[0x10 * 10] = b1[0x0C];
302 |     b1[0x0A] += b1[0x0E];
303 |     out0[0x10 * 6] = b1[0x0A];
304 |     b1[0x0E] += b1[0x09];
305 |     out0[0x10 * 2] = b1[0x0E];
306 |     b1[0x09] += b1[0x0D];
307 |     out1[0x10 * 2] = b1[0x09];
308 |     b1[0x0D] += b1[0x0B];
309 |     out1[0x10 * 6] = b1[0x0D];
310 |     b1[0x0B] += b1[0x0F];
311 |     out1[0x10 * 10] = b1[0x0B];
312 |     out1[0x10 * 14] = b1[0x0F];
313 | 
314 |     b1[0x18] += b1[0x1C];
315 |     out0[0x10 * 15] = b1[0x10] + b1[0x18];
316 |     out0[0x10 * 13] = b1[0x18] + b1[0x14];
317 |     b1[0x1C] += b1[0x1a];
318 |     out0[0x10 * 11] = b1[0x14] + b1[0x1C];
319 |     out0[0x10 * 9] = b1[0x1C] + b1[0x12];
320 |     b1[0x1A] += b1[0x1E];
321 |     out0[0x10 * 7] = b1[0x12] + b1[0x1A];
322 |     out0[0x10 * 5] = b1[0x1A] + b1[0x16];
323 |     b1[0x1E] += b1[0x19];
324 |     out0[0x10 * 3] = b1[0x16] + b1[0x1E];
325 |     out0[0x10 * 1] = b1[0x1E] + b1[0x11];
326 |     b1[0x19] += b1[0x1D];
327 |     out1[0x10 * 1] = b1[0x11] + b1[0x19];
328 |     out1[0x10 * 3] = b1[0x19] + b1[0x15];
329 |     b1[0x1D] += b1[0x1B];
330 |     out1[0x10 * 5] = b1[0x15] + b1[0x1D];
331 |     out1[0x10 * 7] = b1[0x1D] + b1[0x13];
332 |     b1[0x1B] += b1[0x1F];
333 |     out1[0x10 * 9] = b1[0x13] + b1[0x1B];
334 |     out1[0x10 * 11] = b1[0x1B] + b1[0x17];
335 |     out1[0x10 * 13] = b1[0x17] + b1[0x1F];
336 |     out1[0x10 * 15] = b1[0x1F];
337 | }
338 | 
339 | /*
340 |  * the call via dct64 is a trick to force GCC to use
341 |  * (new) registers for the b1,b2 pointer to the bufs[xx] field
342 |  */
343 | void
344 | dct64(real * a, real * b, real * c)
345 | {
346 |     real    bufs[0x40];
347 |     dct64_1(a, b, bufs, bufs + 0x20, c);
348 | }
349 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/dct64_i386.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef MPGLIB_DCT64_I386_H_INCLUDED
23 | #define MPGLIB_DCT64_I386_H_INCLUDED
24 | 
25 | #include "common.h"
26 | 
27 | void    dct64(real * a, real * b, real * c);
28 | 
29 | 
30 | #endif
31 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/decode_i386.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |  * decode_i396.c: Mpeg Layer-1,2,3 audio decoder
  3 |  *
  4 |  * Copyright (C) 1999-2010 The L.A.M.E. project
  5 |  *
  6 |  * Initially written by Michael Hipp, see also AUTHORS and README.
  7 |  *  
  8 |  * This library is free software; you can redistribute it and/or
  9 |  * modify it under the terms of the GNU Library General Public
 10 |  * License as published by the Free Software Foundation; either
 11 |  * version 2 of the License, or (at your option) any later version.
 12 |  *
 13 |  * This library is distributed in the hope that it will be useful,
 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 16 |  * Library General Public License for more details.
 17 |  *
 18 |  * You should have received a copy of the GNU Library General Public
 19 |  * License along with this library; if not, write to the
 20 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 21 |  * Boston, MA 02111-1307, USA.
 22 |  *
 23 |  *
 24 |  * Slighlty optimized for machines without autoincrement/decrement.
 25 |  * The performance is highly compiler dependend. Maybe
 26 |  * the decode.c version for 'normal' processor may be faster
 27 |  * even for Intel processors.
 28 |  */
 29 | 
 30 | /* $Id: decode_i386.c,v 1.22 2010/03/22 14:30:19 robert Exp $ */
 31 | 
 32 | #ifdef HAVE_CONFIG_H
 33 | #include 
 34 | #endif
 35 | 
 36 | #ifdef STDC_HEADERS
 37 | # include 
 38 | # include 
 39 | #else
 40 | # ifndef HAVE_STRCHR
 41 | #  define strchr index
 42 | #  define strrchr rindex
 43 | # endif
 44 | char   *strchr(), *strrchr();
 45 | # ifndef HAVE_MEMCPY
 46 | #  define memcpy(d, s, n) bcopy ((s), (d), (n))
 47 | #  define memmove(d, s, n) bcopy ((s), (d), (n))
 48 | # endif
 49 | #endif
 50 | 
 51 | #if defined(__riscos__) && defined(FPA10)
 52 | #include "ymath.h"
 53 | #else
 54 | #include 
 55 | #endif
 56 | 
 57 | #include "decode_i386.h"
 58 | #include "dct64_i386.h"
 59 | #include "tabinit.h"
 60 | 
 61 | #ifdef WITH_DMALLOC
 62 | #include 
 63 | #endif
 64 | 
 65 | 
 66 |  /* old WRITE_SAMPLE_CLIPPED */
 67 | #define WRITE_SAMPLE_CLIPPED(TYPE,samples,sum,clip) \
 68 |   if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
 69 |   else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
 70 |   else { *(samples) = (TYPE)((sum)>0 ? (sum)+0.5 : (sum)-0.5) ; }
 71 | 
 72 | #define WRITE_SAMPLE_UNCLIPPED(TYPE,samples,sum,clip) \
 73 |   *samples = (TYPE)sum;
 74 | 
 75 |   /* *INDENT-OFF* */
 76 | 
 77 |  /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1_mono* functions */
 78 | #define SYNTH_1TO1_MONO_CLIPCHOICE(TYPE,SYNTH_1TO1)                    \
 79 |   TYPE samples_tmp[64];                                                \
 80 |   TYPE *tmp1 = samples_tmp;                                            \
 81 |   int i,ret;                                                           \
 82 |   int pnt1 = 0;                                                        \
 83 |                                                                        \
 84 |   ret = SYNTH_1TO1 (mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1); \
 85 |   out += *pnt;                                                         \
 86 |                                                                        \
 87 |   for(i=0;i<32;i++) {                                                  \
 88 |     *( (TYPE *) out) = *tmp1;                                          \
 89 |     out += sizeof(TYPE);                                               \
 90 |     tmp1 += 2;                                                         \
 91 |   }                                                                    \
 92 |   *pnt += 32*sizeof(TYPE);                                             \
 93 |                                                                        \
 94 |   return ret; 
 95 | 
 96 |   /* *INDENT-ON* */
 97 | 
 98 | 
 99 | int
100 | synth_1to1_mono(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
101 | {
102 |     SYNTH_1TO1_MONO_CLIPCHOICE(short, synth_1to1)
103 | } int
104 | synth_1to1_mono_unclipped(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
105 | {
106 |     SYNTH_1TO1_MONO_CLIPCHOICE(real, synth_1to1_unclipped)
107 | }
108 | 
109 |     /* *INDENT-OFF* */
110 | /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1* functions */
111 | #define SYNTH_1TO1_CLIPCHOICE(TYPE,WRITE_SAMPLE)         \
112 |   static const int step = 2;                             \
113 |   int bo;                                                \
114 |   TYPE *samples = (TYPE *) (out + *pnt);                 \
115 |                                                          \
116 |   real *b0,(*buf)[0x110];                                \
117 |   int clip = 0;                                          \
118 |   int bo1;                                               \
119 |                                                          \
120 |   bo = mp->synth_bo;                                     \
121 |                                                          \
122 |   if(!channel) {                                         \
123 |     bo--;                                                \
124 |     bo &= 0xf;                                           \
125 |     buf = mp->synth_buffs[0];                            \
126 |   }                                                      \
127 |   else {                                                 \
128 |     samples++;                                           \
129 |     buf = mp->synth_buffs[1];                            \
130 |   }                                                      \
131 |                                                          \
132 |   if(bo & 0x1) {                                         \
133 |     b0 = buf[0];                                         \
134 |     bo1 = bo;                                            \
135 |     dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);        \
136 |   }                                                      \
137 |   else {                                                 \
138 |     b0 = buf[1];                                         \
139 |     bo1 = bo+1;                                          \
140 |     dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);                \
141 |   }                                                      \
142 |                                                          \
143 |   mp->synth_bo = bo;                                     \
144 |                                                          \
145 |   {                                                      \
146 |     int j;                                               \
147 |     real *window = decwin + 16 - bo1;                    \
148 |                                                          \
149 |     for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) \
150 |     {                                                    \
151 |       real sum;                                          \
152 |       sum  = window[0x0] * b0[0x0];                      \
153 |       sum -= window[0x1] * b0[0x1];                      \
154 |       sum += window[0x2] * b0[0x2];                      \
155 |       sum -= window[0x3] * b0[0x3];                      \
156 |       sum += window[0x4] * b0[0x4];                      \
157 |       sum -= window[0x5] * b0[0x5];                      \
158 |       sum += window[0x6] * b0[0x6];                      \
159 |       sum -= window[0x7] * b0[0x7];                      \
160 |       sum += window[0x8] * b0[0x8];                      \
161 |       sum -= window[0x9] * b0[0x9];                      \
162 |       sum += window[0xA] * b0[0xA];                      \
163 |       sum -= window[0xB] * b0[0xB];                      \
164 |       sum += window[0xC] * b0[0xC];                      \
165 |       sum -= window[0xD] * b0[0xD];                      \
166 |       sum += window[0xE] * b0[0xE];                      \
167 |       sum -= window[0xF] * b0[0xF];                      \
168 |                                                          \
169 |       WRITE_SAMPLE (TYPE,samples,sum,clip);              \
170 |     }                                                    \
171 |                                                          \
172 |     {                                                    \
173 |       real sum;                                          \
174 |       sum  = window[0x0] * b0[0x0];                      \
175 |       sum += window[0x2] * b0[0x2];                      \
176 |       sum += window[0x4] * b0[0x4];                      \
177 |       sum += window[0x6] * b0[0x6];                      \
178 |       sum += window[0x8] * b0[0x8];                      \
179 |       sum += window[0xA] * b0[0xA];                      \
180 |       sum += window[0xC] * b0[0xC];                      \
181 |       sum += window[0xE] * b0[0xE];                      \
182 |       WRITE_SAMPLE (TYPE,samples,sum,clip);              \
183 |       b0-=0x10,window-=0x20,samples+=step;               \
184 |     }                                                    \
185 |     window += bo1<<1;                                    \
186 |                                                          \
187 |     for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) \
188 |     {                                                    \
189 |       real sum;                                          \
190 |       sum = -window[-0x1] * b0[0x0];                     \
191 |       sum -= window[-0x2] * b0[0x1];                     \
192 |       sum -= window[-0x3] * b0[0x2];                     \
193 |       sum -= window[-0x4] * b0[0x3];                     \
194 |       sum -= window[-0x5] * b0[0x4];                     \
195 |       sum -= window[-0x6] * b0[0x5];                     \
196 |       sum -= window[-0x7] * b0[0x6];                     \
197 |       sum -= window[-0x8] * b0[0x7];                     \
198 |       sum -= window[-0x9] * b0[0x8];                     \
199 |       sum -= window[-0xA] * b0[0x9];                     \
200 |       sum -= window[-0xB] * b0[0xA];                     \
201 |       sum -= window[-0xC] * b0[0xB];                     \
202 |       sum -= window[-0xD] * b0[0xC];                     \
203 |       sum -= window[-0xE] * b0[0xD];                     \
204 |       sum -= window[-0xF] * b0[0xE];                     \
205 |       sum -= window[-0x0] * b0[0xF];                     \
206 |                                                          \
207 |       WRITE_SAMPLE (TYPE,samples,sum,clip);              \
208 |     }                                                    \
209 |   }                                                      \
210 |   *pnt += 64*sizeof(TYPE);                               \
211 |                                                          \
212 |   return clip;                                           
213 |     /* *INDENT-ON* */
214 | 
215 | 
216 | int
217 | synth_1to1(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
218 | {
219 |     SYNTH_1TO1_CLIPCHOICE(short, WRITE_SAMPLE_CLIPPED)
220 | } int
221 | synth_1to1_unclipped(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
222 | {
223 |     SYNTH_1TO1_CLIPCHOICE(real, WRITE_SAMPLE_UNCLIPPED)
224 | }
225 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/decode_i386.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef DECODE_I386_H_INCLUDED
23 | #define DECODE_I386_H_INCLUDED
24 | 
25 | #include "common.h"
26 | 
27 | int     synth_1to1_mono(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt);
28 | int     synth_1to1(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt);
29 | 
30 | int     synth_1to1_mono_unclipped(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt);
31 | int     synth_1to1_unclipped(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt);
32 | 
33 | #endif
34 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/interface.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef INTERFACE_H_INCLUDED
23 | #define INTERFACE_H_INCLUDED
24 | 
25 | #ifdef __cplusplus
26 | extern  "C" {
27 | #endif
28 | 
29 | #include "common.h"
30 | 
31 |     int     InitMP3(PMPSTR mp);
32 |     int     decodeMP3(PMPSTR mp, unsigned char *inmemory, int inmemsize, char *outmemory,
33 |                       int outmemsize, int *done);
34 |     void    ExitMP3(PMPSTR mp);
35 | 
36 | /* added decodeMP3_unclipped to support returning raw floating-point values of samples. The representation
37 |    of the floating-point numbers is defined in mpg123.h as #define real. It is 64-bit double by default. 
38 |    No more than 1152 samples per channel are allowed. */
39 |     int     decodeMP3_unclipped(PMPSTR mp, unsigned char *inmemory, int inmemsize, char *outmemory,
40 |                                 int outmemsize, int *done);
41 | 
42 | /* added remove_buf to support mpglib seeking */
43 |     void    remove_buf(PMPSTR mp);
44 | 
45 | /* added audiodata_precedesframes to return the number of bitstream frames the audio data will precede the 
46 |    current frame by for Layer 3 data. Aids seeking.
47 |  */
48 |     int     audiodata_precedesframes(PMPSTR mp);
49 | 
50 | /* Resets decoding. Aids seeking. */
51 |     void    decode_reset(PMPSTR mp);
52 | 
53 | #ifdef __cplusplus
54 | }
55 | #endif
56 | #endif
57 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/l2tables.h:
--------------------------------------------------------------------------------
  1 | /*
  2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
  3 |  *
  4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
  5 |  *  
  6 |  * This library is free software; you can redistribute it and/or
  7 |  * modify it under the terms of the GNU Library General Public
  8 |  * License as published by the Free Software Foundation; either
  9 |  * version 2 of the License, or (at your option) any later version.
 10 |  *
 11 |  * This library is distributed in the hope that it will be useful,
 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 14 |  * Library General Public License for more details.
 15 |  *
 16 |  * You should have received a copy of the GNU Library General Public
 17 |  * License along with this library; if not, write to the
 18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 19 |  * Boston, MA 02111-1307, USA.
 20 |  *
 21 |  * Layer 2 Alloc tables .. 
 22 |  * most other tables are calculated on program start (which is (of course)
 23 |  * not ISO-conform) .. 
 24 |  * Layer-3 huffman table is in huffman.h
 25 |  */
 26 | 
 27 | const struct al_table2 alloc_0[] = {
 28 |     {4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
 29 |                                                                                            -511},
 30 |     {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
 31 |     {4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
 32 |                                                                                            -511},
 33 |     {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
 34 |     {4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
 35 |                                                                                            -511},
 36 |     {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
 37 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 38 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 39 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 40 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 41 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 42 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 43 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 44 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 45 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 46 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 47 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 48 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 49 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 50 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 51 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 52 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 53 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 54 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 55 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 56 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 57 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 58 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 59 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 60 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 61 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 62 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 63 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 64 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 65 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
 66 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
 67 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
 68 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767}
 69 | };
 70 | 
 71 | const struct al_table2 alloc_1[] = {
 72 |     {4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
 73 |                                                                                            -511},
 74 |     {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
 75 |     {4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
 76 |                                                                                            -511},
 77 |     {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
 78 |     {4, 0}, {5, 3}, {3, -3}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255}, {10,
 79 |                                                                                            -511},
 80 |     {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383}, {16, -32767},
 81 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 82 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 83 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 84 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 85 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 86 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 87 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 88 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 89 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 90 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 91 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 92 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 93 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 94 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 95 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
 96 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {16, -32767},
 97 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 98 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
 99 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
100 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
101 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
102 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
103 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
104 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
105 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
106 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
107 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
108 |     {3, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {16, -32767},
109 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
110 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
111 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
112 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
113 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
114 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767},
115 |     {2, 0}, {5, 3}, {7, 5}, {16, -32767}
116 | };
117 | 
118 | const struct al_table2 alloc_2[] = {
119 |     {4, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255},
120 |     {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383},
121 |     {4, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255},
122 |     {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383},
123 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
124 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
125 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
126 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
127 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
128 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}
129 | };
130 | 
131 | const struct al_table2 alloc_3[] = {
132 |     {4, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255},
133 |     {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383},
134 |     {4, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127}, {9, -255},
135 |     {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191}, {15, -16383},
136 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
137 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
138 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
139 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
140 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
141 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
142 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
143 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
144 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
145 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}
146 | };
147 | 
148 | const struct al_table2 alloc_4[] = {
149 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
150 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191},
151 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
152 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191},
153 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
154 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191},
155 |     {4, 0}, {5, 3}, {7, 5}, {3, -3}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63}, {8, -127},
156 |     {9, -255}, {10, -511}, {11, -1023}, {12, -2047}, {13, -4095}, {14, -8191},
157 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
158 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
159 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
160 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
161 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
162 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
163 |     {3, 0}, {5, 3}, {7, 5}, {10, 9}, {4, -7}, {5, -15}, {6, -31}, {7, -63},
164 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
165 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
166 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
167 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
168 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
169 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
170 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
171 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
172 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
173 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
174 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
175 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
176 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
177 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
178 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
179 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
180 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
181 |     {2, 0}, {5, 3}, {7, 5}, {10, 9},
182 |     {2, 0}, {5, 3}, {7, 5}, {10, 9}
183 | };
184 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/layer1.c:
--------------------------------------------------------------------------------
  1 | /* 
  2 |  * layer1.c: Mpeg Layer-1 audio decoder 
  3 |  *
  4 |  * Copyright (C) 1999-2010 The L.A.M.E. project
  5 |  *
  6 |  * Initially written by Michael Hipp, see also AUTHORS and README.
  7 |  *  
  8 |  * This library is free software; you can redistribute it and/or
  9 |  * modify it under the terms of the GNU Library General Public
 10 |  * License as published by the Free Software Foundation; either
 11 |  * version 2 of the License, or (at your option) any later version.
 12 |  *
 13 |  * This library is distributed in the hope that it will be useful,
 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 16 |  * Library General Public License for more details.
 17 |  *
 18 |  * You should have received a copy of the GNU Library General Public
 19 |  * License along with this library; if not, write to the
 20 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 21 |  * Boston, MA 02111-1307, USA.
 22 |  */
 23 | 
 24 | /* $Id: layer1.c,v 1.31 2017/08/23 13:22:23 robert Exp $ */
 25 | 
 26 | #ifdef HAVE_CONFIG_H
 27 | # include 
 28 | #endif
 29 | 
 30 | #include 
 31 | #include "common.h"
 32 | #include "decode_i386.h"
 33 | 
 34 | #ifdef WITH_DMALLOC
 35 | #include 
 36 | #endif
 37 | 
 38 | #include "layer1.h"
 39 | 
 40 | static int gd_are_hip_tables_layer1_initialized = 0;
 41 | 
 42 | void
 43 | hip_init_tables_layer1(void)
 44 | {
 45 |     if (gd_are_hip_tables_layer1_initialized) {
 46 |         return;
 47 |     }
 48 |     gd_are_hip_tables_layer1_initialized = 1;
 49 | }
 50 | 
 51 | typedef struct sideinfo_layer_I_struct
 52 | {
 53 |     unsigned char allocation[SBLIMIT][2]; 
 54 |     unsigned char scalefactor[SBLIMIT][2];
 55 | } sideinfo_layer_I;
 56 | 
 57 | static int
 58 | I_step_one(PMPSTR mp, sideinfo_layer_I* si)
 59 | {
 60 |     struct frame *fr = &(mp->fr);
 61 |     int     jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : 32;
 62 |     int     i;
 63 |     int     illegal_value_detected = 0;
 64 |     unsigned char const ba15 = 15; /* bit pattern not allowed, looks like sync(?) */
 65 |     memset(si, 0, sizeof(*si));
 66 |     assert(fr->stereo == 1 || fr->stereo == 2);
 67 | 
 68 |     if (fr->stereo == 2) {
 69 |         for (i = 0; i < jsbound; i++) {
 70 |             unsigned char b0 = get_leq_8_bits(mp, 4);       /* values 0-15 */
 71 |             unsigned char b1 = get_leq_8_bits(mp, 4);       /* values 0-15 */
 72 |             si->allocation[i][0] = b0;
 73 |             si->allocation[i][1] = b1;
 74 |             if (b0 == ba15 || b1 == ba15)
 75 |                 illegal_value_detected = 1;
 76 |         }
 77 |         for (i = jsbound; i < SBLIMIT; i++) {
 78 |             unsigned char b = get_leq_8_bits(mp, 4);        /* values 0-15 */
 79 |             si->allocation[i][0] = b;
 80 |             si->allocation[i][1] = b;
 81 |             if (b == ba15)
 82 |                 illegal_value_detected =  1;
 83 |         }
 84 |         for (i = 0; i < SBLIMIT; i++) {
 85 |             unsigned char n0 = si->allocation[i][0];
 86 |             unsigned char n1 = si->allocation[i][1];
 87 |             unsigned char b0 = n0 ? get_leq_8_bits(mp, 6) : 0;  /* values 0-63 */
 88 |             unsigned char b1 = n1 ? get_leq_8_bits(mp, 6) : 0;  /* values 0-63 */
 89 |             si->scalefactor[i][0] = b0;
 90 |             si->scalefactor[i][1] = b1;
 91 |         }
 92 |     }
 93 |     else {
 94 |         for (i = 0; i < SBLIMIT; i++) {
 95 |             unsigned char b0 =  get_leq_8_bits(mp, 4);          /* values 0-15 */
 96 |             si->allocation[i][0] = b0;
 97 |             if (b0 == ba15)
 98 |                 illegal_value_detected = 1;
 99 |         }
100 |         for (i = 0; i < SBLIMIT; i++) {
101 |             unsigned char n0 = si->allocation[i][0];
102 |             unsigned char b0 = n0 ? get_leq_8_bits(mp, 6) : 0;  /* values 0-63 */
103 |             si->scalefactor[i][0] = b0;
104 |         }
105 |     }
106 |     return illegal_value_detected;
107 | }
108 | 
109 | static void
110 | I_step_two(PMPSTR mp, sideinfo_layer_I *si, real fraction[2][SBLIMIT])
111 | {
112 |     double  r0, r1;
113 |     struct frame *fr = &(mp->fr);
114 |     int     ds_limit = fr->down_sample_sblimit;
115 |     int     i;
116 | 
117 |     assert(fr->stereo == 1 || fr->stereo == 2);
118 |     if (fr->stereo == 2) {
119 |         int     jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : 32;
120 |         for (i = 0; i < jsbound; i++) {
121 |             unsigned char i0 = si->scalefactor[i][0];
122 |             unsigned char i1 = si->scalefactor[i][1];
123 |             unsigned char n0 = si->allocation[i][0];
124 |             unsigned char n1 = si->allocation[i][1];
125 |             assert( i0 < 64 );
126 |             assert( i1 < 64 );
127 |             assert( n0 < 16 );
128 |             assert( n1 < 16 );
129 |             if (n0 > 0) {
130 |                 unsigned short v = get_leq_16_bits(mp, n0 + 1); /* 0-65535 */
131 |                 r0 = (((-1) << n0) + v + 1) * muls[n0 + 1][i0];
132 |             }
133 |             else {
134 |                 r0 = 0;
135 |             }
136 |             if (n1 > 0) {
137 |                 unsigned short v = get_leq_16_bits(mp, n1 + 1); /* 0-65535 */
138 |                 r1 = (((-1) << n1) + v + 1) * muls[n1 + 1][i1];
139 |             }
140 |             else {
141 |                 r1 = 0;
142 |             }
143 |             fraction[0][i] = (real)r0;
144 |             fraction[1][i] = (real)r1;
145 |         }
146 |         for (i = jsbound; i < SBLIMIT; i++) {
147 |             unsigned char i0 = si->scalefactor[i][0];
148 |             unsigned char i1 = si->scalefactor[i][1];
149 |             unsigned char n = si->allocation[i][0];
150 |             assert( i0 < 64 );
151 |             assert( i1 < 64 );
152 |             assert( n < 16 );
153 |             if (n > 0) {
154 |                 unsigned short v = get_leq_16_bits(mp, n + 1); /* 0-65535 */
155 |                 unsigned int w = (((-1) << n) + v + 1);
156 |                 r0 = w * muls[n + 1][i0];
157 |                 r1 = w * muls[n + 1][i1];
158 |             }
159 |             else {
160 |                 r0 = r1 = 0;
161 |             }
162 |             fraction[0][i] = (real)r0;
163 |             fraction[1][i] = (real)r1;
164 |         }
165 |         for (i = ds_limit; i < SBLIMIT; i++) {
166 |             fraction[0][i] = 0.0;
167 |             fraction[1][i] = 0.0;
168 |         }
169 |     }
170 |     else {
171 |         for (i = 0; i < SBLIMIT; i++) {
172 |             unsigned char n = si->allocation[i][0];
173 |             unsigned char j = si->scalefactor[i][0];
174 |             assert( j < 64 );
175 |             assert( n < 16 );
176 |             if (n > 0) {
177 |                 unsigned short v = get_leq_16_bits(mp, n + 1);
178 |                 r0 = (((-1) << n) + v + 1) * muls[n + 1][j];
179 |             }
180 |             else {
181 |                 r0 = 0;
182 |             }
183 |             fraction[0][i] = (real)r0;
184 |         }
185 |         for (i = ds_limit; i < SBLIMIT; i++) {
186 |             fraction[0][i] = 0.0;
187 |         }
188 |     }
189 | }
190 | 
191 | int
192 | decode_layer1_sideinfo(PMPSTR mp)
193 | {
194 |     (void) mp;
195 |     /* FIXME: extract side information and check values */
196 |     return 0;
197 | }
198 | 
199 | int
200 | decode_layer1_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point)
201 | {
202 |     real    fraction[2][SBLIMIT]; /* FIXME: change real -> double ? */
203 |     sideinfo_layer_I si;
204 |     struct frame *fr = &(mp->fr);
205 |     int     single = fr->single;
206 |     int     i, clip = 0;
207 | 
208 |     if (I_step_one(mp, &si)) {
209 |         lame_report_fnc(mp->report_err, "hip: Aborting layer 1 decode, illegal bit allocation value\n");
210 |         return -1;
211 |     }
212 |     if (fr->stereo == 1 || single == 3)
213 |         single = 0;
214 | 
215 |     if (single >= 0) {
216 |         /* decoding one of possibly two channels */
217 |         for (i = 0; i < SCALE_BLOCK; i++) {
218 |             I_step_two(mp, &si, fraction);
219 |             clip += synth_1to1_mono(mp, (real *) fraction[single], pcm_sample, pcm_point);
220 |         }
221 |     }
222 |     else {
223 |         for (i = 0; i < SCALE_BLOCK; i++) {
224 |             int     p1 = *pcm_point;
225 |             I_step_two(mp, &si, fraction);
226 |             clip += synth_1to1(mp, (real *) fraction[0], 0, pcm_sample, &p1);
227 |             clip += synth_1to1(mp, (real *) fraction[1], 1, pcm_sample, pcm_point);
228 |         }
229 |     }
230 | 
231 |     return clip;
232 | }
233 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/layer1.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAYER1_H_INCLUDED
23 | #define LAYER1_H_INCLUDED
24 | 
25 | void    hip_init_tables_layer1(void);
26 | int     decode_layer1_sideinfo(PMPSTR mp);
27 | int     decode_layer1_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point);
28 | 
29 | #endif
30 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/layer2.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | 
23 | #ifndef LAYER2_H_INCLUDED
24 | #define LAYER2_H_INCLUDED
25 | 
26 | 
27 | struct al_table2 {
28 |     short   bits;
29 |     short   d;
30 | };
31 | 
32 | 
33 | 
34 | void    hip_init_tables_layer2(void);
35 | int     decode_layer2_sideinfo(PMPSTR mp);
36 | int     decode_layer2_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point);
37 | 
38 | 
39 | #endif
40 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/layer3.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef LAYER3_H_INCLUDED
23 | #define LAYER3_H_INCLUDED
24 | 
25 | void    hip_init_tables_layer3(void);
26 | int     decode_layer3_sideinfo(PMPSTR mp);
27 | int     decode_layer3_frame(PMPSTR mp, unsigned char *pcm_sample, int *pcm_point,
28 |                   int (*synth_1to1_mono_ptr) (PMPSTR, real *, unsigned char *, int *),
29 |                   int (*synth_1to1_ptr) (PMPSTR, real *, int, unsigned char *, int *));
30 | int     layer3_audiodata_precedesframes(PMPSTR mp);
31 | 
32 | #endif
33 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/mpg123.h:
--------------------------------------------------------------------------------
  1 | /*
  2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
  3 |  *
  4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
  5 |  *  
  6 |  * This library is free software; you can redistribute it and/or
  7 |  * modify it under the terms of the GNU Library General Public
  8 |  * License as published by the Free Software Foundation; either
  9 |  * version 2 of the License, or (at your option) any later version.
 10 |  *
 11 |  * This library is distributed in the hope that it will be useful,
 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 14 |  * Library General Public License for more details.
 15 |  *
 16 |  * You should have received a copy of the GNU Library General Public
 17 |  * License along with this library; if not, write to the
 18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 19 |  * Boston, MA 02111-1307, USA.
 20 |  */
 21 | #ifndef MPG123_H_INCLUDED
 22 | #define MPG123_H_INCLUDED
 23 | 
 24 | #include        
 25 | 
 26 | #ifdef STDC_HEADERS
 27 | # include 
 28 | #else
 29 | # ifndef HAVE_STRCHR
 30 | #  define strchr index
 31 | #  define strrchr rindex
 32 | # endif
 33 | char   *strchr(), *strrchr();
 34 | # ifndef HAVE_MEMCPY
 35 | #  define memcpy(d, s, n) bcopy ((s), (d), (n))
 36 | #  define memmove(d, s, n) bcopy ((s), (d), (n))
 37 | # endif
 38 | #endif
 39 | 
 40 | #include        
 41 | 
 42 | 
 43 | #if defined(__riscos__) && defined(FPA10)
 44 | #include "ymath.h"
 45 | #else
 46 | #include 
 47 | #endif
 48 | 
 49 | #ifndef M_PI
 50 | #define M_PI       3.14159265358979323846
 51 | #endif
 52 | #ifndef M_SQRT2
 53 | #define M_SQRT2    1.41421356237309504880
 54 | #endif
 55 | 
 56 | #ifndef FALSE
 57 | #define         FALSE                   0
 58 | #endif
 59 | #ifndef TRUE
 60 | #define         TRUE                    1
 61 | #endif
 62 | 
 63 | #undef REAL_IS_FLOAT
 64 | #define REAL_IS_FLOAT
 65 | 
 66 | #ifdef REAL_IS_FLOAT
 67 | #  define real float
 68 | #elif defined(REAL_IS_LONG_DOUBLE)
 69 | #  define real long double
 70 | #else
 71 | #  define real double
 72 | #endif
 73 | 
 74 | #define         FALSE                   0
 75 | #define         TRUE                    1
 76 | 
 77 | #define         SBLIMIT                 32
 78 | #define         SSLIMIT                 18
 79 | 
 80 | #define         MPG_MD_STEREO           0
 81 | #define         MPG_MD_JOINT_STEREO     1
 82 | #define         MPG_MD_DUAL_CHANNEL     2
 83 | #define         MPG_MD_MONO             3
 84 | 
 85 | #define MAXFRAMESIZE 2880
 86 | 
 87 | /* AF: ADDED FOR LAYER1/LAYER2 */
 88 | #define         SCALE_BLOCK             12
 89 | 
 90 | 
 91 | /* Pre Shift fo 16 to 8 bit converter table */
 92 | #define AUSHIFT (3)
 93 | 
 94 | struct frame {
 95 |     int     stereo;
 96 |     int     single;          /* single channel (monophonic) */
 97 |     int     lsf;             /* 0 = MPEG-1, 1 = MPEG-2/2.5 */
 98 |     int     mpeg25;          /* 1 = MPEG-2.5, 0 = MPEG-1/2 */
 99 |     int     header_change;
100 |     int     lay;             /* Layer */
101 |     int     error_protection; /* 1 = CRC-16 code following header */
102 |     int     bitrate_index;
103 |     int     sampling_frequency; /* sample rate of decompressed audio in Hz */
104 |     int     padding;
105 |     int     extension;
106 |     int     mode;
107 |     int     mode_ext;
108 |     int     copyright;
109 |     int     original;
110 |     int     emphasis;
111 |     int     framesize;       /* computed framesize */
112 | 
113 |     /* AF: ADDED FOR LAYER1/LAYER2 */
114 |     int     II_sblimit;
115 |     struct al_table2 const *alloc;
116 |     int     down_sample_sblimit;
117 |     int     down_sample;
118 | 
119 | 
120 | };
121 | 
122 | struct gr_info_s {
123 |     int     scfsi;
124 |     unsigned part2_3_length;
125 |     unsigned big_values;
126 |     unsigned scalefac_compress;
127 |     unsigned block_type;
128 |     unsigned mixed_block_flag;
129 |     unsigned table_select[3];
130 |     unsigned subblock_gain[3];
131 |     unsigned maxband[3];
132 |     unsigned maxbandl;
133 |     unsigned maxb;
134 |     unsigned region1start;
135 |     unsigned region2start;
136 |     unsigned preflag;
137 |     unsigned scalefac_scale;
138 |     unsigned count1table_select;
139 |     real   *full_gain[3];
140 |     real   *pow2gain;
141 | };
142 | 
143 | struct III_sideinfo {
144 |     unsigned main_data_begin;
145 |     unsigned private_bits;
146 |     struct {
147 |         struct gr_info_s gr[2];
148 |     } ch[2];
149 | };
150 | 
151 | 
152 | #endif
153 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/mpglib.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | #ifndef _MPGLIB_H_
22 | #define _MPGLIB_H_
23 | 
24 | #include "lame.h"
25 | 
26 | #ifndef plotting_data_defined
27 | #define plotting_data_defined
28 | struct plotting_data;
29 | typedef struct plotting_data plotting_data;
30 | #endif
31 | 
32 | 
33 | extern void lame_report_fnc(lame_report_function f, const char *format, ...);
34 | 
35 | struct buf {
36 |     unsigned char *pnt;
37 |     long    size;
38 |     long    pos;
39 |     struct buf *next;
40 |     struct buf *prev;
41 | };
42 | 
43 | struct framebuf {
44 |     struct buf *buf;
45 |     long    pos;
46 |     struct frame *next;
47 |     struct frame *prev;
48 | };
49 | 
50 | typedef struct mpstr_tag {
51 |     struct buf *head, *tail; /* buffer linked list pointers, tail points to oldest buffer */
52 |     int     vbr_header;      /* 1 if valid Xing vbr header detected */
53 |     int     num_frames;      /* set if vbr header present */
54 |     int     enc_delay;       /* set if vbr header present */
55 |     int     enc_padding;     /* set if vbr header present */
56 |     /* header_parsed, side_parsed and data_parsed must be all set 1
57 |        before the full frame has been parsed */
58 |     int     header_parsed;   /* 1 = header of current frame has been parsed */
59 |     int     side_parsed;     /* 1 = header of sideinfo of current frame has been parsed */
60 |     int     data_parsed;
61 |     int     free_format;     /* 1 = free format frame */
62 |     int     old_free_format; /* 1 = last frame was free format */
63 |     int     bsize;
64 |     int     framesize;
65 |     int     ssize;           /* number of bytes used for side information, including 2 bytes for CRC-16 if present */
66 |     int     dsize;
67 |     int     fsizeold;        /* size of previous frame, -1 for first */
68 |     int     fsizeold_nopadding;
69 |     struct frame fr;         /* holds the parameters decoded from the header */
70 |     struct III_sideinfo sideinfo;
71 |     unsigned char bsspace[2][MAXFRAMESIZE + 1024]; /* bit stream space used ???? */ /* MAXFRAMESIZE */
72 |     real    hybrid_block[2][2][SBLIMIT * SSLIMIT];
73 |     int     hybrid_blc[2];
74 |     unsigned long header;
75 |     int     bsnum;
76 |     real    synth_buffs[2][2][0x110];
77 |     int     synth_bo;
78 |     int     sync_bitstream;  /* 1 = bitstream is yet to be synchronized */
79 | 
80 |     int     bitindex;
81 |     unsigned char *wordpointer;
82 |     plotting_data *pinfo;
83 | 
84 |     lame_report_function report_msg;
85 |     lame_report_function report_dbg;
86 |     lame_report_function report_err;
87 | } MPSTR, *PMPSTR;
88 | 
89 | 
90 | #define MP3_ERR -1
91 | #define MP3_OK  0
92 | #define MP3_NEED_MORE 1
93 | 
94 | 
95 | 
96 | #endif /* _MPGLIB_H_ */
97 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/tabinit.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |  * tabinit.c
  3 |  *
  4 |  * Copyright (C) 1999-2010 The L.A.M.E. project
  5 |  *
  6 |  * Initially written by Michael Hipp, see also AUTHORS and README.
  7 |  *  
  8 |  * This library is free software; you can redistribute it and/or
  9 |  * modify it under the terms of the GNU Library General Public
 10 |  * License as published by the Free Software Foundation; either
 11 |  * version 2 of the License, or (at your option) any later version.
 12 |  *
 13 |  * This library is distributed in the hope that it will be useful,
 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 16 |  * Library General Public License for more details.
 17 |  *
 18 |  * You should have received a copy of the GNU Library General Public
 19 |  * License along with this library; if not, write to the
 20 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 21 |  * Boston, MA 02111-1307, USA.
 22 |  */
 23 | /* $Id: tabinit.c,v 1.17 2017/09/06 15:07:30 robert Exp $ */
 24 | 
 25 | #ifdef HAVE_CONFIG_H
 26 | # include 
 27 | #endif
 28 | 
 29 | #include 
 30 | #include "tabinit.h"
 31 | #include "mpg123.h"
 32 | 
 33 | #ifdef WITH_DMALLOC
 34 | #include 
 35 | #endif
 36 | 
 37 | static int table_init_called = 0;
 38 | 
 39 | real    decwin[512 + 32];
 40 | static real cos64[16], cos32[8], cos16[4], cos8[2], cos4[1];
 41 | real   *pnts[] = { cos64, cos32, cos16, cos8, cos4 };
 42 | 
 43 | /* *INDENT-OFF* */
 44 | 
 45 | static const double dewin[512] = {
 46 |    0.000000000,-0.000015259,-0.000015259,-0.000015259,
 47 |   -0.000015259,-0.000015259,-0.000015259,-0.000030518,
 48 |   -0.000030518,-0.000030518,-0.000030518,-0.000045776,
 49 |   -0.000045776,-0.000061035,-0.000061035,-0.000076294,
 50 |   -0.000076294,-0.000091553,-0.000106812,-0.000106812,
 51 |   -0.000122070,-0.000137329,-0.000152588,-0.000167847,
 52 |   -0.000198364,-0.000213623,-0.000244141,-0.000259399,
 53 |   -0.000289917,-0.000320435,-0.000366211,-0.000396729,
 54 |   -0.000442505,-0.000473022,-0.000534058,-0.000579834,
 55 |   -0.000625610,-0.000686646,-0.000747681,-0.000808716,
 56 |   -0.000885010,-0.000961304,-0.001037598,-0.001113892,
 57 |   -0.001205444,-0.001296997,-0.001388550,-0.001480103,
 58 |   -0.001586914,-0.001693726,-0.001785278,-0.001907349,
 59 |   -0.002014160,-0.002120972,-0.002243042,-0.002349854,
 60 |   -0.002456665,-0.002578735,-0.002685547,-0.002792358,
 61 |   -0.002899170,-0.002990723,-0.003082275,-0.003173828,
 62 |   -0.003250122,-0.003326416,-0.003387451,-0.003433228,
 63 |   -0.003463745,-0.003479004,-0.003479004,-0.003463745,
 64 |   -0.003417969,-0.003372192,-0.003280640,-0.003173828,
 65 |   -0.003051758,-0.002883911,-0.002700806,-0.002487183,
 66 |   -0.002227783,-0.001937866,-0.001617432,-0.001266479,
 67 |   -0.000869751,-0.000442505, 0.000030518, 0.000549316,
 68 |    0.001098633, 0.001693726, 0.002334595, 0.003005981,
 69 |    0.003723145, 0.004486084, 0.005294800, 0.006118774,
 70 |    0.007003784, 0.007919312, 0.008865356, 0.009841919,
 71 |    0.010848999, 0.011886597, 0.012939453, 0.014022827,
 72 |    0.015121460, 0.016235352, 0.017349243, 0.018463135,
 73 |    0.019577026, 0.020690918, 0.021789551, 0.022857666,
 74 |    0.023910522, 0.024932861, 0.025909424, 0.026840210,
 75 |    0.027725220, 0.028533936, 0.029281616, 0.029937744,
 76 |    0.030532837, 0.031005859, 0.031387329, 0.031661987,
 77 |    0.031814575, 0.031845093, 0.031738281, 0.031478882,
 78 |    0.031082153, 0.030517578, 0.029785156, 0.028884888,
 79 |    0.027801514, 0.026535034, 0.025085449, 0.023422241,
 80 |    0.021575928, 0.019531250, 0.017257690, 0.014801025,
 81 |    0.012115479, 0.009231567, 0.006134033, 0.002822876,
 82 |   -0.000686646,-0.004394531,-0.008316040,-0.012420654,
 83 |   -0.016708374,-0.021179199,-0.025817871,-0.030609131,
 84 |   -0.035552979,-0.040634155,-0.045837402,-0.051132202,
 85 |   -0.056533813,-0.061996460,-0.067520142,-0.073059082,
 86 |   -0.078628540,-0.084182739,-0.089706421,-0.095169067,
 87 |   -0.100540161,-0.105819702,-0.110946655,-0.115921021,
 88 |   -0.120697021,-0.125259399,-0.129562378,-0.133590698,
 89 |   -0.137298584,-0.140670776,-0.143676758,-0.146255493,
 90 |   -0.148422241,-0.150115967,-0.151306152,-0.151962280,
 91 |   -0.152069092,-0.151596069,-0.150497437,-0.148773193,
 92 |   -0.146362305,-0.143264771,-0.139450073,-0.134887695,
 93 |   -0.129577637,-0.123474121,-0.116577148,-0.108856201,
 94 |   -0.100311279,-0.090927124,-0.080688477,-0.069595337,
 95 |   -0.057617187,-0.044784546,-0.031082153,-0.016510010,
 96 |   -0.001068115, 0.015228271, 0.032379150, 0.050354004,
 97 |    0.069168091, 0.088775635, 0.109161377, 0.130310059,
 98 |    0.152206421, 0.174789429, 0.198059082, 0.221984863,
 99 |    0.246505737, 0.271591187, 0.297210693, 0.323318481,
100 |    0.349868774, 0.376800537, 0.404083252, 0.431655884,
101 |    0.459472656, 0.487472534, 0.515609741, 0.543823242,
102 |    0.572036743, 0.600219727, 0.628295898, 0.656219482,
103 |    0.683914185, 0.711318970, 0.738372803, 0.765029907,
104 |    0.791213989, 0.816864014, 0.841949463, 0.866363525,
105 |    0.890090942, 0.913055420, 0.935195923, 0.956481934,
106 |    0.976852417, 0.996246338, 1.014617920, 1.031936646,
107 |    1.048156738, 1.063217163, 1.077117920, 1.089782715,
108 |    1.101211548, 1.111373901, 1.120223999, 1.127746582,
109 |    1.133926392, 1.138763428, 1.142211914, 1.144287109,
110 |    1.144989014
111 | };
112 | /* *INDENT-ON* */
113 | 
114 | void
115 | make_decode_tables(long scaleval)
116 | {
117 |     int     i, j, k, kr, divv;
118 |     real   *table, *costab;
119 | 
120 |     if (table_init_called)
121 |         return;
122 | 
123 |     table_init_called = 1;
124 | 
125 |     for (i = 0; i < 5; i++) {
126 |         kr = 0x10 >> i;
127 |         divv = 0x40 >> i;
128 |         costab = pnts[i];
129 |         for (k = 0; k < kr; k++)
130 |             costab[k] = (real) (1.0 / (2.0 * cos(M_PI * ((double) k * 2.0 + 1.0) / (double) divv)));
131 |     }
132 | 
133 |     table = decwin;
134 |     scaleval = -scaleval;
135 |     for (i = 0, j = 0; i < 256; i++, j++, table += 32) {
136 |         if (table < decwin + 512 + 16)
137 |             table[16] = table[0] = (real) (dewin[j] * scaleval);
138 |         if (i % 32 == 31)
139 |             table -= 1023;
140 |         if (i % 64 == 63)
141 |             scaleval = -scaleval;
142 |     }
143 | 
144 |     for ( /* i=256 */ ; i < 512; i++, j--, table += 32) {
145 |         if (table < decwin + 512 + 16)
146 |             table[16] = table[0] = (real) (dewin[j] * scaleval);
147 |         if (i % 32 == 31)
148 |             table -= 1023;
149 |         if (i % 64 == 63)
150 |             scaleval = -scaleval;
151 |     }
152 | }
153 | 
--------------------------------------------------------------------------------
/Sources/LAME/mpglib/tabinit.h:
--------------------------------------------------------------------------------
 1 | /*
 2 |  * Copyright (C) 1999-2010 The L.A.M.E. project
 3 |  *
 4 |  * Initially written by Michael Hipp, see also AUTHORS and README.
 5 |  *  
 6 |  * This library is free software; you can redistribute it and/or
 7 |  * modify it under the terms of the GNU Library General Public
 8 |  * License as published by the Free Software Foundation; either
 9 |  * version 2 of the License, or (at your option) any later version.
10 |  *
11 |  * This library is distributed in the hope that it will be useful,
12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 |  * Library General Public License for more details.
15 |  *
16 |  * You should have received a copy of the GNU Library General Public
17 |  * License along with this library; if not, write to the
18 |  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 |  * Boston, MA 02111-1307, USA.
20 |  */
21 | 
22 | #ifndef MPGLIB_TABINIT_H_INCLUDED
23 | #define MPGLIB_TABINIT_H_INCLUDED
24 | 
25 | #include "mpg123.h"
26 | 
27 | extern real decwin[512 + 32];
28 | extern real *pnts[5];
29 | 
30 | void    make_decode_tables(long scale);
31 | 
32 | #endif
33 | 
--------------------------------------------------------------------------------
/Sources/SwiftLAME/Models/AVAudioBufferData.swift:
--------------------------------------------------------------------------------
 1 | //
 2 | //  Copyright © 2023 Hidden Spectrum, LLC. All rights reserved.
 3 | //
 4 | 
 5 | import AVFAudio
 6 | 
 7 | 
 8 | enum AVAudioChannelData {
 9 |     case float(UnsafePointer>)
10 |     case int16(UnsafePointer>)
11 |     case int32(UnsafePointer>)
12 | }
13 | 
14 | 
15 | extension AVAudioPCMBuffer {
16 |     func getChannelData() throws -> AVAudioChannelData {
17 |         if let floatChannelData {
18 |             return .float(floatChannelData)
19 |         } else if let int16ChannelData {
20 |             return .int16(int16ChannelData)
21 |         } else if let int32ChannelData {
22 |             return .int32(int32ChannelData)
23 |         } else {
24 |             throw SwiftLameError.couldNotReadChannelDataFromPCMBuffer
25 |         }
26 |     }
27 | }
28 | 
--------------------------------------------------------------------------------
/Sources/SwiftLAME/Models/SwiftLameError.swift:
--------------------------------------------------------------------------------
 1 | //
 2 | //  Copyright © 2023 Hidden Spectrum, LLC. All rights reserved.
 3 | //
 4 | 
 5 | import Foundation
 6 | 
 7 | 
 8 | public enum SwiftLameError: Error {
 9 |     case couldNotCreateAudioPCMBuffer
10 |     case couldNotCreateOutputStreamTo(url: URL)
11 |     case couldNotGetRawOutputBufferPointerBaseAddress
12 |     case couldNotReadChannelDataFromPCMBuffer
13 | }
14 | 
--------------------------------------------------------------------------------
/Sources/SwiftLAME/SwiftLameEncoder.swift:
--------------------------------------------------------------------------------
  1 | 
  2 | import AVFAudio
  3 | import LAME
  4 | 
  5 | 
  6 | public struct SwiftLameEncoder {
  7 |     
  8 |     // MARK: Private
  9 |     
 10 |     private let configuration: LameConfiguration
 11 |     private let destinationUrl: URL
 12 |     private let frameCount: AVAudioFrameCount = 1024 * 8
 13 |     private let progress: Progress
 14 |     private let sourceAudioFile: AVAudioFile
 15 |     
 16 |     // MARK: Lifecycle
 17 |     
 18 |     public init(sourceUrl: URL, configuration: LameConfiguration, destinationUrl: URL, progress: Progress = Progress()) throws {
 19 |         self.configuration = configuration
 20 |         self.destinationUrl = destinationUrl
 21 |         self.progress = progress
 22 |         self.sourceAudioFile = try AVAudioFile(forReading: sourceUrl)
 23 |     }
 24 |     
 25 |     // MARK: Encoding
 26 |     
 27 |     public func encode(priority: TaskPriority = .medium) async throws {
 28 |         try await Task(priority: priority) {
 29 |             try _encode()
 30 |         }.value
 31 |     }
 32 |     
 33 |     private func _encode() throws {
 34 |         let audioFormat = sourceAudioFile.processingFormat
 35 |         
 36 |         guard let sourceAudioBuffer = AVAudioPCMBuffer(pcmFormat: audioFormat, frameCapacity: frameCount) else {
 37 |             throw SwiftLameError.couldNotCreateAudioPCMBuffer
 38 |         }
 39 |         guard let outputStream = OutputStream(url: destinationUrl, append: true) else {
 40 |             throw SwiftLameError.couldNotCreateOutputStreamTo(url: destinationUrl)
 41 |         }
 42 |         
 43 |         let lame = Lame(for: sourceAudioFile, configuration: configuration)
 44 |         let mBytesPerFrame = sourceAudioFile.processingFormat.streamDescription.pointee.mBytesPerFrame
 45 |         let bufferCapacity = Int(frameCount * mBytesPerFrame)
 46 |         var tmpEncodingBuffer = Data(count: bufferCapacity)
 47 |         
 48 |         progress.totalUnitCount = Int64(sourceAudioFile.length)
 49 |         
 50 |         outputStream.open()
 51 |         var position: AVAudioFramePosition = 0
 52 |         
 53 |         while position < sourceAudioFile.length {
 54 |             if progress.isCancelled {
 55 |                 break
 56 |             }
 57 |             
 58 |             try sourceAudioFile.read(into: sourceAudioBuffer)
 59 |             
 60 |             position += AVAudioFramePosition(sourceAudioBuffer.frameLength)
 61 |             let isLastFrame = position == sourceAudioFile.length
 62 |             
 63 |             try encodeFrame(with: lame, from: sourceAudioBuffer, to: outputStream, using: &tmpEncodingBuffer, isLastFrame: isLastFrame)
 64 |             
 65 |             progress.completedUnitCount = Int64(position)
 66 |         }
 67 |         
 68 |         outputStream.close()
 69 |         
 70 |         if progress.isCancelled {
 71 |             try? FileManager.default.removeItem(at: destinationUrl)
 72 |         }
 73 |     }
 74 |     
 75 |     private func encodeFrame(
 76 |         with lame: Lame,
 77 |         from sourceAudioBuffer: AVAudioPCMBuffer,
 78 |         to outputStream: OutputStream,
 79 |         using tmpEncodingBuffer: inout Data,
 80 |         isLastFrame: Bool
 81 |     ) throws {
 82 |         let sourceChannelData = try sourceAudioBuffer.getChannelData()
 83 |         let frameCount = sourceAudioBuffer.frameLength
 84 |         let bufferCapacity = tmpEncodingBuffer.count
 85 |         
 86 |         try tmpEncodingBuffer.withUnsafeMutableBytes { (bufferPointer: UnsafeMutableRawBufferPointer) in
 87 |             let memoryBoundBuffer = bufferPointer.bindMemory(to: UInt8.self)
 88 |             guard let bufferAddress = memoryBoundBuffer.baseAddress else {
 89 |                 throw SwiftLameError.couldNotGetRawOutputBufferPointerBaseAddress
 90 |             }
 91 |             
 92 |             let encodeLength = encodeChannelData(
 93 |                 sourceChannelData,
 94 |                 with: lame,
 95 |                 frameCount: frameCount,
 96 |                 usingBufferAt: bufferAddress,
 97 |                 capacity: bufferCapacity
 98 |             )
 99 |             
100 |             outputStream.write(bufferAddress, maxLength: encodeLength)
101 |             
102 |             if isLastFrame {
103 |                 let finalEncodeLength = lame.finalizeEncoding(
104 |                     usingBufferAt: bufferAddress,
105 |                     with: bufferCapacity
106 |                 )
107 |                 outputStream.write(bufferAddress, maxLength: finalEncodeLength)
108 |             }
109 |         }
110 |     }
111 |     
112 |     private func encodeChannelData(
113 |         _ channelData: AVAudioChannelData,
114 |         with lame: Lame,
115 |         frameCount: AVAudioFrameCount,
116 |         usingBufferAt bufferAddress: UnsafeMutablePointer,
117 |         capacity: Int
118 |     ) -> Int {
119 |         switch channelData {
120 |         case .float(let data):
121 |             return lame.encodeIEEEFloatData(data, frameCount: frameCount, fillingBufferAt: bufferAddress, with: capacity)
122 |         case .int16(let data):
123 |             return lame.encodeInt16Data(data, frameCount: frameCount, fillingBufferAt: bufferAddress, with: capacity)
124 |         case .int32(let data):
125 |             return lame.encodeInt32Data(data, frameCount: frameCount, fillingBufferAt: bufferAddress, with: capacity)
126 |         }
127 |     }
128 | }
129 | 
--------------------------------------------------------------------------------
/Sources/SwiftLAME/Wrappers/Lame.swift:
--------------------------------------------------------------------------------
  1 | //
  2 | //  Copyright © 2023 Hidden Spectrum, LLC. All rights reserved.
  3 | //
  4 | 
  5 | import AVFAudio
  6 | import LAME
  7 | 
  8 | 
  9 | final class Lame {
 10 |     
 11 |     // MARK: Internal
 12 |     
 13 |     let isInterleaved: Bool
 14 |     let sourceChannelCount: AVAudioChannelCount
 15 |     
 16 |     // MARK: Private
 17 |     
 18 |     private let lame: lame_t!
 19 |     
 20 |     // MARK: Lifecycle
 21 |     
 22 |     public init(for audioFile: AVAudioFile, configuration: LameConfiguration) {
 23 |         let channelCount = audioFile.processingFormat.channelCount
 24 |         self.sourceChannelCount = channelCount
 25 |         self.isInterleaved = audioFile.processingFormat.isInterleaved
 26 |         
 27 |         let lame = lame_init()
 28 |         lame_set_in_samplerate(lame, Int32(audioFile.processingFormat.sampleRate))
 29 |         lame_set_out_samplerate(lame, configuration.sampleRate.lameRepresentation)
 30 |         lame_set_quality(lame, configuration.quality.rawValue)
 31 |         lame_set_num_channels(lame, Int32(channelCount))
 32 |         configuration.bitrateMode.configure(on: lame)
 33 |         lame_init_params(lame)
 34 |         self.lame = lame
 35 |     }
 36 |     
 37 |     deinit {
 38 |         lame_close(lame)
 39 |     }
 40 |     
 41 |     // MARK: Encoding
 42 |     
 43 |     func encodeIEEEFloatData(
 44 |         _ data: UnsafePointer>,
 45 |         frameCount: AVAudioFrameCount,
 46 |         fillingBufferAt bufferAddress: UnsafeMutablePointer,
 47 |         with capacity: Int
 48 |     ) -> Int {
 49 |         return encodeData(
 50 |             data,
 51 |             frameCount: frameCount,
 52 |             fillingBufferAt: bufferAddress,
 53 |             with: capacity,
 54 |             interleavedEncoder: { (lame, pcm, nsamples, mp3buf, mp3buf_size) in
 55 |                 return lame_encode_buffer_interleaved_ieee_float(lame, pcm, nsamples, mp3buf, mp3buf_size)
 56 |             },
 57 |             nonInterleavedEncoder: lame_encode_buffer_ieee_float
 58 |         )
 59 |     }
 60 |     
 61 |     func encodeInt16Data(
 62 |         _ data: UnsafePointer>,
 63 |         frameCount: AVAudioFrameCount,
 64 |         fillingBufferAt bufferAddress: UnsafeMutablePointer,
 65 |         with capacity: Int
 66 |     ) -> Int {
 67 |         return encodeData(
 68 |             data,
 69 |             frameCount: frameCount,
 70 |             fillingBufferAt: bufferAddress,
 71 |             with: capacity,
 72 |             interleavedEncoder: lame_encode_buffer_interleaved,
 73 |             nonInterleavedEncoder: lame_encode_buffer
 74 |         )
 75 |     }
 76 |     
 77 |     func encodeInt32Data(
 78 |         _ data: UnsafePointer>,
 79 |         frameCount: AVAudioFrameCount,
 80 |         fillingBufferAt bufferAddress: UnsafeMutablePointer,
 81 |         with capacity: Int
 82 |     ) -> Int {
 83 |         return encodeData(
 84 |             data,
 85 |             frameCount: frameCount,
 86 |             fillingBufferAt: bufferAddress,
 87 |             with: capacity,
 88 |             interleavedEncoder: { (lame, pcm, nsamples, mp3buf, mp3buf_size) in
 89 |                 return lame_encode_buffer_interleaved_int(lame, pcm, nsamples, mp3buf, mp3buf_size)
 90 |             },
 91 |             nonInterleavedEncoder: lame_encode_buffer_int
 92 |         )
 93 |     }
 94 |     
 95 |     private func encodeData(
 96 |         _ data: UnsafePointer>,
 97 |         frameCount: AVAudioFrameCount,
 98 |         fillingBufferAt bufferAddress: UnsafeMutablePointer,
 99 |         with capacity: Int,
100 |         interleavedEncoder: (OpaquePointer?, UnsafeMutablePointer, Int32, UnsafeMutablePointer, Int32) -> Int32,
101 |         nonInterleavedEncoder: (OpaquePointer?, UnsafePointer?, UnsafePointer, Int32, UnsafeMutablePointer, Int32) -> Int32
102 |     ) -> Int {
103 |         var encodeLength: Int32
104 |         
105 |         if isInterleaved {
106 |             encodeLength = interleavedEncoder(
107 |                 lame,
108 |                 data.pointee,
109 |                 Int32(frameCount),
110 |                 bufferAddress,
111 |                 Int32(capacity)
112 |             )
113 |         } else {
114 |             let leftChannel = sourceChannelCount == 2 ? data[0] : data.pointee
115 |             let rightChannel = sourceChannelCount == 2 ? data[1] : data.pointee
116 |             encodeLength = nonInterleavedEncoder(
117 |                 lame,
118 |                 leftChannel,
119 |                 rightChannel,
120 |                 Int32(frameCount),
121 |                 bufferAddress,
122 |                 Int32(capacity)
123 |             )
124 |         }
125 |         
126 |         return Int(encodeLength)
127 |     }
128 |     
129 |     // MARK: Finalize
130 |     
131 |     func finalizeEncoding(usingBufferAt bufferAddress: UnsafeMutablePointer, with capacity: Int) -> Int {
132 |         let encodeLength = lame_encode_flush(
133 |             lame,
134 |             bufferAddress,
135 |             Int32(capacity)
136 |         )
137 |         return Int(encodeLength)
138 |     }
139 | }
140 | 
--------------------------------------------------------------------------------
/Sources/SwiftLAME/Wrappers/LameBitrateMode.swift:
--------------------------------------------------------------------------------
 1 | //
 2 | //  Copyright © 2023 Hidden Spectrum, LLC. All rights reserved.
 3 | //
 4 | 
 5 | import Foundation
 6 | import LAME
 7 | import os.log
 8 | 
 9 | 
10 | public enum LameBitrateMode {
11 |     case variable(LameVbrMode)
12 |     case constant(Int32)
13 |     
14 |     func configure(on lame: lame_t?) {
15 |         switch self {
16 |         case .constant(let bitrate):
17 |             lame_set_brate(lame, bitrate)
18 |         case .variable(let vbrMode):
19 |             lame_set_VBR(lame, vbrMode.lameRepresentation)
20 |         }
21 |     }
22 | }
23 | 
24 | 
25 | public enum LameVbrMode: UInt32 {
26 |     case off = 0
27 |     case rh = 2
28 |     case average = 3
29 |     case modernRH = 4
30 |     
31 |     public static let `default`: Self = .modernRH
32 |     
33 |     var lameRepresentation: vbr_mode {
34 |         vbr_mode(rawValue)
35 |     }
36 | }
37 | 
--------------------------------------------------------------------------------
/Sources/SwiftLAME/Wrappers/LameConfiguration.swift:
--------------------------------------------------------------------------------
 1 | //
 2 | //  Copyright © 2023 Hidden Spectrum, LLC. All rights reserved.
 3 | //
 4 | 
 5 | import Foundation
 6 | 
 7 | 
 8 | public struct LameConfiguration {
 9 |     
10 |     // MARK: Internal
11 |     
12 |     let bitrateMode: LameBitrateMode
13 |     let quality: LameQuality
14 |     let sampleRate: LameSampleRate
15 |     
16 |     // MARK: Lifecycle
17 |     
18 |     public init(sampleRate: LameSampleRate = .default, bitrateMode: LameBitrateMode, quality: LameQuality = .standard) {
19 |         self.bitrateMode = bitrateMode
20 |         self.quality = quality
21 |         self.sampleRate = sampleRate
22 |     }
23 | }
24 | 
--------------------------------------------------------------------------------
/Sources/SwiftLAME/Wrappers/LameQuality.swift:
--------------------------------------------------------------------------------
 1 | //
 2 | //  Copyright © 2023 Hidden Spectrum, LLC. All rights reserved.
 3 | //
 4 | 
 5 | import Foundation
 6 | 
 7 | 
 8 | public enum LameQuality: Int32 {
 9 |     case best = 0
10 |     case nearBest = 2
11 |     case standard = 5
12 |     case ok = 7
13 |     case worst = 9
14 | }
15 | 
--------------------------------------------------------------------------------
/Sources/SwiftLAME/Wrappers/LameSampleRate.swift:
--------------------------------------------------------------------------------
 1 | //
 2 | //  Copyright © 2023 Hidden Spectrum, LLC. All rights reserved.
 3 | //
 4 | 
 5 | import Foundation
 6 | 
 7 | 
 8 | public enum LameSampleRate {
 9 |     case `default`
10 |     case custom(Int32)
11 |     
12 |     // MARK: Internal
13 |     
14 |     var lameRepresentation: Int32 {
15 |         switch self {
16 |         case .default:
17 |             0
18 |         case .custom(let sampleRate):
19 |             sampleRate
20 |         }
21 |     }
22 | }
23 | 
--------------------------------------------------------------------------------
/Tests/SwiftLAMETests/SwiftLAMETests.swift:
--------------------------------------------------------------------------------
 1 | import XCTest
 2 | @testable import SwiftLAME
 3 | 
 4 | final class SwiftLAMETests: XCTestCase {
 5 |     func testExample() throws {
 6 |         // XCTest Documentation
 7 |         // https://developer.apple.com/documentation/xctest
 8 | 
 9 |         // Defining Test Cases and Test Methods
10 |         // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
11 |     }
12 | }
13 | 
--------------------------------------------------------------------------------