void Mix_CloseAudio(void) { if (loaded == 1){ MikMod_DisableOutput(); MikMod_Exit(); loaded = 0; } }
void MikMod_Exit(void) { MikMod_DisableOutput(); md_driver->Exit(); md_numchn = md_sfxchn = md_sngchn = 0; md_driver = &drv_nos; initialized = 0; }
void SgShutdown() { SgStopMod(); MikMod_DisableOutput(); sg_thread_termination_requested = true; pthread_join(mikmod_update_thread, NULL); MikMod_Exit(); }
BOOL MikMod_SetNumVoices(int music, int sfx) /* If either parameter is -1, the current set value will be retained. */ { BOOL resume = 0; int t, oldchn = 0; if((music==0) && (sfx==0)) return 0; _mm_critical = 1; if(isplaying) { MikMod_DisableOutput(); oldchn = md_numchn; resume = 1; } if(sfxinfo!=NULL) free(sfxinfo); if(md_sample!=NULL) free(md_sample); md_sample = NULL; sfxinfo = NULL; /*md_softchn = md_hardchn = 0; if(md_mode & DMODE_SOFT_SNDFX) md_softchn = sfx; else md_hardchn = sfx; if(md_mode & DMODE_SOFT_MUSIC) md_softchn += music; else md_hardchn += music; */ if(music != -1) md_sngchn = music; if(sfx != -1) md_sfxchn = sfx; md_numchn = md_sngchn + md_sfxchn; LimitHardVoices(md_driver->HardVoiceLimit); LimitSoftVoices(md_driver->SoftVoiceLimit); if(md_driver->SetNumVoices()) { MikMod_Exit(); md_numchn = md_softchn = md_hardchn = md_sfxchn = md_sngchn = 0; if(_mm_errorhandler!=NULL) _mm_errorhandler(); return 1; } if(md_sngchn || md_sfxchn) md_sample = (SAMPLE **)_mm_calloc(md_sngchn+md_sfxchn, sizeof(SAMPLE *)); if(md_sfxchn) sfxinfo = (UBYTE *)_mm_calloc(md_sfxchn, sizeof(UBYTE)); /* make sure the player doesn't start with garbage */ for(t=oldchn; t<md_numchn; t++) Voice_Stop(t); sfxpool = 0; if(resume) MikMod_EnableOutput(); _mm_critical = 0; return 0; }
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; }