diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/openal_playback.cpp | 87 | ||||
-rwxr-xr-x | tests/runner.py | 7 | ||||
-rw-r--r-- | tests/sounds/audio.wav | bin | 0 -> 190764 bytes |
3 files changed, 94 insertions, 0 deletions
diff --git a/tests/openal_playback.cpp b/tests/openal_playback.cpp new file mode 100644 index 00000000..4afa55fb --- /dev/null +++ b/tests/openal_playback.cpp @@ -0,0 +1,87 @@ +#include <stdio.h> +#include <stdlib.h> +#include <AL/al.h> +#include <AL/alc.h> + +int main() { + ALCdevice* device = alcOpenDevice(NULL); + ALCcontext* context = alcCreateContext(device, NULL); + alcMakeContextCurrent(context); + + ALfloat listenerPos[] = {0.0, 0.0, 0.0}; + ALfloat listenerVel[] = {0.0, 0.0, 0.0}; + ALfloat listenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; + + alListenerfv(AL_POSITION, listenerPos); + alListenerfv(AL_VELOCITY, listenerVel); + alListenerfv(AL_ORIENTATION, listenerOri); + + ALuint buffers[1]; + + alGenBuffers(1, buffers); + + FILE* source = fopen("audio.wav", "rb"); + fseek(source, 0, SEEK_END); + int size = ftell(source); + fseek(source, 0, SEEK_SET); + + unsigned char* buffer = (unsigned char*) malloc(size); + fread(buffer, size, 1, source); + + unsigned offset = 12; // ignore the RIFF header + offset += 8; // ignore the fmt header + offset += 2; // ignore the format type + + unsigned channels = buffer[offset + 1] << 8; + channels |= buffer[offset]; + offset += 2; + printf("Channels: %u\n", channels); + + unsigned frequency = buffer[offset + 3] << 24; + frequency |= buffer[offset + 2] << 16; + frequency |= buffer[offset + 1] << 8; + frequency |= buffer[offset]; + offset += 4; + printf("Frequency: %u\n", frequency); + + offset += 6; // ignore block size and bps + + unsigned bits = buffer[offset + 1] << 8; + bits |= buffer[offset]; + offset += 2; + printf("Bits: %u\n", bits); + + ALenum format = 0; + if(bits == 8) + { + if(channels == 1) + format = AL_FORMAT_MONO8; + else if(channels == 2) + format = AL_FORMAT_STEREO8; + } + else if(bits == 16) + { + if(channels == 1) + format = AL_FORMAT_MONO16; + else if(channels == 2) + format = AL_FORMAT_STEREO16; + } + + offset += 8; // ignore the data chunk + + printf("Start offset: %d\n", offset); + + alBufferData(buffers[0], format, &buffer[offset], size - offset, frequency); + + ALuint sources[1]; + alGenSources(1, sources); + + alSourcei(sources[0], AL_BUFFER, buffers[0]); + + alSourcePlay(sources[0]); + + int result = 1; + REPORT_RESULT(); + + return 0; +} diff --git a/tests/runner.py b/tests/runner.py index 9d6b1a4e..2ffc55ec 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -10984,6 +10984,13 @@ elif 'browser' in str(sys.argv): Popen([PYTHON, EMCC, path_from_root('tests', 'sdl_fog_linear.c'), '-o', 'something.html', '--pre-js', 'reftest.js', '--preload-file', 'screenshot.png', '-s', 'GL_TESTING=1']).communicate() self.run_browser('something.html', 'You should see an image with fog.', '/report_result?0') + def test_openal_playback(self): + shutil.copyfile(path_from_root('tests', 'sounds', 'audio.wav'), os.path.join(self.get_dir(), 'audio.wav')) + open(os.path.join(self.get_dir(), 'openal_playback.cpp'), 'w').write(self.with_report_result(open(path_from_root('tests', 'openal_playback.cpp')).read())) + + Popen([PYTHON, EMCC, '-O2', os.path.join(self.get_dir(), 'openal_playback.cpp'), '--preload-file', 'audio.wav', '-o', 'page.html']).communicate() + self.run_browser('page.html', '', '/report_result?1') + def test_worker(self): # Test running in a web worker output = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world_worker.cpp'), '-o', 'worker.js'], stdout=PIPE, stderr=PIPE).communicate() diff --git a/tests/sounds/audio.wav b/tests/sounds/audio.wav Binary files differnew file mode 100644 index 00000000..dd1b8057 --- /dev/null +++ b/tests/sounds/audio.wav |