diff options
author | Chris Robinson <[email protected]> | 2015-10-14 01:54:50 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2015-10-14 01:54:50 -0700 |
commit | 9012bcf3279558139700ab1ad526c2d7a42be76e (patch) | |
tree | 7f1e5671747ead21484104005e0b068f592cb73a /examples/altonegen.c | |
parent | c18e23477c5efc0183fa809622085b1ed413cb6b (diff) |
Make the tonegen sampling rate match the device rate by default
Diffstat (limited to 'examples/altonegen.c')
-rw-r--r-- | examples/altonegen.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/examples/altonegen.c b/examples/altonegen.c index d8601f7e..191962f0 100644 --- a/examples/altonegen.c +++ b/examples/altonegen.c @@ -113,8 +113,9 @@ int main(int argc, char *argv[]) ALuint source, buffer; ALint last_pos, num_loops; ALint max_loops = 4; - ALint srate = 44100; + ALint srate = -1; ALint tone_freq = 1000; + ALCint dev_rate; ALenum state; int i; @@ -132,7 +133,7 @@ int main(int argc, char *argv[]) " --waveform/-w <type> Waveform type: sine (default), square, sawtooth,\n" " triangle\n" " --freq/-f <hz> Tone frequency (default 1000 hz)\n" -" --srate/-s <sample rate> Sampling rate (default 44100 hz)\n", +" --srate/-s <sample rate> Sampling rate (default output rate)\n", argv[0] ); return 1; @@ -187,6 +188,14 @@ int main(int argc, char *argv[]) return 1; } + { + ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext()); + alcGetIntegerv(device, ALC_FREQUENCY, 1, &dev_rate); + assert(alcGetError(device)==ALC_NO_ERROR && "Failed to get device sample rate"); + } + if(srate < 0) + srate = dev_rate; + /* Load the sound into a buffer. */ buffer = CreateWave(wavetype, tone_freq, srate); if(!buffer) @@ -195,22 +204,9 @@ int main(int argc, char *argv[]) return 1; } - { - ALCdevice *device; - ALCint dev_rate; - ALint buf_rate; - - device = alcGetContextsDevice(alcGetCurrentContext()); - alcGetIntegerv(device, ALC_FREQUENCY, 1, &dev_rate); - assert(alcGetError(device)==ALC_NO_ERROR && "Failed to get device sample rate"); - - alGetBufferi(buffer, AL_FREQUENCY, &buf_rate); - assert(alGetError()==AL_NO_ERROR && "Failed to get buffer sample rate"); - - printf("Playing %dhz tone with %dhz sample rate and %dhz output, for %d second%s...\n", - tone_freq, buf_rate, dev_rate, max_loops+1, max_loops?"s":""); - fflush(stdout); - } + printf("Playing %dhz tone with %dhz sample rate and %dhz output, for %d second%s...\n", + tone_freq, srate, dev_rate, max_loops+1, max_loops?"s":""); + fflush(stdout); /* Create the source to play the sound with. */ source = 0; |