-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathllms.txt
More file actions
115 lines (87 loc) · 3.78 KB
/
Copy pathllms.txt
File metadata and controls
115 lines (87 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Companders - Fixed-Point Audio Companding Library
> companders is a C library providing A-Law and Mu-Law audio companding
> (compression/expansion) using only integer math. It includes IIR DC offset
> correction filters. Designed for embedded systems from 8-bit to 32-bit.
## Project overview
- Name: companders
- Version: 1.0.7
- License: BSD 2-Clause
- Language: C (C99 compatible, C89 with DIO_NO_STDINT)
- Repository: https://github.com/deftio/companders
- Author: M. A. Chatterjee
## What this library does
Companding converts 16-bit linear PCM audio samples to 8-bit logarithmic
representation (and back), preserving dynamic range. This is the same
technique used in G.711 telephony. The library also provides fixed-radix
IIR averagers for estimating and removing DC bias from ADC readings.
No floating point math is used anywhere. All operations use integer
arithmetic with optional bit-shift-only variants for CPUs without fast
divide instructions.
## API (6 functions)
```c
#include <companders.h>
// A-Law (ITU-T G.711, European standard)
DIO_s8 DIO_LinearToALaw(DIO_s16 sample); // 16-bit linear -> 8-bit A-Law
DIO_s16 DIO_ALawToLinear(DIO_s8 aLawByte); // 8-bit A-Law -> 16-bit linear
// Mu-Law (ANSI, American/Japanese standard)
DIO_s8 DIO_LinearToULaw(DIO_s16 sample); // 16-bit linear -> 8-bit Mu-Law
DIO_s16 DIO_ULawToLinear(DIO_s8 uLawByte); // 8-bit Mu-Law -> 16-bit linear
// IIR DC offset correction (fixed-radix math)
DIO_s32 DIO_IIRavgFR(DIO_s32 prevAvg, DIO_u16 windowLen, DIO_s16 newSample, DIO_u8 radix);
DIO_s32 DIO_IIRavgPower2FR(DIO_s32 prevAvg, DIO_u8 windowLenInBits, DIO_s16 newSample, DIO_u8 radix);
```
## Utility macros
```c
DIO_I2FR(x, r) // Integer to fixed-radix: (x) << (r)
DIO_FR2I(x, r) // Fixed-radix to integer: (x) >> (r)
DIO_FR2D(x, r) // Fixed-radix to double (debug/test only)
```
## Version macros
```c
DIO_COMPANDERS_VER_MAJOR // 1
DIO_COMPANDERS_VER_MINOR // 0
DIO_COMPANDERS_VER_PATCH // 7
DIO_COMPANDERS_VER_HEX // 0x00010007 (32-bit 0x00MMmmpp)
DIO_COMPANDERS_VER_STRING // "1.0.7"
```
## Type system
Uses stdint.h by default (uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t).
Define DIO_NO_STDINT before including the header to fall back to char/short/long
typedefs for compilers that lack stdint.h.
## Directory structure
```
src/companders.h - Public header (include this)
src/companders.c - Implementation
test/companders_fulltest.c - Test suite (100% line and function coverage)
examples/
arduino_compander/ - Arduino IDE example (.ino)
platformio_compander/ - PlatformIO example (Arduino framework)
espidf_compander/ - ESP-IDF native example
compandit.c - POSIX command-line demo
```
## Platform support
### POSIX / Desktop (gcc, clang)
Build: `make test` (runs tests), `make build` (builds example), `make coverage`
### Arduino IDE
Install via Library Manager or clone into ~/Arduino/libraries/.
Use: `#include <companders.h>`
Manifest: library.properties
### PlatformIO
Add to platformio.ini: `lib_deps = https://github.com/deftio/companders.git`
Use: `#include <companders.h>`
Manifest: library.json
### ESP-IDF (Espressif)
Add as component in components/ directory or via idf_component.yml dependency.
Use: `#include "companders.h"`
Manifests: idf_component.yml, CMakeLists.txt
Targets: ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6, ESP32-H2
## Dependencies
None. The library is entirely self-contained. Only the POSIX test/example
builds link -lm (for the compandit.c demo which uses DIO_FR2D for printing).
## Key design decisions
- No heap allocation
- No floating point
- No external dependencies
- All lookup tables are const/static (ROM-friendly)
- C++ compatible (extern "C" guards)
- DIO_IIRavgPower2FR uses only shifts (no divide) for low-end CPUs