-
Notifications
You must be signed in to change notification settings - Fork 12
Description
I've tried to write a very simple bit of code to use codec2 on an nrf52 based board (RAK4631), but it hangs when it tries to run the encode function - am I doing something wrong, if not any suggestions on how to debug?
`
#include "codec2.h"
void setup()
{
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 3000)
{
delay(100);
}
else
{
break;
}
}
}
// Missing from the library for the nrF (available for ESP)
int codec2_bytes_per_frame(struct CODEC2 *c2) {
return (codec2_bits_per_frame(c2) + 7) / 8;
}
void loop()
{
Serial.println("Codec Testing....");
CODEC2 *codec2_state;
int codec2_sample_size, codec2_compressed_size, outgoing_buf_size;
short *outgoing_buffer, *incomming_buffer;
unsigned char *out_compressed_buffer;
codec2_state = codec2_create(CODEC2_MODE_3200);
if (codec2_state == NULL)
{
Serial.println("Failed to create Codec2");
return;
}
else
{
Serial.println("Codec2 created");
}
// Set LPC post-filter to improve the clarity of decoded speech
//codec2_set_lpc_post_filter(codec2_state, 1, 0, 0.8, 0.2);
// Number of samples required by Codec2 to process each frame of audio data
codec2_sample_size = codec2_samples_per_frame(codec2_state);
// The amount of data compressed by Codec2
codec2_compressed_size = codec2_bytes_per_frame(codec2_state);
outgoing_buf_size = sizeof(short) * codec2_sample_size;
outgoing_buffer = (short *)malloc(outgoing_buf_size);
out_compressed_buffer = (unsigned char *)malloc(sizeof(unsigned char) * codec2_compressed_size);
// Create a buffer for the incomming data
// For this breif code just use the random data in the buffer upon creation.
incomming_buffer = (short *)malloc(outgoing_buf_size);
Serial.print("Codec2 initialization successful");
Serial.print("codec2_sample_size:");
Serial.println(codec2_sample_size);
Serial.print("codec2_compress_size:");
Serial.println(codec2_compressed_size);
Serial.println("Encoded Block:");
codec2_encode(codec2_state, out_compressed_buffer, outgoing_buffer);
Serial.println("Done");
while(1) ; // stop here.
}`