test: platform: codec2_encode_test: reformat code to new coding style

This commit is contained in:
Silvano Seva 2025-09-12 16:33:15 +02:00
parent 882a7e58ee
commit 12dc81aef2
2 changed files with 21 additions and 18 deletions

View File

@ -85,6 +85,7 @@ platform/targets/GDx/hwconfig.h
platform/targets/linux/emulator/sdl_engine.h
platform/targets/ttwrplus/pmu.h
tests/platform/mic_test.c
tests/platform/codec2_encode_test.c
EOF
)

View File

@ -32,12 +32,11 @@
#include <dsp.h>
static const size_t audioBufSize = 320;
static const size_t dataBufSize = 2*1024;
static const size_t dataBufSize = 2 * 1024;
void error()
{
while(1)
{
while (1) {
platform_ledOn(RED);
sleepFor(0u, 500u);
platform_ledOff(RED);
@ -47,12 +46,13 @@ void error()
void *mic_task(void *arg)
{
(void) arg;
(void)arg;
struct CODEC2 *codec2 = codec2_create(CODEC2_MODE_3200);
int16_t *audioBuf = ((int16_t *) malloc(audioBufSize * sizeof(int16_t)));
if(audioBuf == NULL) error();
uint8_t *dataBuf = ((uint8_t *) malloc(dataBufSize * sizeof(uint8_t)));
int16_t *audioBuf = ((int16_t *)malloc(audioBufSize * sizeof(int16_t)));
if (audioBuf == NULL)
error();
uint8_t *dataBuf = ((uint8_t *)malloc(dataBufSize * sizeof(uint8_t)));
memset(dataBuf, 0x00, dataBufSize);
sleepFor(0u, 500u);
@ -68,19 +68,21 @@ void *mic_task(void *arg)
dsp_resetFilterState(&dcr);
while(pos < dataBufSize)
{
while (pos < dataBufSize) {
dataBlock_t data = inputStream_getData(id);
if(data.data == NULL) error();
if (data.data == NULL)
error();
// Pre-amplification stage
for(size_t i = 0; i < data.len; i++) data.data[i] <<= 3;
for (size_t i = 0; i < data.len; i++)
data.data[i] <<= 3;
// DC removal
dsp_dcRemoval(&dcr, data.data, data.len);
// Post-amplification stage
for(size_t i = 0; i < data.len; i++) data.data[i] *= 20;
for (size_t i = 0; i < data.len; i++)
data.data[i] *= 20;
codec2_encode(codec2, &dataBuf[pos], data.data);
pos += 8;
@ -89,13 +91,13 @@ void *mic_task(void *arg)
platform_ledOff(GREEN);
sleepFor(10u, 0u);
platform_ledOn(RED);
for(size_t i = 0; i < dataBufSize; i++)
{
for (size_t i = 0; i < dataBufSize; i++) {
iprintf("%02x ", dataBuf[i]);
}
platform_ledOff(RED);
while(1) ;
while (1)
;
return 0;
}
@ -105,15 +107,15 @@ int main()
platform_init();
// Create mic input thread
pthread_t mic_thread;
pthread_t mic_thread;
pthread_attr_t mic_attr;
pthread_attr_init(&mic_attr);
pthread_attr_setstacksize(&mic_attr, 20 * 1024);
pthread_create(&mic_thread, &mic_attr, mic_task, NULL);
while(1) ;
while (1)
;
return 0;
}