00001
00003
#include "record.h"
00004
#include "filesys.h"
00005
#include "storage.h"
00006
#include "vs10xx.h"
00007
#include "console.h"
00008
#include "ui.h"
00009
#include "display.h"
00010
00011
00012 extern xdata
unsigned char SPMax;
00013
00015 code
const unsigned char RIFFHeader0[] = {
00016
'R' ,
'I' ,
'F' ,
'F' ,
00017 0x70, 0x70, 0x70, 0x70,
00018
'W' ,
'A' ,
'V' ,
'E' ,
00019
00020
'f' ,
'm' ,
't' ,
' ' ,
00021 0x14, 0x00, 0x00, 0x00,
00022 0x11, 0x00,
00023 0x01, 0x00,
00024 0x80, 0x3e, 0x00, 0x00,
00025 0xd7, 0x0f, 0x00, 0x00,
00026 0x00, 0x01,
00027 0x04, 0x00,
00028 0x02, 0x00,
00029 0xf9, 0x01,
00030
00031
'f' ,
'a' ,
'c' ,
't' ,
00032 0xc8, 0x01, 0x00, 0x00,
00033 0xff, 0xff, 0xff, 0xff
00034
00035 };
00036
00038 code
const unsigned char RIFFHeader504[] = {
00039
'd' ,
'a' ,
't' ,
'a' ,
00040 0x70, 0x70, 0x70, 0x70
00041 };
00042
00043
00101 unsigned char Record(){
00102
00103 xdata
unsigned char blockNumber;
00104 xdata
unsigned long sectorCount;
00105 xdata
unsigned long lastSector;
00106 bit stopRecording = 0;
00107 bit continueRecording = 0;
00108
00109
char oldlevel=0;
00110 blockNumber = 0;
00111 sectorCount = 1;
00112
00113
playingState =
PS_RECORDING;
00114
00115
00116
00117
00118
#ifdef VS1003
00119
00120
Mp3WriteRegister(
SPI_CLOCKF,0x66,0x96);
00121
#else
00122
Mp3WriteRegister(
SPI_CLOCKF,156,204);
00123
#endif
00124
00125
00126
Mp3WriteRegister(
SPI_AICTRL0,0x00,0x09);
00127
Mp3WriteRegister(
SPI_AICTRL1,0x10,0x00);
00128
Mp3WriteRegister(
SPI_MODE,0x18,0x04);
00129
Delay(10);
00130
00131
00132
#ifdef VS1003
00133
00134
Mp3WriteRegister(
SPI_CLOCKF,0x66,0x96);
00135
#else
00136
Mp3WriteRegister(
SPI_CLOCKF,156,204);
00137
#endif
00138
00139
00140
00151
freeSector = 0;
00152
ScanForFreeSector();
00153
sectorAddress.
l =
freeSector;
00154
fragment[0].
start =
freeSector;
00155
00156
00164
for (
temp.
c=0;
temp.
c<56;
temp.
c++){
00165
diskSect.
raw.
buf[
temp.
c] =
RIFFHeader0[
temp.
c];
00166 }
00167
for (
temp.
i=52;
temp.
i<504;
temp.
i++){
00168
diskSect.
raw.
buf[
temp.
i] = 0;
00169 }
00170
for (
temp.
i=504;
temp.
i<512;
temp.
i++){
00171
diskSect.
raw.
buf[
temp.
i] =
RIFFHeader504[
temp.
i-504];
00172 }
00173
00180 lastSector =
freeSector;
00181
WriteDiskSector(
freeSector);
00182
00183
00184
ScanForFreeSector();
00185
sectorAddress.
l =
freeSector;
00186
dataBufPtr =
diskSect.
raw.
buf;
00187
00188
Delay(10);
00189
00190
while (
Mp3ReadRegister(
SPI_HDAT1)>>8)
00191 ;
00192
00193
dataBufPtr =
diskSect.
raw.
buf;
00194 blockNumber = 0;
00195
00196 ConsoleWrite(
"\rRecording, push button to stop...");
00197
while((!
KEY_BUTTON
00198 || (blockNumber!=0)
00199 || ((sectorCount)%(
fatSectorsPerCluster)!=0))
00200 && (!stopRecording)){
00201
00202
GREEN_LED =
LED_ON;
00203
00204
00205
if (
Mp3ReadRegister(
SPI_HDAT1) >= 128){
00206
00207
GREEN_LED =
LED_OFF;
00208 blockNumber++;
00209
00210
00211
if (
dataBufPtr>(
diskSect.
raw.
buf+511)){
00212 ConsoleWrite(
"\rBuffer indexing error. Stop.\r");
00213
while(1);
00214 }
00215
00216
00217
for (
temp.
c=0;
temp.
c<128;
temp.
c++){
00218 data
unsigned int i;
00219 i =
Mp3ReadRegister(
SPI_HDAT0);
00220 *
dataBufPtr++ = (i>>8);
00221 *
dataBufPtr++ = (i&0xff);
00222 }
00223
00224
00225 {
00226
00227
signed int soundlevel;
00228
00229
if (
uiMode ==
UI_TITLE){
00230 soundlevel = (
signed char)
diskSect.
raw.
buf[1]<<7;
00231 soundlevel |=
diskSect.
raw.
buf[0]>>1;
00232
if (soundlevel<0) soundlevel = -soundlevel;
00233
displayValue=0;
00234
while (soundlevel>31){
00235
displayValue++;
00236 soundlevel>>=1;
00237 }
00238
if (soundlevel>19)
displayValue++;
00239
if (soundlevel>12)
displayValue++;
00240
if (soundlevel>6)
displayValue++;
00241
displayValue-=3;
00242
displayValue*=13;
00243
if (oldlevel>
displayValue){
00244
displayValue=oldlevel-3;
00245 }
00246 oldlevel=
displayValue;
00247 }
00248
AvailableProcessorTime();
00249
00250 }
00251
00252 }
00253
00254
00255
00256
Mp3DeselectControl();
00257
00258
if (blockNumber==2){
00259
00260
00261
00262
00263
00264
temp.
l = (sectorCount/8) * 505;
00265
temp.
l /= 1000;
00266
Mp3WriteRegister(
SPI_DECODE_TIME,
temp.
b.b1,
temp.
b.b0);
00267
Mp3DeselectControl();
00268
00269 blockNumber = 0;
00270 sectorCount++;
00271
WriteDiskSector(
sectorAddress.
l);
00272 lastSector =
freeSector;
00273
ScanForFreeSector();
00274
sectorAddress.
l =
freeSector;
00275
dataBufPtr =
diskSect.
raw.
buf;
00276
if (
freeSector!=(lastSector+1)){
00277 stopRecording = 1;
00278 ConsoleWrite(
"\nFragment end - can't continue recording!\n");
00279
InitDisplay(
DS_STATIC,
"FRAGMENT",
" LIMIT!!",0);
00280 continueRecording = 1;
00281 }
00282 }
00283
00284
displayValue = 0;
00285
00286 }
00287
fragment[0].
length = sectorCount;
00288
00289
00290
00291 {
00292 xdata
addressType size;
00293
00294
ReadDiskSector(
fragment[0].start);
00295
00296
00297 size.l = (sectorCount-1)*1010;
00298
diskSect.
raw.
buf[48] = size.b.b0;
00299
diskSect.
raw.
buf[49] = size.b.b1;
00300
diskSect.
raw.
buf[50] = size.b.b2;
00301
diskSect.
raw.
buf[51] = size.b.b3;
00302
00303
00304 size.l = (sectorCount*512)-8;
00305
diskSect.
raw.
buf[4] = size.b.b0;
00306
diskSect.
raw.
buf[5] = size.b.b1;
00307
diskSect.
raw.
buf[6] = size.b.b2;
00308
diskSect.
raw.
buf[7] = size.b.b3;
00309
00310
00311 size.l = (sectorCount*512)-512;
00312
diskSect.
raw.
buf[508] = size.b.b0;
00313
diskSect.
raw.
buf[509] = size.b.b1;
00314
diskSect.
raw.
buf[510] = size.b.b2;
00315
diskSect.
raw.
buf[511] = size.b.b3;
00316
00317
WriteDiskSector(
sectorAddress.
l);
00318 }
00319
00320 ConsoleWrite(
"Registering... FStart:");
00321 ConsolePutUInt(
fragment[0].start);
00322 ConsoleWrite(
"Registering... Size:");
00323 ConsolePutUInt(
fragment[0].length);
00324
00325
00326
fragment[1].
start = 0x0fffffff;
00327
WriteClusterChain();
00328
00331
sectorAddress.
l = 0;
00332
00333
Mp3Reset();
00334
if (continueRecording)
return PS_RECORDING;
00335
return PS_NEXT_SONG;
00336
00337 }
00338