newdigate / teensy-variable-playback

Firmware library: variable playback rate for teensy audio library
MIT License
54 stars 7 forks source link

Click at the end of the sample #32

Closed atoktoto closed 3 years ago

atoktoto commented 3 years ago

First of all thanks for sharing this! Not sure if thats not an issue on my side but AudioPlaySdWavResmp seems to emit click at the end of a sample. I'm using generic piano samples that end with silence for testing.

newdigate commented 3 years ago

Hey Andrjez, :) You're welcome.

I have heard a click at the end during certain circumstances. I got around this issue by inserting 4 samples of silence at the end of the wav file.

There is an improvement to make here - basically, when using interpolation, we need to read ahead at least 2 samples. so the audio is 2 samples behind. and when the wav file reaches the end, it doesn't play the remaining samples that are in the look ahead/interpolation buffer.

newdigate commented 3 years ago

Would be interested to know if this solves your issue, adding extra silence at the end.... Otherwise you could send me the wave file and I will be happy to try to reproduce :) thanks

newdigate commented 3 years ago

There is a feature still be implemented which will solve the "extra silence" at end of sample, which hopefully I can sort out soon..

newdigate commented 3 years ago

Not sure if thats not an issue on my side but AudioPlaySdWavResmp seems to emit click at the end of a sample. I'm using generic piano samples that end with silence for testing.

Hey Andrjez,

I think this is fixed, can you give it a try?

newdigate commented 3 years ago

Not sure if thats not an issue on my side but AudioPlaySdWavResmp seems to emit click at the end of a sample. I'm using generic piano samples that end with silence for testing.

Hey Andrjez,

I think this is fixed, can you give it a try?

atoktoto commented 3 years ago

I will need a day or two to get around to that but I will :)

atoktoto commented 3 years ago

I pulled the current master version, updated the usage to the new API but I'm still getting the click. I cannot attach the WAV file directly so I uploaded it here: https://filebin.net/ds1ul8fvaioo4zvg

newdigate commented 3 years ago

Ok, cool. I suspect it’s something to do with tags. currently I export wav without any extra info. I think I know how to fix it. I’ll have a look when I get back from camping on Monday :)

Thanks for the feedback, really appreciate your testing, cheers.

newdigate commented 3 years ago

That should be fixed now on this branch, feaure/wavheader_datasize - If you'd like to test it, and if it works okay, I'll merge to master branch.

I was able to reproduce the issue initially and after I use the data size from the wav header, the click at the end of the sample is gone, but I never managed to test on the teensy yet. Would be really appreciated if you could confirm, thanks. and thanks for reporting the issue.

atoktoto commented 3 years ago

I did a quick test on a teensy and the click seems to still be there. BUT, I did it in the context of a larger codebase. I'm using AudioPlayArrayResmp now and loading the files like this:

File file = SD.open(filename);
uint64_t size = file.size();
buf = extmem_malloc(size);
file.read(buf, size);
file.close();

playWav((unsigned int *)buf, size / 2);
newdigate commented 3 years ago

Ok, I've applied that fix to the array reader now too, so that code above should hopefully not have a click at the end...

atoktoto commented 3 years ago

πŸŽ‰πŸŽ‰ πŸ₯³ No click now πŸ‘

newdigate commented 3 years ago

Thats awesome! πŸ‘ Yay!!!

newdigate commented 3 years ago

going to merge this branch to master, and delete the feature branch... :)