27 changed files with 99 additions and 70 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@ |
|||||
g++ -o main -I/usr/include/SDL2 main.cpp -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer |
|
||||
|
g++ -o sonquencer -I/usr/include/SDL2 main.cpp -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer |
||||
|
@ -0,0 +1,30 @@ |
|||||
|
|
||||
|
int loadBank(int bank) { |
||||
|
|
||||
|
memset(_sample, 0, sizeof(Mix_Chunk*) * NUM_WAVEFORMS); |
||||
|
|
||||
|
int result = Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 512); |
||||
|
if( result < 0 ) { |
||||
|
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); |
||||
|
exit(-1); |
||||
|
} |
||||
|
|
||||
|
result = Mix_AllocateChannels(4); |
||||
|
if( result < 0 ) { |
||||
|
fprintf(stderr, "Unable to allocate mixing channels: %s\n", SDL_GetError()); |
||||
|
exit(-1); |
||||
|
} |
||||
|
|
||||
|
char waveFileName[17]; |
||||
|
|
||||
|
for( int i = 0; i < NUM_WAVEFORMS; i++ ) { |
||||
|
sprintf(waveFileName, "banks/BANK%d/%d.wav", bank, i+1); |
||||
|
|
||||
|
_sample[i] = Mix_LoadWAV(waveFileName); |
||||
|
if( _sample[i] == NULL ) { |
||||
|
fprintf(stderr, "Unable to load wave file: %s\n", waveFileName); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
Binary file not shown.
@ -0,0 +1,15 @@ |
|||||
|
|
||||
|
void playStep(bool play, int *timer, int *step) { |
||||
|
*timer = *timer >= *step ? 0 : *timer+1; |
||||
|
usleep(1000); |
||||
|
|
||||
|
if(*timer == 0) { |
||||
|
printf("%d\n", *timer); |
||||
|
|
||||
|
Mix_PlayChannel(-1, _sample[1], 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void playSample(int sample) { |
||||
|
Mix_PlayChannel(-1, _sample[sample-1], 0); |
||||
|
} |
Binary file not shown.
Loading…
Reference in new issue