audio_modes.pp 5.5 KB

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