void play_sfx_low (void *sfx) { struct SAMPLE *tmp = sfx; /* set the sample volume */ tmp->volume = (13 - opt.sfx_volume) * 64 / 13; Sample_Play (tmp, 0, 0); }
int Mix_PlayChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ticks) { SAMPLE *sample; sample=(SAMPLE *)chunk; //OK, Mikmod will play any loaded wav at max sound at fisrt! //SO, must change internal sample volume before playing... dirty! sample->volume = voicevolume; v1 = Sample_Play(sample, 0, 0); return 0; }
void SgPlaySound ( char *fullfilename, char *id, bool synchronised ) { SAMPLE *sample = NULL; char *sampleid = id ? id : fullfilename; if ( cache.LookupTree ( sampleid ) ) { // Sound sample already loaded into memory - start it playing sample = cache.GetData ( sampleid ); if ( !sample ) { SgDebugPrintf ( "SoundGarden WARNING : Failed to load sound from cache : %s\n", fullfilename ); cache.RemoveData ( sampleid ); return; } } else { // Load sample and place into cache sample = Sample_Load( fullfilename ); if ( !sample ) { SgDebugPrintf ( "SoundGarden WARNING : failed to load sound %s\n (%s)", fullfilename, MikMod_strerror(MikMod_errno) ); return; } cache.PutData ( sampleid, sample ); } int voice = Sample_Play(sample, 0, SFX_CRITICAL); Voice_SetVolume(voice,128); Voice_SetPanning(voice,PAN_CENTER); Voice_SetFrequency(voice,22000); }
int main(void) { SceCtrlData pad, lastpad; int maxchan = 128; BOOL outputEnabled; MODULE *mf = NULL; SAMPLE *sf = NULL; int voice = 0; int pan = 127; int vol = 127; int freq = 22000; pspDebugScreenInit(); SetupCallbacks(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(1); if (!MikMod_InitThreads()) { printf("MikMod thread init failed\n"); } MikMod_RegisterErrorHandler(my_error_handler); /* register all the drivers */ MikMod_RegisterAllDrivers(); /* register all the module loaders */ MikMod_RegisterAllLoaders(); /* initialize the library */ md_mode = DMODE_16BITS|DMODE_STEREO|DMODE_SOFT_SNDFX|DMODE_SOFT_MUSIC; md_reverb = 0; md_pansep = 128; if (MikMod_Init("")) { printf("Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno)); sceKernelExitGame(); return 0; } MikMod_SetNumVoices(-1, 8); /* get ready to play */ sf = Sample_Load("ms0:/sound.wav"); printf("Starting.\n"); MikMod_EnableOutput(); outputEnabled = 1; if ((mikModThreadID = sceKernelCreateThread("MikMod" ,(void*)&AudioChannelThread,0x12,0x10000,0,NULL)) > 0) { sceKernelStartThread(mikModThreadID, 0 , NULL); } else { printf("Play thread create failed!\n"); } sceCtrlReadBufferPositive(&lastpad, 1); do { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons != lastpad.Buttons) { if(pad.Buttons & PSP_CTRL_CROSS) { voice = Sample_Play(sf,0,0); Voice_SetPanning(voice, pan); } if(pad.Buttons & PSP_CTRL_SQUARE) { outputEnabled = !outputEnabled; if(outputEnabled) MikMod_EnableOutput(); else MikMod_DisableOutput(); } if(pad.Buttons & PSP_CTRL_CIRCLE) { mf = Player_Load("ms0:/MUSIC.XM", maxchan, 0); if (NULL != mf) { mf->wrap = 1; Player_Start(mf); } } if(pad.Buttons & PSP_CTRL_TRIANGLE) { if (NULL != mf) { Player_Stop(); Player_Free(mf); /* To stop the song for real, it needs to be freed. I know, weird... */ mf = NULL; } } if(pad.Buttons & PSP_CTRL_SELECT) printf("Player is %s\n", Player_Active()?"On":"Off"); lastpad = pad; } if(pad.Buttons & PSP_CTRL_LTRIGGER) { Voice_SetPanning(voice, (pan<2)?pan:--pan); printf("pan is %d\n", pan); } if(pad.Buttons & PSP_CTRL_RTRIGGER) { Voice_SetPanning(voice, (pan>254)?pan:++pan); printf("pan is %d\n", pan); } if(pad.Buttons & PSP_CTRL_UP) { Voice_SetVolume(voice, (vol>254)?vol:++vol); printf("vol is %d\n", vol); } if(pad.Buttons & PSP_CTRL_DOWN) { Voice_SetVolume(voice, (vol<2)?vol:--vol); printf("vol is %d\n", vol); } if(pad.Buttons & PSP_CTRL_LEFT) { Voice_SetFrequency(voice, (freq<1001)?freq:(freq -=1000)); printf("freq is %d\n", freq); } if(pad.Buttons & PSP_CTRL_RIGHT) { Voice_SetFrequency(voice, (freq>44000)?freq:(freq +=1000)); printf("freq is %d\n", freq); } sceDisplayWaitVblankStart(); } while(!((pad.Buttons & PSP_CTRL_START) || done)); printf("Stopping.\n"); /* allow audio thread to terminate cleanly */ done = 1; if (mikModThreadID > 0) { SceUInt timeout = 100000; sceKernelWaitThreadEnd(mikModThreadID, &timeout); /* not 100% sure if this is necessary after a clean exit, * but just to make sure any resources are freed: */ sceKernelDeleteThread(mikModThreadID); } Player_Stop(); Player_Free(mf); MikMod_Exit(); sceKernelExitGame(); return 0; }
int main(void) { /* sound effects */ SAMPLE *sfx1, *sfx2; /* voices */ int v1, v2; int i; /* register all the drivers */ MikMod_RegisterAllDrivers(); /* initialize the library */ md_mode |= DMODE_SOFT_SNDFX; if (MikMod_Init("")) { fprintf(stderr, "Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno)); return 1; } /* load samples */ sfx1 = Load("first.wav"); if (!sfx1) { MikMod_Exit(); fprintf(stderr, "Could not load the first sound, reason: %s\n", MikMod_strerror(MikMod_errno)); return 1; } sfx2 = Load("second.wav"); if (!sfx2) { Sample_Free(sfx1); MikMod_Exit(); fprintf(stderr, "Could not load the second sound, reason: %s\n", MikMod_strerror(MikMod_errno)); return 1; } /* reserve 2 voices for sound effects */ MikMod_SetNumVoices(-1, 2); /* get ready to play */ MikMod_EnableOutput(); /* play first sample */ v1 = Sample_Play(sfx1, 0, 0); do { MikMod_Update(); MikMod_Sleep(100000); } while (!Voice_Stopped(v1)); for (i = 0; i < 10; i++) { MikMod_Update(); MikMod_Sleep(100000); } /* half a second later, play second sample */ v2 = Sample_Play(sfx2, 0, 0); do { MikMod_Update(); MikMod_Sleep(100000); } while (!Voice_Stopped(v2)); for (i = 0; i < 10; i++) { MikMod_Update(); MikMod_Sleep(100000); } MikMod_DisableOutput(); Sample_Free(sfx2); Sample_Free(sfx1); MikMod_Exit(); return 0; }