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

📄 record.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
//****************************************************************************//// RECORD.C - Routines for recording and compressing audio into a file.//// Copyright (c) 1999,2000,2001 Cirrus Logic, Inc.////****************************************************************************#include "globals.h"#include "../hwport.h"//****************************************************************************//// Only include this code if the record capability is needed.////****************************************************************************#ifdef REQUIRE_RECORD//****************************************************************************//// Finds the file index of the given file.////****************************************************************************static unsigned longFindFile(unsigned short *pusName, unsigned long ulDrive){    unsigned short usFileName[64];    tDir sDir;    unsigned long ulFileNum;    //    // Open the root directory of the specified drive.    //    if(FSOpenDir(&sDir, ulDrive, (unsigned short *)"\\\0\0") == 0)    {        return(-1);    }    //    // Scan through the files in the root directory.    //    ulFileNum = 0;    while(1)    {        //        // Read the name of the next file in the directory.        //        if(FSReadDir(&sDir, usFileName, FS_TYPE_FILE) == 0)        {            //            // We reached the end of the directory, so close the directory and            // return an error.            //            FSCloseDir(&sDir);            return(-1);        }        //        // Compare the name of this file with the file in question.        //        if(wcscmp(usFileName, pusName) == 0)        {            //            // This is the file we are looking for, so stop looking.            //            break;        }        //        // Increment the file number.        //        ulFileNum++;    }    //    // Close the directory.    //    FSCloseDir(&sDir);    //    // Return the file number.    //    return(ulFileNum);}//****************************************************************************//// Adds a new track to the list of tracks on the media.////****************************************************************************static unsigned longAddTrack(unsigned short *pusName, unsigned long ulDrive, unsigned long ulCodec){    unsigned long ulFileNum, ulTrackNum, ulIdx;    //    // Get the index number of this file.    //    ulFileNum = FindFile(pusName, ulDrive);    if(ulFileNum == -1)    {        //        // This should never occur, but just in case...        //        return(0);    }    //    // See if this track on the first or second drive.    //    if(ulDrive == 0)    {        //        // This track is on the first drive, so loop through all the tracks.        //        for(ulTrackNum = 0; ulTrackNum < MAX_TRACKS; ulTrackNum++)        {            //            // If the file index number of the new track is less than the file            // index number of the current track, or the current track is on            // the second drive, then this is the place to insert the new            // track.            //            if((((pusTracks[ulTrackNum] & TRACK_FILE_MASK) >>                 TRACK_FILE_SHIFT) >= ulFileNum) ||               (pusTracks[ulTrackNum] & TRACK_DRIVE_MASK))            {                break;            }        }    }    //    // Otherwise, the new track is on the second drive.    //    else    {        //        // Find the first track which is on the second drive.        //        for(ulTrackNum = 0; ulTrackNum < MAX_TRACKS; ulTrackNum++)        {            if(pusTracks[ulTrackNum] & TRACK_DRIVE_MASK)            {                break;            }        }        //        // Loop through all the tracks on the second drive.        //        for(; ulTrackNum < MAX_TRACKS; ulTrackNum++)        {            //            // If the file index number of the new track is less than the file            // index number of the current track, then this is the place to            // insert the new track.            //            if((((pusTracks[ulTrackNum] & TRACK_FILE_MASK) >>                 TRACK_FILE_SHIFT) >= ulFileNum) ||               (pusTracks[ulTrackNum] == 0xffff))            {                break;            }        }    }    //    // If we scanned through all the available tracks and could not find a    // place for this track, then we have more tracks than we know how to deal    // with.  In this case, simply return zero.    //    if(ulTrackNum == MAX_TRACKS)    {        return(0);    }    //    // Move all the tracks that appear after the new track up one entry in the    // track list.    //    for(ulIdx = MAX_TRACKS - 1; ulIdx > ulTrackNum; ulIdx--)    {        //        // Move the previous track entry into this track entry.        //        pusTracks[ulIdx] = pusTracks[ulIdx - 1];        //        // If the new track is on the first drive and this track is on the        // first drive, then the file number for this track needs to be changed        // to reflect the new file which has been created.        //        if((ulDrive == 0) && !(pusTracks[ulIdx] & TRACK_DRIVE_MASK))        {            pusTracks[ulIdx]++;        }        //        // Otherwise, if the new track is on the second drive and this track is        // on the second drive, then the file number for this track needs to be        // changed to reflect the new file which has been created.        //        else if((ulDrive == 1) && (pusTracks[ulIdx] & TRACK_DRIVE_MASK) &&                (pusTracks[ulIdx] != 0xffff))        {            pusTracks[ulIdx]++;        }    }    //    // Insert the entry for this track into the list.    //    pusTracks[ulTrackNum] =        ((ulDrive << TRACK_DRIVE_SHIFT) & TRACK_DRIVE_MASK) |        ((ulCodec << TRACK_CODEC_SHIFT) & TRACK_CODEC_MASK) |        ((ulFileNum << TRACK_FILE_SHIFT) & TRACK_FILE_MASK);    //    // Return the track number of the new track.    //    return(ulTrackNum);}//****************************************************************************//// Removes a track for the list of tracks on the media.////****************************************************************************#ifdef NOT_USED_YETstatic voidRemoveTrack(unsigned short *pusName, unsigned long ulDrive){    unsigned long ulFileNum, ulTrackNum, ulIdx;    //    // Get the index number of this file.    //    ulFileNum = FindFile(pusName, ulDrive);    if(ulFileNum == -1)    {        //        // We could not find the specified file, so there is nothing to do.        //        return;    }    //    // Loop through all the tracks.    //    for(ulTrackNum = 0; ulTrackNum < MAX_TRACKS; ulTrackNum++)    {        //        // We should stop looking if we found a file on the same drive which        // is the same file number or greater.        //        if(((pusTracks[ulTrackNum] & TRACK_FILE_MASK) >= ulFileNum) &&           (((pusTracks[ulTrackNum] & TRACK_DRIVE_MASK) >>             TRACK_DRIVE_SHIFT) == ulDrive) &&           (pusTracks[ulTrackNum] != 0xffff))        {            break;        }    }    //    // See if we found a track which is effected by the removal of this file.    //    if(ulTrackNum == MAX_TRACKS)    {        //        // There is no track corresponding to this file, so there is nothing        // to do.        //        return;    }    //    // See if we found this file in the track list.    //    if((pusTracks[ulTrackNum] & TRACK_FILE_MASK) == ulFileNum)    {        //        // Loop through all the tracks after the one corresponding to this        // file.        //        for(ulIdx = ulTrackNum; ulIdx < (MAX_TRACKS - 1); ulIdx++)        {            //            // Copy the subsequent track into the current track.            //            pusTracks[ulIdx] = pusTracks[ulIdx + 1];        }    }    //    // Loop through the remaining tracks.    //    for(; ulTrackNum < MAX_TRACKS; ulTrackNum++)    {        //        // Stop scanning if this track is not on the correct drive.        //        if((((pusTracks[ulTrackNum] & TRACK_DRIVE_MASK) >>             TRACK_DRIVE_SHIFT) != ulDrive) ||           (pusTracks[ulTrackNum] == 0xffff))        {            break;        }        //        // Decrement the file number of this track.

⌨️ 快捷键说明

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