audio.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. (*
  2. $Id: audio.inc 25 2007-12-10 21:06:46Z p4p3r0 $
  3. ------------------------------------------------------------------------------
  4. Copyright (C) 2005
  5. Jason Rogers (dovoto)
  6. Dave Murphy (WinterMute)
  7. This software is provided 'as-is', without any express or implied
  8. warranty. In no event will the authors be held liable for any
  9. damages arising from the use of this software.
  10. Permission is granted to anyone to use this software for any
  11. purpose, including commercial applications, and to alter it and
  12. redistribute it freely, subject to the following restrictions:
  13. 1. The origin of this software must not be misrepresented; you
  14. must not claim that you wrote the original software. If you use
  15. this software in a product, an acknowledgment in the product
  16. documentation would be appreciated but is not required.
  17. 2. Altered source versions must be plainly marked as such, and
  18. must not be misrepresented as being the original software.
  19. 3. This notice may not be removed or altered from any source
  20. distribution.
  21. ------------------------------------------------------------------------------
  22. Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  23. (http://www.freepascal.org)
  24. Copyright (C) 2006 Francesco Lombardi
  25. Check http://sourceforge.net/projects/libndsfpc for updates
  26. ------------------------------------------------------------------------------
  27. $Log$
  28. *)
  29. {$ifndef ARM7}
  30. {$error Audio is only available on the ARM7}
  31. {$endif ARM7}
  32. {$ifdef NDS_IMPLEMENTATION}
  33. function SOUND_VOL(n: cint): cint; inline;
  34. begin
  35. SOUND_VOL := (n);
  36. end;
  37. function SOUND_FREQ(n: cint): cint; inline;
  38. begin
  39. SOUND_FREQ := ((-$1000000 div (n)));
  40. end;
  41. {$endif NDS_IMPLEMENTATION}
  42. {$ifdef NDS_INTERFACE}
  43. const
  44. SOUND_ENABLE = (1 shl 15);
  45. SOUND_REPEAT = (1 shl 27);
  46. SOUND_ONE_SHOT = (1 shl 28);
  47. SOUND_FORMAT_16BIT = (1 shl 29);
  48. SOUND_FORMAT_8BIT = (0 shl 29);
  49. SOUND_FORMAT_PSG = (3 shl 29);
  50. SOUND_FORMAT_ADPCM = (2 shl 29);
  51. SOUND_16BIT = (1 shl 29);
  52. SOUND_8BIT = (0);
  53. {$endif NDS_INTERFACE}
  54. {$ifdef NDS_IMPLEMENTATION}
  55. function SOUND_PAN(n: cint): cint; inline;
  56. begin
  57. SOUND_PAN := ((n) shl 16);
  58. end;
  59. {$endif NDS_IMPLEMENTATION}
  60. {$ifdef NDS_INTERFACE}
  61. const
  62. SCHANNEL_ENABLE = (1 shl 31);
  63. {$endif NDS_INTERFACE}
  64. {$ifdef NDS_IMPLEMENTATION}
  65. //---------------------------------------------------------------------------------
  66. // registers
  67. //---------------------------------------------------------------------------------
  68. function SCHANNEL_CR(n: cint): pcuint32; inline;
  69. begin
  70. SCHANNEL_CR := pcuint32($04000400 + ((n) shl 4));
  71. end;
  72. function SCHANNEL_VOL(n: cint): pcuint8; inline;
  73. begin
  74. SCHANNEL_VOL := pcuint8($04000400 + ((n) shl 4));
  75. end;
  76. function SCHANNEL_PAN(n: cint): pcuint8; inline;
  77. begin
  78. SCHANNEL_PAN := pcuint8($04000402 + ((n) shl 4));
  79. end;
  80. function SCHANNEL_SOURCE(n: cint): pcuint32; inline;
  81. begin
  82. SCHANNEL_SOURCE := pcuint32($04000404 + ((n) shl 4));
  83. end;
  84. function SCHANNEL_TIMER(n: cint): pcuint16; inline;
  85. begin
  86. SCHANNEL_TIMER := pcuint16($04000408 + ((n) shl 4));
  87. end;
  88. function SCHANNEL_REPEAT_POINT(n: cint): pcuint16; inline;
  89. begin
  90. SCHANNEL_REPEAT_POINT := pcuint16($0400040A + ((n) shl 4));
  91. end;
  92. function SCHANNEL_LENGTH(n: cint): pcuint32; inline;
  93. begin
  94. SCHANNEL_LENGTH := pcuint32($0400040C + ((n) shl 4));
  95. end;
  96. {$endif NDS_IMPLEMENTATION}
  97. {$ifdef NDS_INTERFACE}
  98. const
  99. SOUND_CR : pcuint16 = pointer($04000500);
  100. SOUND_MASTER_VOL : pcuint8 = pointer($04000500);
  101. //---------------------------------------------------------------------------------
  102. // not sure on the following
  103. //---------------------------------------------------------------------------------
  104. SOUND_BIAS : pcuint16 = pointer($04000504);
  105. SOUND508 : pcuint16 = pointer($04000508);
  106. SOUND510 : pcuint16 = pointer($04000510);
  107. SOUND514 : pcuint16 = pointer($04000514);
  108. SOUND518 : pcuint16 = pointer($04000518);
  109. SOUND51C : pcuint16 = pointer($0400051C);
  110. (*---------------------------------------------------------------------------------
  111. microphone code based on neimod's microphone example.
  112. See: http://neimod.com/dstek/
  113. Chris Double ([email protected])
  114. http://www.double.co.nz/nintendo_ds
  115. ---------------------------------------------------------------------------------*)
  116. (*---------------------------------------------------------------------------------
  117. Read a byte from the microphone
  118. ---------------------------------------------------------------------------------*)
  119. function MIC_ReadData(): cuint8; cdecl; external;
  120. (*---------------------------------------------------------------------------------
  121. Fill the buffer with data from the microphone. The buffer will be
  122. signed sound data at 16kHz. Once the length of the buffer is
  123. reached, no more data will be stored. Uses ARM7 timer 0.
  124. ---------------------------------------------------------------------------------*)
  125. procedure StartRecording(buffer: pcuint8; length: cint); cdecl; external;
  126. (*---------------------------------------------------------------------------------
  127. Stop recording data, and return the length of data recorded.
  128. ---------------------------------------------------------------------------------*)
  129. function StopRecording(): cint; cdecl; external;
  130. (* This must be called during IRQ_TIMER0 *)
  131. procedure ProcessMicrophoneTimerIRQ(); cdecl; external;
  132. procedure PM_SetAmp(control: cuint8); cdecl; external;
  133. {$endif NDS_INTERFACE}
  134. {$ifdef NDS_IMPLEMENTATION}
  135. //---------------------------------------------------------------------------------
  136. // Turn the microphone on
  137. //---------------------------------------------------------------------------------
  138. procedure MIC_On(); inline;
  139. begin
  140. PM_SetAmp(PM_AMP_ON);
  141. end;
  142. //---------------------------------------------------------------------------------
  143. // Turn the microphone off
  144. //---------------------------------------------------------------------------------
  145. procedure MIC_Off(); inline;
  146. begin
  147. PM_SetAmp(PM_AMP_OFF);
  148. end;
  149. {$endif NDS_IMPLEMENTATION}
  150. {$ifdef NDS_INTERFACE}
  151. function SOUND_VOL(n: cint): cint; inline;
  152. function SOUND_FREQ(n: cint): cint; inline;
  153. function SOUND_PAN(n: cint): cint; inline;
  154. function SCHANNEL_CR(n: cint): pcuint32; inline;
  155. function SCHANNEL_VOL(n: cint): pcuint8; inline;
  156. function SCHANNEL_PAN(n: cint): pcuint8; inline;
  157. function SCHANNEL_SOURCE(n: cint): pcuint32; inline;
  158. function SCHANNEL_TIMER(n: cint): pcuint16; inline;
  159. function SCHANNEL_REPEAT_POINT(n: cint): pcuint16; inline;
  160. function SCHANNEL_LENGTH(n: cint): pcuint32; inline;
  161. procedure MIC_On(); inline;
  162. procedure MIC_Off(); inline;
  163. {$endif NDS_INTERFACE}