xref: /aosp_15_r20/external/flac/README.md (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1*600f14f4SXin Li<!---
2*600f14f4SXin Li/* FLAC - Free Lossless Audio Codec
3*600f14f4SXin Li * Copyright (C) 2001-2009  Josh Coalson
4*600f14f4SXin Li * Copyright (C) 2011-2023  Xiph.Org Foundation
5*600f14f4SXin Li *
6*600f14f4SXin Li * This file is part the FLAC project.  FLAC is comprised of several
7*600f14f4SXin Li * components distributed under different licenses.  The codec libraries
8*600f14f4SXin Li * are distributed under Xiph.Org's BSD-like license (see the file
9*600f14f4SXin Li * COPYING.Xiph in this distribution).  All other programs, libraries, and
10*600f14f4SXin Li * plugins are distributed under the LGPL or GPL (see COPYING.LGPL and
11*600f14f4SXin Li * COPYING.GPL).  The documentation is distributed under the Gnu FDL (see
12*600f14f4SXin Li * COPYING.FDL).  Each file in the FLAC distribution contains at the top the
13*600f14f4SXin Li * terms under which it may be distributed.
14*600f14f4SXin Li *
15*600f14f4SXin Li * Since this particular file is relevant to all components of FLAC,
16*600f14f4SXin Li * it may be distributed under the Xiph.Org license, which is the least
17*600f14f4SXin Li * restrictive of those mentioned above.  See the file COPYING.Xiph in this
18*600f14f4SXin Li * distribution.
19*600f14f4SXin Li */
20*600f14f4SXin Li--->
21*600f14f4SXin Li
22*600f14f4SXin Li# Free Lossless Audio Codec (FLAC)
23*600f14f4SXin Li
24*600f14f4SXin LiFLAC is open source software that can reduce the amount of storage space
25*600f14f4SXin Lineeded to store digital audio signals without needing to remove
26*600f14f4SXin Liinformation in doing so.
27*600f14f4SXin Li
28*600f14f4SXin LiThe files read and produced by this software are called FLAC files. As
29*600f14f4SXin Lithese files (which follow the [FLAC format](https://xiph.org/flac/format.html))
30*600f14f4SXin Lican be read from and written to by other software as well, this software
31*600f14f4SXin Liis often referred to as the FLAC reference implementation.
32*600f14f4SXin Li
33*600f14f4SXin LiFLAC has been developed by volunteers. If you want to help out, see
34*600f14f4SXin LiCONTRIBUTING.md for more information.
35*600f14f4SXin Li
36*600f14f4SXin Li## Components
37*600f14f4SXin Li
38*600f14f4SXin LiFLAC is comprised of
39*600f14f4SXin Li  * libFLAC, a library which implements reference encoders and
40*600f14f4SXin Li    decoders for native FLAC and Ogg FLAC, and a metadata interface
41*600f14f4SXin Li  * libFLAC++, a C++ object wrapper library around libFLAC
42*600f14f4SXin Li  * `flac`, a command-line program for encoding and decoding files
43*600f14f4SXin Li  * `metaflac`, a command-line program for viewing and editing FLAC
44*600f14f4SXin Li    metadata
45*600f14f4SXin Li  * user and API documentation
46*600f14f4SXin Li
47*600f14f4SXin LiThe libraries (libFLAC, libFLAC++) are licensed under Xiph.org's
48*600f14f4SXin LiBSD-like license (see COPYING.Xiph). All other programs and plugins are
49*600f14f4SXin Lilicensed under the GNU General Public License (see COPYING.GPL). The
50*600f14f4SXin Lidocumentation is licensed under the GNU Free Documentation License
51*600f14f4SXin Li(see COPYING.FDL).
52*600f14f4SXin Li
53*600f14f4SXin Li## Documentation
54*600f14f4SXin Li
55*600f14f4SXin LiFor documentation of the `flac` and `metaflac` command line tools, see
56*600f14f4SXin Lithe directory man, which contains the files flac.md and metaflac.md
57*600f14f4SXin Li
58*600f14f4SXin LiThe API documentation is in html and is generated by Doxygen. It can be
59*600f14f4SXin Lifound in the directory doc/html/api. It is included in a release tarball
60*600f14f4SXin Liand must be build with Doxygen when the source is taken directly from
61*600f14f4SXin Ligit.
62*600f14f4SXin Li
63*600f14f4SXin LiThe directory examples contains example source code on using libFLAC and
64*600f14f4SXin LilibFLAC++.
65*600f14f4SXin Li
66*600f14f4SXin LiDocumentation concerning the FLAC format itself (which can be used to
67*600f14f4SXin Licreate software reading and writing FLAC software independent from
68*600f14f4SXin LilibFLAC) was included in previous releases, but can now be found on
69*600f14f4SXin Lihttps://datatracker.ietf.org/doc/draft-ietf-cellar-flac/ Additionally
70*600f14f4SXin Lia set of files for conformance testing called the FLAC decoder testbench
71*600f14f4SXin Lican be found at https://github.com/ietf-wg-cellar/flac-test-files
72*600f14f4SXin Li
73*600f14f4SXin LiIf you have questions about FLAC that this document does not answer,
74*600f14f4SXin Liplease submit them at the following tracker so this document can be
75*600f14f4SXin Liimproved:
76*600f14f4SXin Li
77*600f14f4SXin Lihttps://github.com/xiph/flac/issues
78*600f14f4SXin Li
79*600f14f4SXin Li## Building FLAC
80*600f14f4SXin Li
81*600f14f4SXin LiAll components of the FLAC project can be build with a variety of
82*600f14f4SXin Licompilers (including GCC, Clang, Visual Studio, Intel C++ Compiler) on
83*600f14f4SXin Limany architectures (inluding x86, x86_64, ARMv7, ARMv8 and PowerPC)
84*600f14f4SXin Lifor many different operating systems.
85*600f14f4SXin Li
86*600f14f4SXin LiTo do this, FLAC provides two build systems: one using GNU's autotools
87*600f14f4SXin Liand one with CMake. Both differ slighly in configuration options, but
88*600f14f4SXin Lishould be considered equivalent for most use cases.
89*600f14f4SXin Li
90*600f14f4SXin LiFLAC used to provide files specifically for building with Visual Studio,
91*600f14f4SXin Libut these have been removed in favor of using CMake.
92*600f14f4SXin Li
93*600f14f4SXin Li## Building with CMake
94*600f14f4SXin Li
95*600f14f4SXin LiCMake is a cross-platform build system. FLAC can be built on Windows,
96*600f14f4SXin LiLinux, Mac OS X using CMake.
97*600f14f4SXin Li
98*600f14f4SXin LiYou can use either CMake's CLI or GUI. We recommend you to have a
99*600f14f4SXin Liseparate build folder outside the repository in order to not spoil it
100*600f14f4SXin Liwith generated files. It is possible however to do a so-called in-tree
101*600f14f4SXin Libuild, in that case /path/to/flac-build in the following examples is
102*600f14f4SXin Liequal to /path/to/flac-source.
103*600f14f4SXin Li
104*600f14f4SXin Li### CMake CLI
105*600f14f4SXin Li
106*600f14f4SXin LiGo to your build folder and run something like this:
107*600f14f4SXin Li
108*600f14f4SXin Li```
109*600f14f4SXin Li/path/to/flac-build$ cmake /path/to/flac-source
110*600f14f4SXin Li```
111*600f14f4SXin Li
112*600f14f4SXin Lior e.g. in Windows shell
113*600f14f4SXin Li
114*600f14f4SXin Li```
115*600f14f4SXin LiC:\path\to\flac-build> cmake \path\to\flac-source
116*600f14f4SXin Li```
117*600f14f4SXin Li
118*600f14f4SXin Li(provided that cmake is in your %PATH% variable)
119*600f14f4SXin Li
120*600f14f4SXin LiThat will generate build scripts for the default build system (e.g.
121*600f14f4SXin LiMakefiles for UNIX). After that you start build with a command like
122*600f14f4SXin Lithis:
123*600f14f4SXin Li
124*600f14f4SXin Li```
125*600f14f4SXin Li/path/to/flac-build$ make
126*600f14f4SXin Li```
127*600f14f4SXin Li
128*600f14f4SXin LiAnd afterwards you can run tests or install the built libraries and
129*600f14f4SXin Liheaders
130*600f14f4SXin Li
131*600f14f4SXin Li```
132*600f14f4SXin Li/path/to/flac-build$ make test
133*600f14f4SXin Li/path/to/flac-build$ make install
134*600f14f4SXin Li```
135*600f14f4SXin Li
136*600f14f4SXin LiIf you want use a build system other than default add -G flag to cmake,
137*600f14f4SXin Lie.g.:
138*600f14f4SXin Li
139*600f14f4SXin Li```
140*600f14f4SXin Li/path/to/flac-build$ cmake /path/to/flac-source -GNinja
141*600f14f4SXin Li/path/to/flac-build$ ninja
142*600f14f4SXin Li```
143*600f14f4SXin Li
144*600f14f4SXin Lior:
145*600f14f4SXin Li
146*600f14f4SXin Li```
147*600f14f4SXin Li/path/to/flac-build$ cmake /path/to/flac-source -GXcode
148*600f14f4SXin Li```
149*600f14f4SXin Li
150*600f14f4SXin LiUse cmake --help to see the list of available generators.
151*600f14f4SXin Li
152*600f14f4SXin LiBy default CMake will search for OGG. If CMake fails to find it you can
153*600f14f4SXin Lihelp CMake by specifying the exact path:
154*600f14f4SXin Li
155*600f14f4SXin Li```
156*600f14f4SXin Li/path/to/flac-build$ cmake /path/to/flac-source -DOGG_ROOT=/path/to/ogg
157*600f14f4SXin Li```
158*600f14f4SXin Li
159*600f14f4SXin LiIf you would like CMake to build OGG alongside FLAC, you can place the
160*600f14f4SXin Liogg sources directly in the flac source directory as a subdirectory with
161*600f14f4SXin Lithe name ogg, for example:
162*600f14f4SXin Li
163*600f14f4SXin Li```
164*600f14f4SXin Li/path/to/flac-source/ogg
165*600f14f4SXin Li```
166*600f14f4SXin Li
167*600f14f4SXin LiIf you don't want to build flac with OGG support you can tell CMake not
168*600f14f4SXin Lito look for OGG:
169*600f14f4SXin Li
170*600f14f4SXin Li```
171*600f14f4SXin Li/path/to/flac-build$ cmake /path/to/flac-source -DWITH_OGG=OFF
172*600f14f4SXin Li```
173*600f14f4SXin Li
174*600f14f4SXin LiOther FLAC's options (e.g. building C++ lib or docs) can also be put to
175*600f14f4SXin Licmake through -D flag. If you want to know what options are available,
176*600f14f4SXin Liuse -LH:
177*600f14f4SXin Li
178*600f14f4SXin Li```
179*600f14f4SXin Li/path/to/flac-build$ cmake /path/to/flac-source -LH
180*600f14f4SXin Li```
181*600f14f4SXin Li
182*600f14f4SXin Li### CMake GUI (for Visual Studio)
183*600f14f4SXin LiIt is likely that you would prefer to use the CMake GUI if you use
184*600f14f4SXin LiVisual Studio to build FLAC. It's in essence the same process as
185*600f14f4SXin Libuilding using CLI.
186*600f14f4SXin Li
187*600f14f4SXin LiOpen cmake-gui. In the window select a source directory (the
188*600f14f4SXin Lirepository's root), a build directory (some other directory outside the
189*600f14f4SXin Lirepository). Then press button "Configure". CMake will ask you which
190*600f14f4SXin Libuild system you prefer. Choose that version of Visual Studio which you
191*600f14f4SXin Lihave on your system, choose whether you want to build for Win32 or x64.
192*600f14f4SXin LiPress OK.
193*600f14f4SXin Li
194*600f14f4SXin LiAfter CMake finishes you can change the configuration to your liking and
195*600f14f4SXin Liif you change anything, run Configure again. With the "Generate" button,
196*600f14f4SXin LiCMake creates Visual Studio files, which can be opened from Visual
197*600f14f4SXin LiStudio. With the button "Open Project" CMake will launch Visual Studio
198*600f14f4SXin Liand open the generated solution. You can use the project files as usual
199*600f14f4SXin Libut remember that they were generated by CMake. That means that your
200*600f14f4SXin Lichanges (e.g. some additional compile flags) will be lost when you run
201*600f14f4SXin LiCMake next time.
202*600f14f4SXin Li
203*600f14f4SXin LiCMake searches by default for OGG on your system and returns an error
204*600f14f4SXin Liif it cannot find it. If you want to build OGG alongside FLAC, you can
205*600f14f4SXin Lidownload the OGG sources and extract them in a subdirectory of the FLAC
206*600f14f4SXin Lisource directory with the name ogg (i.e. /path/to/flac-source/ogg)
207*600f14f4SXin Libefore running CMake. If you don't want to build FLAC with OGG support,
208*600f14f4SXin Liuntick the box following WITH_OGG flag in the list of variables in
209*600f14f4SXin Licmake-gui window and run "Configure" again.
210*600f14f4SXin Li
211*600f14f4SXin LiIf CMake fails to find MSVC compiler then running cmake-gui from MS
212*600f14f4SXin LiDeveloper comand prompt should help.
213*600f14f4SXin Li
214*600f14f4SXin Li## Building with GNU autotools
215*600f14f4SXin Li
216*600f14f4SXin LiFLAC uses autoconf and libtool for configuring and building. To
217*600f14f4SXin Liconfigure a build, open a commmand line/terminal and run `./configure`
218*600f14f4SXin LiYou can provide options to this command, which are listed by running
219*600f14f4SXin Li`./configure --help`.
220*600f14f4SXin Li
221*600f14f4SXin LiIn case the configure script is not present (for example when building
222*600f14f4SXin Lifrom git and not from a release tarball), it can be generated by running
223*600f14f4SXin Li`./autogen.sh`. This may require a libtool development package though.
224*600f14f4SXin Li
225*600f14f4SXin LiAfter configuration, build with `make`, verify the build with
226*600f14f4SXin Li`make check` and install with `make install`. Installation might require
227*600f14f4SXin Liadministrator priviledged, i.e. `sudo make install`.
228*600f14f4SXin Li
229*600f14f4SXin LiThe 'make check' step is optional; omit it to skip all the tests, which
230*600f14f4SXin Lican take about an hour to complete. Even though it will stop with an
231*600f14f4SXin Liexplicit message on any failure, it does print out a lot of stuff so you
232*600f14f4SXin Limight want to capture the output to a file if you're having a problem.
233*600f14f4SXin LiAlso, don't run 'make check' as root because it confuses some of the
234*600f14f4SXin Litests.
235*600f14f4SXin Li
236*600f14f4SXin LiSummarizing:
237*600f14f4SXin Li
238*600f14f4SXin Li```
239*600f14f4SXin Li./configure
240*600f14f4SXin Limake && make check
241*600f14f4SXin Lisudo make install
242*600f14f4SXin Li```
243*600f14f4SXin Li
244*600f14f4SXin Li## Note to embedded developers
245*600f14f4SXin Li
246*600f14f4SXin LilibFLAC has grown larger over time as more functionality has been
247*600f14f4SXin Liincluded, but much of it may be unnecessary for a particular embedded
248*600f14f4SXin Liimplementation.  Unused parts may be pruned by some simple editing of
249*600f14f4SXin Liconfigure.ac and src/libFLAC/Makefile.am; the following dependency
250*600f14f4SXin Ligraph shows which modules may be pruned without breaking things
251*600f14f4SXin Lifurther down:
252*600f14f4SXin Li
253*600f14f4SXin Li```
254*600f14f4SXin Limetadata.h
255*600f14f4SXin Li    stream_decoder.h
256*600f14f4SXin Li    format.h
257*600f14f4SXin Li
258*600f14f4SXin Listream_encoder.h
259*600f14f4SXin Li    stream_decoder.h
260*600f14f4SXin Li    format.h
261*600f14f4SXin Li
262*600f14f4SXin Listream_decoder.h
263*600f14f4SXin Li    format.h
264*600f14f4SXin Li```
265*600f14f4SXin Li
266*600f14f4SXin LiIn other words, for pure decoding applications, both the stream encoder
267*600f14f4SXin Liand metadata editing interfaces can be safely removed. Note that this
268*600f14f4SXin Liis specific to building the libraries for embedded use. The command line
269*600f14f4SXin Litools do not provide such compartmentalization, and require a complete
270*600f14f4SXin LilibFLAC build to function.
271*600f14f4SXin Li
272*600f14f4SXin LiThere is a section dedicated to embedded use in the libFLAC API
273*600f14f4SXin LiHTML documentation (see doc/html/api/index.html).
274*600f14f4SXin Li
275*600f14f4SXin LiAlso, there are several places in the libFLAC code with comments marked
276*600f14f4SXin Liwith "OPT:" where a #define can be changed to enable code that might be
277*600f14f4SXin Lifaster on a specific platform.  Experimenting with these can yield
278*600f14f4SXin Lifaster binaries.
279