⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 play.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
//****************************************************************************//// PLAY.C - Routines for playing audio from a file.//// Copyright (c) 1999,2000,2001 Cirrus Logic, Inc.////****************************************************************************#include "globals.h"#include "../hwport.h"//****************************************************************************//// OpenTrack prepares to decode and play the specified track.////****************************************************************************static voidOpenTrack(tFile *pFile){    unsigned long ulSampleRate, ulChannels, ulDrive, ulFile, ulCodec;    unsigned short usFileName[64];    tDir sDir;    //    // Get the drive, file number, and codec for this track.    //    ulDrive = (pusTracks[ulTrack] & TRACK_DRIVE_MASK) >> TRACK_DRIVE_SHIFT;    ulFile = (pusTracks[ulTrack] & TRACK_FILE_MASK) >> TRACK_FILE_SHIFT;    ulCodec = (pusTracks[ulTrack] & TRACK_CODEC_MASK) >> TRACK_CODEC_SHIFT;    //    // Open the root directory of the first drive.    //    FSOpenDir(&sDir, ulDrive, (unsigned short *)"\\\0\0");    //    // Skip to the appropriate file in the root directory.    //    do    {        FSReadDir(&sDir, usFileName, FS_TYPE_FILE);    }    while(ulFile--);    //    // Close the directory.    //    FSCloseDir(&sDir);    //    // Open this file.    //    FSOpen(pFile, ulDrive, usFileName, FS_OPEN_READ | FS_OPEN_DECRYPT);    //    // See if we are able to decode this file.    //    CodecOpen(ulCodec, CODEC_OPEN_DECODE, pFile);    //    // Set the sample rate of the output processing.    //    CodecGetSampleRate(&ulSampleRate);    CodecGetChannels(&ulChannels);    OutputSetFormat(ulSampleRate, ulChannels);    //    // Set the output buffer for the decoder.    //    CodecSetBuffer(OutputGetInputBuffer());    //    // Try to load the Audible meta-data for this file.    //#ifdef SUPPORT_AUDIBLE    AudibleLoadMetaData(ulDrive, usFileName);#endif    //    // Inform the user interface that a new file has been loaded.    //    UIFileLoaded(usFileName, ulTrack);    //    // Inform the user interface of the current time.    //#ifdef SUPPORT_AUDIBLE    CodecGetTime(&ulDrive);    UISetCurrentTime(ulDrive);#endif}//****************************************************************************//// CloseTrack closes the currently opened file.////****************************************************************************static voidCloseTrack(tFile *pFile){    BufferState *pBuffer;#ifdef SUPPORT_AUDIBLE    unsigned long ulPosition;#endif    //    // Get the output processing's input buffer.    //    pBuffer = OutputGetInputBuffer();    //    // Wait until all of the output data has been consumed.    //    while(!BufferIsEmpty(pBuffer))    {        //        // Put the EP7209 into IDLE mode.        //        Halt();    }    //    // Get the current playback position.    //#ifdef SUPPORT_AUDIBLE    CodecGetTime(&ulPosition);#endif    //    // Close the codec.    //    CodecClose();    //    // Close the file.    //    FSClose(pFile);    //    // Save the current playback position if this is an Audible program.    //#ifdef SUPPORT_AUDIBLE    FSSetWriteScratch((unsigned char *)ulEndOfRAM);    AudibleUpdateMetaData((unsigned char *)(ulEndOfRAM + 512), ulPosition);    FSSetWriteScratch(0);#endif}//****************************************************************************//// NextTrack closes the current track and advances to the next track.////****************************************************************************static voidNextTrack(tFile *pFile){    //    // Close the currently opened track.    //    CloseTrack(pFile);    //    // Skip to the next track.    //    ulTrack++;    //    // If this was the last track, then go back to the first track.    //    if(pusTracks[ulTrack] == 0xffff)    {        //        // See if the external media has been inserted.        //        if(ulSystemFlags & SYSFLAG_MEDIA_INSERT)        {            //            // Handle the insert of the external media.            //            MediaInserted();        }        //        // See if this is still the last track.        //        if(pusTracks[ulTrack] == 0xffff)        {            //            // Go back to the first track.            //            ulTrack = 0;        }    }    //    // Open the next track.    //    OpenTrack(pFile);}//****************************************************************************//// PreviousTrack closes the current track and advances to the previous track.////****************************************************************************static voidPreviousTrack(tFile *pFile){    //    // Close the currently opened track.    //    CloseTrack(pFile);    //    // See if we are at the first track.    //    if(ulTrack == 0)    {        //        // See if the external media has been inserted.        //        if(ulSystemFlags & SYSFLAG_MEDIA_INSERT)        {            //            // Handle the insert of the external media.            //            MediaInserted();        }        //        // Find the final track.        //        for(ulTrack = 0; ulTrack < (MAX_TRACKS - 1); ulTrack++)        {            //            // Is the next track the final track?            //            if(pusTracks[ulTrack + 1] == 0xffff)            {                break;            }        }    }    //    // Otherwise, simply skip to the previous track.    //    else    {        ulTrack--;    }    //    // Open the previous track.    //    OpenTrack(pFile);}//****************************************************************************//// Play decodes an audio file and plays it out via the digital audio// interface.////****************************************************************************unsigned longPlay(void){    tFile sFile;    unsigned long ulButtons, ulMode;    //    // Set the player mode to stopped.    //    ulMode = MODE_STOP;    //    // Open the current track.    //    OpenTrack(&sFile);    //    // Inform the user interface that we are stopped.    //    UISetMode(MODE_STOP);    //    // Handle playback operations until we encounter a condition which causes    // us to leave playback mode (i.e. download, the record button, etc.).    //    while(1)    {        //        // See if we are playing.        //        if(ulMode == MODE_PLAY)        {            //            // See if the decoder is able to decode the next frame.            //            while(CodecCanDecode() == 0)            {                //                // Put the EP7209 into HALT mode.                //                Halt();            }            //            // Tell the decoder to decode another frame.            //            if(CodecDecode() == 0)            {                //                // If this is an Audible program, then set the played through                // indicator.                //#ifdef SUPPORT_AUDIBLE                if(AudibleIsAudibleProgram())                {                    AudibleSetPlayedThrough();                }#endif                //                // Seek to the beginning of the song.                //                CodecSeek(0);                //                // If we are in repeat one track mode, then we simply continue                // playback of this track.                //                if((ulSystemFlags & SYSFLAG_REPEAT_MASK) == SYSFLAG_REPEAT_ONE)                {                    //                    // Inform the user interface of the new song position.                    //                    UISetCurrentTime(0);                }                else                {                    //                    // Otherwise, go to the next track.                    //                    NextTrack(&sFile);                    //                    // If we are back at track zero, then see if we need to                    // stop the player (i.e. we are not in repeat all mode).                    //                    if((ulTrack == 0) &&                       ((ulSystemFlags & SYSFLAG_REPEAT_MASK) !=                        SYSFLAG_REPEAT_ALL))                    {                        //                        // Disable the output processing.  This function will                        // wait until all the data has been played before                        // shutting down the digital audio interface and                        // returning.                        //                        OutputDisable();                        //                        // Stop the player.                        //                        ulMode = MODE_STOP;                        //                        // Inform the user interface that we are now stopped.                        //                        UISetMode(MODE_STOP);                    }                }            }            else            {                unsigned long ulTime;                //                // Get the new time.                //                CodecGetTime(&ulTime);                //                // Inform the user interface of the new time.                //                UISetCurrentTime(ulTime);            }        }        else        {            //            // Put the EP7209 into HALT mode.            //            Halt();        }        //        // See if the removable media has been removed.        //        if(ulSystemFlags & SYSFLAG_MEDIA_REMOVE)        {            //            // Handle the removal of the external media.            //            MediaRemoved();            //            // See if the current track was on the external media.            //            if(pusTracks[ulTrack] == 0xffff)            {                //                // The current track is no longer available, so close it now.                //                CloseTrack(&sFile);                //                // Go back to the first track.                //                ulTrack = 0;                //                // If there are now no tracks available, then we return.                //                if(pusTracks[0] == 0xffff)                {                    //                    // There are no tracks, so inform the user interface of                    // that fact.                    //                    UINoTracks();                    //                    // Disable the output processing.  This function will wait                    // until all the data has been played before shutting down                    // the digital audio interface and returning.                    //                    OutputDisable();                    //                    // Inform the user interface that we are stopped.                    //                    UISetMode(MODE_STOP);                    //                    // Return indicating that there is nothing further to do.                    //                    return(0);                }                //                // Open the first track.                //                OpenTrack(&sFile);                //                // If we are not stopped, then we should be unless we are in                // repeat all mode.                //                if((ulMode != MODE_STOP) &&                   ((ulSystemFlags & SYSFLAG_REPEAT_MASK) !=                    SYSFLAG_REPEAT_ALL))                {                    //                    // Disable the output processing.  This function will wait                    // until all the data has been played before shutting down                    // the digital audio interface and returning.                    //                    OutputDisable();                    //                    // Change the mode to stopped.                    //                    ulMode = MODE_STOP;                    //                    // Inform the user interface of the new mode.                    //                    UISetMode(MODE_STOP);                }            }        }        //        // Get the current set of pressed virtual buttons.        //        ulButtons = UIGetButtons();        //        // Is a download being requested?        //        if(ulSystemFlags & SYSFLAG_START_DOWNLOAD)        {            //            // Disable the output processing.  This function will wait until            // all the data has been played before shutting down the digital            // audio interface and returning.            //            OutputDisable();            //            // Close the current file.            //            CloseTrack(&sFile);            //            // Return indicating that there is nothing further to do.            //            return(0);        }        //        // Is the power button being pressed?        //        else if(ulButtons & BUTTON_POWER)        {            //            // Disable the output processing.  This function will wait until            // all the data has been played before shutting down the digital            // audio interface and returning.            //            OutputDisable();            //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -