Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SDL_MAIN_HANDLED
- #include <kit_sdl2/kit_all.h>
- int main(int argc, char** argv){
- //initialize kmixer and core, which kmixer relies on
- if(kit_coreInit(0)<0) return 1;
- if(kit_kmixerInit(-0.5f)<0) return 2; //use only half the cpu cores present
- //set up device specification, which optionally doubles as voice 1's spec
- kit_kmixerVoiceSpec specO,spec={0};
- spec.callback = NULL;
- spec.freq = 44100;
- spec.samples = 4096;
- spec.stereo = SDL_TRUE;
- spec.format = 0; //AUDIO_F32;
- kit_kmixerDevice* device = kit_kmixerDeviceOpen(NULL,0,&spec,&specO);
- if(device==NULL) return 3;
- //todo: SOLVE THE PROBLEM WITH ADDING TRACKS
- Uint32 asyncID = kit_kmixerAsyncAdd(device, SDL_TRUE, SDL_TRUE, 0, 3);
- if(!asyncID){ SDL_Log("error=\"%s\"",SDL_GetError()); return 5; }
- kit_acodecPCM* bgm = kit_acodecWAVRead("dat/44100_f32_stereo_lotus.wav");
- if(!bgm){ SDL_Log("bgm error=\"%s\"",SDL_GetError()); return 4; }
- bgm->loopCount = 1;
- kit_acodecPCM* choir = kit_acodecWAVRead("dat/44100_f32_stereo_choir.wav");
- if(!choir){ SDL_Log("choir error=\"%s\"",SDL_GetError()); return 4; }
- kit_acodecPCM* jingle = kit_acodecWAVRead("dat/44100_f32_stereo_jingle.wav");
- if(!jingle){ SDL_Log("jingle error=\"%s\"",SDL_GetError()); return 4; }
- kit_acodecPCM* mboxA3 = kit_acodecWAVRead("dat/44100_f32_stereo_mboxA3.wav");
- if(!mboxA3){ SDL_Log("mboxA3 error=\"%s\"",SDL_GetError()); return 4; }
- kit_kmixerDeviceUnpauseAndWait(device);
- Uint32 trackNum;
- SDL_Log("play bgm (with 1 loop)");
- Uint32 bgmTrack = kit_kmixerAsyncPlayPVS(device, asyncID, bgm,
- 0.0f, 0.33f,0.33f, 0.8);
- SDL_Delay(2000);
- SDL_Log("pan left");
- kit_kmixerAsyncPlayP(device, asyncID, choir, -0.5f);
- SDL_Delay(2000);
- SDL_Log("pan right");
- kit_kmixerAsyncPlayP(device, asyncID, choir, 0.5f);
- SDL_Delay(2500);
- SDL_Log("speed up");
- trackNum = kit_kmixerAsyncPlayV(device, asyncID, jingle, 0.6f,0.6f);
- kit_kmixerAsyncSetTrackDeltaS2(device, asyncID, trackNum, 1);
- while(kit_kmixerAsyncGetTrackPlayState(device,asyncID,trackNum)) SDL_Delay(100);
- SDL_Log("slow down");
- trackNum = kit_kmixerAsyncPlayV(device, asyncID, jingle, 0.6f,0.6f);
- kit_kmixerAsyncSetTrackDeltaS2(device, asyncID, trackNum, -1);
- while(kit_kmixerAsyncGetTrackPlayState(device,asyncID,trackNum)) SDL_Delay(100);
- SDL_Delay(1000);
- for(int i=1; i<=4; ++i){
- SDL_Log("music box note at: A%i",i+2);
- trackNum = kit_kmixerAsyncPlayPVS(device, asyncID, mboxA3, 0.0f, 0.7f,0.7f, (double)i);
- SDL_Delay(750);
- kit_kmixerAsyncStopTrack(device, asyncID, trackNum);
- }
- kit_kmixerAsyncSetTrackDeltaS2(device, asyncID, bgmTrack, -2*0.8);
- while(kit_kmixerAsyncGetActiveTracks(device,asyncID)) SDL_Delay(100);
- kit_kmixerDevicePauseAndWait(device);
- kit_acodecPCMDestroy(&mboxA3);
- kit_acodecPCMDestroy(&jingle);
- kit_acodecPCMDestroy(&choir);
- kit_acodecPCMDestroy(&bgm);
- kit_kmixerDeviceClose(&device);
- kit_kmixerQuit();
- kit_coreQuit();
- kit_coreLog("(If this is a nonzero value, that means there's a memory leak!)");
- SDL_Quit(); //kit_coreQuit includes SDL_Quit, but the above log itself seems to use heap
- kit_coreLog("# of allocations = %i",SDL_GetNumAllocations());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement