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

📄 record_8h.html

📁 MP3 Player Source Code
💻 HTML
📖 第 1 页 / 共 3 页
字号:
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>(SPI_CLOCKF,0x66,0x96); 00121 <span class="preprocessor">#else</span>00122 <span class="preprocessor"></span>  <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(SPI_CLOCKF,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>(SPI_AICTRL0,0x00,0x09); <span class="comment">//Set sample rate divider=9</span>00127   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(SPI_AICTRL1,0x10,0x00); <span class="comment">//AutoGain OFF, reclevel 0x1000</span>00128   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(SPI_MODE,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>(SPI_CLOCKF,0x66,0x96); 00135 <span class="preprocessor">#else</span>00136 <span class="preprocessor"></span>  <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(SPI_CLOCKF,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>(freeSector);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>(SPI_HDAT1)&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>(SPI_HDAT1) &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 00210       <span class="comment">//dataBufPtr should point inside disk buffer, this should never fail:</span>00211       <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>&gt;(<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>+511)){00212         ConsoleWrite(<span class="stringliteral">"\rBuffer indexing error. Stop.\r"</span>);00213         <span class="keywordflow">while</span>(1); <span class="comment">//stop</span>00214       }00215       00216       <span class="comment">//Get the data</span>00217       <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;128;<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a>++){00218         data <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00219         i = <a class="code" href="vs10xx_8h.html#a38">Mp3ReadRegister</a>(SPI_HDAT0);         00220         *<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++ = (i&gt;&gt;8);00221         *<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++ = (i&amp;0xff);00222       }00223       00224       00225       { <span class="comment">//Do basic SOUND LEVEL BAR calculation based on the 1 linear</span>00226         <span class="comment">//sample in block[0] and [1]</span>00227         <span class="keywordtype">signed</span> <span class="keywordtype">int</span> soundlevel;00228         <span class="comment">// the user interface (level bar) calculation</span>00229         <span class="keywordflow">if</span> (<a class="code" href="player_8c.html#a6">uiMode</a> == <a class="code" href="ui_8h.html#a24a2">UI_TITLE</a>){00230           soundlevel = (<span class="keywordtype">signed</span> <span class="keywordtype">char</span>)<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>[1]&lt;&lt;7;00231           soundlevel |= <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>[0]&gt;&gt;1;00232           <span class="keywordflow">if</span> (soundlevel&lt;0) soundlevel = -soundlevel;00233           <a class="code" href="display_8c.html#a5">displayValue</a>=0;00234           <span class="keywordflow">while</span> (soundlevel&gt;31){00235             <a class="code" href="display_8c.html#a5">displayValue</a>++;         00236             soundlevel&gt;&gt;=1;00237           }00238           <span class="keywordflow">if</span> (soundlevel&gt;19) <a class="code" href="display_8c.html#a5">displayValue</a>++;00239           <span class="keywordflow">if</span> (soundlevel&gt;12) <a class="code" href="display_8c.html#a5">displayValue</a>++;00240           <span class="keywordflow">if</span> (soundlevel&gt;6) <a class="code" href="display_8c.html#a5">displayValue</a>++;00241           <a class="code" href="display_8c.html#a5">displayValue</a>-=3;00242           <a class="code" href="display_8c.html#a5">displayValue</a>*=13;00243           <span class="keywordflow">if</span> (oldlevel&gt;<a class="code" href="display_8c.html#a5">displayValue</a>){00244             <a class="code" href="display_8c.html#a5">displayValue</a>=oldlevel-3;00245           }00246           oldlevel=<a class="code" href="display_8c.html#a5">displayValue</a>;       00247         }     00248         <a class="code" href="player_8c.html#a12">AvailableProcessorTime</a>();00249         00250       }<span class="comment">//SOUND LEVEL BAR calculation</span>00251       00252     }<span class="comment">//if there was data to read</span>00253     00254     00255     <span class="comment">//Release SCI chip select, we might want to use MMC card</span>00256     <a class="code" href="board_8h.html#a5">Mp3DeselectControl</a>();00257     

⌨️ 快捷键说明

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