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

📄 player.c

📁 MP3 Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
  case UI_TREBLE: //Show treble bar    LcdSelectFont(lcdFont_barchars);    displayStyle = DS_PERCENTAGE;    strcpy(displayTitle,"Treble: ");    displayValue = (treble/5)*4;    if (displayValue<1) displayValue = 1;    break;  case UI_RECLEVEL: //Show recording level    if (playingState==PS_RECORDING){      LcdSelectFont(lcdFont_barchars);      displayStyle = DS_PERCENTAGE;      strcpy(displayTitle,"RecLevel");      displayValue = (reclevel);      if (reclevel==0){	strcpy(displayTitle,"RecLevel <Auto> ");	displayStyle = DS_RAWTEXT; //Reveal the "auto" text      }    }else{      //Not in recording      displayStyle = DS_NO_YES;      strcpy (displayTitle, "Record? ");    }    break;  case UI_SPEC: // Spectrum analyzer    if (playingState == PS_RECORDING){      uiMode++; //Don't show specana when recording    }    LcdSelectFont(lcdFont_vertical_barchars);    displayStyle = DS_RAWTEXT;    ScreenSetPlayTime();    // Request to read Spectrum Analyzer register    Mp3WriteRegister(7, 0x18, 0x04);    // Read Spectrum Analyzer registers    {      for (i=0;i<8;i++) { //for each band i in [0..7]	signed char thisband = Mp3ReadRegister(6);		/* thisband now has spectrum value 0..63. We adjust it a little	   for best image on the evakit LCD. You also get peak values	   etc from the chip but we don't use them in the evakit screen.	   we use 8 bands, but up to 23 are obtainable from the chip. */	thisband &= 63;                /* mask all but level info */	thisband >>= 1;                /* LCD resolution is not high */	thisband -= 3;                 /* base offset */ 	if (i==0) thisband -= 2;       /* decrease bass bar level */	if (i==6) thisband += 1;       /* increase treble bar level */	if (i==7) thisband += 1;       /* increase treble bar level */	if (thisband>7) thisband = 7;  /* high limit */	if (thisband<0) thisband =' '; /* low limit */	displayTitle[i+8] = thisband; //Store to display mem	      }//for each band    }    break;      } //switch(uiMode)      // Buttons handler  // Perform mode-dependent button handling  if ((KEY_BUTTON) && (uiReturnDelay < UI_RETURN_DELAY-20)){    LcdReset();    uiMode++;    uiReturnDelay = UI_RETURN_DELAY;  }  switch(uiMode){  case UI_TITLE:  case UI_SPEC:    if (KEY_FARRIGHT){      playingState = PS_NEXT_SONG; /* Request */    }          if (KEY_FARLEFT){      playingState = PS_PREVIOUS_SONG; /* Request */    }          break;  case UI_VOLUME:        if (KEY_FARLEFT){      uiReturnDelay = UI_RETURN_DELAY;      if (volume++ == 254) volume = 254; //Change + limit to 254 (minimum vol)      Mp3SetVolume(volume,volume);    }        if (KEY_FARRIGHT){      uiReturnDelay = UI_RETURN_DELAY;      if (volume-- == 0) volume = 0; //Change + limit to 0 (maximum volume)      Mp3SetVolume(volume,volume);    }    break; // UI_VOLUME  case UI_BASS:  case UI_TREBLE: //BASS and TREBLE use the same VS10xx register    bassUpdateNeeded = 0;        //First let's see if a key is pressed; does the user want to set level?    if (uiMode==UI_BASS){ //BASS screen is active      if (KEY_FARLEFT){	bassUpdateNeeded = 1;	if (bass-- == 0) bass = 0; //Change + limit to 0 (OFF setting)      }      if (KEY_FARRIGHT){	bassUpdateNeeded = 1;	if (bass++ == 127) bass = 127; //Change + limit to 127 (max setting)      }    }else{ //TREBLE screen is active            if (KEY_FARLEFT){	bassUpdateNeeded = 1; //SCI_BASS is for both bass and treble	if (treble-- == 0) treble = 0; //Change + limit to 0 (OFF setting)      }      if (KEY_FARRIGHT){	bassUpdateNeeded = 1; //SCI_BASS is for both bass and treble	if (treble++ == 127) treble = 127; //Change + limit to 127 (max)      }          }    if (bassUpdateNeeded){      unsigned int newBassRegister;      //User has pushed button to alter bass/treble register      //calculate new value      /** Bass/Treble setting calculation        *       * There are 2 or 4 adjustments possible:       * - Bass Frequency (1011B/E, 1002, 10x3) : 2..15 -> 20..1500 Hz       * - Bass boost (1011B/E, 1002, 10x3) : 0..15 -> 0ff..+15dB)       * - Treble Frequency (1011E, 10x3) : 0..15 -> 0..15kHz       * - Treble level (1011E, 10x3) : -8..+7 -> -12..+10.5dB       *        * In this software, all are adjusted based from a single setting       * (0..128) for bass and another for treble. You may wish to allow       * user to control frequency and level separately or set fixed       * frequencies for a known speaker type. This algorithm increases       * the frequency range of adjustment with the increasing level.       */             //Let's start from bass frequency setting.      //min(0) should give 2 (20Hz), max(127) should give 15 (150Hz)      newBassRegister = (bass + 23) / 10; //into bits 3..0, clear hibits            //Bass boost level.      //min(0) should give 0, max(127) should give 15      newBassRegister |= (bass>>3)<<4; //insert to bits 7..4      //Then the treble frequency      //min(0) should give 15(15kHx), max(127) should give 2(2kHz)      newBassRegister |= (((148-treble)>>3)+2)<<8; //insert into bits 11..8      //Finally the treble value (-8..7)      //min(0) should give -8, max(127) should give 7;      newBassRegister |= ((treble>>3)-8)<<12; //insert into bits 15..12                  uiReturnDelay = UI_RETURN_DELAY;      if (Mp3ReadRegister(SPI_BASS)!=newBassRegister){	Mp3WriteRegister(SPI_BASS,newBassRegister>>8,newBassRegister&0xff);      }      //i = newBassRegister;      //displayTitle[4] = lcd_hexchars[i>>12];      //displayTitle[5] = lcd_hexchars[(i>>8)&0x0f];      //displayTitle[6] = lcd_hexchars[(i>>4)&0x0f];      //displayTitle[7] = lcd_hexchars[i&0x0f];        }    break; // UI_BASS and UI_TREBLE  case UI_RECLEVEL:        if (playingState==PS_RECORDING){      if (KEY_FARRIGHT){	uiReturnDelay = UI_RETURN_DELAY;	if (reclevel++ == 100){	  reclevel = 100;	}	Mp3WriteRegister(SPI_AICTRL1,			 ((int)reclevel*32)>>8,((int)reclevel*32)&0xff);	SPIPutChar(0);SPIWait();      }            if (KEY_FARLEFT){	uiReturnDelay = UI_RETURN_DELAY;	if (reclevel-- == 0){	  reclevel = 0;	}	Mp3WriteRegister(SPI_AICTRL1,			 ((int)reclevel*32)>>8,((int)reclevel*32)&0xff);	SPIPutChar(0);SPIWait();      }    }else{      //Not in recording      if (KEY_FARRIGHT){	//Enter recording mode	playingState=PS_RECORDING; //request to record      }    }    break; // UI_RECLEVEL  case UI_STOP:        if (KEY_FARRIGHT){      playingState = PS_END_OF_SONG; /* Request to abort playing */    }          break; // UI_STOP      case UI_CUE:        if (playingState == PS_NORMAL){ /* Only control when PS_NORMAL */      if (KEY_FARRIGHT){	uiReturnDelay = UI_RETURN_DELAY; /* Don't go back to title just yet */	playingState = PS_CUE; /* Request */      }            if (KEY_FARLEFT){	uiReturnDelay = UI_RETURN_DELAY;	playingState = PS_REWIND; /* Request */      }          }    break; // UI_SKIP  case UI_END_OF_MODES:    uiMode = UI_TITLE;    break; // UI_END_OF_MODES      } //End Switch  // Draw screen  UpdateDisplay();}  /** Plays a disk file. Returns 1) if the file ends or 2) if the global    variable playingState is not PS_NORMAL i.e. user has requested     stop or next or previous.*/void PlayCurrentFile(){  xdata char c, nFragments;  playingState = PS_NORMAL; /* Request to play normally */  //uiMode = UI_SPEC; /* User interface: show title SPECANA FOR VS1003*/  LcdLocateHome();  LcdPutConstantString("Opening ");  ConsoleWrite ("Building file fragment table...");  nFragments = BuildFragmentTable(); /* Too slow, rewrite! */  ConsoleWrite("\rFragments: ");  ConsolePutUInt(nFragments);  LcdLocateHome();  LcdPutConstantString("Playing ");  for (c=0; c<nFragments; c++){    sectorAddress.l = fragment[c].start;    ConsoleWrite ("\rPlayer: Playing from sector ");    ConsolePutUInt (sectorAddress.l);    if (PlayDiskSectors(fragment[c].length)!=0){      Mp3WriteRegister(SPI_MODE,0,SM_OUTOFWAV);      SendZerosToVS10xx();      return; //return without touching the value of playingState    }  }  SendZerosToVS10xx();  // After finishing normally default to requesting to play next song          playingState = PS_NEXT_SONG;}/** Program Entry Point. * In the final program, main() should be very small. * Currently it's the playground for developing the player * functionality. Most of it will be cleared away to new * functions soon. */void main(){  unsigned int currentFile;  InitBoard();  // Start "User Interface" timer  ET0 = 1;  EA = 1;   TR0 = 1;  //LcdSplashScreen();   InitDisplay (DS_STATIC,"        ","        ",0);    ConsoleWrite ("\rVLSIPlayer\rStarting up.\r\r");       LcdReset();  LcdPutConstantString ("Filesys ");  LcdLocateLine2();  LcdPrintGenericResult (InitFileSystem());  Mp3Reset();  LoadPatch();  StartPatch();  // If left button is pressed during boot, enter recording.  if (KEY_FARLEFT){    while(KEY_LEFT)      ;    Record();  }  #ifdef VS1003  uiMode = UI_SPEC;   //For VS1003 default to SPECTRUM ANALYZER screen#else  uiMode = UI_TITLE;  //For others, default to TITLE screen#endif    playingState = PS_NEXT_SONG;  currentFile = 1;  while (1){    ConsoleWrite("SPMax: ");ConsolePutHex8(SPMax);    ConsoleWrite("PlayingState: ");ConsolePutHex8(playingState);    // has someone requested to record?    if (playingState == PS_RECORDING){      uiMode = UI_TITLE;      playingState = Record(); //record returns PS_NEXT_SONG or PS_RECORDING      while (KEY_BUTTON)	; //Wait until button is depressed      ConsoleWrite("\rFinished recording.\r");            currentFile = 1;      playingState == PS_NEXT_SONG;	    }            if (OpenFile(currentFile)){      currentFile = 1;      if (OpenFile(currentFile)){	LcdReset();	LcdPutConstantString("No files.");	while(1);      }    }       LcdReset();    LcdPutConstantString("File ");    LcdPutUInt(currentFile);    LcdLocateLine2();    for (temp.c=0; temp.c<8; temp.c++){      LcdPutChar(currentFileName[temp.c]);    }                while ((KEY_BUTTON)||(KEY_FARLEFT)||(KEY_FARRIGHT)||	   (KEY_LEFT)||(KEY_RIGHT))      ; /* Wait until no key is pressed */    while (((!KEY_BUTTON)&&(!KEY_FARLEFT)&&(!KEY_FARRIGHT))	   &&(playingState == PS_NORMAL))      ; /* Wait untis some key is pressed or playing state not normal*/        /* See if keystroke requests previous/next song */    if (KEY_FARLEFT) currentFile--;    if (KEY_FARRIGHT) currentFile++;    if (currentFile==0) currentFile = 1;    if (KEY_BUTTON || 	(playingState==PS_NEXT_SONG) || 	(playingState==PS_PREVIOUS_SONG)){      while (KEY_BUTTON)	;      PlayCurrentFile();      ConsoleWrite ("Playing state after playing is: ");      ConsolePutUInt (playingState);            if (playingState == PS_PREVIOUS_SONG) currentFile--;      if (playingState == PS_NEXT_SONG) currentFile++;      if (currentFile==0) currentFile = 1;      if (playingState == PS_END_OF_SONG) playingState = PS_NORMAL;                        Mp3SoftReset();      LoadPatch();      StartPatch();      while ((KEY_BUTTON)||(KEY_FARLEFT)||(KEY_FARRIGHT)||	     (KEY_LEFT)||(KEY_RIGHT))	; /* Wait until no key is pressed */    }      }   }

⌨️ 快捷键说明

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