We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello guys, some one have experience to playing an wave file sampled at 44100Khz with 8 bit resolution mono by PWM micro device ? I use STM Cortex 103 and I have also demo board that use this way to playng the file wave, but on board there is a SPI flash with file wave content. I in my real application don't have this memory and I can use only SDcard. I have one timer interrupt that every 22 uS (time of sampled) operates taking one byte from buffer, so the buffer (large 2048 bytes) will reach the last byte after 45mS. In this time I must refill the old buffer and so way alternately. Teorically it should work but I have big problem... some times the refill of buffer from SdCard is too slow.. fread from keil library lose 90mS... incredible !! If I use only fread without starting the PWM, it works correctly. Some suggestion ?
Thank a lot Nicola
If you only have 8-bit resolution, then you should also drop the sampling rate. 11kHz would probably be a better sampling rate.
Thank for your reply. It is true but at this problem I'll think later because now the my primary problem is another.
Cheers, Nicola
How many bytes do you read from the SD-Card with a single fread()?
I don't know much about this, but it seems that, the less bytes you fread(), the better performance you get.
It was long time ago (more than one year), and I did not keep my earlier versions of that demo projects of wav file playing, so I can't recall the details, but I remember that, at the earlier stage, I fread() as many bytes as I can, and the result was bad. then I "guess" that, there might be some cache mechanism implemented by RL-Flash, I tried to fread() as less bytes as I need, and the result was better.
Thanks John, I Tryed use to Fread() to read also only one byte, but sometime the read is very very long time. Maybe the problem doesn't in file system library but elsewhere. I'm using the RTX SO with one only task... but shouldn't to depend by this.
have one timer interrupt that every 22 uS (time of sampled) operates taking one byte from buffer
Are you generating an interrupt each 22us? That sounds like a serious overhead to me. Can't you collect more bytes, less frequently?
Hello Michael, I just reloading the PWM register every 22Us and it's a very fast operation (I use 64Mhz clock). The 22uS is the time to sample of the file wave and when the buffer (2048 bytes) is empty I read the file in SdCard again.
Thank, Cheers
Nicola
=> when the buffer (2048 bytes) is empty I read the file in SdCard again. <=
In my demo project, I fread() several bytes, then check if it is time to play sound.
while ( playcnt < Samp2Play ) { if (wavBufTAIL == (BUFSIZE-1) ) { wavBufTAILnxt = 0; } else { wavBufTAILnxt = wavBufTAIL + 1; } if ( ( wavBufTAILnxt != wavBufHEAD ) && ( fpos < Samp2Play ) ) { switch ( swh ) { case 1: fread(&sample1BUF, 1, 1, wav); wav_BUFFER[wavBufTAIL] = sample1BUF; break; default: break; } fpos++; wavBufTAIL = wavBufTAILnxt; } if ( timer0_counter == 0 ) { if ( wavBufHEAD != wavBufTAIL ) { DACR = (wav_BUFFER[wavBufHEAD] << 6) | DAC_BIAS; playcnt++; if ( wavBufHEAD == (BUFSIZE-1) ) { wavBufHEAD = 0; } else { wavBufHEAD++; } } timer0_counter = SampRate; } }