Re #457: audio working in Companion, Simulator and simu using SDL library (use SIMU_AUDIO=YES to enable)

Re #457: case insensitive f_stat() and f_open() for SIMU
This commit is contained in:
Damjan Adamic
2015-02-22 15:49:15 +01:00
parent 434baf15c4
commit 41cd128ad5
14 changed files with 351 additions and 54 deletions
+31 -4
View File
@@ -362,14 +362,17 @@ void referenceModelAudioFiles()
// Eliminates directories / non wav files
if (len < 5 || strcasecmp(fn+len-4, SOUNDS_EXT) || (fno.fattrib & AM_DIR)) continue;
TRACE("referenceModelAudioFiles(): using file: %s", fn);
// Phases Audio Files <phasename>-[on|off].wav
for (int i=0; i<MAX_FLIGHT_MODES && !found; i++) {
for (int event=0; event<2; event++) {
getPhaseAudioFile(path, i, event);
// TRACE("referenceModelAudioFiles(): searching for %s in %s", filename, fn);
if (!strcasecmp(filename, fn)) {
sdAvailablePhaseAudioFiles |= MASK_PHASE_AUDIO_FILE(i, event);
found = true;
TRACE("\tfound: %s", filename);
break;
}
}
@@ -378,9 +381,11 @@ void referenceModelAudioFiles()
// Switches Audio Files <switchname>-[up|mid|down].wav
for (int i=0; i<SWSRC_LAST_SWITCH+NUM_XPOTS*XPOTS_MULTIPOS_COUNT && !found; i++) {
getSwitchAudioFile(path, i);
// TRACE("referenceModelAudioFiles(): searching for %s in %s", filename, fn);
if (!strcasecmp(filename, fn)) {
sdAvailableSwitchAudioFiles |= MASK_SWITCH_AUDIO_FILE(i);
found = true;
TRACE("\tfound: %s", filename);
}
}
@@ -388,9 +393,11 @@ void referenceModelAudioFiles()
for (int i=0; i<NUM_LOGICAL_SWITCH && !found; i++) {
for (int event=0; event<2; event++) {
getLogicalSwitchAudioFile(path, i, event);
// TRACE("referenceModelAudioFiles(): searching for %s in %s", filename, fn);
if (!strcasecmp(filename, fn)) {
sdAvailableLogicalSwitchAudioFiles |= MASK_LOGICAL_SWITCH_AUDIO_FILE(i, event);
found = true;
TRACE("\tfound: %s", filename);
break;
}
}
@@ -499,10 +506,14 @@ void audioTask(void* pdata)
void mixSample(uint16_t * result, int sample, unsigned int fade)
{
#if defined(SIMU_AUDIO)
*result = limit(0, *result + ((sample >> fade) ), 0xFFFF);
#else
*result = limit(0, *result + ((sample >> fade) >> 4), 4095);
#endif
}
#if defined(SDCARD) && !defined(SIMU)
#if defined(SDCARD)
#define RIFF_CHUNK_SIZE 12
uint8_t wavBuffer[AUDIO_BUFFER_SIZE*2];
@@ -695,7 +706,11 @@ void AudioQueue::wakeup()
// write silence in the buffer
for (uint32_t i=0; i<AUDIO_BUFFER_SIZE; i++) {
#if defined(SIMU_AUDIO)
buffer->data[i] = 0x8000; /* silence */
#else
buffer->data[i] = 0x8000 >> 4; /* silence */
#endif
}
// mix the priority context (only tones)
@@ -751,6 +766,7 @@ void AudioQueue::wakeup()
// push the buffer if needed
if (size > 0) {
__disable_irq();
// TRACE("pushing buffer %d\n", bufferWIdx);
bufferWIdx = nextBufferIdx(bufferWIdx);
buffer->size = size;
buffer->state = dacQueue(buffer) ? AUDIO_BUFFER_PLAYING : AUDIO_BUFFER_FILLED;
@@ -793,6 +809,10 @@ bool AudioQueue::isPlaying(uint8_t id)
void AudioQueue::playTone(uint16_t freq, uint16_t len, uint16_t pause, uint8_t flags, int8_t freqIncr)
{
#if defined(SIMU) && !defined(SIMU_AUDIO)
return;
#endif
CoEnterMutexSection(audioMutex);
if (freq && freq < BEEP_MIN_FREQ) {
@@ -849,9 +869,13 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id)
TRACE("playFile(\"%s\", flags=%x, id=%d)", filename, flags, id);
if (strlen(filename) > AUDIO_FILENAME_MAXLEN) {
TRACE("file name too long! maximum length is %d characters", AUDIO_FILENAME_MAXLEN);
return;
}
fflush(stdout);
#else
#if !defined(SIMU_AUDIO)
return;
#endif
#endif
if (!sdMounted())
return;
@@ -887,7 +911,6 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id)
}
CoLeaveMutexSection(audioMutex);
#endif
}
void AudioQueue::stopPlay(uint8_t id)
@@ -896,6 +919,10 @@ void AudioQueue::stopPlay(uint8_t id)
TRACE("stopPlay(id=%d)", id);
#endif
#if defined(SIMU) && !defined(SIMU_AUDIO)
return;
#endif
// For the moment it's only needed to stop the background music
if (backgroundContext.fragment.id == id) {
backgroundContext.fragment.type = FRAGMENT_EMPTY;