Exemple #1
0
int Audio_Play(char *filename){

    char* suffix = strrchr(filename, '.');
    
    if(MediaType=="mp3"){
         MP3_End();
         }
    else if(MediaType=="ogg"){
         OGG_End();
         }
    else if(MediaType=="mod"){
         MIKMOD_End();
         }
	   
     if (stricmp(suffix, ".mp3") == 0) {
                         MP3_Init(NULL);
                         MP3_Load(filename);
                         MediaType = "mp3";
                         MP3_Play();
                         }
                         
     else if (stricmp(suffix, ".ogg") == 0) {
                         OGG_Init(NULL);
                         OGG_Load(filename);
                         MediaType = "ogg";
                         OGG_Play();
                         }
     //Doesnt work :(
     else if (stricmp(suffix, ".mod") == 0 || stricmp(suffix, ".xm") == 0 || stricmp(suffix, ".it") == 0 || stricmp(suffix, ".s3m") == 0 || stricmp(suffix, ".stm") == 0 || stricmp(suffix, ".mtm") == 0 || stricmp(suffix, ".it") == 0 || stricmp(suffix, ".669") == 0 || stricmp(suffix, ".far") == 0 || stricmp(suffix, ".dsm") == 0 || stricmp(suffix, ".med") == 0 || stricmp(suffix, ".ult") == 0 || stricmp(suffix, ".uni") == 0) {
                         MIKMOD_Init(NULL);
                         MIKMOD_Load(filename);
                         MediaType = "mod";
                         MIKMOD_Play();
                         }
}
Exemple #2
0
int main(int argc,char* argv[]){
  int len;
  int total=0;
  float length;
  int r;
  int audio_fd;
  
  mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
  if(!mp3file){  printf("file not found\n");  exit(1); }
  
  GetCpuCaps(&gCpuCaps);

  // MPEG Audio:
#ifdef USE_FAKE_MONO
  MP3_Init(0);
#else
  MP3_Init();
#endif
  MP3_samplerate=MP3_channels=0;
  len=MP3_DecodeFrame(buffer,-1);
  
  audio_fd=open("/dev/dsp", O_WRONLY);
  if(audio_fd<0){  printf("Can't open audio device\n");exit(1); }
  r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
  r=MP3_channels-1;ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
  r=MP3_samplerate;ioctl (audio_fd, SNDCTL_DSP_SPEED, &r);
  printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r,MP3_samplerate);
  
  while(1){
      int len2;
      if(len==0) len=MP3_DecodeFrame(buffer,-1);
      if(len<=0) break; // EOF
      
      // play it
      len2=write(audio_fd,buffer,len);
      if(len2<0) break; // ERROR?
      len-=len2; total+=len2;
      if(len>0){
          // this shouldn't happen...
          memcpy(buffer,buffer+len2,len);
          putchar('!');fflush(stdout);
      }
  }
  
  fclose(mp3file);
  
}
Exemple #3
0
static int init(sh_audio_t *sh)
{
  // MPEG Audio:
  dec_audio_sh=sh; // save sh_audio for the callback:
//  MP3_Init(fakemono,mplayer_accel,&mplayer_audio_read); // TODO!!!
#ifdef USE_FAKE_MONO
  MP3_Init(fakemono);
#else
  MP3_Init();
#endif
  MP3_samplerate=MP3_channels=0;
  sh->a_buffer_len=MP3_DecodeFrame(sh->a_buffer,-1);
  if(!sh->a_buffer_len) return 0; // unsupported layer/format
  sh->channels=2; // hack
  sh->samplesize=2;
  sh->samplerate=MP3_samplerate;
  sh->i_bps=MP3_bitrate*(1000/8);
  MP3_PrintHeader();
  return 1;
}
int main(int argc,char* argv[]){
  int len;
  int total=0;
  unsigned int time1;
  float length;
#ifdef DUMP_PCM
  FILE *f=NULL;
  f=fopen("test.pcm","wb");
#endif

  mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
  if(!mp3file){  printf("file not found\n");  exit(1); }

  GetCpuCaps(&gCpuCaps);

  // MPEG Audio:
#ifdef CONFIG_FAKE_MONO
  MP3_Init(0);
#else
  MP3_Init();
#endif
  MP3_samplerate=MP3_channels=0;

  time1=GetTimer();
  while((len=MP3_DecodeFrame(buffer,-1))>0 && total<2000000){
      total+=len;
      // play it
#ifdef DUMP_PCM
      fwrite(buffer,len,1,f);
#endif
      //putchar('.');fflush(stdout);
  }
  time1=GetTimer()-time1;
  length=(float)total/(float)(MP3_samplerate*MP3_channels*2);
  printf("\nDecoding time: %8.6f\n",(float)time1*0.000001f);
  printf("Uncompressed size: %d bytes  (%8.3f secs)\n",total,length);
  printf("CPU usage at normal playback: %5.2f %%\n",time1*0.0001f/length);

  fclose(mp3file);
  return 0;
}
Exemple #5
0
void
psp_audio_init()
{
  psp_audio_chid = sceAudioChReserve(-1, 1024, 0);
  psp_audio_thid = sceKernelCreateThread( "audio_thread",(void*)&psp_audio_thread,0x12,0x10000,0,NULL);
	sceKernelStartThread( psp_audio_thid, 0, 0);

  MP3_Init();

  psp_cdaudio_chid = sceAudioChReserve(-1, 1024, 0);
  psp_cdaudio_thid = sceKernelCreateThread( "cdaudio_thread",(void*)&psp_cdaudio_thread,0x12,0x10000,0,NULL);
	sceKernelStartThread( psp_cdaudio_thid, 0, 0);
}
Exemple #6
0
int
psp_mp3_play_file(char* filename, int repeat)
{
# ifndef LINUX_MODE
  isRepeatMode = repeat;

  MP3_Stop();
  MP3_Init();
  if (! MP3_Load(filename)) {
    MP3_Stop();
  } else {
    MP3_Play();
  }
# endif
}
Exemple #7
0
int main() {
    pspDebugScreenInit();
    SetupCallbacks();
    scePowerSetClockFrequency(333, 333, 166);
    
    pspAudioInit();
    SceCtrlData pad;
    int i;

    tzset();
    printf("Hello World\n");
    time_t now;
    now = time(NULL);
    printf("Started %s\n", ctime(&now));

    MP3_Init(1);
    MP3_Load("test.mp3");
    MP3_Play();
    while(1) {
            sceCtrlReadBufferPositive(&pad, 1);
            if(pad.Buttons & PSP_CTRL_CROSS) {
                      break;
            } else if(pad.Buttons & PSP_CTRL_CIRCLE) {
                      MP3_Pause();
                      for(i=0; i<10; i++) {
                                sceDisplayWaitVblankStart();
                      }
            }

            if (MP3_EndOfStream() == 1) {
                      MP3_Stop();
            }
    }
    MP3_Stop();
    MP3_FreeTune();
    sceKernelSleepThread();
    return 0;
    }
