No more scratch at the end of wav files playback
This commit is contained in:
+11
-11
@@ -165,7 +165,7 @@ void audioTask(void* pdata)
|
|||||||
#if defined(SDCARD) && !defined(SIMU)
|
#if defined(SDCARD) && !defined(SIMU)
|
||||||
if (toneWavFile[0]) {
|
if (toneWavFile[0]) {
|
||||||
FRESULT result = FR_OK;
|
FRESULT result = FR_OK;
|
||||||
UINT read;
|
UINT read = 0;
|
||||||
uint16_t * bufdata = wavSamplesBuffer;
|
uint16_t * bufdata = wavSamplesBuffer;
|
||||||
if (toneWavFile[1]) {
|
if (toneWavFile[1]) {
|
||||||
result = f_open(&wavFile, toneWavFile, FA_OPEN_EXISTING | FA_READ);
|
result = f_open(&wavFile, toneWavFile, FA_OPEN_EXISTING | FA_READ);
|
||||||
@@ -183,22 +183,22 @@ void audioTask(void* pdata)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != FR_OK || f_read(&wavFile, (uint8_t *)bufdata, 2*WAV_BUFFER_SIZE, &read) != FR_OK || read == 0) {
|
read = 0;
|
||||||
toneWavFile[0] = '\0';
|
if (result != FR_OK || f_read(&wavFile, (uint8_t *)bufdata, 2*WAV_BUFFER_SIZE, &read) != FR_OK || read != 2*WAV_BUFFER_SIZE) {
|
||||||
f_close(&wavFile);
|
for (uint32_t i=read/2; i<WAV_BUFFER_SIZE; i++)
|
||||||
|
bufdata[i] = 0x8000;
|
||||||
|
DACC->DACC_TNCR = read/4;
|
||||||
toneStop();
|
toneStop();
|
||||||
DACC->DACC_TPR = CONVERT_PTR(Sine_values);
|
toneWavFile[0] = '\0';
|
||||||
DACC->DACC_TCR = 50 ; // words, 100 16 bit values
|
toneWavFile[1] = 0;
|
||||||
DACC->DACC_TNPR = CONVERT_PTR(Sine_values);
|
f_close(&wavFile);
|
||||||
DACC->DACC_TNCR = 50 ; // words, 100 16 bit values
|
|
||||||
audioState = 0;
|
audioState = 0;
|
||||||
}
|
}
|
||||||
#if 1
|
#if 1
|
||||||
else {
|
{
|
||||||
read /= 2;
|
read /= 2;
|
||||||
for (uint32_t i=0; i<read; i++) {
|
for (uint32_t i=0; i<read; i++)
|
||||||
bufdata[i] = ((uint16_t)0x8000 + ((int16_t)(bufdata[i]))) >> 4;
|
bufdata[i] = ((uint16_t)0x8000 + ((int16_t)(bufdata[i]))) >> 4;
|
||||||
}
|
|
||||||
if (toneWavFile[1]) {
|
if (toneWavFile[1]) {
|
||||||
toneWavFile[1] = '\0';
|
toneWavFile[1] = '\0';
|
||||||
register Dacc *dacptr = DACC;
|
register Dacc *dacptr = DACC;
|
||||||
|
|||||||
Reference in New Issue
Block a user