diff options
author | Chris Robinson <[email protected]> | 2016-09-08 12:05:08 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-09-08 12:14:28 -0700 |
commit | 0f24f49a44a12d139692d0846b2722de2213f1a8 (patch) | |
tree | ed7a9c9954e56082a27bebfa07fc4c6fbce18c43 /examples/altonegen.c | |
parent | b21e481827b660e7439fcebb505cdb0349517a54 (diff) |
Allow specifying the device to open for the examples
Diffstat (limited to 'examples/altonegen.c')
-rw-r--r-- | examples/altonegen.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/examples/altonegen.c b/examples/altonegen.c index 74a04ee2..422e6d66 100644 --- a/examples/altonegen.c +++ b/examples/altonegen.c @@ -133,6 +133,7 @@ static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate) int main(int argc, char *argv[]) { enum WaveType wavetype = WT_Sine; + const char *appname = argv[0]; ALuint source, buffer; ALint last_pos, num_loops; ALint max_loops = 4; @@ -142,13 +143,24 @@ int main(int argc, char *argv[]) ALenum state; int i; - for(i = 1;i < argc;i++) + argv++; argc--; + if(InitAL(&argv, &argc) != 0) + return 1; + + if(!alIsExtensionPresent("AL_EXT_FLOAT32")) + { + fprintf(stderr, "Required AL_EXT_FLOAT32 extension not supported on this device!\n"); + CloseAL(); + return 1; + } + + for(i = 0;i < argc;i++) { if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { fprintf(stderr, "OpenAL Tone Generator\n" "\n" -"Usage: %s <options>\n" +"Usage: %s [-device <name>] <options>\n" "\n" "Available options:\n" " --help/-h This help text\n" @@ -157,8 +169,9 @@ int main(int argc, char *argv[]) " triangle, impulse\n" " --freq/-f <hz> Tone frequency (default 1000 hz)\n" " --srate/-s <sample rate> Sampling rate (default output rate)\n", - argv[0] + appname ); + CloseAL(); return 1; } else if(i+1 < argc && strcmp(argv[i], "-t") == 0) @@ -204,15 +217,6 @@ int main(int argc, char *argv[]) } } - InitAL(); - - if(!alIsExtensionPresent("AL_EXT_FLOAT32")) - { - fprintf(stderr, "Required AL_EXT_FLOAT32 extension not supported on this device!\n"); - CloseAL(); - return 1; - } - { ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext()); alcGetIntegerv(device, ALC_FREQUENCY, 1, &dev_rate); |