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

📄 record_8c-source.html

📁 MP3 Player Source Code
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>VLSI Solution Oy Evaluation MP3 Player Source Code Documentation</title><link href="doxygen.css" rel="stylesheet" type="text/css"><img src="vlsi_small.gif" hspace="20" bordercolor="#ffffff"  alt="VLSI Solution Oy"><b>VLSI Solution Oy Evaluation MP3 Player Source Code Documentation</b><p></p></head><body><!-- Generated by Doxygen 1.3.7 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>record.c</h1><a href="record_8c.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 00003 <span class="preprocessor">#include "<a class="code" href="record_8h.html">record.h</a>"</span>00004 <span class="preprocessor">#include "<a class="code" href="filesys_8h.html">filesys.h</a>"</span>00005 <span class="preprocessor">#include "<a class="code" href="storage_8h.html">storage.h</a>"</span>00006 <span class="preprocessor">#include "<a class="code" href="vs10xx_8h.html">vs10xx.h</a>"</span>00007 <span class="preprocessor">#include "console.h"</span>00008 <span class="preprocessor">#include "<a class="code" href="ui_8h.html">ui.h</a>"</span>00009 <span class="preprocessor">#include "<a class="code" href="display_8h.html">display.h</a>"</span>00010 00011 <a name="l00012"></a><a class="code" href="record_8c.html#a0">00012</a> <span class="keyword">extern</span> xdata <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="player_8c.html#a7">SPMax</a>;00013 <a name="l00015"></a><a class="code" href="record_8c.html#a1">00015</a> code <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="record_8c.html#a1">RIFFHeader0</a>[] = {00016   <span class="charliteral">'R'</span> , <span class="charliteral">'I'</span> , <span class="charliteral">'F'</span> , <span class="charliteral">'F'</span> , <span class="comment">// Chunk ID (RIFF)</span>00017   0x70, 0x70, 0x70, 0x70, <span class="comment">// Chunk payload size (calculate after rec!)</span>00018   <span class="charliteral">'W'</span> , <span class="charliteral">'A'</span> , <span class="charliteral">'V'</span> , <span class="charliteral">'E'</span> , <span class="comment">// RIFF resource format type</span>00019   00020   <span class="charliteral">'f'</span> , <span class="charliteral">'m'</span> , <span class="charliteral">'t'</span> , <span class="charliteral">' '</span> , <span class="comment">// Chunk ID (fmt )</span>00021   0x14, 0x00, 0x00, 0x00, <span class="comment">// Chunk payload size (0x14 = 20 bytes)</span>00022   0x11, 0x00,             <span class="comment">// Format Tag (IMA ADPCM)</span>00023   0x01, 0x00,             <span class="comment">// Channels (1)</span>00024   0x80, 0x3e, 0x00, 0x00, <span class="comment">// Sample Rate, 0x3e80 = 16.0kHz</span>00025   0xd7, 0x0f, 0x00, 0x00, <span class="comment">// Average Bytes Per Second</span>00026   0x00, 0x01,             <span class="comment">// Data Block Size (256 bytes) </span>00027   0x04, 0x00,             <span class="comment">// ADPCM encoded bits per sample (4 bits)</span>00028   0x02, 0x00,             <span class="comment">// Extra data (2 bytes)</span>00029   0xf9, 0x01,             <span class="comment">// Samples per Block (505 samples)</span>00030   00031   <span class="charliteral">'f'</span> , <span class="charliteral">'a'</span> , <span class="charliteral">'c'</span> , <span class="charliteral">'t'</span> , <span class="comment">// Chunk ID (fact)</span>00032   0xc8, 0x01, 0x00, 0x00, <span class="comment">// Chunk payload size (456 bytes (zeropad!))</span>00033   0xff, 0xff, 0xff, 0xff  <span class="comment">// Number of Samples (calculate after rec!)</span>00034   <span class="comment">// Insert 448 zeroes here!</span>00035 };00036 <a name="l00038"></a><a class="code" href="record_8c.html#a2">00038</a> code <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="record_8c.html#a2">RIFFHeader504</a>[] = {00039   <span class="charliteral">'d'</span> , <span class="charliteral">'a'</span> , <span class="charliteral">'t'</span> , <span class="charliteral">'a'</span> , <span class="comment">// Chunk ID (data)</span>00040   0x70, 0x70, 0x70, 0x70  <span class="comment">// Chunk payload size (calculate after rec!)</span>00041 };00042 00043 <a name="l00101"></a><a class="code" href="record_8h.html#a0">00101</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="record_8c.html#a3">Record</a>(){00102 00103   xdata <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> blockNumber;00104   xdata <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sectorCount;00105   xdata <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> lastSector;00106   bit stopRecording = 0;00107   bit continueRecording = 0;00108 00109   <span class="keywordtype">char</span> oldlevel=0;00110   blockNumber = 0;00111   sectorCount = 1;00112 00113   <a class="code" href="player_8c.html#a3">playingState</a> = <a class="code" href="ui_8h.html#a25a23">PS_RECORDING</a>; <span class="comment">//Inform the world that rec mode is on.</span>00114 00115   <span class="comment">// Kick vs10xx into action!</span>00116 00117   <span class="comment">/* Set clock register, doubler etc. */</span>00118 <span class="preprocessor">#ifdef VS1003</span>00119 <span class="preprocessor"></span>  <span class="comment">// Set base xtal 14.7456MHZ (0x0696) | multiplier:fixed 2.5 (0x600)</span>00120   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a5">SPI_CLOCKF</a>,0x66,0x96); 00121 <span class="preprocessor">#else</span>00122 <span class="preprocessor"></span>  <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a5">SPI_CLOCKF</a>,156,204); <span class="comment">//for 14.576MHz XTAL</span>00123 <span class="preprocessor">#endif</span>00124 <span class="preprocessor"></span>  00125   <span class="comment">//Set sample rate 16khz for VS1003 (6.4kHz for VS1002 :( )</span>00126   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a14">SPI_AICTRL0</a>,0x00,0x09); <span class="comment">//Set sample rate divider=9</span>00127   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a15">SPI_AICTRL1</a>,0x10,0x00); <span class="comment">//AutoGain OFF, reclevel 0x1000</span>00128   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a2">SPI_MODE</a>,0x18,0x04);    <span class="comment">//RECORD,NEWMODE,RESET</span>00129   <a class="code" href="board_8h.html#a49">Delay</a>(10);00130 00131   <span class="comment">/* Set clock register, doubler etc. */</span>00132 <span class="preprocessor">#ifdef VS1003</span>00133 <span class="preprocessor"></span>  <span class="comment">// Set base xtal 14.7456MHZ (0x0696) | multiplier:fixed 2.5 (0x600)</span>00134   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a5">SPI_CLOCKF</a>,0x66,0x96); 00135 <span class="preprocessor">#else</span>00136 <span class="preprocessor"></span>  <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a5">SPI_CLOCKF</a>,156,204); <span class="comment">//for 14.576MHz XTAL</span>00137 <span class="preprocessor">#endif</span>00138 <span class="preprocessor"></span> 00139 00140   <span class="comment">// Locate free space</span>00151 <span class="comment"></span>  <a class="code" href="filesys_8c.html#a10">freeSector</a> = 0;00152   <a class="code" href="filesys_8c.html#a17">ScanForFreeSector</a>();00153   <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="filesys_8c.html#a10">freeSector</a>;00154   <a class="code" href="filesys_8c.html#a6">fragment</a>[0].<a class="code" href="structfragmentEntry.html#o0">start</a> = <a class="code" href="filesys_8c.html#a10">freeSector</a>;00155 00156 00164   <span class="keywordflow">for</span> (<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a>=0; <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a>&lt;56; <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a>++){ <span class="comment">//temp is unsafe global temp variable.</span>00165     <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>[<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a>] = <a class="code" href="record_8c.html#a1">RIFFHeader0</a>[<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a>];00166   }00167   <span class="keywordflow">for</span> (<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>=52; <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>&lt;504; <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>++){00168     <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>[<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>] = 0;00169   }00170   <span class="keywordflow">for</span> (<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>=504; <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>&lt;512; <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>++){00171     <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>[<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>] = <a class="code" href="record_8c.html#a2">RIFFHeader504</a>[<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>-504];00172   }00173 00180   lastSector = <a class="code" href="filesys_8c.html#a10">freeSector</a>;00181   <a class="code" href="storage_8h.html#a4">WriteDiskSector</a>(<a class="code" href="filesys_8c.html#a10">freeSector</a>);00182   00183   <span class="comment">/* Get a new free sector */</span>00184   <a class="code" href="filesys_8c.html#a17">ScanForFreeSector</a>();00185   <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="filesys_8c.html#a10">freeSector</a>;00186   <a class="code" href="buffer_8c.html#a1">dataBufPtr</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>;00187   00188   <a class="code" href="board_8h.html#a49">Delay</a>(10);00189   <span class="comment">//Sync to incoming audio frame...</span>00190   <span class="keywordflow">while</span> (<a class="code" href="vs10xx_8h.html#a38">Mp3ReadRegister</a>(<a class="code" href="vs10xx_8h.html#a11">SPI_HDAT1</a>)&gt;&gt;8) <span class="comment">//lots of data in buffer</span>00191     ; <span class="comment">//Wait until buffer level restarts from 0</span>00192   00193   <a class="code" href="buffer_8c.html#a1">dataBufPtr</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>; <span class="comment">//reset dataBufPtr to start of filebuffer</span>00194   blockNumber = 0;00195 00196   ConsoleWrite(<span class="stringliteral">"\rRecording, push button to stop..."</span>);00197   <span class="keywordflow">while</span>((!<a class="code" href="board_8h.html#a14">KEY_BUTTON</a> 00198         || (blockNumber!=0)00199         || ((sectorCount)%(<a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>)!=0))00200         &amp;&amp; (!stopRecording)){  00201      00202     <a class="code" href="board_8h.html#a11">GREEN_LED</a> = <a class="code" href="board_8h.html#a12">LED_ON</a>;00203 00204     <span class="comment">//Check for data</span>00205     <span class="keywordflow">if</span> (<a class="code" href="vs10xx_8h.html#a38">Mp3ReadRegister</a>(<a class="code" href="vs10xx_8h.html#a11">SPI_HDAT1</a>) &gt;= 128){ 00206       <span class="comment">//there is a data block to be read...</span>00207       <a class="code" href="board_8h.html#a11">GREEN_LED</a> = <a class="code" href="board_8h.html#a13">LED_OFF</a>;00208       blockNumber++;00209 

⌨️ 快捷键说明

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