Skip to content

Commit

Permalink
Release V2.1 R1
Browse files Browse the repository at this point in the history
New KaRadio32 Release 2.1 R1.
Some streams was not well received (Beatles radio and some 320K
streams).
Added a font mapping for utf8 extended latin characters.
wake and sleep timers corrected
  • Loading branch information
karawin committed Feb 18, 2021
1 parent ec6daa7 commit f03d246
Show file tree
Hide file tree
Showing 24 changed files with 713 additions and 560 deletions.
Binary file added binaries/KaRadio32_20R0.bin
Binary file not shown.
Binary file added binaries/KaRadio32_20R1.bin
Binary file not shown.
Binary file not shown.
Binary file added binaries/KaRadio32_21R1.bin
Binary file not shown.
5 changes: 3 additions & 2 deletions components/audio_player/audio_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static int start_decoder_task(player_t *player)

task_func = fdkaac_decoder_task;
task_name = (char*)"fdkaac_decoder_task";
stack_depth = 7000; //6144;
stack_depth = 6900; //6144;
break;

/*
Expand Down Expand Up @@ -144,7 +144,7 @@ int audio_stream_consumer(const char *recv_buf, ssize_t bytes_read,
t = 0;
// uint32_t trigger = (bigSram())? (70*1024):(20*1024);
// bool buffer_ok = (bytes_in_buf > trigger);
bool buffer_ok = (fill_level > bigSram()?20:50); // in %
bool buffer_ok = (fill_level > (bigSram()?10:70)); // in %
if (buffer_ok)
{
// buffer is filled, start decoder
Expand All @@ -155,6 +155,7 @@ int audio_stream_consumer(const char *recv_buf, ssize_t bytes_read,
clientDisconnect("decoder failed");
return -1;
}
ESP_LOGI(TAG, "Buffer fill %u%%, %d // %d bytes", fill_level, bytes_in_buf,spiRamFifoLen());
}
}

Expand Down
11 changes: 1 addition & 10 deletions components/audio_renderer/audio_renderer1.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
uint8_t* outBuf8;
uint32_t* outBuf32;
uint64_t* outBuf64;

if (buf_len == 0) return; // decoder error
// handle changed sample rate
if(renderer_instance->sample_rate != buf_desc->sample_rate)
{
Expand Down Expand Up @@ -340,15 +340,6 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
}
// if (bytes_written != bytes_left) ESP_LOGV(TAG, "written: %d, len: %d",bytes_written,bytes_left);

/* size_t bytes_left = buf_len*(2/buf_desc->num_channels);
size_t bytes_written = 0;
while(bytes_left > 0 && renderer_status != STOPPED) {
res = i2s_write(renderer_instance->i2s_num, (const char*) outBuf8, bytes_left,& bytes_written, max_wait);
if (res != ESP_OK) {
ESP_LOGE(TAG, "i2s_write error %d",res);
}
if (bytes_written != buf_len*(2/buf_desc->num_channels))ESP_LOGV(TAG, "written: %d, len: %d",bytes_written,bytes_left);
*/

bytes_left -= bytes_written;
buf += (bytes_written );
Expand Down
57 changes: 14 additions & 43 deletions components/fdk-aac_decoder/fdk_aac_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void fdkaac_decoder_task(void *pvParameters)
buffer_t *pcm_buf = buf_create(OUTPUT_BUFFER_SIZE);

/* allocate bitstream buffer */
buffer_t *in_buf = buf_create(INPUT_BUFFER_SIZE*24);
buffer_t *in_buf = buf_create(INPUT_BUFFER_SIZE*48);
fill_read_buffer(in_buf);

