Skip to content

Commit 9a7953b

Browse files
committed
updated ci.yml for github actions
1 parent c4940d8 commit 9a7953b

File tree

5 files changed

+129
-66
lines changed

5 files changed

+129
-66
lines changed

.github/workflows/ci.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ jobs:
2727
run: |
2828
./companders_fulltest
2929
30-
# - name: Capture coverage info
31-
# run: |
32-
# lcov --directory . --capture --output-file coverage.info
33-
34-
# - name: Filter out system and test code
35-
# run: |
36-
# lcov --remove coverage.info 'tests/*' '/usr/*' 'test-library*' --output-file coverage.info
30+
- name: Capture coverage info
31+
run: |
32+
lcov --directory . --capture --output-file coverage.info
33+
34+
- name: Filter out system and test code
35+
run: |
36+
lcov --remove coverage.info 'tests/*' '/usr/*' 'test-library*' --output-file coverage.info
3737
38-
# - name: List coverage info
39-
# run: |
40-
# lcov --list coverage.info
38+
- name: List coverage info
39+
run: |
40+
lcov --list coverage.info
4141

companders.c

+64-45
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
#include "companders.h"
3939

4040
const static DIO_s8 LogTable[128] =
41-
{
42-
1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
43-
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
44-
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
45-
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
41+
{
42+
1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
43+
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
44+
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
45+
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
46+
};
4647

48+
4749
DIO_s8 DIO_LinearToALaw(DIO_s16 sample)
4850
{
4951
const DIO_s16 cClip = 32635;
@@ -109,6 +111,25 @@ DIO_s16 DIO_ALawToLinear(DIO_s8 aLawByte)
109111
return ALawDecompTable[addr];
110112
}
111113

114+
static DIO_s8 MuLawLogTable[256] =
115+
{
116+
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
117+
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
118+
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
119+
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
120+
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
121+
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
122+
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
123+
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
124+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
125+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
126+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
127+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
128+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
129+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
130+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
131+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
132+
};
112133
#define cBias 0x84
113134
#define cClip 32635
114135

@@ -125,52 +146,50 @@ DIO_s8 DIO_LinearToULaw(DIO_s16 sample)
125146
sample = cClip;
126147
sample += cBias;
127148

128-
// Convert the magnitude to uLaw
129-
if (sample >= 256)
130-
{
131-
exponent = LogTable[(sample >> 7) & 0xFF];
132-
mantissa = (sample >> (exponent + 3)) & 0x0F;
133-
compandedValue = ~((sign | (exponent << 4) | mantissa) & 0xFF);
134-
}
135-
else
136-
{
137-
compandedValue = ~((sign | sample >> 4) & 0xFF);
138-
}
149+
150+
exponent = MuLawLogTable[(sample >> 7) & 0xFF];
151+
mantissa = (sample >> (exponent + 3)) & 0x0F;
152+
compandedValue = ~(sign | (exponent << 4) | mantissa);
139153

140-
return compandedValue;
154+
return (DIO_s8) compandedValue&0xff;
141155
}
142156

143157
DIO_s16 DIO_ULawToLinear(DIO_s8 uLawByte)
144158
{
145159
static const DIO_s16 ULawDecompTable[256] = {
146-
-32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
147-
-23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
148-
-15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
149-
-11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316,
150-
-7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
151-
-5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
152-
-3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
153-
-2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
154-
-1884, -1828, -1772, -1716, -1660, -1604, -1548, -1492,
155-
-1436, -1380, -1324, -1268, -1212, -1156, -1100, -1044,
156-
-988, -932, -876, -820, -764, -708, -652, -596,
157-
-556, -532, -508, -484, -460, -436, -412, -388,
158-
-364, -340, -316, -292, -268, -244, -220, -196,
159-
-172, -148, -124, -100, -76, -52, -28, -4,
160-
32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
161-
23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
162-
15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
163-
11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
164-
7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
165-
5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
166-
3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
167-
2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
168-
1884, 1828, 1772, 1716, 1660, 1604, 1548, 1492,
169-
1436, 1380, 1324, 1268, 1212, 1156, 1100, 1044,
170-
988, 932, 876, 820, 764, 708, 652, 596,
171-
556, 532, 508, 484, 460, 436, 412, 388,
172-
364, 340, 316, 292, 268, 244, 220, 196,
173-
172, 148, 124, 100, 76, 52, 28, 4};
160+
-32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
161+
-23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
162+
-15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
163+
-11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
164+
-7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
165+
-5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
166+
-3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
167+
-2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
168+
-1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
169+
-1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
170+
-876, -844, -812, -780, -748, -716, -684, -652,
171+
-620, -588, -556, -524, -492, -460, -428, -396,
172+
-372, -356, -340, -324, -308, -292, -276, -260,
173+
-244, -228, -212, -196, -180, -164, -148, -132,
174+
-120, -112, -104, -96, -88, -80, -72, -64,
175+
-56, -48, -40, -32, -24, -16, -8, -1,
176+
32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
177+
23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
178+
15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
179+
11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
180+
7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
181+
5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
182+
3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
183+
2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
184+
1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
185+
1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
186+
876, 844, 812, 780, 748, 716, 684, 652,
187+
620, 588, 556, 524, 492, 460, 428, 396,
188+
372, 356, 340, 324, 308, 292, 276, 260,
189+
244, 228, 212, 196, 180, 164, 148, 132,
190+
120, 112, 104, 96, 88, 80, 72, 64,
191+
56, 48, 40, 32, 24, 16, 8, 0
192+
};
174193

