PA_Sound.h

Go to the documentation of this file.
00001 #ifndef _PA_Sound9
00002 #define _PA_Sound9
00003 
00004 
00005 
00013 #include "../Sound9.h"
00014 #include "PA_GBFS.h"
00015 #include "PA_FS.h"
00016 #include <PA9.h>
00017 
00018        // 256KB to load MOD files into. Actual size necessary is the size 
00019        // of your largest MOD file (probably less than 256KB).
00020 #define SND_MEM_POOL_SIZE   256*1024
00021 
00022 
00023 extern TransferSound snd;
00024 extern u32 *sndMemPool;
00025 
00026 typedef struct{ // Default sound format
00027        u8 volume;
00028        s16 freq;
00029        s16 format;
00030 } PA_SoundOptions;
00031 
00032 extern PA_SoundOptions PA_SoundOption;
00033 
00034 extern u32 *FS_mod;
00035 extern u32 *FS_wav[16]; // 16 channels...
00036 
00037 
00038 
00039 //Stream vars
00040 extern u32 *Stream_Gap[16];
00041 extern u32 *Stream_End[16];
00042 extern u32 *Stream_Datas[16]; 
00043 extern u32 *Stream_Regen_Ptr[16];
00044 extern s64    Stream_Length[16];
00045 extern u32    Stream_Last_Tick[16];
00046 extern s32    Stream_Repeat[16];
00047 extern u8     Stream_Timer[16];
00048 
00049 //plays an 8 bit mono sample at 11025Hz
00050 
00051 
00052 
00053 
00054 
00055 
00076 void PA_SetDefaultSound(u8 volume, int freq, s16 format);
00077 
00078 
00084 extern inline void PA_InitSound(void) {
00085        SndInit9 ();
00086        sndMemPool = (u32*)0x2200000;
00087        SndSetMemPool(sndMemPool, SND_MEM_POOL_SIZE);
00088        PA_SetDefaultSound(127, 11025, 0);
00089        FS_mod = NULL; // Initialise a small portion of memory, will make it bigger later on...
00090        u8 i;
00091        for (i = 0; i < 16; i++)
00092        {
00093               FS_wav[i] = NULL; // to be able to free
00094        }
00095 
00096 }
00097 
00098 
00099 
00105 extern void PA_InitStreamSound(void);
00106 
00112 extern void PA_RegenStream(void);
00113 
00119 extern void FillTheGap(u8 PA_Channel, u32 size);
00120 
00150 void PA_PlaySoundEx2(u8 PA_Channel, const void* data, s32 length, u8 volume, int freq, s16 format, BOOL repeat, int repeatPoint);
00151 
00175 extern inline void PA_PlaySoundEx(u8 PA_Channel, const void* data, s32 length, u8 volume, int freq, s16 format){
00176 PA_PlaySoundEx2(PA_Channel, data, length, volume, freq, format,false,0);
00177 }
00178 
00199 extern inline void PA_PlayGBFSSoundEx(u8 PA_Channel, u16 FS_wav_number, u8 volume, int freq, s16 format){
00200 s32 length = (PA_GBFSfile[FS_wav_number].Length >> 2) + 1; // Pour etre sur...
00201        free(FS_wav[PA_Channel]);
00202        FS_wav[PA_Channel] = (u32*)malloc(length << 2);
00203        
00204        DMA_Copy(PA_GBFSfile[FS_wav_number].File, FS_wav[PA_Channel], length, DMA_32NOW);
00205 
00206        PA_PlaySoundEx(PA_Channel, (void*)FS_wav[PA_Channel], length << 2, volume, freq, format);
00207 }
00208 
00235 extern inline void PA_PlayGBFSSoundEx2(u8 PA_Channel, u16 FS_wav_number, u8 volume, int freq, s16 format, BOOL repeat, int repeatPoint){
00236 s32 length = (PA_GBFSfile[FS_wav_number].Length >> 2) + 1; // Pour etre sur...
00237        free(FS_wav[PA_Channel]);
00238        FS_wav[PA_Channel] = (u32*)malloc(length << 2);
00239        
00240        DMA_Copy(PA_GBFSfile[FS_wav_number].File, FS_wav[PA_Channel], length, DMA_32NOW);
00241 
00242        PA_PlaySoundEx2(PA_Channel, (void*)FS_wav[PA_Channel], length << 2, volume, freq, format, repeat, repeatPoint);
00243 
00244 }
00245 
00246 
00267 extern inline void PA_PlayFSSoundEx(u8 PA_Channel, u16 PAFS_wav_number, u8 volume, int freq, s16 format){
00268        PA_Malloc((void**)FS_wav[PA_Channel], PA_FSFile[PAFS_wav_number].Length+4);
00269 
00270        s32 i;
00271        s32 length = (PA_FSFile[PAFS_wav_number].Length>>2) + 1; // Pour etre sur...
00272        for (i = 0; i < length; i++) FS_wav[PA_Channel][i] = ((u32*)PA_PAFSFile(PAFS_wav_number))[i];
00273        
00274        PA_PlaySoundEx(PA_Channel, (void*)FS_wav[PA_Channel], length << 2, volume, freq, format);
00275 }
00276 
00303 extern inline void PA_PlayFSSoundEx2(u8 PA_Channel, u16 PAFS_wav_number, u8 volume, int freq, s16 format, BOOL repeat, int repeatPoint){
00304        PA_Malloc((void**)FS_wav[PA_Channel], PA_FSFile[PAFS_wav_number].Length+4);
00305 
00306        s32 i;
00307        s32 length = (PA_FSFile[PAFS_wav_number].Length>>2) + 1; // Pour etre sur...
00308        for (i = 0; i < length; i++) FS_wav[PA_Channel][i] = ((u32*)PA_PAFSFile(PAFS_wav_number))[i];
00309        
00310        PA_PlaySoundEx2(PA_Channel, (void*)FS_wav[PA_Channel], length << 2, volume, freq, format, repeat, repeatPoint);
00311 }
00312 
00340 extern void PA_StopSound(u8 PA_Channel);
00341 extern inline void PA_PlayFSStreamSoundEx2(u8 PA_Channel, u16 PAFS_wav_number, u8 volume, int freq, s16 format, BOOL repeat, int repeatPoint);
00342 
00363 extern inline void PA_PlaySound(u8 PA_Channel, const void* data, s32 length, u8 volume, u32 freq){
00364 PA_PlaySoundEx2(PA_Channel, data, length, volume, freq, 1,false,0);
00365 }
00366 
00384 extern inline void PA_PlayGBFSSound(u8 PA_Channel, u16 FS_wav_number, u8 volume, u32 freq){
00385 s32 length = (PA_GBFSfile[FS_wav_number].Length >> 2) + 1; // Pour etre sur...
00386        free(FS_wav[PA_Channel]);
00387        FS_wav[PA_Channel] = (u32*)malloc(length << 2);
00388        
00389        DMA_Copy(PA_GBFSfile[FS_wav_number].File, FS_wav[PA_Channel], length, DMA_32NOW);
00390 
00391        PA_PlaySound(PA_Channel, (void*)FS_wav[PA_Channel], length << 2, volume, freq);
00392 
00393        SndPlay(PA_Channel, (void*)FS_wav[PA_Channel], length << 2, volume, freq, 0, false, 0);
00394 }
00395 
00396 
00414 extern inline void PA_PlayFSSound(u8 PA_Channel, u16 PAFS_wav_number, u8 volume, u32 freq){
00415        PA_Malloc((void**)(FS_wav[PA_Channel]), PA_FSFile[PAFS_wav_number].Length+4);
00416 
00417        s32 i;
00418        s32 length = (PA_FSFile[PAFS_wav_number].Length>>2) + 1; // Pour etre sur...
00419        for (i = 0; i < length; i++) FS_wav[PA_Channel][i] = ((u32*)PA_PAFSFile(PAFS_wav_number))[i];
00420        
00421        PA_PlaySound(PA_Channel, (void*)FS_wav[PA_Channel], length << 2, volume, freq);
00422 }
00423 
00424 
00425 
00438 #define PA_PlaySimpleSound(PA_Channel, sound) PA_PlaySoundEx(PA_Channel, (void*)sound, (u32)sound##_size, PA_SoundOption.volume, PA_SoundOption.freq, PA_SoundOption.format)
00439 
00440 
00452 extern inline void PA_PlayGBFSSimpleSound(u8 PA_Channel, u16 FS_wav_number){
00453 s32 length = (PA_GBFSfile[FS_wav_number].Length >> 2) + 1; // Pour etre sur...
00454        free(FS_wav[PA_Channel]);
00455        FS_wav[PA_Channel] = (u32*)malloc(length << 2);
00456        
00457        DMA_Copy(PA_GBFSfile[FS_wav_number].File, FS_wav[PA_Channel], length, DMA_32NOW);
00458 
00459        PA_PlaySound(PA_Channel, (void*)FS_wav[PA_Channel], length << 2, PA_SoundOption.volume, PA_SoundOption.freq);
00460 }
00461 
00462 
00463 
00464 
00476 extern inline void PA_PlayFSSimpleSound(u8 PA_Channel, u16 PAFS_wav_number){
00477        PA_Malloc((void**)(FS_wav[PA_Channel]), PA_FSFile[PAFS_wav_number].Length+4);
00478 
00479        s32 i;
00480        s32 length = (PA_FSFile[PAFS_wav_number].Length>>2) + 1; // Pour etre sur...
00481        for (i = 0; i < length; i++) FS_wav[PA_Channel][i] = ((u32*)PA_PAFSFile(PAFS_wav_number))[i];
00482        
00483        PA_PlaySound(PA_Channel, (void*)FS_wav[PA_Channel], PA_FSFile[PAFS_wav_number].Length, PA_SoundOption.volume, PA_SoundOption.freq);
00484 }
00485 
00486 
00487 
00488 
00489 
00490 
00499 #define PA_PlayMod(mod_snd) SndPlayMOD((u8*)mod_snd)
00500 
00501 
00510 extern inline void PA_PlayGBFSMod(u16 FS_mod_number){
00511 s32 length = (PA_GBFSfile[FS_mod_number].Length >> 2) + 1; // Pour etre sur...
00512        free(FS_mod);
00513        FS_mod = (u32*)malloc(length << 2);
00514 
00515        DMA_Copy(PA_GBFSfile[FS_mod_number].File, FS_mod, length, DMA_32NOW);
00516 
00517        PA_PlayMod(FS_mod);
00518 }
00519 
00520 
00529 extern inline void PA_PlayFSMod(u16 PAFS_mod_number){
00530        PA_Malloc((void**)((u32)(&FS_mod)), PA_FSFile[PAFS_mod_number].Length+4);
00531 
00532        s32 i;
00533        s32 length = (PA_FSFile[PAFS_mod_number].Length>>2) + 1; // Pour etre sur...
00534        for (i = 0; i < length; i++) FS_mod[i] = ((u32*)PA_PAFSFile(PAFS_mod_number))[i];
00535        
00536        PA_PlayMod(FS_mod);
00537 }
00538 
00539 
00540 
00546 #define PA_StopMod() SndStopMOD()
00547 
00548 
00557 #define PA_PauseMod(u8) SndPauseMOD(u8)
00558 
00559 
00560 
00569 void PA_StopStream(u8 PA_Channel);
00570 
00579 void PA_PauseStream(u8 PA_Channel);
00580 
00589 void PA_UnpauseStream(u8 PA_Channel);
00590 
00591 
00600 extern inline u8 PA_SoundChannelIsBusy(u8 PA_Channel)   {
00601        return ((volatile u8)PA_IPC.Sound[PA_Channel].Busy);
00602 }
00603 
00609 extern inline s8 PA_GetFreeSoundChannel(void){
00610        u8 i;
00611        for (i = 0; i < 16; i++) if (!PA_SoundChannelIsBusy(i)) return i;
00612        
00613        return -1;
00614 }
00615 
00616 
00628 extern inline void PA_SetSoundChannelVol(u8 PA_Channel, u8 Volume){
00629        PA_IPC.Sound[PA_Channel].Volume = (Volume&127) + (1<<7);  // Volume level
00630 }
00631 
00632 
00641 extern inline void PA_SetSoundVol(u8 Volume){
00642        PA_IPC.Sound[16].Volume = (Volume&127) + (1<<7);  // Volume level, enable change bit
00643 }
00644 
00645 
00646 
00658 extern inline void PA_SetSoundChannelPan(u8 PA_Channel, u8 Pan){
00659        PA_IPC.Sound[PA_Channel].Pan = (Pan&127) + (1<<7);  // Pan level
00660 }
00661  // end of SoundARM9
00663 
00690 //void PA_PlayGBFSStreamSoundEx2(u8 PA_Channel, u16 FS_wav_number, u8 volume, int freq, s16 format, BOOL repeat, int repeatPoint);
00691 
00692 
00693 
00705 //extern inline void PA_MicStartRecording(u8* buffer, int length){StartRecording(buffer, length);}
00706 
00712 //#define PA_MicStopRecording() StopRecording()
00713 
00714 
00715 
00716 #endif

Generated on Tue Jan 30 23:00:22 2007 for PAlib by  doxygen 1.5.1-p1