Exemple #8
0
//int main(void) __attribute__((noreturn)); // Main never returns so don't waste stack space on it.
int main(void)
{
  Uint16 TempInt;


  // Set up the I/O lines

  DDRA = PortDirA;
  DDRB = PortDirB;
  SD_PowerOn();
  DDRC = PortDirC;
  DDRD = PortDirD;

  PINA = PortPullUpA;
  PINB = PortPullUpB;
  PINC = PortPullUpC;
  PIND = PortPullUpD;

  //set the channel is the keyboard.
  //mp3 init finish ,after reset the slave board have volume;
  SetBit(SelAPort, Sel0A);
  SetBit(SelAPort, Sel1A);
  SetBit(SelBPort, Sel0B);
  SetBit(SelBPort, Sel1B);
  SetBit(SelCPort, Sel0C);
  SetBit(SelCPort, Sel1C);
  LastError = 0;            // Indicate no errors yet

  // Init the peripherals

  Timer_Init();                               // Set up timers
  UART_Init();
  InitKey();
  BCMessageInit(BCAMP3Contoller);

  wdt_enable(WDTO_8S);//wdt 8s
  // Set up key vars

  UART_Rx(CmdRxBuf, 1);
  Track         = 1;
  IdleTime      = 0;
  FlashPhase    = 0;
  Volume        = 0;
  PreMuteVolume = 0;
  Ramp          = NoRamp;
  LastKey       = 0;
  for(Bay = LeftBay; Bay <= NoBay; Bay++) {
    BayProduct[Bay] = UnknownProduct;
    BaySource[Bay]  = 0xff;
  }
  Bay           = LeftBay;
  SlaveMode     = false;
  SlaveModePara = 0;
  sei();      // Enable global interrupts

  // Print product build banner

  wdt_reset();
  UART_TxStr("\r\n======================================\r\n031-517-202 ");
  UART_TxChar('0' + SWVerMajor);
  UART_TxChar('.');
  UART_TxChar('0' + SWVerMinor);
  UART_TxChar('.');
  UART_TxChar('0' + SWVerFix);
  UART_TxChar(' ');
  UART_TxStr(__TIME__);
  UART_TxChar(' ');
  UART_TxStr(__DATE__);
  UART_TxStr("\r\n======================================\r\n");

  // For reset the slave board maybe volume very high so have noise
  // so first set volume is 0

  wdt_reset();
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCALeftBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCACenterBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg
  ExchangeBoardMsg(BCARightBay, BCTVolume, 0, 0, BCTAck);
  BCMessageReceive(RxBuf);      // Finished with it so get ready for next msg

  // Test the LEDs while bays boot up

  DelayMS(100);                     // Allow some time for keypad to boot up
  UART_TxStr("Testing LEDs\r\n");
  for (TempInt = 1; TempInt <= 2; TempInt++){
    for (Key = 1; Key <= MaxKey; Key++) {
      if(!SetLamp(Key)){
        SlaveMode = true;
        break;
      }
      DelayMS(250);
      wdt_reset();//feed the watchdog
    }
    if(SlaveMode)
      break;
  }

  // Show version number

  if(!SlaveMode){
    SetLamps(0);
    DelayMS(1000);
    SetLamps(LeftLEDs | SWVerMajor);
    DelayMS(2000);
    wdt_reset();
    SetLamps(RightLEDs | SWVerMinor);
    DelayMS(2000);
    wdt_reset();
    SetLamps(LeftLEDs | RightLEDs | SWVerFix);
    DelayMS(2000);
    wdt_reset();
  }

  // Load EEPROM settings

  SetLamp(1);
  LoadEEPROMSetting();
  UART_TxStr("Settings:\r\n");
  PrintSettings();


  //wait for tablet ready wait 60 seconds
  if(SlaveMode)
  {
    UART_TxStr("Wait for tablet ready\r\n");
    for(TempInt = 0; TempInt < 6000; TempInt++)
    {
      DelayMS(10);
      CheckForBoardMsg();
      wdt_reset();
    }
  }
  // Prepare MP3 decoder for work

  wdt_reset();       // Feed the watchdog
  DelayMS(500);
  SetLamp(4);
  Timer_Clear();
  for (TempInt = 1; TempInt <= 5; TempInt++) {
    if (MP3_Init())
      break;          // If init ok exit loop
    wdt_reset();      // Feed the watchdog
    DelayMS(250);     // Wait before trying again
  }
  MP3_Volume(250);
  UART_TxStr("MP3 init time = ");
  UART_TxNum(Timer_Read(), 1);
  UART_TxStr("mS\r\n");

  // Find the last track on the card
  wdt_reset();
  SetLamp(3);
  for (Tracks = 1; Tracks <= 99; Tracks++) {
    if (!MP3_OpenFile(Tracks))
      break;
  }
  Tracks--;

  SetBassTreble();  // Set the audio curve


  // Determine what is connected

  wdt_reset();
  SetLamp(2);
  SearchDevices();

  if(!SlaveMode)
  {
    ConfigDevices();    // Configure connected devices

    SetIdleState();
    MP3_Track(1);
    if (!InputPresent[MP3In])       // If no MP3 player display error
      ShowError(ErrorNoMP3, false);
  }

  UART_TxStr("Start up complete\r\n");

  //
  // Enter the main loop
  //

  Timer_Clear();
  SlaveModeTimerClear();
  for( ; ; ) {              // Run forever
    if (SlaveMode) {        // In slave mode only handle slave mode messages
      CheckForBoardMsg();
      if(SlaveModeTimerRead() > 5000)
      {
        UART_TxNum(SlaveModeTimerRead(),5);
        UART_TxStr("\r\nMore than 5 seconds change to normal mode\r\n");
        SlaveMode = false;//return to Normal mode
        SearchDevices();
        Volume = 99; //if Volume == IdleVolume the not need send the volume so need give the diffent IdleVolume value
        Bay = RightBay;
        SetIdleState();
        SetMux(Input,LeftBay);
        SetMux(Input,CenterBay);
        SetMux(Input,RightBay);
      }
      wdt_reset();  // Update the watchdog
    } else {                //  Not in slave mode so feed the MP3 engine

      if (MP3Ready && !MP3_Process())
        MainLoop(0);        // Tell the main loop we have stopped playback

      //  Call the main loop if it is due

      if (Timer_Read() >= LoopPeriod) {     // Run the main loop at 10Hz
        Timer_Clear();
        MainLoop(1);        // Tell the main loop we are still playing a track
      }
    }
  }
  return 0;
}