175194
return ULawDecompTable[(unsigned char)uLawByte];
176195
}

companders.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern "C"
4545
{
4646
#endif
4747

48-
#define DIO_COMPANDERS_VER (0x000010005) //00 01 00 05 in hex
48+
#define DIO_COMPANDERS_VER (0x000010006) //00 01 00 05 in hex
4949

5050
//"DIO" prefixes are to assist in prevent name collisions if global namespace is used.
5151

companders_fulltest.c

+50-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,48 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
#include <assert.h>
3939
#include "companders.h"
4040

41+
//=========================================================
42+
const int cBias = 0x84;
43+
const int cClip = 32635;
44+
45+
static char MuLawCompressTable[256] =
46+
{
47+
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
48+
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
49+
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
50+
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
51+
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
52+
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
53+
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
54+
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
55+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
56+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
57+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
58+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
59+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
60+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
61+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
62+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
63+
};
64+
65+
unsigned char LinearToMuLawSample(short sample)
66+
{
67+
int sign = (sample >> 8) & 0x80;
68+
if (sign)
69+
sample = (short)-sample;
70+
if (sample > cClip)
71+
sample = cClip;
72+
sample = (short)(sample + cBias);
73+
int exponent = (int)MuLawCompressTable[(sample>>7) & 0xFF];
74+
int mantissa = (sample >> (exponent+3)) & 0x0F;
75+
int compressedByte = ~ (sign | (exponent << 4) | mantissa);
76+
77+
return (unsigned char)compressedByte;
78+
}
79+
80+
81+
82+
//=========================================================
4183

4284
void test_LinearToALaw() {
4385
DIO_s16 testSamples[] = {-2460, -338, -1, 499, 980};
@@ -63,23 +105,24 @@ void test_ALawToLinear() {
63105

64106
void test_LinearToULaw() {
65107
DIO_s16 testSamples[] = {-2460, -338, -1, 499, 7000};
66-
DIO_s8 expectedResults[] = { 0x01c, 0x048, 0x07e, 0x0bf, 0x084};
108+
DIO_s8 expectedResults[] = { 59, 98, 127, 220, 164};
67109
size_t numSamples = sizeof(testSamples) / sizeof(testSamples[0]);
68110
for (size_t i = 0; i < numSamples; ++i) {
69111
DIO_s8 companded = DIO_LinearToULaw(testSamples[i]);
70-
printf("Linear to u-Law: %5d -> %5d (expected: %5d)\n", testSamples[i], companded), (int)expectedResults[i];
71-
// assert(companded == expectedResults[i]);
112+
DIO_s8 compandedTest = LinearToMuLawSample(testSamples[i]);
113+
printf("Linear to u-Law: %5d -> %5d (expected: %5d %5d)\n", testSamples[i], companded, compandedTest, expectedResults[i]);
114+
assert(companded == expectedResults[i]);
72115
}
73116
}
74117

75118
void test_ULawToLinear() {
76-
DIO_s8 testSamples[] = { 0x1c, 0x61, 0x7e, 0xbf, 0x84};
77-
DIO_s16 expectedResults[] = {-2463, -89, -2, 495, 7007};
119+
DIO_s8 testSamples[] = { 0x1c, 0x61, 0, 0xbf, 0x84};
120+
DIO_s16 expectedResults[] = {-9852, -356, -32124, 1980, 28028};
78121
size_t numSamples = sizeof(testSamples) / sizeof(testSamples[0]);
79122
for (size_t i = 0; i < numSamples; ++i) {
80123
DIO_s16 linear = DIO_ULawToLinear(testSamples[i]);
81-
printf("u-Law to Linear: %5d -> %5d (expected: %5d)\n", testSamples[i], linear, expectedResults[i]);
82-
// assert(linear == expectedResults[i]);
124+
printf("u-Law to Linear: %5d -> %5d (expected: %5d)\n", testSamples[i], linear, expectedResults[i]);
125+
assert(linear == expectedResults[i]);
83126
}
84127
}
85128

makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# makefile for compandit tests (simple integer compander lib for embedded systems)
1+
# makefile for compander tests (simple integer compander lib for embedded systems)
22
# @author M A Chatterjee <deftio [at] deftio [dot] com>
33

44
CC=gcc
5-
CFLAGS=-I. -Wall
5+
CFLAGS=-I. -Wall
6+
CFLAGS_TEST=-I. -Wall -ftest-coverage -fprofile-arcs
67
DEPS = companders.h
78
OBJ = companders.o compandit.o
89
TEST_OBJ = companders.o companders_fulltest.o
@@ -14,7 +15,7 @@ compandit: $(OBJ)
1415
$(CC) -o $@ $^ $(CFLAGS) -lm
1516

1617
companders_fulltest: $(TEST_OBJ)
17-
$(CC) -o $@ $^ $(CFLAGS) -lm
18+
$(CC) -o $@ $^ $(CFLAGS_TEST) -lm
1819

1920
test: companders_fulltest
2021
./companders_fulltest

0 commit comments

Comments
 (0)