VLSI Solution Oy VLSI Solution Oy Evaluation MP3 Player Source Code Documentation

Main Page | Class List | File List | Class Members | File Members | Related Pages

record.c File Reference

ADPCM Recording. More...

#include "record.h"
#include "filesys.h"
#include "storage.h"
#include "vs10xx.h"
#include "console.h"
#include "ui.h"
#include "display.h"
#include "lcd.h"
#include "oggvorbis_44k2ch.plg"

Include dependency graph for record.c:

Include dependency graph

Go to the source code of this file.

Functions

unsigned short LinToDB (unsigned short n)
void LoadUserCode (void)
unsigned char Record ()

Variables

xdata unsigned char SPMax
const unsigned short linToDBTab [5] = {36781, 41285, 46341, 52016, 58386}


Detailed Description

ADPCM Recording.

Definition in file record.c.


Function Documentation

unsigned short LinToDB unsigned short  n  ) 
 

Definition at line 26 of file record.c.

References linToDBTab.

Referenced by Record().

00026 { 00027 int res = 96, i; 00028 00029 if (!n) /* No signal should return minus infinity */ 00030 return 0; 00031 00032 while (n < 32768U) { /* Amplify weak signals */ 00033 res -= 6; 00034 n <<= 1; 00035 } 00036 00037 for (i=0; i<5; i++) /* Find exact scale */ 00038 if (n > linToDBTab[i]) 00039 res++; 00040 00041 return res; 00042 }

void LoadUserCode void   ) 
 

Definition at line 45 of file record.c.

References Mp3WriteRegister.

Referenced by Record().

00045 { 00046 int i = 0; 00047 00048 while (i<sizeof(plugin)/sizeof(plugin[0])) { 00049 unsigned short addr, n, val; 00050 addr = plugin[i++]; 00051 n = plugin[i++]; 00052 if (n & 0x8000U) { /* RLE run, replicate n samples */ 00053 n &= 0x7FFF; 00054 val = plugin[i++]; 00055 while (n--) { 00056 Mp3WriteRegister(addr, val>>8, val & 0xff); 00057 } 00058 } else { /* Copy run, copy n samples */ 00059 while (n--) { 00060 val = plugin[i++]; 00061 Mp3WriteRegister(addr, val>>8, val & 0xff); 00062 } 00063 } 00064 } 00065 }

unsigned char Record  ) 
 

Definition at line 68 of file record.c.

References AvailableProcessorTime(), DiskBlock::Raw::buf, Temp::c, dataBufPtr, Delay(), diskSect, displayValue, DS_STATIC, fragment, freeSector, GREEN_LED, InitDisplay(), KEY_BUTTON, Address::l, LcdLocateHome, LcdLocateLine2, LcdPutHex16(), LED_OFF, LED_ON, fragmentEntry::length, LinToDB(), LoadUserCode(), MP3_DREQ, Mp3DeselectControl, Mp3ReadRegister(), Mp3SoftReset(), Mp3WriteRegister, playingState, PS_NEXT_SONG, PS_RECORDING, DiskBlock::raw, RED_LED, ScanForFreeSector(), sectorAddress, SPI_AIADDR, SPI_AICTRL0, SPI_AICTRL1, SPI_AICTRL2, SPI_AICTRL3, SPI_CLOCKF, SPI_HDAT0, SPI_HDAT1, SPI_MODE, fragmentEntry::start, temp, WriteClusterChain(), and WriteDiskSector().

Referenced by main().

