aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/alffplay.c15
-rw-r--r--examples/alhrtf.c34
-rw-r--r--examples/allatency.c11
-rw-r--r--examples/alreverb.c11
-rw-r--r--examples/alstream.c9
-rw-r--r--examples/altonegen.c28
-rw-r--r--examples/common/alhelpers.c30
-rw-r--r--examples/common/alhelpers.h2
8 files changed, 89 insertions, 51 deletions
diff --git a/examples/alffplay.c b/examples/alffplay.c
index 2d38216f..e95dede6 100644
--- a/examples/alffplay.c
+++ b/examples/alffplay.c
@@ -1332,6 +1332,7 @@ int main(int argc, char *argv[])
SDL_Renderer *renderer;
ALCdevice *device;
ALCcontext *context;
+ int fileidx;
if(argc < 2)
{
@@ -1389,7 +1390,17 @@ int main(int argc, char *argv[])
SDL_RenderPresent(renderer);
/* Open an audio device */
- device = alcOpenDevice(NULL);
+ fileidx = 1;
+ device = NULL;
+ if(argc > 3 && strcmp(argv[1], "-device") == 0)
+ {
+ fileidx = 3;
+ device = alcOpenDevice(argv[2]);
+ if(!device)
+ fprintf(stderr, "OpenAL: could not open \"%s\" - trying default\n", argv[2]);
+ }
+ if(!device)
+ device = alcOpenDevice(NULL);
if(!device)
{
fprintf(stderr, "OpenAL: could not open device - exiting\n");
@@ -1429,7 +1440,7 @@ int main(int argc, char *argv[])
movState = av_mallocz(sizeof(MovieState));
- av_strlcpy(movState->filename, argv[1], sizeof(movState->filename));
+ av_strlcpy(movState->filename, argv[fileidx], sizeof(movState->filename));
packet_queue_init(&movState->audio.q);
packet_queue_init(&movState->video.q);
diff --git a/examples/alhrtf.c b/examples/alhrtf.c
index 23d60a74..3964a7c6 100644
--- a/examples/alhrtf.c
+++ b/examples/alhrtf.c
@@ -122,28 +122,18 @@ int main(int argc, char **argv)
ALdouble angle;
ALenum state;
- /* Print out usage if no file was specified */
- if(argc < 2 || (strcmp(argv[1], "-hrtf") == 0 && argc < 4))
+ /* Print out usage if no arguments were specified */
+ if(argc < 2)
{
- fprintf(stderr, "Usage: %s [-hrtf <name>] <soundfile>\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-device <name>] [-hrtf <name>] <soundfile>\n", argv[0]);
return 1;
}
- /* Initialize OpenAL with the default device, and check for HRTF support. */
- if(InitAL() != 0)
+ /* Initialize OpenAL, and check for HRTF support. */
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
return 1;
- if(strcmp(argv[1], "-hrtf") == 0)
- {
- hrtfname = argv[2];
- soundname = argv[3];
- }
- else
- {
- hrtfname = NULL;
- soundname = argv[1];
- }
-
device = alcGetContextsDevice(alcGetCurrentContext());
if(!alcIsExtensionPresent(device, "ALC_SOFT_HRTF"))
{
@@ -164,6 +154,18 @@ int main(int argc, char **argv)
has_angle_ext = alIsExtensionPresent("AL_EXT_STEREO_ANGLES");
printf("AL_EXT_STEREO_ANGLES%s found\n", has_angle_ext?"":" not");
+ /* Check for user-preferred HRTF */
+ if(strcmp(argv[0], "-hrtf") == 0)
+ {
+ hrtfname = argv[1];
+ soundname = argv[2];
+ }
+ else
+ {
+ hrtfname = NULL;
+ soundname = argv[0];
+ }
+
/* Enumerate available HRTFs, and reset the device using one. */
alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtf);
if(!num_hrtf)
diff --git a/examples/allatency.c b/examples/allatency.c
index afef43ca..56d96b9e 100644
--- a/examples/allatency.c
+++ b/examples/allatency.c
@@ -125,15 +125,16 @@ int main(int argc, char **argv)
ALdouble offsets[2];
ALenum state;
- /* Print out usage if no file was specified */
+ /* Print out usage if no arguments were specified */
if(argc < 2)
{
- fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-device <name>] <filename>\n", argv[0]);
return 1;
}
- /* Initialize OpenAL with the default device, and check for EFX support. */
- if(InitAL() != 0)
+ /* Initialize OpenAL, and check for source_latency support. */
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
return 1;
if(!alIsExtensionPresent("AL_SOFT_source_latency"))
@@ -166,7 +167,7 @@ int main(int argc, char **argv)
#undef LOAD_PROC
/* Load the sound into a buffer. */
- buffer = LoadSound(argv[1]);
+ buffer = LoadSound(argv[0]);
if(!buffer)
{
CloseAL();
diff --git a/examples/alreverb.c b/examples/alreverb.c
index 7d2bb343..ec71f354 100644
--- a/examples/alreverb.c
+++ b/examples/alreverb.c
@@ -217,15 +217,16 @@ int main(int argc, char **argv)
ALuint source, buffer, effect, slot;
ALenum state;
- /* Print out usage if no file was specified */
+ /* Print out usage if no arguments were specified */
if(argc < 2)
{
- fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-device <name] <filename>\n", argv[0]);
return 1;
}
- /* Initialize OpenAL with the default device, and check for EFX support. */
- if(InitAL() != 0)
+ /* Initialize OpenAL, and check for EFX support. */
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
return 1;
if(!alcIsExtensionPresent(alcGetContextsDevice(alcGetCurrentContext()), "ALC_EXT_EFX"))
@@ -269,7 +270,7 @@ int main(int argc, char **argv)
#undef LOAD_PROC
/* Load the sound into a buffer. */
- buffer = LoadSound(argv[1]);
+ buffer = LoadSound(argv[0]);
if(!buffer)
{
CloseAL();
diff --git a/examples/alstream.c b/examples/alstream.c
index 63478d6a..65a04475 100644
--- a/examples/alstream.c
+++ b/examples/alstream.c
@@ -270,14 +270,15 @@ int main(int argc, char **argv)
StreamPlayer *player;
int i;
- /* Print out usage if no file was specified */
+ /* Print out usage if no arguments were specified */
if(argc < 2)
{
- fprintf(stderr, "Usage: %s <filenames...>\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-device <name>] <filenames...>\n", argv[0]);
return 1;
}
- if(InitAL() != 0)
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
return 1;
if(alIsExtensionPresent("AL_SOFT_buffer_samples"))
@@ -292,7 +293,7 @@ int main(int argc, char **argv)
player = NewPlayer();
/* Play each file listed on the command line */
- for(i = 1;i < argc;i++)
+ for(i = 0;i < argc;i++)
{
const char *namepart;
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);
diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c
index 4582321c..43548b5c 100644
--- a/examples/common/alhelpers.c
+++ b/examples/common/alhelpers.c
@@ -29,6 +29,7 @@
* channel configs and sample types. */
#include <stdio.h>
+#include <string.h>
#include "AL/al.h"
#include "AL/alc.h"
@@ -37,15 +38,26 @@
#include "alhelpers.h"
-/* InitAL opens the default device and sets up a context using default
- * attributes, making the program ready to call OpenAL functions. */
-int InitAL(void)
+/* InitAL opens a device and sets up a context using default attributes, making
+ * the program ready to call OpenAL functions. */
+int InitAL(char ***argv, int *argc)
{
+ const ALCchar *name;
ALCdevice *device;
ALCcontext *ctx;
- /* Open and initialize a device with default settings */
- device = alcOpenDevice(NULL);
+ /* Open and initialize a device */
+ device = NULL;
+ if(argc && argv && *argc > 1 && strcmp((*argv)[0], "-device") == 0)
+ {
+ device = alcOpenDevice((*argv)[1]);
+ if(!device)
+ fprintf(stderr, "Failed to open \"%s\", trying default\n", (*argv)[1]);
+ (*argv) += 2;
+ (*argc) -= 2;
+ }
+ if(!device)
+ device = alcOpenDevice(NULL);
if(!device)
{
fprintf(stderr, "Could not open a device!\n");
@@ -62,7 +74,13 @@ int InitAL(void)
return 1;
}
- printf("Opened \"%s\"\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
+ name = NULL;
+ if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT"))
+ name = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
+ if(!name || alcGetError(device) != AL_NO_ERROR)
+ name = alcGetString(device, ALC_DEVICE_SPECIFIER);
+ printf("Opened \"%s\"\n", name);
+
return 0;
}
diff --git a/examples/common/alhelpers.h b/examples/common/alhelpers.h
index 1b4d2fbf..9f60df2a 100644
--- a/examples/common/alhelpers.h
+++ b/examples/common/alhelpers.h
@@ -35,7 +35,7 @@ void AL_APIENTRY wrap_BufferSamples(ALuint buffer, ALuint samplerate,
const ALvoid *data);
/* Easy device init/deinit functions. InitAL returns 0 on success. */
-int InitAL(void);
+int InitAL(char ***argv, int *argc);
void CloseAL(void);
#ifdef __cplusplus