TWD in low-latency task

vyo2003
Posts: 19
Joined: Fri Dec 22, 2017 8:36 am

TWD in low-latency task

Postby vyo2003 » Mon Jul 30, 2018 9:31 pm

I develop simple library for playing audio via DAC. In it, using task as data provider is very common pattern (it is very simple to use).

However, task watch dog is triggered very soon. I saw recommendation about turning off TWD completely, but requiring this to do for my library isn't very good, is it?

What is the best way to solve this problem? I use queue to transfer data from task to player function (called using `esp_timer`).
Thanks for your help :D!

vyo2003
Posts: 19
Joined: Fri Dec 22, 2017 8:36 am

Re: TWD in low-latency task

Postby vyo2003 » Mon Jul 30, 2018 10:01 pm

Some news: idle task isn't triggered on esp_timer core, not provider task.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: TWD in low-latency task

Postby ESP_Angus » Tue Jul 31, 2018 3:36 am

Most likely, your task is busy-waiting somewhere (ie polling in a while loop) so it always occupies the CPU and never allows the idle task to run. Try to find a way to block until an interrupt occurs, or until data is received via queue, that doesn't use polling. If you must use polling, find a place you can call vTaskDelay() in the polling loop.

If you're able to share your code, it may be possible to give more specific suggestions.

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: TWD in low-latency task

Postby ESP_Sprite » Tue Jul 31, 2018 3:55 am

Also note that the I2S driver allows you to send samples to the DAC without any CPU involvement at all, allowing you to play sounds while having nearly the full power of the CPU available to do other things. You may want to switch to that instead.

vyo2003
Posts: 19
Joined: Fri Dec 22, 2017 8:36 am

Re: TWD in low-latency task

Postby vyo2003 » Tue Jul 31, 2018 10:49 am

At first, thanks for I2S suggestion. I know about it very well, but my library is for ones like me who don't want external device for playing some audio.

Now back to discussion:
It is pretty fun that library itself doesn't include mistake, but my test program does. This is how it looks:

Code: Select all

#include <sound.h>
#include <soundProviderPcm.h>
#include <memory>

const extern long unsigned int voice_length;
const extern uint8_t voice_data[];

void play_voice() {
	auto provider = std::make_unique<SoundProviderPcm>(voice_data, voice_length, 8000);
	auto player = std::make_unique<SoundMixer>(1, 0, DAC_GPIO25_CHANNEL);
	provider->repeat = true;
	player->play(0, provider.get());
	while (true) {};
}

extern "C" void app_main() {
	play_voice();
}
Just added

Code: Select all

vTaskDelay(100);
to while loop and it is working now!

If you want to look at library:
https://github.com/v1993/esp32-sound (Bug: https://github.com/v1993/esp32-sound/issues/4)
https://github.com/v1993/esp32-sound-pcm

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: TWD in low-latency task

Postby WiFive » Tue Jul 31, 2018 5:13 pm

vyo2003 wrote:At first, thanks for I2S suggestion. I know about it very well, but my library is for ones like me who don't want external device for playing some audio.
He means i2s will write to internal dac too.

Who is online

Users browsing this forum: No registered users and 93 guests