|
@@ -2,6 +2,7 @@ |
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
#include <gccore.h>
|
|
|
+#include <asndlib.h>
|
|
|
#include "gcmodplay.h"
|
|
|
|
|
|
//#define _GCMOD_DEBUG
|
|
@@ -13,6 +14,9 @@ static BOOL thr_running = FALSE; |
|
|
static BOOL sndPlaying = FALSE;
|
|
|
static MODSNDBUF sndBuffer;
|
|
|
|
|
|
+static s32 have_samples = 0;
|
|
|
+static s32 mod_freq = 48000;
|
|
|
+
|
|
|
static u32 shiftVal = 0;
|
|
|
static vu32 curr_audio = 0;
|
|
|
static u32 curr_datalen[2] = {0,0};
|
|
@@ -44,7 +48,8 @@ static void* player(void *arg) |
|
|
printf("player(run callback)\n\n");
|
|
|
start = gettime();
|
|
|
#endif
|
|
|
- sndBuffer.callback(sndBuffer.usr_data,(u8*)audioBuf[curr_audio],curr_datalen[curr_audio]);
|
|
|
+ sndBuffer.callback(sndBuffer.usr_data,((u8*)audioBuf[curr_audio]),curr_datalen[curr_audio]);
|
|
|
+ have_samples = 2;
|
|
|
#ifdef _GCMOD_DEBUG
|
|
|
end = gettime();
|
|
|
printf("player(end callback,%d - %d us)\n\n",curr_audio,diff_usec(start,end));
|
|
@@ -60,22 +65,43 @@ static void* player(void *arg) |
|
|
|
|
|
static void dmaCallback()
|
|
|
{
|
|
|
+#ifndef __SNDLIB_H__
|
|
|
MODPlay *mp = (MODPlay*)sndBuffer.usr_data;
|
|
|
MOD *mod = &mp->mod;
|
|
|
+#endif
|
|
|
|
|
|
#ifdef _GCMOD_DEBUG
|
|
|
static long long start = 0,end = 0;
|
|
|
|
|
|
end = gettime();
|
|
|
if(start) printf("dmaCallback(%p,%d,%d - after %d ms)\n",(void*)audioBuf[curr_audio],curr_datalen,curr_audio,diff_msec(start,end));
|
|
|
#endif
|
|
|
+
|
|
|
+#ifndef __SNDLIB_H__
|
|
|
AUDIO_StopDMA();
|
|
|
AUDIO_InitDMA((u32)audioBuf[curr_audio],curr_datalen[curr_audio]);
|
|
|
AUDIO_StartDMA();
|
|
|
|
|
|
curr_audio ^= 1;
|
|
|
curr_datalen[curr_audio] = (mod->samplespertick<<shiftVal);
|
|
|
LWP_ThreadSignal(player_queue);
|
|
|
+#else
|
|
|
+ if(have_samples==0) {
|
|
|
+ have_samples = 1;
|
|
|
+ LWP_ThreadSignal(player_queue);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(have_samples==1) return;
|
|
|
+ if(have_samples==2) {
|
|
|
+ if(SND_AddVoice(0,audioBuf[curr_audio], curr_datalen[curr_audio])!=0) return; // Sorry I am busy: try again
|
|
|
+
|
|
|
+ curr_datalen[curr_audio]=0;
|
|
|
+ have_samples=0;
|
|
|
+ curr_audio ^= 1;
|
|
|
+ curr_datalen[curr_audio]=SNDBUFFERSIZE;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
#ifdef _GCMOD_DEBUG
|
|
|
start = gettime();
|
|
|
printf("dmaCallback(%p,%d,%d,%d us) leave\n",(void*)audioBuf[curr_audio],curr_datalen,curr_audio,diff_usec(end,start));
|
|
@@ -90,6 +116,11 @@ static void mixCallback(void *usrdata,u8 *stream,u32 len) |
|
|
#ifdef _GCMOD_DEBUG
|
|
|
printf("mixCallback(%p,%p,%d) enter\n",stream,usrdata,len);
|
|
|
#endif
|
|
|
+ if(mp->manual_polling)
|
|
|
+ mod->notify = &mp->paused;
|
|
|
+ else
|
|
|
+ mod->notify = NULL;
|
|
|
+
|
|
|
mod->mixingbuf = stream;
|
|
|
mod->mixingbuflen = len;
|
|
|
|
|
@@ -132,10 +163,18 @@ static s32 SndBufStart(MODSNDBUF *sndbuf) |
|
|
curr_datalen[0] = SNDBUFFERSIZE;
|
|
|
curr_datalen[1] = SNDBUFFERSIZE;
|
|
|
if(LWP_CreateThread(&hplayer,player,NULL,player_stack,STACKSIZE,80)!=-1) {
|
|
|
+#ifndef __SNDLIB_H__
|
|
|
AUDIO_RegisterDMACallback(dmaCallback);
|
|
|
AUDIO_InitDMA((u32)audioBuf[curr_audio],curr_datalen[curr_audio]);
|
|
|
AUDIO_StartDMA();
|
|
|
curr_audio ^= 1;
|
|
|
+#else
|
|
|
+ SND_SetVoice(0, VOICE_STEREO_16BIT, mod_freq,0, audioBuf[curr_audio], curr_datalen[curr_audio], 255, 255, dmaCallback);
|
|
|
+ have_samples=0;
|
|
|
+
|
|
|
+ curr_audio ^= 1;
|
|
|
+ SND_Pause(0);
|
|
|
+#endif
|
|
|
return 1;
|
|
|
}
|
|
|
sndPlaying = FALSE;
|
|
@@ -146,10 +185,12 @@ static s32 SndBufStart(MODSNDBUF *sndbuf) |
|
|
static void SndBufStop()
|
|
|
{
|
|
|
if(!sndPlaying) return;
|
|
|
-
|
|
|
+#ifndef __SNDLIB_H__
|
|
|
AUDIO_StopDMA();
|
|
|
AUDIO_RegisterDMACallback(NULL);
|
|
|
-
|
|
|
+#else
|
|
|
+ SND_StopVoice(0);
|
|
|
+#endif
|
|
|
curr_audio = 0;
|
|
|
sndPlaying = FALSE;
|
|
|
curr_datalen[0] = 0;
|
|
@@ -197,7 +238,12 @@ void MODPlay_Init(MODPlay *mod) |
|
|
{
|
|
|
memset(mod,0,sizeof(MODPlay));
|
|
|
|
|
|
- AUDIO_Init(NULL);
|
|
|
+#ifndef __SNDLIB_H__
|
|
|
+ AUDIO_Init(NULL);
|
|
|
+#else
|
|
|
+ SND_Pause(0);
|
|
|
+ SND_StopVoice(0);
|
|
|
+#endif
|
|
|
MODPlay_SetFrequency(mod,48000);
|
|
|
MODPlay_SetStereo(mod,TRUE);
|
|
|
|
|
@@ -215,13 +261,15 @@ void MODPlay_Init(MODPlay *mod) |
|
|
s32 MODPlay_SetFrequency(MODPlay *mod,u32 freq)
|
|
|
{
|
|
|
if(freq==mod->playfreq) return 0;
|
|
|
-
|
|
|
+#ifndef __SNDLIB_H__
|
|
|
if(freq==32000 || freq==48000) {
|
|
|
if(freq==32000)
|
|
|
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ);
|
|
|
else
|
|
|
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
|
|
|
-
|
|
|
+#else
|
|
|
+ mod_freq = 48000;
|
|
|
+#endif
|
|
|
mod->playfreq = freq;
|
|
|
updateWaveFormat(mod);
|
|
|
return 0;
|
|
@@ -289,7 +337,7 @@ s32 MODPlay_AllocSFXChannels(MODPlay *mod,u32 sfxchans) |
|
|
s32 MODPlay_Pause(MODPlay *mod,BOOL pause)
|
|
|
{
|
|
|
if(!mod->playing) return -1;
|
|
|
- mod->paused = TRUE;
|
|
|
+ mod->paused = pause;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -298,3 +346,29 @@ s32 MODPlay_TriggerNote(MODPlay *mod,u32 chan,u8 inst,u16 freq,u8 vol) |
|
|
if(mod->mod.modraw==0) return -1;
|
|
|
return MOD_TriggerNote(&mod->mod,chan,inst,freq,vol);
|
|
|
}
|
|
|
+
|
|
|
+// add by Hermes
|
|
|
+
|
|
|
+/* void MODPlay_SetVolume(MODPlay *mod, s32 musicvolume, s32 sfxvolume)
|
|
|
+
|
|
|
+Set the volume levels for the MOD music (call it after MODPlay_SetMOD())
|
|
|
+
|
|
|
+mod: the MODPlay pointer
|
|
|
+
|
|
|
+musicvolume: in range 0 to 64
|
|
|
+sfxvolume: in range 0 to 64
|
|
|
+
|
|
|
+*/
|
|
|
+
|
|
|
+void MODPlay_SetVolume(MODPlay *mod, s32 musicvolume, s32 sfxvolume)
|
|
|
+{
|
|
|
+ if(musicvolume<0) musicvolume=0;
|
|
|
+ if(musicvolume>64) musicvolume=64;
|
|
|
+
|
|
|
+ if(sfxvolume<0) sfxvolume=0;
|
|
|
+ if(sfxvolume>64) sfxvolume=64;
|
|
|
+
|
|
|
+ mod->mod.musicvolume= musicvolume;
|
|
|
+ mod->mod.sfxvolume = sfxvolume;
|
|
|
+}
|
|
|
+
|
0 comments on commit
300427d