From 9a7953bbca548de594c5d3570d59d53db2324eb8 Mon Sep 17 00:00:00 2001 From: deftio Date: Thu, 8 Aug 2024 19:28:25 -0700 Subject: [PATCH] updated ci.yml for github actions --- .github/workflows/ci.yml | 20 +++---- companders.c | 109 +++++++++++++++++++++++---------------- companders.h | 2 +- companders_fulltest.c | 57 +++++++++++++++++--- makefile | 7 +-- 5 files changed, 129 insertions(+), 66 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c4e8df..d16b845 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,15 +27,15 @@ jobs: run: | ./companders_fulltest -# - name: Capture coverage info -# run: | -# lcov --directory . --capture --output-file coverage.info - -# - name: Filter out system and test code -# run: | -# lcov --remove coverage.info 'tests/*' '/usr/*' 'test-library*' --output-file coverage.info + - name: Capture coverage info + run: | + lcov --directory . --capture --output-file coverage.info + + - name: Filter out system and test code + run: | + lcov --remove coverage.info 'tests/*' '/usr/*' 'test-library*' --output-file coverage.info -# - name: List coverage info -# run: | -# lcov --list coverage.info + - name: List coverage info + run: | + lcov --list coverage.info diff --git a/companders.c b/companders.c index 2cd348a..f3b447f 100644 --- a/companders.c +++ b/companders.c @@ -38,12 +38,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "companders.h" const static DIO_s8 LogTable[128] = - { - 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, - 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, - 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, - 7, 7, 7, 7, 7, 7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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,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 +}; #define cBias 0x84 #define cClip 32635 @@ -125,52 +146,50 @@ DIO_s8 DIO_LinearToULaw(DIO_s16 sample) sample = cClip; sample += cBias; - // Convert the magnitude to uLaw - if (sample >= 256) - { - exponent = LogTable[(sample >> 7) & 0xFF]; - mantissa = (sample >> (exponent + 3)) & 0x0F; - compandedValue = ~((sign | (exponent << 4) | mantissa) & 0xFF); - } - else - { - compandedValue = ~((sign | sample >> 4) & 0xFF); - } + + exponent = MuLawLogTable[(sample >> 7) & 0xFF]; + mantissa = (sample >> (exponent + 3)) & 0x0F; + compandedValue = ~(sign | (exponent << 4) | mantissa); - return compandedValue; + return (DIO_s8) compandedValue&0xff; } DIO_s16 DIO_ULawToLinear(DIO_s8 uLawByte) { static const DIO_s16 ULawDecompTable[256] = { - -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956, - -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764, - -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412, - -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316, - -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140, - -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, - -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004, - -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, - -1884, -1828, -1772, -1716, -1660, -1604, -1548, -1492, - -1436, -1380, -1324, -1268, -1212, -1156, -1100, -1044, - -988, -932, -876, -820, -764, -708, -652, -596, - -556, -532, -508, -484, -460, -436, -412, -388, - -364, -340, -316, -292, -268, -244, -220, -196, - -172, -148, -124, -100, -76, -52, -28, -4, - 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956, - 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, - 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412, - 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, - 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140, - 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, - 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004, - 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, - 1884, 1828, 1772, 1716, 1660, 1604, 1548, 1492, - 1436, 1380, 1324, 1268, 1212, 1156, 1100, 1044, - 988, 932, 876, 820, 764, 708, 652, 596, - 556, 532, 508, 484, 460, 436, 412, 388, - 364, 340, 316, 292, 268, 244, 220, 196, - 172, 148, 124, 100, 76, 52, 28, 4}; + -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956, + -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764, + -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412, + -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316, + -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140, + -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, + -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004, + -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, + -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436, + -1372, -1308, -1244, -1180, -1116, -1052, -988, -924, + -876, -844, -812, -780, -748, -716, -684, -652, + -620, -588, -556, -524, -492, -460, -428, -396, + -372, -356, -340, -324, -308, -292, -276, -260, + -244, -228, -212, -196, -180, -164, -148, -132, + -120, -112, -104, -96, -88, -80, -72, -64, + -56, -48, -40, -32, -24, -16, -8, -1, + 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956, + 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, + 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412, + 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, + 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140, + 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, + 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004, + 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, + 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436, + 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, + 876, 844, 812, 780, 748, 716, 684, 652, + 620, 588, 556, 524, 492, 460, 428, 396, + 372, 356, 340, 324, 308, 292, 276, 260, + 244, 228, 212, 196, 180, 164, 148, 132, + 120, 112, 104, 96, 88, 80, 72, 64, + 56, 48, 40, 32, 24, 16, 8, 0 + }; return ULawDecompTable[(unsigned char)uLawByte]; } diff --git a/companders.h b/companders.h index 7cab0fc..7589d7c 100644 --- a/companders.h +++ b/companders.h @@ -45,7 +45,7 @@ extern "C" { #endif -#define DIO_COMPANDERS_VER (0x000010005) //00 01 00 05 in hex +#define DIO_COMPANDERS_VER (0x000010006) //00 01 00 05 in hex //"DIO" prefixes are to assist in prevent name collisions if global namespace is used. diff --git a/companders_fulltest.c b/companders_fulltest.c index 0301153..7860440 100644 --- a/companders_fulltest.c +++ b/companders_fulltest.c @@ -38,6 +38,48 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "companders.h" +//========================================================= +const int cBias = 0x84; +const int cClip = 32635; + +static char MuLawCompressTable[256] = +{ + 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, + 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 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, + 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, + 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, + 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, + 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, + 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 +}; + +unsigned char LinearToMuLawSample(short sample) +{ + int sign = (sample >> 8) & 0x80; + if (sign) + sample = (short)-sample; + if (sample > cClip) + sample = cClip; + sample = (short)(sample + cBias); + int exponent = (int)MuLawCompressTable[(sample>>7) & 0xFF]; + int mantissa = (sample >> (exponent+3)) & 0x0F; + int compressedByte = ~ (sign | (exponent << 4) | mantissa); + + return (unsigned char)compressedByte; +} + + + +//========================================================= void test_LinearToALaw() { DIO_s16 testSamples[] = {-2460, -338, -1, 499, 980}; @@ -63,23 +105,24 @@ void test_ALawToLinear() { void test_LinearToULaw() { DIO_s16 testSamples[] = {-2460, -338, -1, 499, 7000}; - DIO_s8 expectedResults[] = { 0x01c, 0x048, 0x07e, 0x0bf, 0x084}; + DIO_s8 expectedResults[] = { 59, 98, 127, 220, 164}; size_t numSamples = sizeof(testSamples) / sizeof(testSamples[0]); for (size_t i = 0; i < numSamples; ++i) { DIO_s8 companded = DIO_LinearToULaw(testSamples[i]); - printf("Linear to u-Law: %5d -> %5d (expected: %5d)\n", testSamples[i], companded), (int)expectedResults[i]; - // assert(companded == expectedResults[i]); + DIO_s8 compandedTest = LinearToMuLawSample(testSamples[i]); + printf("Linear to u-Law: %5d -> %5d (expected: %5d %5d)\n", testSamples[i], companded, compandedTest, expectedResults[i]); + assert(companded == expectedResults[i]); } } void test_ULawToLinear() { - DIO_s8 testSamples[] = { 0x1c, 0x61, 0x7e, 0xbf, 0x84}; - DIO_s16 expectedResults[] = {-2463, -89, -2, 495, 7007}; + DIO_s8 testSamples[] = { 0x1c, 0x61, 0, 0xbf, 0x84}; + DIO_s16 expectedResults[] = {-9852, -356, -32124, 1980, 28028}; size_t numSamples = sizeof(testSamples) / sizeof(testSamples[0]); for (size_t i = 0; i < numSamples; ++i) { DIO_s16 linear = DIO_ULawToLinear(testSamples[i]); - printf("u-Law to Linear: %5d -> %5d (expected: %5d)\n", testSamples[i], linear, expectedResults[i]); - // assert(linear == expectedResults[i]); + printf("u-Law to Linear: %5d -> %5d (expected: %5d)\n", testSamples[i], linear, expectedResults[i]); + assert(linear == expectedResults[i]); } } diff --git a/makefile b/makefile index e6777ff..0c7a79a 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,9 @@ -# makefile for compandit tests (simple integer compander lib for embedded systems) +# makefile for compander tests (simple integer compander lib for embedded systems) # @author M A Chatterjee CC=gcc -CFLAGS=-I. -Wall +CFLAGS=-I. -Wall +CFLAGS_TEST=-I. -Wall -ftest-coverage -fprofile-arcs DEPS = companders.h OBJ = companders.o compandit.o TEST_OBJ = companders.o companders_fulltest.o @@ -14,7 +15,7 @@ compandit: $(OBJ) $(CC) -o $@ $^ $(CFLAGS) -lm companders_fulltest: $(TEST_OBJ) - $(CC) -o $@ $^ $(CFLAGS) -lm + $(CC) -o $@ $^ $(CFLAGS_TEST) -lm test: companders_fulltest ./companders_fulltest