📄 record.c
字号:
// pusTracks[ulTrackNum]--; }}#endif//****************************************************************************//// Determines a unique file name for storing a voice file.////****************************************************************************static unsigned longGetUniqueName(unsigned long ulDrive, unsigned short *pusName){ unsigned short usFileName[64]; tDir sDir; unsigned long ulIdx; // // The unique name we will generate is "VOICExxx.WAV", where xxx will be // 000 through 999. Generate the fixed portion of the file name in the // file name buffer. // pusName[0] = 'V'; pusName[1] = 'O'; pusName[2] = 'I'; pusName[3] = 'C'; pusName[4] = 'E'; pusName[8] = '.'; pusName[9] = 'W'; pusName[10] = 'A'; pusName[11] = 'V'; pusName[12] = '\0'; // // Loop through the 1000 possible index numbers. // for(ulIdx = 0; ulIdx < 1000; ulIdx++) { // // Add the index number to the "xxx" portion of the file name. // pusName[5] = '0' + ((ulIdx / 100) % 10); pusName[6] = '0' + ((ulIdx / 10) % 10); pusName[7] = '0' + (ulIdx % 10); // // Open the root directory on the specified drive. // if(FSOpenDir(&sDir, ulDrive, (unsigned short *)"\\\0\0") == 0) { return(0); } // // Read every file from the directory. // while(1) { // // Read the next file name from the directory. // if(FSReadDir(&sDir, usFileName, FS_TYPE_FILE) == 0) { // // We've checked each file in the directory, and none of them // have the current name, so it is unique. Return success. // FSCloseDir(&sDir); return(1); } // // See if this file name matches the "unique" file name. // if(wcscmp(usFileName, pusName) == 0) { // // The names match, so stop searching and advance to the next // index. // break; } } // // Close the directory. // FSCloseDir(&sDir); } // // We tried all 1000 possible names and could not find a unique name, so // return a failure. // return(0);}//****************************************************************************//// Record captures and compresses audio (presumably voice) from the analog// input and writes it into a file.////****************************************************************************unsigned longRecord(void){ tFile sFile; unsigned short pusName[16]; unsigned long ulSampleRate, ulTemp; short *psData; long lLength; // // Get a unique file name to record into. // if(GetUniqueName(0, pusName) == 0) { return(0); } // // Provide a scratch buffer to the file system for use while writing data // to the file. // FSSetWriteScratch((unsigned char *)ulEndOfRAM); ulEndOfRAM += 512; // // Create the file to hold the recorded data. // if(FSOpen(&sFile, 0, pusName, FS_OPEN_CREATE | FS_OPEN_READ | FS_OPEN_WRITE) == 0) { FSSetWriteScratch(0); ulEndOfRAM -= 512; return(0); } // // Open the codec. // if(CodecOpen(-1, CODEC_OPEN_ENCODE, &sFile) == 0) { FSClose(&sFile); FSDelete(0, pusName); FSSetWriteScratch(0); ulEndOfRAM -= 512; return(0); } // // Enable the input processing. // CodecGetSampleRate(&ulSampleRate); CodecGetCaptureBuffer(&psData, &lLength); if(InputEnable(ulSampleRate, psData, lLength) == 0) { FSClose(&sFile); FSDelete(0, pusName); FSSetWriteScratch(0); ulEndOfRAM -= 512; return(0); } // // Get the index of the codec. // CodecGetIndex(&ulTemp); // // Add the new file to the track list. // ulTrack = AddTrack(pusName, 0, ulTemp); // // Inform the user interface that a new file has been loaded. // UIFileLoaded(pusName, ulTrack); // // Set the output buffer for the decoder. // CodecSetBuffer(InputGetOutputBuffer()); // // Inform the user interface that we are recording. // UISetMode(MODE_RECORD); // // Main record loop. We explicitly break out of the loop when we are done // recording. // while(1) { // // See if the encoder is able to encode another frame. // while(CodecCanEncode() == 0) { // // Put the EP7209 into HALT mode. // Halt(); } // // Tell the encoder to encode another frame. // if(CodecEncode() == 0) { ulTemp = 0; break; } // // Get the new time. // CodecGetTime(&ulTemp); // // Inform the user interface of the new time. // UISetCurrentTime(ulTemp); // // Get the current set of pressed virtual buttons. // ulTemp = UIGetButtons(); // // Is a download being requested? // if(ulSystemFlags & SYSFLAG_START_DOWNLOAD) { // // Stop recording so we can honor the download request. // ulTemp = 0; break; } // // Is the power button being pressed? // else if(ulTemp & BUTTON_POWER) { // // Stop recording. // ulTemp = BUTTON_POWER; break; } // // Is the stop button being pressed? // else if(ulTemp & BUTTON_STOP) { // // Stop recording. // ulTemp = 0; break; } // // Is the loopback button being pressed? //#ifdef REQUIRE_LOOPBACK else if(ulTemp & BUTTON_LOOPBACK) { // // Stop recording. // ulTemp = BUTTON_LOOPBACK; break; }#endif } // // Close the codec. // CodecClose(); // // Disable the input processing. // InputDisable(); // // Close the file. // FSClose(&sFile); // // Take the scratch buffer back from the file system since we are done // writing data to the file. // FSSetWriteScratch(0); ulEndOfRAM -= 512; // // Return the appropriate value. // return(ulTemp);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -