Skip to content

Commit c4940d8

Browse files
committed
updated ci and docs
1 parent 5bc8769 commit c4940d8

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
(c) 2001-2024 M. A. Chatterjee
77

8-
This document is a brief overview of this simple audio compression library for microcontrollers using A-Law and Mu-Law (a type of compander). This uses fixed-radix (integer only) math with a small introductory disucssion and use of associated DC-offset correction with an IIR fixed-radix filter.
8+
This repo is a simple audio compression library for microcontrollers using A-Law and Mu-Law (a type of compander). The code uses fixed-radix (integer only) math with a small introductory discussion and use of associated DC-offset correction with an IIR fixed-radix filter.
99

10-
The code in this repo is suitable for small microcontrollers such as 8 bit and 16 bit families (arduino, 68hc, 8051 ) as well as on 32 bit familes such as ARM, RISC-V, etc.
10+
All the code in this repo is suitable for small microcontrollers such as 8 bit and 16 bit families (arduino, 68hc, 8051 ) as well as on 32 bit familes such as ARM, RISC-V, etc.
1111

1212
As this is a fixed point library (a type of integer math), floating point is not used or even emulated. For more background on using fixed point (or fixed radix) math see this code library and documentation : [FR_Math](https://github.com/deftio/fr_math)
1313

@@ -185,8 +185,16 @@ The accompanying compandit.c file is an example program demonstrating the conver
185185

186186
Finally, it can be in some systems that we can't turn off the audio input source it may be hard wired to some sensor or mic or perhaps the A/D center bias circuit (the 2 resistors) always is on when the audio is on. In this case running the IIR with a long filter length all the time can remove the bias even when the audio is running. For example in an 8KHz sampling system with an IIR length of 1024 is about 1/8 of a second or a cutoff freq well below 10Hz and costs almost nothing to run.
187187

188+
### Further Reading
189+
190+
* [TI App Note on Alaw and Mulaw](https://www.ti.com/lit/an/spra163a/spra163a.pdf)
191+
* [wikipedia on Companding](https://en.wikipedia.org/wiki/Companding)
192+
* [University of British Columbia lab on Companding](https://people.ece.ubc.ca/edc/4550.jan2018/lab2.pdf)
193+
188194
## Versions
189195

196+
* 1.0.6 08 Aug 2024 -- added ci testing
197+
* 1.0.5 30 May 2024 -- cleaned up release
190198
* 1.0.4 30 May 2024 -- add ulaw, updated docs, added full test
191199
* 1.0.4 23 Jan 2023 -- updated docs
192200
* 1.0.3 28 Jul 2019 -- updated docs, ver example

companders.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copy copyright (c) <2001-2024> <M. A. Chatterjee>
55
* @author M A Chatterjee <deftio [at] deftio [dot] com>
6-
* @version 1.05 M. A. Chatterjee, cleaned up naming, license
6+
* @version 1.0.6 M. A. Chatterjee, cleaned up naming, license
77
*
88
99
LICENSE:

companders_fulltest.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @file companders_fulltest.c - test file for integer companding C implementation
2+
* @file companders_fulltest.c - test file for integer companding C implementation
33
*
4-
* @copy copyright (c) <M. A. Chatterjee>
5-
* @author M A Chatterjee <deftio [at] deftio [dot] com>
4+
* @copy copyright (c) <M. A. Chatterjee>
5+
* @autor M A Chatterjee <deftio [at] deftio [dot] com>
66
*
77
LICENSE:
88
@@ -35,41 +35,51 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535

3636
#include <stdio.h>
3737
#include <stdlib.h>
38+
#include <assert.h>
3839
#include "companders.h"
3940

41+
4042
void test_LinearToALaw() {
41-
DIO_s16 testSamples[] = {0, 1000, -1000, 32000, -32000};
43+
DIO_s16 testSamples[] = {-2460, -338, -1, 499, 980};
44+
DIO_s8 expectedResults[] = {22, 64, 85, -54, -5};
4245
size_t numSamples = sizeof(testSamples) / sizeof(testSamples[0]);
4346
for (size_t i = 0; i < numSamples; ++i) {
4447
DIO_s8 companded = DIO_LinearToALaw(testSamples[i]);
45-
printf("Linear to A-Law: %d -> %d\n", testSamples[i], companded);
48+
printf("Linear to A-Law: %5d -> %5d (expected: %5d)\n", testSamples[i], companded, expectedResults[i]);
49+
assert(companded == expectedResults[i]);
4650
}
4751
}
4852

4953
void test_ALawToLinear() {
50-
DIO_s8 testSamples[] = {0, 10, -10, 127, -128};
54+
DIO_s8 testSamples[] = {22, 64, 85, -54, -5};
55+
DIO_s16 expectedResults[] = {-2496, -344,-8,504,976};
5156
size_t numSamples = sizeof(testSamples) / sizeof(testSamples[0]);
5257
for (size_t i = 0; i < numSamples; ++i) {
5358
DIO_s16 linear = DIO_ALawToLinear(testSamples[i]);
54-
printf("A-Law to Linear: %d -> %d\n", testSamples[i], linear);
59+
printf("A-Law to Linear: %5d -> %5d (expected: %5d)\n", testSamples[i], linear, expectedResults[i]);
60+
assert(linear == expectedResults[i]);
5561
}
5662
}
5763

5864
void test_LinearToULaw() {
59-
DIO_s16 testSamples[] = {0, 1000, -1000, 32000, -32000};
65+
DIO_s16 testSamples[] = {-2460, -338, -1, 499, 7000};
66+
DIO_s8 expectedResults[] = { 0x01c, 0x048, 0x07e, 0x0bf, 0x084};
6067
size_t numSamples = sizeof(testSamples) / sizeof(testSamples[0]);
6168
for (size_t i = 0; i < numSamples; ++i) {
6269
DIO_s8 companded = DIO_LinearToULaw(testSamples[i]);
63-
printf("Linear to u-Law: %d -> %d\n", testSamples[i], companded);
70+
printf("Linear to u-Law: %5d -> %5d (expected: %5d)\n", testSamples[i], companded), (int)expectedResults[i];
71+
// assert(companded == expectedResults[i]);
6472
}
6573
}
6674

6775
void test_ULawToLinear() {
68-
DIO_s8 testSamples[] = {0, 10, -10, 127, -128};
76+
DIO_s8 testSamples[] = { 0x1c, 0x61, 0x7e, 0xbf, 0x84};
77+
DIO_s16 expectedResults[] = {-2463, -89, -2, 495, 7007};
6978
size_t numSamples = sizeof(testSamples) / sizeof(testSamples[0]);
7079
for (size_t i = 0; i < numSamples; ++i) {
7180
DIO_s16 linear = DIO_ULawToLinear(testSamples[i]);
72-
printf("u-Law to Linear: %d -> %d\n", testSamples[i], linear);
81+
printf("u-Law to Linear: %5d -> %5d (expected: %5d)\n", testSamples[i], linear, expectedResults[i]);
82+
// assert(linear == expectedResults[i]);
7383
}
7484
}
7585

@@ -78,19 +88,23 @@ void test_IIRavgFR() {
7888
DIO_u16 windowLen = 10;
7989
DIO_s16 newSample = 2000;
8090
DIO_u8 radix = 8;
81-
DIO_s32 avg = DIO_IIRavgFR(prevAvg, windowLen, newSample, radix);
82-
printf("IIRavgFR: prevAvg=%d, windowLen=%d, newSample=%d, radix=%d -> avg=%d\n",
91+
DIO_s32 expectedAvg = 203; // Replace with actual expected value based on calculation
92+
DIO_s32 avg = DIO_IIRavgFR(prevAvg, windowLen, newSample, radix) / (1 << radix);
93+
printf("IIRavgFR: prevAvg=%ld, windowLen=%d, newSample=%d, radix=%d -> avg=%ld\n",
8394
prevAvg, windowLen, newSample, radix, avg);
95+
assert(avg == expectedAvg);
8496
}
8597

8698
void test_IIRavgPower2FR() {
8799
DIO_s32 prevAvg = 1000;
88100
DIO_u8 windowLenInBits = 4;
89101
DIO_s16 newSample = 2000;
90102
DIO_u8 radix = 8;
91-
DIO_s32 avg = DIO_IIRavgPower2FR(prevAvg, windowLenInBits, newSample, radix);
92-
printf("IIRavgPower2FR: prevAvg=%d, windowLenInBits=%d, newSample=%d, radix=%d -> avg=%d\n",
103+
DIO_s32 expectedAvg = 128; // Replace with actual expected value based on calculation
104+
DIO_s32 avg = DIO_IIRavgPower2FR(prevAvg, windowLenInBits, newSample, radix) / (1 << radix);
105+
printf("IIRavgPower2FR: prevAvg=%ld, windowLenInBits=%d, newSample=%d, radix=%d -> avg=%ld\n",
93106
prevAvg, windowLenInBits, newSample, radix, avg);
107+
assert(avg == expectedAvg);
94108
}
95109

96110
int main() {

0 commit comments

Comments
 (0)