27 changed files with 150 additions and 0 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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@ |
|||
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,104 @@ |
|||
#include <stdio.h> |
|||
#include "SDL.h" |
|||
#include "SDL_mixer.h" |
|||
#include "SDL_image.h" |
|||
#include <unistd.h> |
|||
#include <syslog.h> |
|||
#include <string.h> |
|||
#include <math.h> |
|||
|
|||
#define NUM_WAVEFORMS 6 |
|||
|
|||
Mix_Chunk* _sample[NUM_WAVEFORMS]; |
|||
|
|||
#include "players.cpp" |
|||
#include "loaders.cpp" |
|||
|
|||
int main(int argc, char** argv) { |
|||
|
|||
bool done = false; |
|||
bool play = true; |
|||
int timer = 0; |
|||
int step = 500; |
|||
|
|||
SDL_Window* window; |
|||
SDL_Renderer* renderer; |
|||
|
|||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO ); |
|||
atexit(SDL_Quit); |
|||
|
|||
window = SDL_CreateWindow("Sonquencer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 400, 300, 0); |
|||
renderer = SDL_CreateRenderer(window, -1, 0); |
|||
|
|||
SDL_SetRenderDrawColor(renderer, 100, 100, 100, 255); |
|||
SDL_Delay(1000); |
|||
|
|||
if(loadBank(1) == false) {return -1;} |
|||
|
|||
SDL_Event event; |
|||
|
|||
while (!done) { |
|||
bool gotEvent = SDL_PollEvent(&event); |
|||
|
|||
SDL_RenderClear(renderer); |
|||
SDL_RenderPresent(renderer); |
|||
|
|||
while (!done && gotEvent) { |
|||
switch (event.type) { |
|||
case SDL_KEYDOWN: |
|||
|
|||
switch (event.key.keysym.sym) { |
|||
case SDLK_ESCAPE: |
|||
Mix_CloseAudio(); |
|||
SDL_Quit(); |
|||
return 0; |
|||
break; |
|||
case SDLK_1: |
|||
playSample(1); |
|||
break; |
|||
case SDLK_2: |
|||
playSample(2); |
|||
break; |
|||
case SDLK_3: |
|||
playSample(3); |
|||
break; |
|||
case SDLK_4: |
|||
playSample(4); |
|||
break; |
|||
case SDLK_5: |
|||
playSample(5); |
|||
break; |
|||
case SDLK_6: |
|||
playSample(6); |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
break; |
|||
|
|||
case SDL_QUIT: |
|||
done = true; |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
|
|||
if( !done ) { gotEvent = SDL_PollEvent(&event); } |
|||
|
|||
} |
|||
|
|||
playStep(play, &timer, &step); |
|||
} |
|||
|
|||
|
|||
for( int i = 0; i < NUM_WAVEFORMS; i++ ) { |
|||
Mix_FreeChunk(_sample[i]); |
|||
} |
|||
|
|||
Mix_CloseAudio(); |
|||
SDL_Quit(); |
|||
return 0; |
|||
} |
|||
|
@ -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