00001 /*--------------------------------------------------------------------------------- 00002 00003 ARM7 audio control 00004 00005 Copyright (C) 2005 00006 Michael Noland (joat) 00007 Jason Rogers (dovoto) 00008 Dave Murphy (WinterMute) 00009 00010 This software is provided 'as-is', without any express or implied 00011 warranty. In no event will the authors be held liable for any 00012 damages arising from the use of this software. 00013 00014 Permission is granted to anyone to use this software for any 00015 purpose, including commercial applications, and to alter it and 00016 redistribute it freely, subject to the following restrictions: 00017 00018 1. The origin of this software must not be misrepresented; you 00019 must not claim that you wrote the original software. If you use 00020 this software in a product, an acknowledgment in the product 00021 documentation would be appreciated but is not required. 00022 2. Altered source versions must be plainly marked as such, and 00023 must not be misrepresented as being the original software. 00024 3. This notice may not be removed or altered from any source 00025 distribution. 00026 00027 ---------------------------------------------------------------------------------*/ 00028 00029 #ifndef AUDIO_ARM7_INCLUDE 00030 #define AUDIO_ARM7_INCLUDE 00031 00032 //--------------------------------------------------------------------------------- 00033 // Sound (ARM7 only) 00034 //--------------------------------------------------------------------------------- 00035 #ifndef ARM7 00036 #error Audio is only available on the ARM7 00037 #endif 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00043 #include <nds/arm7/serial.h> 00044 #include <nds/system.h> 00045 00046 #define SOUND_VOL(n) (n) 00047 #define SOUND_FREQ(n) ((-0x1000000 / (n))) 00048 #define SOUND_ENABLE BIT(15) 00049 00050 #define SOUND_REPEAT BIT(27) 00051 #define SOUND_ONE_SHOT BIT(28) 00052 00053 #define SOUND_FORMAT_16BIT (1<<29) 00054 #define SOUND_FORMAT_8BIT (0<<29) 00055 #define SOUND_FORMAT_PSG (3<<29) 00056 #define SOUND_FORMAT_ADPCM (2<<29) 00057 00058 #define SOUND_PAN(n) ((n) << 16) 00059 00060 #define SCHANNEL_ENABLE BIT(31) 00061 00062 //--------------------------------------------------------------------------------- 00063 // registers 00064 //--------------------------------------------------------------------------------- 00065 00066 #define REG_MASTER_VOLUME (*(vu8*)0x4000500) 00067 #define REG_SOUNDCNT (*(vu16*)0x4000500) 00068 #define REG_SOUNDBIAS (*(vu32*)0x4000504) 00069 00070 00071 #define SCHANNEL_CR(n) (*(vu32*)(0x04000400 + ((n)<<4))) 00072 #define SCHANNEL_VOL(n) (*(vu8*)(0x04000400 + ((n)<<4))) 00073 #define SCHANNEL_PAN(n) (*(vu8*)(0x04000402 + ((n)<<4))) 00074 #define SCHANNEL_SOURCE(n) (*(vu32*)(0x04000404 + ((n)<<4))) 00075 #define SCHANNEL_TIMER(n) (*(vu16*)(0x04000408 + ((n)<<4))) 00076 #define SCHANNEL_REPEAT_POINT(n) (*(vu16*)(0x0400040A + ((n)<<4))) 00077 #define SCHANNEL_LENGTH(n) (*(vu32*)(0x0400040C + ((n)<<4))) 00078 00079 00080 //--------------------------------------------------------------------------------- 00081 // Sound Capture Registers 00082 //--------------------------------------------------------------------------------- 00083 #define REG_SNDCAP0CNT (*(vu8*)0x04000508) 00084 #define REG_SNDCAP1CNT (*(vu8*)0x04000509) 00085 00086 #define REG_SNDCAP0DAD (*(vu32*)0x04000510) 00087 #define REG_SNDCAP0LEN (*(vu16*)0x04000514) 00088 #define REG_SNDCAP1DAD (*(vu32*)0x04000518) 00089 #define REG_SNDCAP1LEN (*(vu16*)0x0400051C) 00090 00091 typedef void (*MIC_BUF_SWAP_CB)(u8* completedBuffer, int length); 00092 00093 00094 00095 00096 /*--------------------------------------------------------------------------------- 00097 microphone code based on neimod's microphone example. 00098 See: http://neimod.com/dstek/ 00099 Chris Double (chris.double@double.co.nz) 00100 http://www.double.co.nz/nintendo_ds 00101 ---------------------------------------------------------------------------------*/ 00102 00103 00104 /*--------------------------------------------------------------------------------- 00105 Read a byte from the microphone 00106 ---------------------------------------------------------------------------------*/ 00107 u8 micReadData8(); 00108 u16 micReadData12(); 00109 00110 /*--------------------------------------------------------------------------------- 00111 Fill the buffer with data from the microphone. The buffer will be 00112 signed sound data at 16kHz. Once the length of the buffer is 00113 reached, no more data will be stored. Uses ARM7 timer 0. 00114 ---------------------------------------------------------------------------------*/ 00115 void micStartRecording(u8* buffer, int length, int freq, int timer, bool eightBitSample, MIC_BUF_SWAP_CB bufferSwapCallback); 00116 00117 /*--------------------------------------------------------------------------------- 00118 Stop recording data, and return the length of data recorded. 00119 ---------------------------------------------------------------------------------*/ 00120 int micStopRecording(void); 00121 00122 /* This must be called during IRQ_TIMER0 */ 00123 void micTimerHandler(void); 00124 00125 void micSetAmp(u8 control, u8 gain); 00126 00127 //--------------------------------------------------------------------------------- 00128 // Turn the microphone on 00129 //--------------------------------------------------------------------------------- 00130 static inline void micOn(void) { 00131 //--------------------------------------------------------------------------------- 00132 micSetAmp(PM_AMP_ON, PM_GAIN_160); 00133 } 00134 00135 00136 //--------------------------------------------------------------------------------- 00137 // Turn the microphone off 00138 //--------------------------------------------------------------------------------- 00139 static inline void micOff(void) { 00140 //--------------------------------------------------------------------------------- 00141 micSetAmp(PM_AMP_OFF, 0); 00142 } 00143 00144 void installSoundFIFO(void); 00145 00146 #ifdef __cplusplus 00147 } 00148 #endif 00149 00150 #endif 00151