/** * @function OpenWav * @brief open a wav file & start playback * @param const char *path: file path * @return int8_t: -1 -> error; 0 -> ok, the file is being played */ int8_t OpenWav(const char *path) { int8_t res = -1; WavStop(); /*open the file*/ if(f_open(&pFile, "waveform.wav", FA_OPEN_EXISTING | FA_READ) == FR_OK) { /*TODO: check & get wav file information*/ /*WAV files are assumed to be 16bits 1CH 44.1kHz on this project*/ //wav_get_file_info()... /*load file into buffers 1 & 2*/ isBuffer1Empty = true; isBuffer2Empty = true; LoadBuffers(); /*configure the playback frequency & its associated callback*/ TmrSetFrequency(WAV_TIMER, 44100); TmrSetCallback(WAV_TIMER, Callback_1CH_16BITS); /*we always start playback by using BUFFER_1*/ bufferToUse = BUFFER_1; /*start playback*/ //WavPlay(); res = 0; } return res; }
/** * @function WavPlay * @brief launch the WAV playback * @param void (*pOut) (uint16_t dataIn): function to use for playback output * @return none */ void WavPlay(void (*_pOut) (uint16_t dataIn)) { if(isBuffer1Empty == false && _pOut != NULL) { /*if the buffer is not empty (i.e wav file is consistant)*/ pOut = _pOut; TmrLaunch(WAV_TIMER); state = WAV_PLAYING; } else { WavStop(); } }
/** * @function WavProcess * @brief WAV player task; shall be called cyclically * @param none * @return none */ void WavProcess(void) { switch(state) { /*WAV_STOPPED / WAV_PAUSED -> nothing to do*/ case WAV_STOPPED: case WAV_PAUSED: break; /*WAV_PLAYING: check if the buffers are not empty / if the music is finished*/ case WAV_PLAYING: if(LoadBuffers() < 0) { WavStop(); } break; default: WavStop(); break; } }
/** * @function ARB_Stop * @brief stop the arbitrary handler (stop timer, clear current sample #id) * @param arb_st *arb: pointer to the arbitrary waveform handler * @return none */ void ARB_Stop(arb_st *arb) { if(arb != NULL) { arb->run = 0; arb->currentSample = 0; /*stop the timer first, then the DDS*/ TmrStop(ARB_TIMER); AD9834_Stop(0); /*kill the wav playback if any*/ if(arb->waveformType == ARB_WAVE_WAV) { WavStop(); } } }
BOOL CPlayer::UnpreparePlayback(BOOL fEos, BOOL fError) { if (fEos) { if (m_pOutHdr) { OutputBuffer(m_pOutHdr, m_cbOutBuf - m_cbOutBufLeft); m_pOutHdr = NULL; m_cbOutBufLeft = 0; } while (!m_Output.IsFlushed()) { if (m_fPlay && GetStatus() == MAP_STATUS_PLAY) { m_Output.Pause(FALSE); m_fPlay = FALSE; } Sleep(1); if (m_fSeek) return FALSE; if (m_fStop) break; UpdatePeek(); } } m_Output.Close(); m_Echo.Close(); m_Reverb.Close(); m_BassBoost.Close(); m_3DChorus.Close(); m_Decoder.Destroy(); if (!m_Options.fAlwaysOpenDevice || fError) m_Output.CloseAll(); if (m_fOpen == OPEN_URL) { m_Receiver.Disconnect(); m_StreamingStatus = MAP_STREAMING_DISCONNECTED; } m_pOutHdr = NULL; m_cbOutBufLeft = 0; m_nSeek = 0; m_fPlay = FALSE; m_fStop = FALSE; m_fSeek = FALSE; switch (m_fOpen) { case OPEN_PLUGIN: PlugInStop(); break; case OPEN_MPG_FILE: MpgStop(); break; case OPEN_OV_FILE: OvStop(); break; case OPEN_WAV_FILE: WavStop(); break; case OPEN_URL: NetStop(); break; } PostMessage(m_hwndMessage, MAP_MSG_PEEK, 0, 0); UpdateStatus(MAP_STATUS_STOP, fError); return TRUE; }