-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
speaker streaming and playRaw() #29
Comments
Hello. @belm0 If you can present code that can reproduce the problem, please show it to me. |
@belm0 Please prepare multiple data buffers on the user code side and use them in order. Specifically, there are two ways to do this. Method 1
Method 2
|
I was using double buffer-- I'm surprised that triple buffer is needed. However, I've updated my test to use 4 buffers, and the output is still not smooth. So I must be missing something obvious. M5.begin();
M5.Speaker.begin();
M5.Speaker.setVolume(64);
M5.Speaker.tone(2000, 100);
delay(1000);
int buf_size = 4096;
auto buf = new uint8_t[buf_size];
int blk_size = buf_size / 4;
int count = 0;
for (int index = 0; ; index = (index + 1) % 4) {
auto blk = buf + blk_size * index;
for (int i = 0; i < blk_size; ++i) {
blk[i] = count % 99;
++count;
}
M5.Speaker.playRAW(blk, blk_size, 22050, false, 1, 0);
} |
@belm0 |
@belm0
|
Thank you. I did intend sawtooth wave in the test. I haven't looked at the output waveform, but I can hear that it has obvious artifacts. And the artifact varies with the configured buffer size. I'm using Core2. Here is zip with crude recording of buf_size 4096 and 2048 cases. |
I have a Core Basic too, and it seems to be the same problem. So is it about library or platform version?
Audio demos seem OK, and when I use i2c API directly it sounds as expected. |
test.mp4I am unable to reproduce the phenomenon. I have no idea what the cause is. M5Unified : v0.0.7 |
It seems to be working now-- sorry for the trouble. The original problem was using double instead of triple buffering. However, to make the example code shared above, I switched to Arduino IDE that had an old M5Unified version (0.0.5) which seems to have some other problem. On v0.0.7 or latest Speaker code it seems OK. In Speaker.hpp, if you would mention that playRaw() needs triple buffer for streaming it might be helpful to others. Thank you! |
I am glad your problem was resolved. |
memo: The thread calling playRaw() should have priority >= 1, even for applications with low CPU use. Otherwise there may be several milliseconds of delay either in waking the thread or receiving notifications, causing missed buffer deadlines. |
This ticket can be closed as resolved; the OP has indicated to be happy with the answer (and a description was added to the comments). |
Naively, I thought that repeated calls to
Speaker.playRaw()
on the same channel withstop_current_sound=false
would connect exactly, without a gap. But I tried it and there seems to be clicking artifacts due to a gap.We could use it to simply stream from an audio file or real-time generated waveform.
Since Speaker has multiple channels and various functionality, it would be nice to combine streaming on one channel with one-shot sounds on other channels under a single API.
Do I understand it correctly? 🙏 @lovyan03
The text was updated successfully, but these errors were encountered: