Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 24 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#define SRC_INVALID INT_MAX
#define DEFAULT_MUTE_KEYCODE 0x46 /* Scroll Lock */
#define MAX_NUM_SAMPLES 3 /* Maximum number of samples per key */

#define TEST_ERROR(_msg) \
error = alGetError(); \
Expand Down Expand Up @@ -124,6 +125,8 @@ int main(int argc, char **argv)
open_console();
}

srand(time(0));

/* Create openal context */

ALCdevice *device = NULL;
Expand Down Expand Up @@ -301,23 +304,38 @@ int play(int code, int press)
handle_mute_key(code == opt_mute_keycode);
}

static ALuint buf[512] = { 0 };
static ALuint src[512] = { 0 };
static ALuint buf[512 * MAX_NUM_SAMPLES] = { 0 };
static ALuint src[512 * MAX_NUM_SAMPLES] = { 0 };

/* 0 <= "code" <= 255, which means that 0 <= "idx" <= 511. We could
* then add "$rand * 512" to jump to one of the possible samples for
* this keycode. */
int idx = code + press * 256;

if(src[idx] == 0) {
/* Find a valid sample for this key. Assumes that a key either has
* MAX_NUM_SAMPLES samples or just one sample. */
char fname[256];
int rand_off = rand() % MAX_NUM_SAMPLES;
snprintf(fname, sizeof fname, "%s/%02x-%d-%d.wav", opt_path_audio, code, press, rand_off);
if (access(fname, R_OK) != 0)
{
printd("Sample #%d not found, falling back to #0");
rand_off = 0;
snprintf(fname, sizeof fname, "%s/%02x-%d-%d.wav", opt_path_audio, code, press, rand_off);
}

char fname[256];
snprintf(fname, sizeof(fname), "%s/%02x-%d.wav", opt_path_audio, code, press);
printd("Decided to use sample #%d (%s)", rand_off, fname);

idx += rand_off * 512;

if(src[idx] == 0) {
printd("Loading audio file \"%s\"", fname);

buf[idx] = alureCreateBufferFromFile(fname);
if(buf[idx] == 0) {

if(opt_fallback_sound) {
snprintf(fname, sizeof(fname), "%s/%02x-%d.wav", opt_path_audio, 0x31, press);
snprintf(fname, sizeof(fname), "%s/%02x-%d-0.wav", opt_path_audio, 0x31, press);
buf[idx] = alureCreateBufferFromFile(fname);
} else {
fprintf(stderr, "Error opening audio file \"%s\": %s\n", fname, alureGetErrorString());
Expand Down
Binary file added wav/01-0-0.wav
Binary file not shown.
Binary file added wav/01-0-1.wav
Binary file not shown.
Binary file added wav/01-0-2.wav
Binary file not shown.
Binary file removed wav/01-0.wav
Binary file not shown.
Binary file added wav/01-1-0.wav
Binary file not shown.
Binary file added wav/01-1-1.wav
Binary file not shown.
Binary file added wav/01-1-2.wav
Binary file not shown.
Binary file removed wav/01-1.wav
Binary file not shown.
Binary file added wav/02-0-0.wav
Binary file not shown.
Binary file added wav/02-0-1.wav
Binary file not shown.
Binary file added wav/02-0-2.wav
Binary file not shown.
Binary file removed wav/02-0.wav
Binary file not shown.
Binary file added wav/02-1-0.wav
Binary file not shown.
Binary file added wav/02-1-1.wav
Binary file not shown.
Binary file added wav/02-1-2.wav
Binary file not shown.
Binary file removed wav/02-1.wav
Binary file not shown.
Binary file added wav/03-0-0.wav
Binary file not shown.
Binary file added wav/03-0-1.wav
Binary file not shown.
Binary file added wav/03-0-2.wav
Binary file not shown.
Binary file removed wav/03-0.wav
Binary file not shown.
Binary file added wav/03-1-0.wav
Binary file not shown.
Binary file added wav/03-1-1.wav
Binary file not shown.
Binary file added wav/03-1-2.wav
Binary file not shown.
Binary file removed wav/03-1.wav
Binary file not shown.
Binary file added wav/04-0-0.wav
Binary file not shown.
Binary file added wav/04-0-1.wav
Binary file not shown.
Binary file added wav/04-0-2.wav
Binary file not shown.
Binary file removed wav/04-0.wav
Binary file not shown.
Binary file added wav/04-1-0.wav
Binary file not shown.
Binary file added wav/04-1-1.wav
Binary file not shown.
Binary file added wav/04-1-2.wav
Binary file not shown.
Binary file removed wav/04-1.wav
Binary file not shown.
Binary file added wav/05-0-0.wav
Binary file not shown.
Binary file added wav/05-0-1.wav
Binary file not shown.
Binary file added wav/05-0-2.wav
Binary file not shown.
Binary file removed wav/05-0.wav
Binary file not shown.
Binary file added wav/05-1-0.wav
Binary file not shown.
Binary file added wav/05-1-1.wav
Binary file not shown.
Binary file added wav/05-1-2.wav
Binary file not shown.
Binary file removed wav/05-1.wav
Binary file not shown.
Binary file added wav/06-0-0.wav
Binary file not shown.
Binary file added wav/06-0-1.wav
Binary file not shown.
Binary file added wav/06-0-2.wav
Binary file not shown.
Binary file removed wav/06-0.wav
Binary file not shown.
Binary file added wav/06-1-0.wav
Binary file not shown.
Binary file added wav/06-1-1.wav
Binary file not shown.
Binary file added wav/06-1-2.wav
Binary file not shown.
Binary file removed wav/06-1.wav
Binary file not shown.
Binary file added wav/07-0-0.wav
Binary file not shown.
Binary file added wav/07-0-1.wav
Binary file not shown.
Binary file added wav/07-0-2.wav
Binary file not shown.
Binary file removed wav/07-0.wav
Binary file not shown.
Binary file added wav/07-1-0.wav
Binary file not shown.
Binary file added wav/07-1-1.wav
Binary file not shown.
Binary file added wav/07-1-2.wav
Binary file not shown.
Binary file removed wav/07-1.wav
Binary file not shown.
Binary file added wav/08-0-0.wav
Binary file not shown.
Binary file added wav/08-0-1.wav
Binary file not shown.
Binary file added wav/08-0-2.wav
Binary file not shown.
Binary file removed wav/08-0.wav
Binary file not shown.
Binary file added wav/08-1-0.wav
Binary file not shown.
Binary file added wav/08-1-1.wav
Binary file not shown.
Binary file added wav/08-1-2.wav
Binary file not shown.
Binary file removed wav/08-1.wav
Binary file not shown.
Binary file added wav/09-0-0.wav
Binary file not shown.
Binary file added wav/09-0-1.wav
Binary file not shown.
Binary file removed wav/09-0.wav
Binary file not shown.
Binary file added wav/09-1-0.wav
Binary file not shown.
Binary file added wav/09-1-1.wav
Binary file not shown.
Binary file removed wav/09-1.wav
Binary file not shown.
Binary file added wav/0a-0-0.wav
Binary file not shown.
Binary file added wav/0a-0-1.wav
Binary file not shown.
Binary file added wav/0a-0-2.wav
Binary file not shown.
Binary file removed wav/0a-0.wav
Binary file not shown.
Binary file added wav/0a-1-0.wav
Binary file not shown.
Binary file added wav/0a-1-1.wav
Binary file not shown.
Binary file added wav/0a-1-2.wav
Binary file not shown.
Binary file removed wav/0a-1.wav
Binary file not shown.
Binary file added wav/0b-0-0.wav
Binary file not shown.
Binary file added wav/0b-0-1.wav
Binary file not shown.
Binary file added wav/0b-0-2.wav
Binary file not shown.
Binary file removed wav/0b-0.wav
Binary file not shown.
Binary file added wav/0b-1-0.wav
Binary file not shown.
Binary file added wav/0b-1-1.wav
Binary file not shown.
Binary file added wav/0b-1-2.wav
Binary file not shown.
Binary file removed wav/0b-1.wav
Binary file not shown.
Binary file added wav/0c-0-0.wav
Binary file not shown.
Binary file added wav/0c-0-1.wav
Binary file not shown.
Binary file added wav/0c-0-2.wav
Binary file not shown.
Binary file removed wav/0c-0.wav
Binary file not shown.
Binary file added wav/0c-1-0.wav
Binary file not shown.
Binary file added wav/0c-1-1.wav
Binary file not shown.
Binary file added wav/0c-1-2.wav
Binary file not shown.
Binary file removed wav/0c-1.wav
Binary file not shown.
Binary file added wav/0d-0-0.wav
Binary file not shown.
Binary file added wav/0d-0-1.wav
Binary file not shown.
Binary file added wav/0d-0-2.wav
Binary file not shown.
Binary file removed wav/0d-0.wav
Binary file not shown.
Binary file added wav/0d-1-0.wav
Binary file not shown.
Binary file added wav/0d-1-1.wav
Binary file not shown.
Binary file added wav/0d-1-2.wav
Binary file not shown.
Binary file removed wav/0d-1.wav
Binary file not shown.
Binary file added wav/0e-0-0.wav
Binary file not shown.
Binary file added wav/0e-0-1.wav
Binary file not shown.
Binary file added wav/0e-0-2.wav
Binary file not shown.
Binary file removed wav/0e-0.wav
Binary file not shown.
Binary file added wav/0e-1-0.wav
Binary file not shown.
Binary file added wav/0e-1-1.wav
Binary file not shown.
Binary file added wav/0e-1-2.wav
Binary file not shown.
Binary file removed wav/0e-1.wav
Binary file not shown.
Binary file added wav/0f-0-0.wav
Binary file not shown.
Binary file added wav/0f-0-1.wav
Binary file not shown.
Binary file added wav/0f-0-2.wav
Binary file not shown.
Binary file removed wav/0f-0.wav
Binary file not shown.
Binary file added wav/0f-1-0.wav
Binary file not shown.
Binary file added wav/0f-1-1.wav
Binary file not shown.
Binary file added wav/0f-1-2.wav
Binary file not shown.
Binary file removed wav/0f-1.wav
Binary file not shown.
Binary file added wav/10-0-0.wav
Binary file not shown.
Binary file added wav/10-0-1.wav
Binary file not shown.
Binary file added wav/10-0-2.wav
Binary file not shown.
Binary file removed wav/10-0.wav
Binary file not shown.
Binary file added wav/10-1-0.wav
Binary file not shown.
Binary file added wav/10-1-1.wav
Binary file not shown.
Binary file added wav/10-1-2.wav
Binary file not shown.
Binary file removed wav/10-1.wav
Binary file not shown.
Binary file added wav/11-0-0.wav
Binary file not shown.
Binary file added wav/11-0-1.wav
Binary file not shown.
Binary file added wav/11-0-2.wav
Binary file not shown.
Binary file removed wav/11-0.wav
Binary file not shown.
Binary file added wav/11-1-0.wav
Binary file not shown.
Binary file added wav/11-1-1.wav
Binary file not shown.
Binary file added wav/11-1-2.wav
Binary file not shown.
Binary file removed wav/11-1.wav
Binary file not shown.
Binary file added wav/12-0-0.wav
Binary file not shown.
Binary file added wav/12-0-1.wav
Binary file not shown.
Binary file added wav/12-0-2.wav
Binary file not shown.
Binary file removed wav/12-0.wav
Binary file not shown.
Binary file added wav/12-1-0.wav
Binary file not shown.
Binary file added wav/12-1-1.wav
Binary file not shown.
Binary file added wav/12-1-2.wav
Binary file not shown.
Binary file removed wav/12-1.wav
Binary file not shown.
Binary file added wav/13-0-0.wav
Binary file not shown.
Binary file added wav/13-0-1.wav
Binary file not shown.
Binary file added wav/13-0-2.wav
Binary file not shown.
Binary file removed wav/13-0.wav
Binary file not shown.
Binary file added wav/13-1-0.wav
Binary file not shown.
Binary file added wav/13-1-1.wav
Binary file not shown.
Binary file added wav/13-1-2.wav
Binary file not shown.
Binary file removed wav/13-1.wav
Binary file not shown.
Binary file added wav/14-0-0.wav
Binary file not shown.
Binary file added wav/14-0-1.wav
Binary file not shown.
Binary file added wav/14-0-2.wav
Binary file not shown.
Binary file removed wav/14-0.wav
Binary file not shown.
Binary file added wav/14-1-0.wav
Binary file not shown.
Binary file added wav/14-1-1.wav
Binary file not shown.
Binary file added wav/14-1-2.wav
Binary file not shown.
Binary file removed wav/14-1.wav
Binary file not shown.
Binary file added wav/15-0-0.wav
Binary file not shown.
Binary file added wav/15-0-1.wav
Binary file not shown.
Binary file added wav/15-0-2.wav
Binary file not shown.
Binary file removed wav/15-0.wav
Binary file not shown.
Binary file added wav/15-1-0.wav
Binary file not shown.
Binary file added wav/15-1-1.wav
Binary file not shown.
Binary file added wav/15-1-2.wav
Binary file not shown.
Binary file removed wav/15-1.wav
Binary file not shown.
Binary file added wav/16-0-0.wav
Binary file not shown.
Binary file added wav/16-0-1.wav
Binary file not shown.
Binary file added wav/16-0-2.wav
Binary file not shown.
Binary file removed wav/16-0.wav
Binary file not shown.
Binary file added wav/16-1-0.wav
Binary file not shown.
Binary file added wav/16-1-1.wav
Binary file not shown.
Binary file added wav/16-1-2.wav
Binary file not shown.
Binary file removed wav/16-1.wav
Binary file not shown.
Binary file added wav/17-0-0.wav
Binary file not shown.
Binary file added wav/17-0-1.wav
Binary file not shown.
Binary file added wav/17-0-2.wav
Binary file not shown.
Binary file removed wav/17-0.wav
Binary file not shown.
Binary file added wav/17-1-0.wav
Binary file not shown.
Binary file added wav/17-1-1.wav
Binary file not shown.
Binary file added wav/17-1-2.wav
Binary file not shown.
Binary file removed wav/17-1.wav
Binary file not shown.
Binary file added wav/18-0-0.wav
Binary file not shown.
Binary file added wav/18-0-1.wav
Binary file not shown.
Binary file added wav/18-0-2.wav
Binary file not shown.
Binary file removed wav/18-0.wav
Binary file not shown.
Binary file added wav/18-1-0.wav
Binary file not shown.
Binary file added wav/18-1-1.wav
Binary file not shown.
Binary file added wav/18-1-2.wav
Binary file not shown.
Binary file removed wav/18-1.wav
Binary file not shown.
Binary file added wav/19-0-0.wav
Binary file not shown.
Binary file added wav/19-0-1.wav
Binary file not shown.
Binary file added wav/19-0-2.wav
Binary file not shown.
Binary file removed wav/19-0.wav
Binary file not shown.
Binary file added wav/19-1-0.wav
Binary file not shown.
Binary file added wav/19-1-1.wav
Binary file not shown.
Binary file added wav/19-1-2.wav
Binary file not shown.
Binary file removed wav/19-1.wav
Binary file not shown.
Binary file added wav/1a-0-0.wav
Binary file not shown.
Binary file added wav/1a-0-1.wav
Binary file not shown.
Binary file added wav/1a-0-2.wav
Binary file not shown.
Binary file removed wav/1a-0.wav
Binary file not shown.
Binary file added wav/1a-1-0.wav
Binary file not shown.
Binary file added wav/1a-1-1.wav
Binary file not shown.
Binary file added wav/1a-1-2.wav
Binary file not shown.
Binary file removed wav/1a-1.wav
Binary file not shown.
Binary file added wav/1b-0-0.wav
Binary file not shown.
Binary file added wav/1b-0-1.wav
Binary file not shown.
Binary file added wav/1b-0-2.wav
Binary file not shown.
Binary file removed wav/1b-0.wav
Binary file not shown.
Binary file added wav/1b-1-0.wav
Binary file not shown.
Binary file added wav/1b-1-1.wav
Binary file not shown.
Binary file added wav/1b-1-2.wav
Binary file not shown.
Binary file removed wav/1b-1.wav
Binary file not shown.
Binary file added wav/1c-0-0.wav
Binary file not shown.
Binary file added wav/1c-0-1.wav
Binary file not shown.
Binary file added wav/1c-0-2.wav
Binary file not shown.
Binary file removed wav/1c-0.wav
Binary file not shown.
Binary file added wav/1c-1-0.wav
Binary file not shown.
Binary file added wav/1c-1-1.wav
Binary file not shown.
Binary file added wav/1c-1-2.wav
Binary file not shown.
Binary file removed wav/1c-1.wav
Binary file not shown.
Binary file added wav/1d-0-0.wav
Binary file not shown.
Binary file added wav/1d-0-1.wav
Binary file not shown.
Binary file added wav/1d-0-2.wav
Binary file not shown.
Binary file removed wav/1d-0.wav
Binary file not shown.
Binary file added wav/1d-1-0.wav
Binary file not shown.
Binary file added wav/1d-1-1.wav
Binary file not shown.
Binary file added wav/1d-1-2.wav
Binary file not shown.
Binary file removed wav/1d-1.wav
Binary file not shown.
Binary file added wav/1e-0-0.wav
Binary file not shown.
Binary file added wav/1e-0-1.wav
Binary file not shown.
Binary file added wav/1e-0-2.wav
Binary file not shown.
Binary file removed wav/1e-0.wav
Binary file not shown.
Binary file added wav/1e-1-0.wav
Binary file not shown.
Binary file added wav/1e-1-1.wav
Binary file not shown.
Binary file added wav/1e-1-2.wav
Binary file not shown.
Binary file removed wav/1e-1.wav
Binary file not shown.
Binary file added wav/1f-0-0.wav
Binary file not shown.
Binary file added wav/1f-0-1.wav
Binary file not shown.
Binary file added wav/1f-0-2.wav
Binary file not shown.
Binary file removed wav/1f-0.wav
Binary file not shown.
Binary file added wav/1f-1-0.wav
Binary file not shown.
Binary file added wav/1f-1-1.wav
Binary file not shown.
Binary file added wav/1f-1-2.wav
Binary file not shown.
Binary file removed wav/1f-1.wav
Binary file not shown.
Binary file added wav/20-0-0.wav
Binary file not shown.
Binary file added wav/20-0-1.wav
Binary file not shown.
Binary file added wav/20-0-2.wav
Binary file not shown.
Binary file removed wav/20-0.wav
Binary file not shown.
Binary file added wav/20-1-0.wav
Binary file not shown.
Binary file added wav/20-1-1.wav
Binary file not shown.
Binary file added wav/20-1-2.wav
Binary file not shown.
Binary file removed wav/20-1.wav
Binary file not shown.
Binary file added wav/21-0-0.wav
Binary file not shown.
Binary file added wav/21-0-1.wav
Binary file not shown.
Binary file added wav/21-0-2.wav
Binary file not shown.
Binary file removed wav/21-0.wav
Binary file not shown.
Binary file added wav/21-1-0.wav
Binary file not shown.
Binary file added wav/21-1-1.wav
Binary file not shown.
Binary file added wav/21-1-2.wav
Binary file not shown.
Binary file removed wav/21-1.wav
Binary file not shown.
Binary file added wav/22-0-0.wav
Binary file not shown.
Binary file added wav/22-0-1.wav
Binary file not shown.
Binary file added wav/22-0-2.wav
Binary file not shown.
Binary file removed wav/22-0.wav
Binary file not shown.
Binary file added wav/22-1-0.wav
Binary file not shown.
Binary file added wav/22-1-1.wav
Binary file not shown.
Binary file added wav/22-1-2.wav
Binary file not shown.
Binary file removed wav/22-1.wav
Binary file not shown.
Binary file added wav/23-0-0.wav
Binary file not shown.
Binary file added wav/23-0-1.wav
Binary file not shown.
Binary file added wav/23-0-2.wav
Binary file not shown.
Binary file removed wav/23-0.wav
Binary file not shown.
Binary file added wav/23-1-0.wav
Binary file not shown.
Binary file added wav/23-1-1.wav
Binary file not shown.
Binary file added wav/23-1-2.wav
Binary file not shown.
Binary file removed wav/23-1.wav
Binary file not shown.
Binary file added wav/24-0-0.wav
Binary file not shown.
Binary file added wav/24-0-1.wav
Binary file not shown.
Binary file added wav/24-0-2.wav
Binary file not shown.
Binary file removed wav/24-0.wav
Binary file not shown.
Binary file added wav/24-1-0.wav
Binary file not shown.
Binary file added wav/24-1-1.wav
Binary file not shown.
Binary file added wav/24-1-2.wav
Binary file not shown.
Binary file removed wav/24-1.wav
Binary file not shown.
Binary file added wav/25-0-0.wav
Binary file not shown.
Binary file added wav/25-0-1.wav
Binary file not shown.
Binary file added wav/25-0-2.wav
Binary file not shown.
Binary file removed wav/25-0.wav
Binary file not shown.
Binary file added wav/25-1-0.wav
Binary file not shown.
Binary file added wav/25-1-1.wav
Binary file not shown.
Binary file added wav/25-1-2.wav
Binary file not shown.
Binary file removed wav/25-1.wav
Binary file not shown.
Binary file added wav/26-0-0.wav
Binary file not shown.
Binary file added wav/26-0-1.wav
Binary file not shown.
Binary file added wav/26-0-2.wav
Binary file not shown.
Binary file removed wav/26-0.wav
Binary file not shown.
Binary file added wav/26-1-0.wav
Binary file not shown.
Loading