2
0

audio_modes.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. program AudioModes;
  2. {$L build/soundbank.bin.o}
  3. {$mode objfpc}
  4. uses
  5. ctypes, nds9, maxmod9;
  6. (***********************************************
  7. * this example demonstrates the 3 audio modes
  8. *
  9. * functions used:
  10. * mmInitDefaultMem(soundbank)
  11. * Initialize with default settings
  12. *
  13. * mmLoad( module )
  14. * Loads a module to be played
  15. *
  16. * mmStart( module )
  17. * Starts playback of a module
  18. *
  19. * mmStop()
  20. * Stops module playback
  21. *
  22. * mmSelectMode( mode )
  23. * Selects the audio mode
  24. * modes:
  25. * 0: MM_MODE_A, hardware audio mode
  26. * 1: MM_MODE_B, interpolated audio mode
  27. * 2: MM_MODE_C, extended audio mode
  28. *********************************************************)
  29. var
  30. soundbank_bin_end: array [0..0] of cuint8; cvar; external;
  31. soundbank_bin: array [0..0] of cuint8; cvar; external;
  32. soundbank_bin_size: cuint32; cvar; external;
  33. const
  34. MOD_KEYG_SUBTONAL = 0;
  35. MOD_PURPLE_MOTION_INSPIRATION = 1;
  36. MOD_REZ_MONDAY = 2;
  37. MSL_NSONGS = 3;
  38. MSL_NSAMPS = 65;
  39. MSL_BANKSIZE = 68;
  40. SHOW_TEXT: pchar = #10 +
  41. ' Maxmod Audio Modes Example'#10#10 +
  42. ' Song: '#10 +
  43. ' Mode: '#10#10 +
  44. ' Left/Right: Select Song'#10 +
  45. ' Up/Down: Change Audio Mode'#10 +
  46. ' A: Start Playback'#10 +
  47. ' B: Stop Playback'#10#10 +
  48. ' Tip: Play subtonal with the'#10 +
  49. ' extended mode or else it won''t'#10 +
  50. ' sound right.'#10#10 +
  51. ' Another Tip: The interpolated'#10 +
  52. ' mode doesn''t work in current'#10 +
  53. ' emulators.';
  54. var
  55. // song order
  56. song_order: array [0..2] of cshort = ( MOD_KEYG_SUBTONAL, MOD_REZ_MONDAY, MOD_PURPLE_MOTION_INSPIRATION );
  57. // rez-monday.mod is a bit loud, so we will lower the volume to 500 (normal volume is 1024)
  58. song_volumes: array [0..2] of cshort = ( 1024, 500, 1024 );
  59. // strings for the "Song: " display
  60. song_titles: array [0..2] of pchar = (
  61. 'subtonal (30ch) ',
  62. 'monday (14ch) ',
  63. 'inspiration (4ch)');
  64. // strings for the "Mode: " display
  65. audiomode_names: array [0..2] of pchar = (
  66. 'A - Hardware (16ch) ',
  67. 'B - Interpolated (16ch)',
  68. 'C - Extended (30ch) ');
  69. song: integer = 0;
  70. mode: integer = 0;
  71. keys: integer;
  72. procedure print_song(song: cint);
  73. begin
  74. iprintf(#27'[3;7H%s', song_titles[song] );
  75. end;
  76. procedure print_mode(mode: cint);
  77. begin
  78. iprintf(#27'[4;7H%s', audiomode_names[mode] );
  79. end;
  80. begin
  81. //---------------------------------------------------------
  82. // setup console
  83. //---------------------------------------------------------
  84. consoleDemoInit();
  85. // set a dark blue backdrop
  86. BG_PALETTE_SUB[0] := RGB15( 0, 0, 10 );
  87. //---------------------------------------------------------
  88. // init maxmod with default settings
  89. //---------------------------------------------------------
  90. mmInitDefaultMem(mm_addr(@soundbank_bin));
  91. //---------------------------------------------------------
  92. // load songs (must be loaded before using with mmStart)
  93. //---------------------------------------------------------
  94. mmLoad( MOD_KEYG_SUBTONAL );
  95. mmLoad( MOD_REZ_MONDAY );
  96. mmLoad( MOD_PURPLE_MOTION_INSPIRATION );
  97. //---------------------------------------------------------
  98. // display screen info
  99. //---------------------------------------------------------
  100. iprintf( SHOW_TEXT );
  101. print_song( song );
  102. print_mode( mode );
  103. //---------------------------------------------------------
  104. // main loop
  105. //---------------------------------------------------------
  106. while true do
  107. begin
  108. //-----------------------------------------------------
  109. // get new keypad input
  110. //-----------------------------------------------------
  111. scanKeys();
  112. keys := keysDown();
  113. //-----------------------------------------------------
  114. // LEFT: select previous song
  115. //-----------------------------------------------------
  116. if( keys and KEY_LEFT ) <> 0 then
  117. begin
  118. dec(song);
  119. if( song < 0 ) then song := 2;
  120. print_song( song );
  121. end;
  122. //-----------------------------------------------------
  123. // RIGHT: select next song
  124. //-----------------------------------------------------
  125. if( keys and KEY_RIGHT ) <> 0 then
  126. begin
  127. inc(song);
  128. if( song > 2 ) then song := 0;
  129. print_song( song );
  130. end;
  131. //-----------------------------------------------------
  132. // A: start song
  133. //-----------------------------------------------------
  134. if( keys and KEY_A ) <> 0 then
  135. begin
  136. mmSetModuleVolume( song_volumes[song] );
  137. // loop module until stopped with B keypress
  138. mmStart( song_order[song], MM_PLAY_LOOP );
  139. end;
  140. //-----------------------------------------------------
  141. // B: stop song
  142. //-----------------------------------------------------
  143. if( keys and KEY_B ) <> 0 then
  144. begin
  145. mmStop();
  146. end;
  147. //-----------------------------------------------------
  148. // UP: next audio mode
  149. //-----------------------------------------------------
  150. if( keys and KEY_UP ) <> 0 then
  151. begin
  152. inc(mode);
  153. if( mode > 2 ) then mode := 0;
  154. print_mode( mode );
  155. // switch audio mode
  156. mmSelectMode( mode );
  157. end;
  158. //-----------------------------------------------------
  159. // DOWN: previous audio mode
  160. //-----------------------------------------------------
  161. if( keys and KEY_DOWN )<> 0 then
  162. begin
  163. dec(mode);
  164. if( mode < 0 ) then mode := 2;
  165. print_mode( mode );
  166. // switch audio mode
  167. mmSelectMode( mode );
  168. end;
  169. //-----------------------------------------------------
  170. // wait until next frame
  171. //-----------------------------------------------------
  172. swiWaitForVBlank();
  173. end;
  174. end.