diff options
author | Chris Robinson <[email protected]> | 2016-08-24 03:49:45 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-08-24 03:49:45 -0700 |
commit | d8e9b3c621762e3d9e2b81034e19aa0d671247ae (patch) | |
tree | 1c9ceb2e22018844c918d739d640c47dec0b0e93 /examples | |
parent | 849f85549d47a4e1aecdfbdd3300c866fb288fca (diff) |
Also rotate stereo sounds in the alhrtf example
Diffstat (limited to 'examples')
-rw-r--r-- | examples/alhrtf.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/examples/alhrtf.c b/examples/alhrtf.c index 2e6e7148..23d60a74 100644 --- a/examples/alhrtf.c +++ b/examples/alhrtf.c @@ -113,6 +113,7 @@ static ALuint LoadSound(const char *filename) int main(int argc, char **argv) { ALCdevice *device; + ALboolean has_angle_ext; ALuint source, buffer; const char *soundname; const char *hrtfname; @@ -157,6 +158,12 @@ int main(int argc, char **argv) LOAD_PROC(device, alcResetDeviceSOFT); #undef LOAD_PROC + /* Check for the AL_EXT_STEREO_ANGLES extension to be able to also rotate + * stereo sources. + */ + has_angle_ext = alIsExtensionPresent("AL_EXT_STEREO_ANGLES"); + printf("AL_EXT_STEREO_ANGLES%s found\n", has_angle_ext?"":" not"); + /* Enumerate available HRTFs, and reset the device using one. */ alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtf); if(!num_hrtf) @@ -232,12 +239,25 @@ int main(int argc, char **argv) do { al_nssleep(10000000); - /* Rotate the source around the listener by about 1/4 cycle per second. - * Only affects mono sounds. + /* Rotate the source around the listener by about 1/4 cycle per second, + * and keep it within -pi...+pi. */ angle += 0.01 * M_PI * 0.5; + if(angle > M_PI) + angle -= M_PI*2.0; + + /* This only rotates mono sounds. */ alSource3f(source, AL_POSITION, (ALfloat)sin(angle), 0.0f, -(ALfloat)cos(angle)); + if(has_angle_ext) + { + /* This rotates stereo sounds with the AL_EXT_STEREO_ANGLES + * extension. Angles are specified counter-clockwise in radians. + */ + ALfloat angles[2] = { (ALfloat)(M_PI/6.0 - angle), (ALfloat)(-M_PI/6.0 - angle) }; + alSourcefv(source, AL_STEREO_ANGLES, angles); + } + alGetSourcei(source, AL_SOURCE_STATE, &state); } while(alGetError() == AL_NO_ERROR && state == AL_PLAYING); |