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

📄 record_8c.html

📁 MP3播放器源代码, VS1003B
💻 HTML
📖 第 1 页 / 共 3 页
字号:
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#a51">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     00258     <span class="keywordflow">if</span> (blockNumber==2){ <span class="comment">//2 blocks (512 bytes) received, write to disk...</span>00259       00260       <span class="comment">//If we update the SPI_DECODE_TIME, it will show on player screen :)</span>00261       <span class="comment">//we can do it, no problem. Here is the calculation for 16khz;</span>00262       <span class="comment">//for 16kHz sample rate, 505 samples/block, 8 disk sectors are</span>00263       <span class="comment">//exactly 505 milliseconds. </span>00264       <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o2">l</a> = (sectorCount/8) * 505;00265       <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o2">l</a> /= 1000;00266       <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(SPI_DECODE_TIME,<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o7">b</a>.b1,<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o7">b</a>.b0);00267       <a class="code" href="board_8h.html#a5">Mp3DeselectControl</a>();00268 00269       blockNumber = 0;00270       sectorCount++;00271       <a class="code" href="storage_8h.html#a4">WriteDiskSector</a>(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00272       lastSector = <a class="code" href="filesys_8c.html#a10">freeSector</a>;00273       <a class="code" href="filesys_8c.html#a17">ScanForFreeSector</a>(); <span class="comment">//this would be the proper way to go...</span>00274       <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>; <span class="comment">//keep all variables in proper values</span>00275       <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 data buffer pointer</span>00276       <span class="keywordflow">if</span> (<a class="code" href="filesys_8c.html#a10">freeSector</a>!=(lastSector+1)){ <span class="comment">//end of continuous space, must break!</span>00277         stopRecording = 1;00278         ConsoleWrite(<span class="stringliteral">"\nFragment end - can't continue recording!\n"</span>);00279         <a class="code" href="display_8h.html#a14">InitDisplay</a>(DS_STATIC,<span class="stringliteral">"FRAGMENT"</span>,<span class="stringliteral">" LIMIT!!"</span>,0);00280         continueRecording = 1;00281       }00282     }00283     00284     <a class="code" href="display_8c.html#a5">displayValue</a> = 0;00285     00286   }<span class="comment">//while not button - stop recording when BUTTON is pressed</span>00287   <a class="code" href="filesys_8c.html#a6">fragment</a>[0].<a class="code" href="structfragmentEntry.html#o1">length</a> = sectorCount;00288   00289 00290   <span class="comment">//Enter size information to RIFF header..</span>00291   {00292     xdata <a class="code" href="unionAddress.html">addressType</a> size;00293 00294     <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(fragment[0].start);00295     00296     <span class="comment">//Patch in number of samples</span>00297     size.l = (sectorCount-1)*1010;00298     <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>[48] = size.b.b0;00299     <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>[49] = size.b.b1;00300     <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>[50] = size.b.b2;00301     <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>[51] = size.b.b3;00302 00303     <span class="comment">//Patch in size of RIFF chunk...</span>00304     size.l = (sectorCount*512)-8;00305     <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>[4] = size.b.b0;00306     <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>[5] = size.b.b1;00307     <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>[6] = size.b.b2;00308     <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>[7] = size.b.b3;00309 00310     <span class="comment">//Patch in size of DATA chunk...</span>00311     size.l = (sectorCount*512)-512;00312     <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>[508] = size.b.b0;00313     <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>[509] = size.b.b1;00314     <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>[510] = size.b.b2;00315     <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] = size.b.b3;00316 00317     <a class="code" href="storage_8h.html#a4">WriteDiskSector</a>(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00318   }00319 00320   ConsoleWrite(<span class="stringliteral">"Registering... FStart:"</span>);00321   ConsolePutUInt(fragment[0].start);00322   ConsoleWrite(<span class="stringliteral">"Registering... Size:"</span>);00323   ConsolePutUInt(fragment[0].length);

⌨️ 快捷键说明

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