HANDLE_AACDECODER handle = NULL;
Expand All @@ -55,37 +55,6 @@ void fdkaac_decoder_task(void *pvParameters)
/* select bitstream format */
if (player->media_stream->content_type == AUDIO_MP4)
{
/*
demux_res_t demux_res;
stream_t input_stream;
memset(&demux_res, 0, sizeof(demux_res));
stream_create(&input_stream, in_buf);
fill_read_buffer(in_buf);
if (!qtmovie_read(&input_stream, &demux_res)) {
ESP_LOGE(TAG, "qtmovie_read failed");
goto cleanup;
} else {
ESP_LOGI(TAG, "qtmovie_read success");
}
//create decoder instance
handle = aacDecoder_Open(TT_MP4_RAW,1); // num layers
if (handle == NULL) {
ESP_LOGE(TAG, "malloc failed %d", __LINE__);
goto cleanup;
}
// If out-of-band config data (AudioSpecificConfig(ASC) or StreamMuxConfig(SMC)) is available
// uint8_t ascData[1] = {demux_res.codecdata};
// const uint32_t ascDataLen[1] = {demux_res.codecdata_len};
err = aacDecoder_ConfigRaw(handle,(UCHAR **) &demux_res.codecdata, &demux_res.codecdata_len);
if (err != AAC_DEC_OK) {
ESP_LOGE(TAG, "aacDecoder_ConfigRaw error %d", err);
goto cleanup;
}
*/
goto cleanup;
} else {
/* create decoder instance */
Expand All @@ -111,32 +80,36 @@ void fdkaac_decoder_task(void *pvParameters)
while (!player->media_stream->eof) {

/* re-fill buffer if necessary */
if (buf_data_unread(in_buf) == 0) {
if (buf_data_unread(in_buf) == 0) {
fill_read_buffer(in_buf);
vTaskDelay(3);
}
// vTaskDelay(1);
if(player->decoder_command == CMD_STOP) {
goto abort;
} }

// watchgog reset
TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed=1;
TIMERG0.wdt_wprotect=0;


if(player->decoder_command == CMD_STOP) {
/* if(player->decoder_command == CMD_STOP) {
goto abort;
}

*/
// bytes_avail will be updated and indicate "how much data is left"
size_t bytes_avail = buf_data_unread(in_buf);
aacDecoder_Fill(handle, &in_buf->read_pos, &bytes_avail, &bytes_avail);

uint32_t bytes_taken = buf_data_unread(in_buf) - bytes_avail;
buf_seek_rel(in_buf, bytes_taken);

// buf_seek_rel(in_buf, bytes_taken);
in_buf->read_pos += bytes_taken;
in_buf->bytes_consumed += bytes_taken;

err = aacDecoder_DecodeFrame(handle, (short int *) pcm_buf->base,
pcm_buf->len, flags);


// need more bytes, lets refill
if(err == AAC_DEC_TRANSPORT_SYNC_ERROR || err == AAC_DEC_NOT_ENOUGH_BITS) {
continue;
Expand Down Expand Up @@ -166,14 +139,12 @@ void fdkaac_decoder_task(void *pvParameters)
pcm_format.num_channels = mStreamInfo->numChannels;
pcm_format.sample_rate = mStreamInfo->sampleRate;
}
// vTaskDelay(1);
// taskYIELD ();

render_samples((char *) pcm_buf->base, pcm_size, &pcm_format);

// ESP_LOGI(TAG, "fdk_aac_decoder stack: %d\n", uxTaskGetStackHighWaterMark(NULL));
// ESP_LOGI(TAG, "%u free heap %u", __LINE__, esp_get_free_heap_size());

// about 32K free heap at this point
}
goto cleanup;
// exit on internal error
Expand All @@ -189,7 +160,7 @@ void fdkaac_decoder_task(void *pvParameters)
ESP_LOGI(TAG, "aac decoder finished %x %x",(int)in_buf,(int)pcm_buf);
aacDecoder_Close(handle);
spiRamFifoReset();
buf_destroy(in_buf);
//buf_destroy(in_buf);
buf_destroy(pcm_buf);
//esp_task_wdt_delete(NULL);

Expand Down
25 changes: 11 additions & 14 deletions components/fifo/spiram_fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
static unsigned fifoRpos;
static unsigned fifoWpos;
static unsigned fifoFill;
static xSemaphoreHandle semCanRead;
static xSemaphoreHandle semCanWrite;
//static xSemaphoreHandle semCanRead;
//static xSemaphoreHandle semCanWrite;
static xSemaphoreHandle mux;
static long fifoOvfCnt, fifoUdrCnt;

Expand All @@ -44,7 +44,7 @@ static long fifoOvfCnt, fifoUdrCnt;
//Re-define a bunch of things so we use the internal buffer
#undef SPIRAMSIZE
//allocate enough for about one mp3 frame

//#define SPIRAMSIZE (42*1024)
//static char fakespiram[SPIRAMSIZE];
static char *fakespiram;
#define spiRamInit() while(0)
Expand Down Expand Up @@ -72,11 +72,10 @@ int spiRamFifoInit() {
fifoFill=0;
fifoOvfCnt=0;
fifoUdrCnt=0;
vSemaphoreCreateBinary(semCanRead);
vSemaphoreCreateBinary(semCanWrite);
// vSemaphoreCreateBinary(semCanRead);
// vSemaphoreCreateBinary(semCanWrite);
mux=xSemaphoreCreateMutex();
// spiRamInit();
// return (spiRamTest());
return ((int) fakespiram);
}

Expand All @@ -88,8 +87,8 @@ void spiRamFifoReset() {
fifoOvfCnt=0;
fifoUdrCnt=0;
memset( fakespiram, 0, SPIRAMSIZE );
xSemaphoreGive(semCanWrite);
xSemaphoreTake(semCanRead, portMAX_DELAY);
// xSemaphoreGive(semCanWrite);
// xSemaphoreTake(semCanRead, portMAX_DELAY);
xSemaphoreGive(mux);
}

Expand Down Expand Up @@ -120,7 +119,7 @@ void spiRamFifoRead(char *buff, unsigned len) {
fifoRpos += n;
if (fifoRpos>=SPIRAMSIZE) fifoRpos=0;
xSemaphoreGive(mux);
xSemaphoreGive(semCanWrite); //Indicate writer thread there's some free room in the fifo
// xSemaphoreGive(semCanWrite); //Indicate writer thread there's some free room in the fifo
}
} else {printf("spiRamFifoRead MUX take failed\n"); }
}
Expand All @@ -146,7 +145,7 @@ void spiRamFifoWrite(const char *buff, unsigned buffLen) {
// Drat, not enough free room in FIFO. Wait till there's some read and try again.
fifoOvfCnt++;
xSemaphoreGive(mux);
xSemaphoreTake(semCanWrite, portMAX_DELAY);
// xSemaphoreTake(semCanWrite, portMAX_DELAY);
vTaskDelay(10);
} else {
// Write the data.
Expand All @@ -157,7 +156,7 @@ void spiRamFifoWrite(const char *buff, unsigned buffLen) {
fifoWpos += n;
if (fifoWpos >= SPIRAMSIZE) fifoWpos = 0;
xSemaphoreGive(mux);
xSemaphoreGive(semCanRead); // Tell reader thread there's some data in the fifo.
// xSemaphoreGive(semCanRead); // Tell reader thread there's some data in the fifo.
}
} else {printf(" spiRamFifoWrite MUX take failed\n"); }
}
Expand All @@ -180,7 +179,6 @@ unsigned spiRamFifoFree() {
void spiRamFifoDestroy() {
if (fakespiram) free (fakespiram);
}

unsigned spiRamFifoLen() {
return SPIRAMSIZE;
}
Expand All @@ -199,5 +197,4 @@ long spiRamGetUnderrunCt() {
long ret=fifoUdrCnt;
xSemaphoreGive(mux);
return ret;
}

}
Loading

0 comments on commit f03d246

Please sign in to comment.