?? record_8c.html
字號:
<!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 Page</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div><h1>record.c File Reference</h1>ADPCM Recording. <a href="#_details">More...</a><p><code>#include "<a class="el" href="record_8h-source.html">record.h</a>"</code><br><code>#include "<a class="el" href="filesys_8h-source.html">filesys.h</a>"</code><br><code>#include "<a class="el" href="storage_8h-source.html">storage.h</a>"</code><br><code>#include "<a class="el" href="vs10xx_8h-source.html">vs10xx.h</a>"</code><br><code>#include "console.h"</code><br><code>#include "<a class="el" href="ui_8h-source.html">ui.h</a>"</code><br><code>#include "<a class="el" href="display_8h-source.html">display.h</a>"</code><br><p>Include dependency graph for record.c:<p><center><img src="record_8c__incl.png" border="0" usemap="#record.c_map" alt="Include dependency graph"></center><map name="record.c_map"><area href="record_8h.html" shape="rect" coords="6,93,60,117" alt=""><area href="filesys_8h.html" shape="rect" coords="84,93,140,117" alt=""><area href="buffer_8h.html" shape="rect" coords="88,18,136,42" alt=""><area href="board_8h.html" shape="rect" coords="164,18,214,42" alt=""><area href="vs10xx_8h.html" shape="rect" coords="164,93,222,117" alt=""><area href="storage_8h.html" shape="rect" coords="246,93,308,117" alt=""><area href="ui_8h.html" shape="rect" coords="420,93,457,117" alt=""><area href="display_8h.html" shape="rect" coords="481,93,540,117" alt=""></map><p><a href="record_8c-source.html">Go to the source code of this file.</a><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>unsigned char </td><td class="memItemRight" valign=bottom><a class="el" href="record_8c.html#a3">Record</a> ()</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Record ADPCM. <a href="#a3"></a><br><br></td></tr><tr><td colspan=2><br><h2>Variables</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>xdata unsigned char </td><td class="memItemRight" valign=bottom><a class="el" href="record_8c.html#a0">SPMax</a></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>code const unsigned char </td><td class="memItemRight" valign=bottom><a class="el" href="record_8c.html#a1">RIFFHeader0</a> []</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">first part of RIFF Header, insert 444 zeroes after this <a href="#a1"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>code const unsigned char </td><td class="memItemRight" valign=bottom><a class="el" href="record_8c.html#a2">RIFFHeader504</a> []</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">second part of RIFF Header, bytes 504...511 <a href="#a2"></a><br><br></td></tr></table><hr><a name="_details"></a><h2>Detailed Description</h2>ADPCM Recording. <p><p>Definition in file <a class="el" href="record_8c-source.html">record.c</a>.<hr><h2>Function Documentation</h2><a class="anchor" name="a3" doxytag="record.c::Record" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> unsigned char Record </td> <td class="md" valign="top">( </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Record ADPCM. <p>Recording is probably the least straightforward task with vs10xx, though it's not difficult! The main tasks are:<ul><li>prepare storage space to save recording</li><li>write a strictly special kind of RIFF header to start of file <dl compact><dt><b>Warning:</b></dt><dd>the RIFF header must be of the kind stated in datasheet!</dd></dl></li><li>set sampling speed (Clk/256 divider at SPI_AICTRL0)<ul><li>divider 4 is minimum, giving:<ul><li>24kHz @ 24.576MHz</li><li>42kHz with VS1003, 12.288Mhz xtal, clock multiplier 3.5</li></ul></li><li>divider 12 gives 8kHz @ 24.576Mhz</li><li>remember to put the correct sample rate in the RIFF header too!</li></ul></li><li>set recording level (gain at SPI_AICTRL1)<ul><li>this is digital gain, depends on mic signal level<ul><li>mic/line input impedance is 100 kilo-ohms</li><li>for VS1002, 100...150mVpp signal level gives best resolution</li><li>for VS1003, 50...100mVpp is best for mic, 2Vpp for line in</li></ul></li><li>0x1000 is a good first guess for the gain value</li><li>value 0 sets autogain</li></ul></li><li>SPI_VOLUME register controls the loopback volume to earphones</li><li>reset vs10xx with ADPCM recording mode bit SM_ADPCM (SPI_MODE.12) set<ul><li>for vs1003, to select line in instead of mic, set SPI_MODE.14</li></ul></li><li>monitor ADPCM_DATA_AVAILABLE level in SPI_HDAT1</li><li>when data is available, read it into a disksector buffer<ul><li>data is provided in 256-byte (128-word) blocks<ul><li>overfilling buffer resets and aligns automatically to block boundary</li><li>the fourth byte in a block is always 0x00.</li><li>check big-endianness / little-endianness for your processor</li></ul></li></ul></li><li>Be relaxed with your timing when reading the SCI registers, give VS10xx a few microseconds time to update the register value after each read. You might need to slower your SPI clock slightly since VS10xx can accept SCI data at slightly faster rate than it is able to provide it.</li><li>save disksector buffers to disk</li><li>at end of recording, set SM_OUT_OF_WAV / do a reset of vs10xx</li><li>insert correct length information in the RIFF HEADER</li><li>finalize diskfile (write FAT records and dir entry)</li></ul><p><dl compact><dt><b>Remarks:</b></dt><dd>in this test version, recording more is entered by pressing the LEFT button while booting and then releasing it after "Filesys OK" message<p>this version can only record continuous fragments, If a fragment boundary is reached, recording will stop. The main player loop is constructed so that in this situation record() is called again to continue recording to a new file.<p>Most MMC handling issues (bugs) seem to be corrected now but the filesystem code might still overwrite files or corrupt FAT tables in some type of MMC card. You are warned, this is beta quality software :)</dd></dl><p><dl compact><dt><b><a class="el" href="todo.html#_todo000003">Todo:</a></b></dt><dd>VS1002 recording: only new sample rate values need to be calculated. </dd></dl><p>This recording function can only save data into a continuous area on disk. The Fragment Table fragment[] is used in a special way for recording (to save microcontroller RAM space). fragment[0].start is the first disk sector of the file fragment[0].length will contain the number of disk sectors for the file.<p><dl compact><dt><b><a class="el" href="bug.html#_bug000001">Bug:</a></b></dt><dd>In case of fragmented filesystem, this version will not function properly. </dd></dl><p>The RIFF header is constructed in a special way (to make life a bit easier). The most proper way to do it would be to take the header "as is" from the datasheet. But to make life a bit easier, the header here is extended to be 512 bytes (a disk sector) long by adding zeroes to the 'fact' chunk. 'junk' chunks should not be used.<p>The preliminary header is written to disk prior to recording (to give some chances of recovering track in case of battery failure etc). It has a ridiculously long track length. After recording, the header must be rewritten with correct track length.<p><dl compact><dt><b><a class="el" href="todo.html#_todo000004">Todo:</a></b></dt><dd>second FAT table update</dd></dl><p>Definition at line <a class="el" href="record_8c-source.html#l00101">101</a> of file <a class="el" href="record_8c-source.html">record.c</a>.<p>References <a class="el" href="player_8c-source.html#l00332">AvailableProcessorTime()</a>, <a class="el" href="unionTemp.html#o7">Temp::b</a>, <a class="el" href="buffer_8h-source.html#l00107">DiskBlock::Raw::buf</a>, <a class="el" href="board_8h-source.html#l00253">Temp::c</a>, <a class="el" href="buffer_8c-source.html#l00013">dataBufPtr</a>, <a class="el" href="board_8c-source.html#l00036">Delay()</a>, <a class="el" href="buffer_8c-source.html#l00010">diskSect</a>, <a class="el" href="display_8c-source.html#l00015">displayValue</a>, <a class="el" href="display_8h-source.html#l00008">DS_STATIC</a>, <a class="el" href="filesys_8c-source.html#l00032">fatSectorsPerCluster</a>, <a class="el" href="filesys_8c.html#a6">fragment</a>, <a class="el" href="filesys_8c-source.html#l00062">freeSector</a>, <a class="el" href="board_8h-source.html#l00081">GREEN_LED</a>, <a class="el" href="board_8h-source.html#l00254">Temp::i</a>, <a class="el" href="display_8c-source.html#l00023">InitDisplay()</a>, <a class="el" href="board_8h-source.html#l00095">KEY_BUTTON</a>, <a class="el" href="buffer_8h-source.html#l00129">Address::l</a>, <a class="el" href="board_8h-source.html#l00255">Temp::l</a>, <a class="el" href="board_8h-source.html#l00087">LED_OFF</a>, <a class="el" href="board_8h-source.html#l00084">LED_ON</a>, <a class="el" href="filesys_8h-source.html#l00027">fragmentEntry::length</a>, <a class="el" href="board_8h-source.html#l00052">Mp3DeselectControl</a>, <a class="el" href="vs10xx_8c-source.html#l00017">Mp3ReadRegister()</a>, <a class="el" href="vs10xx_8c-source.html#l00069">Mp3Reset()</a>, <a class="el" href="vs10xx_8h-source.html#l00068">Mp3WriteRegister</a>, <a class="el" href="player_8c-source.html#l00226">playingState</a>, <a class="el" href="ui_8h.html#a25a14">PS_NEXT_SONG</a>, <a class="el" href="ui_8h.html#a25a23">PS_RECORDING</a>, <a class="el" href="unionDiskBlock.html#o1">DiskBlock::raw</a>, <a class="el" href="storage_8c-source.html#l00110">ReadDiskSector()</a>, <a class="el" href="record_8c-source.html#l00015">RIFFHeader0</a>, <a class="el" href="record_8c-source.html#l00038">RIFFHeader504</a>, <a class="el" href="filesys_8c-source.html#l00248">ScanForFreeSector()</a>, <a class="el" href="buffer_8c-source.html#l00015">sectorAddress</a>, <a class="el" href="vs10xx_8h-source.html#l00031">SPI_AICTRL0</a>, <a class="el" href="vs10xx_8h-source.html#l00032">SPI_AICTRL1</a>, <a class="el" href="vs10xx_8h-source.html#l00022">SPI_CLOCKF</a>, <a class="el" href="vs10xx_8h-source.html#l00023">SPI_DECODE_TIME</a>, <a class="el" href="vs10xx_8h-source.html#l00027">SPI_HDAT0</a>, <a class="el" href="vs10xx_8h-source.html#l00028">SPI_HDAT1</a>, <a class="el" href="vs10xx_8h-source.html#l00019">SPI_MODE</a>, <a class="el" href="filesys_8h-source.html#l00026">fragmentEntry::start</a>, <a class="el" href="board_8c.html#a0">temp</a>, <a class="el" href="ui_8h.html#a24a2">UI_TITLE</a>, <a class="el" href="player_8c-source.html#l00236">uiMode</a>, <a class="el" href="filesys_8c-source.html#l00129">WriteClusterChain()</a>, and <a class="el" href="storage_8c-source.html#l00183">WriteDiskSector()</a>.<p>Referenced by <a class="el" href="player_8c-source.html#l00765">main()</a>.<p><pre class="fragment"><div>00101 {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>(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#a51">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>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -