Skip to content

Commit

Permalink
feat(sim): startup can be slow when scanning SYSTEM audio files (#5822)
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored Jan 25, 2025
1 parent fa5dea6 commit 0e8f893
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions radio/src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ void referenceSystemAudioFiles()

sdAvailableSystemAudioFiles.reset();

#if defined(SIMU)
// f_readdir does an f_stat call on every file when running in the simulator
// so it is faster to just call f_stat on the files we are interested in
for (int i=0; i<AU_SPECIAL_SOUND_FIRST; i++) {
getSystemAudioFile(path, i);
if (f_stat(path, nullptr) == FR_OK)
sdAvailableSystemAudioFiles.setBit(i);
}
#else
// On the radio f_readdir on the whole SYSTEM folder is faster than
// calling f_stat for each audio file name
char * filename = strAppendSystemAudioPath(path);
*(filename-1) = '\0';

Expand All @@ -227,15 +238,17 @@ void referenceSystemAudioFiles()
if (len < 5 || strcasecmp(fno.fname+len-4, SOUNDS_EXT) || (fno.fattrib & AM_DIR)) continue;

for (int i=0; i<AU_SPECIAL_SOUND_FIRST; i++) {
getSystemAudioFile(path, i);
if (!strcasecmp(filename, fno.fname)) {
strcpy(path, audioFilenames[i]);
strcat(path, SOUNDS_EXT);
if (!strcasecmp(path, fno.fname)) {
sdAvailableSystemAudioFiles.setBit(i);
break;
}
}
}
f_closedir(&dir);
}
#endif
}

void referenceModelAudioFiles()
Expand Down

0 comments on commit 0e8f893

Please sign in to comment.