//***************************************************************************** // //! Starts playback of a song. //! //! \param pusSong is a pointer to the song data structure. //! \param ulLength is the length of the song data structure in bytes. //! //! This function starts the playback of a song or sound effect. If a song //! or sound effect is already being played, its playback is canceled and the //! new song is started. //! //! \return None. // //***************************************************************************** void SoundPlay(const unsigned short *pusSong, unsigned long ulLength) { // // Set the format of the audio stream. // SoundSetFormat(48000, 16, 2); // // Save the music buffer. // g_ulMusicCount = 0; g_ulMusicSize = ulLength * 2; g_pusMusic = pusSong; g_ulPlaying = 0; g_sOutBuffers[0].pulData = 0; g_sOutBuffers[1].pulData = 0; if(SoundNextTone() != 0) { SoundBufferPlay(g_pulTxBuf, g_ulSize, BufferCallback); SoundBufferPlay(g_pulTxBuf, g_ulSize, BufferCallback); } }
//////////////////////////////////////////////////////////// /// Show the initial video //////////////////////////////////////////////////////////// void IntroShow() { struct Video VideoIntro; VideoLoad(&VideoIntro, INTRO_VIDEO_THEME); SoundBufferPlay(INTRO_SOUND_THEME, false, 0, 0, 0); while (VideoIntro.Loaded && !VideoIntro.Finished) { // Render it VideoRender(&VideoIntro, false, 0, 0, WindowWidth, WindowHeight); // Display on window handle WindowDisplay(); // Process input events WindowProcessEvents(); } // Stop music SoundBufferStop(); // Delete the video VideoDelete(&VideoIntro); }
//***************************************************************************** // // Handles playback of the single buffer when playing tones. // //***************************************************************************** static void BufferCallback(const void *pvBuffer, unsigned long ulEvent) { if((ulEvent & BUFFER_EVENT_FREE) && (g_ulTicks != 0)) { // // Kick off another request for a buffer playback. // SoundBufferPlay(pvBuffer, g_ulSize, BufferCallback); // // Count down before stopping. // g_ulTicks--; } else { // // Stop requesting transfers. // I2STxDisable(I2S0_BASE); } }
//***************************************************************************** // // This function is called to decode a buffer into a playable buffer. // //***************************************************************************** void Decode(void *pvBuffer, unsigned long ulSize) { // // If in pass through mode then just copy the data to the play buffer. // if(HWREGBITW(&g_ulFlags, FLAG_BYPASS)) { memcpy(g_pucPlay, pvBuffer, PLAY_BUFFER_INC); } else { // // Decode the frame and write it out to play buffer. // SpeexDecode(pvBuffer, ulSize, g_pucPlay, PLAY_BUFFER_INC); } // // Schedule the new buffer to start playing. // SoundBufferPlay(g_pucPlay, PLAY_BUFFER_INC, PlayBufferCallback); // // Advance the play pointer. // g_pucPlay += PLAY_BUFFER_INC; // // Wrap the play pointer if necessary. // if(g_pucPlay >= &g_pucPlayBuffer[PLAY_BUFFER_SIZE]) { g_pucPlay = g_pucPlayBuffer; } }