| bool AudioPlaySdWav::play(const char *filename) | bool AudioPlaySdWav::play(const char *filename) | ||||
| { | { | ||||
| stop(); | stop(); | ||||
| #if defined(HAS_KINETIS_SDHC) | |||||
| if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStartUsingSPI(); | |||||
| #else | |||||
| AudioStartUsingSPI(); | AudioStartUsingSPI(); | ||||
| #endif | |||||
| __disable_irq(); | __disable_irq(); | ||||
| wavfile = SD.open(filename); | wavfile = SD.open(filename); | ||||
| __enable_irq(); | __enable_irq(); | ||||
| if (!wavfile) return false; | |||||
| if (!wavfile) { | |||||
| #if defined(HAS_KINETIS_SDHC) | |||||
| if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStopUsingSPI(); | |||||
| #else | |||||
| AudioStopUsingSPI(); | |||||
| #endif | |||||
| return false; | |||||
| } | |||||
| buffer_length = 0; | buffer_length = 0; | ||||
| buffer_offset = 0; | buffer_offset = 0; | ||||
| state_play = STATE_STOP; | state_play = STATE_STOP; | ||||
| if (b1) release(b1); | if (b1) release(b1); | ||||
| if (b2) release(b2); | if (b2) release(b2); | ||||
| wavfile.close(); | wavfile.close(); | ||||
| #if defined(HAS_KINETIS_SDHC) | |||||
| if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStopUsingSPI(); | |||||
| #else | |||||
| AudioStopUsingSPI(); | AudioStopUsingSPI(); | ||||
| #endif | |||||
| } else { | } else { | ||||
| __enable_irq(); | __enable_irq(); | ||||
| } | } | ||||
| } | } | ||||
| end: // end of file reached or other reason to stop | end: // end of file reached or other reason to stop | ||||
| wavfile.close(); | wavfile.close(); | ||||
| #if defined(HAS_KINETIS_SDHC) | |||||
| if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStopUsingSPI(); | |||||
| #else | |||||
| AudioStopUsingSPI(); | AudioStopUsingSPI(); | ||||
| #endif | |||||
| state_play = STATE_STOP; | state_play = STATE_STOP; | ||||
| state = STATE_STOP; | state = STATE_STOP; | ||||
| cleanup: | cleanup: |