xref: /btstack/3rd-party/lc3-google/README.md (revision 4930cef6e21e6da2d7571b9259c7f0fb8bed3d01)
1*4930cef6SMatthias Ringwald# Low Complexity Communication Codec (LC3)
2*4930cef6SMatthias Ringwald
3*4930cef6SMatthias RingwaldThe LC3 is an efficient low latency audio codec.
4*4930cef6SMatthias Ringwald
5*4930cef6SMatthias Ringwald[_Low Complexity Communication Codec_](https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=502107&vId=542963)
6*4930cef6SMatthias Ringwald
7*4930cef6SMatthias Ringwald## Overview
8*4930cef6SMatthias Ringwald
9*4930cef6SMatthias RingwaldThe directory layout is as follows :
10*4930cef6SMatthias Ringwald- include:      Library interface
11*4930cef6SMatthias Ringwald- src:          Source files
12*4930cef6SMatthias Ringwald- tools:        Standalone encoder/decoder tools
13*4930cef6SMatthias Ringwald- test:         Python implentation, used as reference for unit testing
14*4930cef6SMatthias Ringwald- build:        Building outputs
15*4930cef6SMatthias Ringwald- bin:          Compilation output
16*4930cef6SMatthias Ringwald
17*4930cef6SMatthias Ringwald## How to build
18*4930cef6SMatthias Ringwald
19*4930cef6SMatthias RingwaldThe default toolchain used is GCC. Invoke `make` to build the library.
20*4930cef6SMatthias Ringwald
21*4930cef6SMatthias Ringwald```sh
22*4930cef6SMatthias Ringwald$ make -j
23*4930cef6SMatthias Ringwald```
24*4930cef6SMatthias Ringwald
25*4930cef6SMatthias RingwaldCompiled library `liblc3.a` will be found in `bin` directory.
26*4930cef6SMatthias Ringwald
27*4930cef6SMatthias Ringwald#### Cross compilation
28*4930cef6SMatthias Ringwald
29*4930cef6SMatthias RingwaldThe cc, as, ld and ar can be selected with respective Makefile variables `CC`,
30*4930cef6SMatthias Ringwald`AS`, `LD` and `AR`. The `AS` and `LD` selections are optionnal, and fallback
31*4930cef6SMatthias Ringwaldto `CC` selection when not defined.
32*4930cef6SMatthias Ringwald
33*4930cef6SMatthias RingwaldThe `LIBC` must be set to `bionic` for android cross-compilation. This switch
34*4930cef6SMatthias Ringwaldprevent link with `pthread` and `rt` libraries, that is included in the
35*4930cef6SMatthias Ringwaldbionic libc.
36*4930cef6SMatthias Ringwald
37*4930cef6SMatthias RingwaldFollowing example build for android, using NDK toolset.
38*4930cef6SMatthias Ringwald
39*4930cef6SMatthias Ringwald```sh
40*4930cef6SMatthias Ringwald$ make -j CC=path_to_android_ndk_prebuilt/toolchain-prefix-clang LIBC=bionic
41*4930cef6SMatthias Ringwald```
42*4930cef6SMatthias Ringwald
43*4930cef6SMatthias RingwaldCompiled library will be found in `bin` directory.
44*4930cef6SMatthias Ringwald
45*4930cef6SMatthias Ringwald## Tools
46*4930cef6SMatthias Ringwald
47*4930cef6SMatthias RingwaldTools can be all compiled, while involking `make` as follows :
48*4930cef6SMatthias Ringwald
49*4930cef6SMatthias Ringwald```sh
50*4930cef6SMatthias Ringwald$ make tools
51*4930cef6SMatthias Ringwald```
52*4930cef6SMatthias Ringwald
53*4930cef6SMatthias RingwaldThe standalone encoder `elc3` take a `wave` file as input and encode it
54*4930cef6SMatthias Ringwaldaccording given parameter. The LC3 binary file format used is the non
55*4930cef6SMatthias Ringwaldstandard format described by the reference encoder / decoder tools.
56*4930cef6SMatthias RingwaldThe standalone decoder `dlc3` do the inverse operation.
57*4930cef6SMatthias Ringwald
58*4930cef6SMatthias RingwaldRefer to `elc3 -h` or `dlc3 -h` for options.
59*4930cef6SMatthias Ringwald
60*4930cef6SMatthias RingwaldNote that `elc3` output bitstream to standard output when output file is
61*4930cef6SMatthias Ringwaldomitted. On the other side `dlc3` read from standard input when input output
62*4930cef6SMatthias Ringwaldfile are omitted.
63*4930cef6SMatthias RingwaldIn such way you can easly test encoding / decoding loop with :
64*4930cef6SMatthias Ringwald
65*4930cef6SMatthias Ringwald```sh
66*4930cef6SMatthias Ringwald$ ./elc3 <in.wav> -b <bitrate> | ./dlc3 > <out.wav>
67*4930cef6SMatthias Ringwald```
68*4930cef6SMatthias Ringwald
69*4930cef6SMatthias RingwaldAdding Linux `aplay` tools, you will be able to instant hear the result :
70*4930cef6SMatthias Ringwald
71*4930cef6SMatthias Ringwald```sh
72*4930cef6SMatthias Ringwald$ ./elc3 <in.wav> -b <bitrate> | ./dlc3 | aplay
73*4930cef6SMatthias Ringwald```
74*4930cef6SMatthias Ringwald
75*4930cef6SMatthias Ringwald## Test
76*4930cef6SMatthias Ringwald
77*4930cef6SMatthias RingwaldA python implementation of the encoder is provided in `test` diretory.
78*4930cef6SMatthias RingwaldThe C implementation is unitary validated against this implementation and
79*4930cef6SMatthias Ringwaldintermediate values given in Appendix C of the specification.
80*4930cef6SMatthias Ringwald
81*4930cef6SMatthias Ringwald#### Prerequisite
82*4930cef6SMatthias Ringwald
83*4930cef6SMatthias Ringwald```sh
84*4930cef6SMatthias Ringwald# apt install python3 python3-dev python3-pip
85*4930cef6SMatthias Ringwald$ pip3 install scipy numpy
86*4930cef6SMatthias Ringwald```
87*4930cef6SMatthias Ringwald
88*4930cef6SMatthias Ringwald#### Running test suite
89*4930cef6SMatthias Ringwald
90*4930cef6SMatthias Ringwald```sh
91*4930cef6SMatthias Ringwald$ make test
92*4930cef6SMatthias Ringwald```
93*4930cef6SMatthias Ringwald
94*4930cef6SMatthias Ringwald
95*4930cef6SMatthias Ringwald## Conformance
96*4930cef6SMatthias Ringwald
97*4930cef6SMatthias RingwaldThe proposed encoder and decoder implementation have been fully tested and
98*4930cef6SMatthias Ringwaldvalidated.
99*4930cef6SMatthias Ringwald
100*4930cef6SMatthias RingwaldFor more detail on conformance, refer to [_Bluetooth Conformance
101*4930cef6SMatthias RingwaldDocuments and scripts_](https://www.bluetooth.com/specifications/specs/low-complexity-communication-codec-1-0/)
102*4930cef6SMatthias Ringwald
103