You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.8 KiB
83 lines
1.8 KiB
|
|
int loadBank(int bank) {
|
|
|
|
printf("\nLoading bank %d ...\n", bank);
|
|
memset(samples, 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);
|
|
|
|
samples[i] = Mix_LoadWAV(waveFileName);
|
|
if( samples[i] == NULL ) {
|
|
fprintf(stderr, "Unable to load wave file: %s\n", waveFileName);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
void loadPattern(int patternNum) {
|
|
printf("\nLoading pattern %d ...\n", patternNum);
|
|
|
|
FILE *fp;
|
|
char *line = NULL;
|
|
size_t len = 0;
|
|
ssize_t read;
|
|
int lineCount = 0;
|
|
char patternFile[16];
|
|
|
|
int bank = 0;
|
|
int cols = 0;
|
|
int rows = 0;
|
|
|
|
sprintf(patternFile, "patterns/pattern%d", patternNum);
|
|
fp = fopen(patternFile, "r");
|
|
if(fp == NULL) {exit(EXIT_FAILURE);}
|
|
|
|
while ((read = getline(&line, &len, fp)) != -1) {
|
|
//printf("Retrieved line of length %zu:\n", read);
|
|
if(lineCount == 0) { bank = line[10]-'0'; }
|
|
if(lineCount == 1) { rows = line[10]-'0'; }
|
|
|
|
if(lineCount > 1) {
|
|
if(lineCount == 2) {
|
|
cols = read-1;
|
|
}
|
|
for(int i=0; i<cols; i++) {
|
|
pattern[lineCount-2][i] = line[i];
|
|
}
|
|
}
|
|
lineCount++;
|
|
}
|
|
|
|
printf("Pattern: %d\nBank: %d\nColumns: %d\nRows: %d\n", patternNum, bank, cols, rows);
|
|
|
|
matrix[0] = rows;
|
|
matrix[1] = cols;
|
|
|
|
for(int i=0; i<rows; i++) {
|
|
for(int y=0; y<cols; y++) {
|
|
printf("%d ", pattern[i][y]-'0');
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
fclose(fp);
|
|
if(line) {free(line);}
|
|
loadBank(bank);
|
|
}
|