00068 { 00069 xdata unsigned char blockNumber; 00070 xdata unsigned long sectorCount; 00071 xdata unsigned long lastSector; 00072 bit stopRecording = 0; 00073 bit continueRecording = 0; 00074 char newDisplayValue ; 00075 00076 00077 00078 blockNumber = 0; 00079 sectorCount = 1; 00080 00081 playingState = PS_RECORDING; //Inform the world that rec mode is on. 00082 00083 00084 // Locate free space 00094 // Locate a free sector on storage. Uses global u_int freeSector 00095 freeSector = 0; 00096 ScanForFreeSector(); sectorAddress.l = freeSector; 00097 fragment[0].start = freeSector; 00098 lastSector = freeSector; 00099 dataBufPtr = diskSect.raw.buf; 00100 blockNumber = 0; 00101 ConsoleWrite("\rRecording, push button to stop..."); 00102 00103 00104 // Kick vs10xx into action! 00105 Mp3WriteRegister(SPI_CLOCKF, 0xc0,0x00); Delay(1); while(!MP3_DREQ); 00106 Mp3WriteRegister(SPI_AICTRL0, 0x00,0x00); Delay(1); while(!MP3_DREQ); 00107 LoadUserCode(); 00108 Mp3WriteRegister(SPI_MODE, 0x58,0x00); Delay(1); while(!MP3_DREQ); 00109 Mp3WriteRegister(SPI_AICTRL1, 0x00,0x00); Delay(1); while(!MP3_DREQ); 00110 Mp3WriteRegister(SPI_AICTRL2, 0x10,0x00); Delay(1); while(!MP3_DREQ); 00111 Mp3WriteRegister(SPI_AICTRL3, 0x00,0x00); Delay(1); while(!MP3_DREQ); 00112 Mp3WriteRegister(SPI_AIADDR, 0x00,0x34); 00113 00114 00115 00116 00117 00118 while(!stopRecording){ 00119 00120 //Delay(100); 00121 00122 { //Do basic SOUND LEVEL BAR calculation based on the 1 linear 00123 //sample in block[0] and [1] 00124 signed int soundlevel; 00125 // the user interface (level bar) calculation 00126 00127 if (KEY_BUTTON) { 00128 ConsoleWrite("\rMODE: "); 00129 ConsolePutUInt(Mp3ReadRegister(SPI_MODE)); 00130 Mp3WriteRegister(SPI_AICTRL3, 0x00,0x01); 00131 } 00132 00133 if (Mp3ReadRegister(SPI_AICTRL3) & 1){ 00134 stopRecording = 1; 00135 } 00136 00137 00138 soundlevel = Mp3ReadRegister(SPI_AICTRL0); 00139 Mp3WriteRegister(SPI_AICTRL0,0,0); 00140 00141 if (soundlevel){ 00142 00143 #if 0 00144 newDisplayValue=0; 00145 while (soundlevel){ 00146 newDisplayValue++; 00147 soundlevel>>=1; 00148 } 00149 newDisplayValue*=7; 00150 #endif 00151 00152 soundlevel = LinToDB(soundlevel); 00153 soundlevel *= 3; 00154 soundlevel -= 185; 00155 if (soundlevel < 0) soundlevel = 0; 00156 newDisplayValue = soundlevel; 00157 00158 00159 #if 1 00160 displayValue = newDisplayValue; 00161 #else 00162 if (newDisplayValue>=displayValue){ 00163 displayValue = newDisplayValue; 00164 } else { 00165 if (displayValue) displayValue--; 00166 } 00167 #endif 00168 } 00169 //displayValue = newDisplayValue; 00170 //ConsolePutUInt(displayValue); 00171 00172 00173 #if 1 00174 AvailableProcessorTime(); 00175 #else 00176 LcdLocateHome(); 00177 LcdPutHex16 (Mp3ReadRegister(SPI_AICTRL0)); 00178 LcdPutHex16 (Mp3ReadRegister(SPI_AICTRL1)); 00179 LcdLocateLine2(); 00180 LcdPutHex16 (Mp3ReadRegister(SPI_AICTRL2)); 00181 LcdPutHex16 (Mp3ReadRegister(SPI_AICTRL3)); 00182 00183 #endif 00184 00185 00186 }//SOUND LEVEL BAR calculation 00187 00188 00189 //ConsolePutUInt(Mp3ReadRegister(SPI_HDAT1)); 00190 if (Mp3ReadRegister(SPI_HDAT1) > 255){ 00191 //there is a data block to be read... 00192 GREEN_LED = LED_ON; 00193 blockNumber++; 00194 dataBufPtr = diskSect.raw.buf; 00195 00196 for (temp.c=0;temp.c<128;temp.c++){ 00197 data unsigned int i; 00198 i = Mp3ReadRegister(SPI_HDAT0); 00199 *dataBufPtr++ = (i>>8); 00200 *dataBufPtr++ = (i&0xff); 00201 i = Mp3ReadRegister(SPI_HDAT0); 00202 *dataBufPtr++ = (i>>8); 00203 *dataBufPtr++ = (i&0xff); 00204 } 00205 00206 //Release SCI chip select, we might want to use MMC card 00207 Mp3DeselectControl(); 00208 00209 RED_LED = LED_ON; 00210 blockNumber = 0; 00211 sectorCount++; 00212 WriteDiskSector(sectorAddress.l); 00213 lastSector = freeSector; 00214 ScanForFreeSector(); //this would be the proper way to go... 00215 sectorAddress.l = freeSector; //keep all variables in proper values 00216 dataBufPtr = diskSect.raw.buf; //reset data buffer pointer 00217 if (freeSector!=(lastSector+1)){ //end of continuous space, must break! 00218 stopRecording = 1; 00219 ConsoleWrite("\nFragment end - can't continue recording!\n"); 00220 InitDisplay(DS_STATIC,"FRAGMENT"," LIMIT!!",0); 00221 continueRecording = 1; 00222 } 00223 00224 RED_LED = LED_OFF; 00225 GREEN_LED = LED_OFF; 00226 00227 //if there was data to read 00228 } else { 00229 Delay(1); 00230 } 00231 00232 00233 00234 }//while not button - stop recording when BUTTON is pressed 00235 00236 00237 00238 while (Mp3ReadRegister(SPI_HDAT1) > 0){ 00239 int n = Mp3ReadRegister(SPI_HDAT1); 00240 n -= 256; 00241 00242 00243 //there is a data block to be read... 00244 GREEN_LED = LED_ON; 00245 blockNumber++; 00246 dataBufPtr = diskSect.raw.buf; 00247 00248 for (temp.c=0;temp.c<128;temp.c++){ 00249 data unsigned int i; 00250 i = Mp3ReadRegister(SPI_HDAT0); 00251 *dataBufPtr++ = (i>>8); 00252 *dataBufPtr++ = (i&0xff); 00253 i = Mp3ReadRegister(SPI_HDAT0); 00254 *dataBufPtr++ = (i>>8); 00255 *dataBufPtr++ = (i&0xff); 00256 } 00257 00258 if (n<0) { 00259 for (temp.c = 0; temp.c<(-n); temp.c++){ 00260 *--dataBufPtr = 0; 00261 *--dataBufPtr = 0; 00262 } 00263 } 00264 00265 00266 //Release SCI chip select, we might want to use MMC card 00267 Mp3DeselectControl(); 00268 00269 RED_LED = LED_ON; 00270 blockNumber = 0; 00271 sectorCount++; 00272 WriteDiskSector(sectorAddress.l); 00273 lastSector = freeSector; 00274 ScanForFreeSector(); //this would be the proper way to go... 00275 sectorAddress.l = freeSector; //keep all variables in proper values 00276 dataBufPtr = diskSect.raw.buf; //reset data buffer pointer 00277 if (freeSector!=(lastSector+1)){ //end of continuous space, must break! 00278 stopRecording = 1; 00279 ConsoleWrite("\nFragment end - can't continue recording!\n"); 00280 InitDisplay(DS_STATIC,"FRAGMENT"," LIMIT!!",0); 00281 continueRecording = 1; 00282 } 00283 00284 RED_LED = LED_OFF; 00285 GREEN_LED = LED_OFF; 00286 00287 if (n<0){ 00288 break; 00289 } 00290 00291 }//if there was data to read 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 fragment[0].length = sectorCount; 00305 ConsoleWrite("Registering... FStart:"); 00306 ConsolePutUInt(fragment[0].start); 00307 ConsoleWrite("Registering... Size:"); 00308 ConsolePutUInt(fragment[0].length); 00309 //Create FAT records. 00310 fragment[1].start = 0x0fffffff; //fragment 0 is the only fragment 00311 WriteClusterChain(); //register newly created file in FAT FS 00312 00315 sectorAddress.l = 0; //force sector reload for next access 00316 00317 Mp3SoftReset(); 00318 return PS_NEXT_SONG; 00319 00320 }

Here is the call graph for this function:


Variable Documentation

const unsigned short linToDBTab[5] = {36781, 41285, 46341, 52016, 58386}
 

Definition at line 16 of file record.c.

Referenced by LinToDB().

xdata unsigned char SPMax
 

Definition at line 11 of file record.c.

Referenced by main(), and timer0_interrupt().


All software copyright 2000-2004 VLSI Solution OY. Redistribution of these software modules are limited to promotional use only and only with the VS1011 / VS1002 / VS1003 MP3-Evakit evaluation boards. Free or commercial use of these software modules in MP3 players is ok if the product includes MP3 decoder chip(s) from VLSI. You can request the complete (compilable) package from mp3@vlsi.fi