playmp3.pp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. program playmp3;
  2. {$J+}
  3. {$macro on}
  4. {$mode objfpc}
  5. uses
  6. cmem, ctypes, gctypes, asndlib, mp3player, gccore;
  7. // include generated header
  8. {$include inc/sample.mp3.inc}
  9. {$L build/sample.mp3.o}
  10. var
  11. xfb: pcuint32 = nil;
  12. rmode: PGXRModeObj = nil;
  13. begin
  14. // Initialise the video system
  15. VIDEO_Init();
  16. // Initialise the attached controllers
  17. WPAD_Init();
  18. // Initialise the audio subsystem
  19. ASND_Init();
  20. MP3Player_Init();
  21. // Obtain the preferred video mode from the system
  22. // This will correspond to the settings in the Wii menu
  23. rmode := VIDEO_GetPreferredMode(nil);
  24. // Allocate memory for the display in the uncached region
  25. xfb := SYS_AllocateFramebuffer(rmode);
  26. // Initialise the console, required for printf
  27. console_init(xfb,20,20,rmode^.fbWidth,rmode^.xfbHeight,rmode^.fbWidth*VI_DISPLAY_PIX_SZ);
  28. // Set up the video registers with the chosen mode
  29. VIDEO_Configure(rmode);
  30. // Tell the video hardware where our display memory is
  31. VIDEO_SetNextFramebuffer(xfb);
  32. // Make the display visible
  33. VIDEO_SetBlack(FALSE);
  34. // Flush the video register changes to the hardware
  35. VIDEO_Flush();
  36. // Wait for Video setup to complete
  37. VIDEO_WaitVSync();
  38. if (rmode^.viTVMode and VI_NON_INTERLACE) <> 0 then VIDEO_WaitVSync();
  39. // The console understands VT terminal escape codes
  40. // This positions the cursor on row 2, column 0
  41. // we can use variables for this with format codes too
  42. // e.g. printf ("\x1b[%d;%dH", row, column );
  43. printf(#$1b'[2;0H');
  44. printf('Playing sample MP3 file...Press HOME to exit.'#10);
  45. MP3Player_PlayBuffer(@sample_mp3, sample_mp3_size, nil);
  46. while true do
  47. begin
  48. // Call WPAD_ScanPads each loop, this reads the latest controller states
  49. WPAD_ScanPads();
  50. // WPAD_ButtonsDown tells us which buttons were pressed in this loop
  51. // this is a "one shot" state which will not fire again until the button has been released
  52. // We return to the launcher application via exit
  53. if ( WPAD_ButtonsDown(0) and WPAD_BUTTON_HOME ) <> 0 then exit;
  54. // Wait for the next frame
  55. VIDEO_WaitVSync();
  56. end;
  57. end.