xref: /btstack/3rd-party/lc3-google/README.md (revision 4c4eb519208b4224604d94b3ed1931841ddd93bb)
14930cef6SMatthias Ringwald# Low Complexity Communication Codec (LC3)
24930cef6SMatthias Ringwald
34930cef6SMatthias RingwaldThe LC3 is an efficient low latency audio codec.
44930cef6SMatthias Ringwald
54930cef6SMatthias Ringwald[_Low Complexity Communication Codec_](https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=502107&vId=542963)
64930cef6SMatthias Ringwald
74930cef6SMatthias Ringwald## Overview
84930cef6SMatthias Ringwald
94930cef6SMatthias RingwaldThe directory layout is as follows :
104930cef6SMatthias Ringwald- include:      Library interface
114930cef6SMatthias Ringwald- src:          Source files
124930cef6SMatthias Ringwald- tools:        Standalone encoder/decoder tools
134930cef6SMatthias Ringwald- test:         Python implentation, used as reference for unit testing
144930cef6SMatthias Ringwald- build:        Building outputs
154930cef6SMatthias Ringwald- bin:          Compilation output
164930cef6SMatthias Ringwald
174930cef6SMatthias Ringwald## How to build
184930cef6SMatthias Ringwald
194930cef6SMatthias RingwaldThe default toolchain used is GCC. Invoke `make` to build the library.
204930cef6SMatthias Ringwald
214930cef6SMatthias Ringwald```sh
224930cef6SMatthias Ringwald$ make -j
234930cef6SMatthias Ringwald```
244930cef6SMatthias Ringwald
254930cef6SMatthias RingwaldCompiled library `liblc3.a` will be found in `bin` directory.
264930cef6SMatthias Ringwald
274930cef6SMatthias Ringwald#### Cross compilation
284930cef6SMatthias Ringwald
294930cef6SMatthias RingwaldThe cc, as, ld and ar can be selected with respective Makefile variables `CC`,
304930cef6SMatthias Ringwald`AS`, `LD` and `AR`. The `AS` and `LD` selections are optionnal, and fallback
314930cef6SMatthias Ringwaldto `CC` selection when not defined.
324930cef6SMatthias Ringwald
334930cef6SMatthias RingwaldThe `LIBC` must be set to `bionic` for android cross-compilation. This switch
344930cef6SMatthias Ringwaldprevent link with `pthread` and `rt` libraries, that is included in the
354930cef6SMatthias Ringwaldbionic libc.
364930cef6SMatthias Ringwald
374930cef6SMatthias RingwaldFollowing example build for android, using NDK toolset.
384930cef6SMatthias Ringwald
394930cef6SMatthias Ringwald```sh
404930cef6SMatthias Ringwald$ make -j CC=path_to_android_ndk_prebuilt/toolchain-prefix-clang LIBC=bionic
414930cef6SMatthias Ringwald```
424930cef6SMatthias Ringwald
434930cef6SMatthias RingwaldCompiled library will be found in `bin` directory.
444930cef6SMatthias Ringwald
454930cef6SMatthias Ringwald## Tools
464930cef6SMatthias Ringwald
474930cef6SMatthias RingwaldTools can be all compiled, while involking `make` as follows :
484930cef6SMatthias Ringwald
494930cef6SMatthias Ringwald```sh
504930cef6SMatthias Ringwald$ make tools
514930cef6SMatthias Ringwald```
524930cef6SMatthias Ringwald
534930cef6SMatthias RingwaldThe standalone encoder `elc3` take a `wave` file as input and encode it
544930cef6SMatthias Ringwaldaccording given parameter. The LC3 binary file format used is the non
554930cef6SMatthias Ringwaldstandard format described by the reference encoder / decoder tools.
564930cef6SMatthias RingwaldThe standalone decoder `dlc3` do the inverse operation.
574930cef6SMatthias Ringwald
584930cef6SMatthias RingwaldRefer to `elc3 -h` or `dlc3 -h` for options.
594930cef6SMatthias Ringwald
604930cef6SMatthias RingwaldNote that `elc3` output bitstream to standard output when output file is
614930cef6SMatthias Ringwaldomitted. On the other side `dlc3` read from standard input when input output
624930cef6SMatthias Ringwaldfile are omitted.
634930cef6SMatthias RingwaldIn such way you can easly test encoding / decoding loop with :
644930cef6SMatthias Ringwald
654930cef6SMatthias Ringwald```sh
664930cef6SMatthias Ringwald$ ./elc3 <in.wav> -b <bitrate> | ./dlc3 > <out.wav>
674930cef6SMatthias Ringwald```
684930cef6SMatthias Ringwald
694930cef6SMatthias RingwaldAdding Linux `aplay` tools, you will be able to instant hear the result :
704930cef6SMatthias Ringwald
714930cef6SMatthias Ringwald```sh
724930cef6SMatthias Ringwald$ ./elc3 <in.wav> -b <bitrate> | ./dlc3 | aplay
734930cef6SMatthias Ringwald```
744930cef6SMatthias Ringwald
754930cef6SMatthias Ringwald## Test
764930cef6SMatthias Ringwald
774930cef6SMatthias RingwaldA python implementation of the encoder is provided in `test` diretory.
784930cef6SMatthias RingwaldThe C implementation is unitary validated against this implementation and
794930cef6SMatthias Ringwaldintermediate values given in Appendix C of the specification.
804930cef6SMatthias Ringwald
814930cef6SMatthias Ringwald#### Prerequisite
824930cef6SMatthias Ringwald
834930cef6SMatthias Ringwald```sh
844930cef6SMatthias Ringwald# apt install python3 python3-dev python3-pip
854930cef6SMatthias Ringwald$ pip3 install scipy numpy
864930cef6SMatthias Ringwald```
874930cef6SMatthias Ringwald
884930cef6SMatthias Ringwald#### Running test suite
894930cef6SMatthias Ringwald
904930cef6SMatthias Ringwald```sh
914930cef6SMatthias Ringwald$ make test
924930cef6SMatthias Ringwald```
934930cef6SMatthias Ringwald
944930cef6SMatthias Ringwald## Conformance
954930cef6SMatthias Ringwald
964930cef6SMatthias RingwaldThe proposed encoder and decoder implementation have been fully tested and
974930cef6SMatthias Ringwaldvalidated.
984930cef6SMatthias Ringwald
994930cef6SMatthias RingwaldFor more detail on conformance, refer to [_Bluetooth Conformance
1004930cef6SMatthias RingwaldDocuments and scripts_](https://www.bluetooth.com/specifications/specs/low-complexity-communication-codec-1-0/)
1014930cef6SMatthias Ringwald
102*4c4eb519SMatthias Ringwald## Listening Test
103*4c4eb519SMatthias Ringwald
104*4c4eb519SMatthias RingwaldThe codec was [_here_](https://hydrogenaud.io/index.php/topic,122575.0.html)
105*4c4eb519SMatthias Ringwaldsubjectively evaluated in a blind listening test.
106*4c4eb519SMatthias Ringwald
107*4c4eb519SMatthias Ringwald## Meson build system
108*4c4eb519SMatthias Ringwald
109*4c4eb519SMatthias RingwaldMeson build system is also available to build and install lc3 codec in Linux
110*4c4eb519SMatthias Ringwaldenvironment.
111*4c4eb519SMatthias Ringwald
112*4c4eb519SMatthias Ringwald```sh
113*4c4eb519SMatthias Ringwald$ meson build
114*4c4eb519SMatthias Ringwald$ cd build
115*4c4eb519SMatthias Ringwald$ ninja
116*4c4eb519SMatthias Ringwald$ sudo ninja install
117*4c4eb519SMatthias Ringwald```
118*4c4eb519SMatthias Ringwald
119