# HG changeset patch # User koda # Date 1374787777 -7200 # Node ID b769a8e38cbd1f21ebb70d485d20377419bb6640 # Parent 915436ff64ab658cd7d6e40b3c9b50d7cd3244f9 strip out libopenalbridge too diff -r 915436ff64ab -r b769a8e38cbd cmake_modules/cpackvars.cmake --- a/cmake_modules/cpackvars.cmake Thu Jul 25 23:20:06 2013 +0200 +++ b/cmake_modules/cpackvars.cmake Thu Jul 25 23:29:37 2013 +0200 @@ -84,10 +84,9 @@ "cmake_uninstall\\\\.cmake$" "CMakeCache\\\\.txt$" "build_windows_.*\\\\.bat$" -# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" + "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" # "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/frontlib" # "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/cmdlineClient" - "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libopenalbridge" "^${CMAKE_CURRENT_SOURCE_DIR}/misc/winutils/bin" "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/promotional_art" "^${CMAKE_CURRENT_SOURCE_DIR}/tools/templates" diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/CMakeLists.txt --- a/misc/libopenalbridge/CMakeLists.txt Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -find_package(OpenAL REQUIRED) -find_package(OggVorbis REQUIRED) -include_directories(${OPENAL_INCLUDE_DIR}) -include_directories(${OGGVORBIS_INCLUDE_DIRS}) - -#set destination directory for library -set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}) - -#list of source files for libraries -set(openal_src openalbridge.c loaders.c wrappers.c commands.c) - -#build a static library for human systems -set (build_type STATIC) - -#visualstudio and windows in general don't like static linking, so we're building the library in shared mode -if(WIN32) -#workaround for visualstudio (wants headers in the source list) - set(openal_src *.h ${openal_src}) -#deps for the shared library - link_libraries(${VORBISFILE_LIBRARY}) - link_libraries(${VORBIS_LIBRARY}) - link_libraries(${OGG_LIBRARY}) - link_libraries(${OPENAL_LIBRARY}) -#build a shared library - set (build_type SHARED) -endif() - -#compiles and links actual library -add_library (openalbridge ${build_type} ${openal_src}) - -if(WIN32) -if(MSVC) - set_target_properties(openalbridge PROPERTIES LINK_FLAGS /DEF:openalbridge.def) -endif(MSVC) -#install it in the executable directory - install(TARGETS openalbridge DESTINATION bin) -endif(WIN32) - -#type make openalbridge_test to get a small executable test -add_executable(openalbridge_test "${hedgewars_SOURCE_DIR}/misc/libopenalbridge/tester.c") -target_link_libraries(openalbridge_test openalbridge ${OPENAL_LIBRARY} ${OGGVORBIS_LIBRARIES}) - diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/commands.c --- a/misc/libopenalbridge/commands.c Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,222 +0,0 @@ -/* - * commands.c - * Hedgewars - * - * Created by Vittorio on 13/06/10. - * Copyright 2010 __MyCompanyName__. All rights reserved. - * - */ - -#include "commands.h" -#include "wrappers.h" - -ALfloat old_gain; -extern ALuint *Sources; -extern ALuint cache_size, cache_index, sources_number; -extern ALboolean instances_number; -extern al_sound_t *the_sounds; - -void openal_pausesound (uint32_t index) { - if (openal_ready() == AL_TRUE && index < cache_size) - alSourcePause(Sources[the_sounds[index].source_index]); -} - - -void openal_stopsound (uint32_t index) { - if (openal_ready() == AL_TRUE && index < cache_size) - alSourceStop(Sources[the_sounds[index].source_index]); -} - - -void openal_playsound (unsigned int index) { - ALboolean needsSource = AL_TRUE; - ALfloat SourcePosition[] = { 0.0, 0.0, 0.0 }; - ALfloat SourceVelocity[] = { 0.0, 0.0, 0.0 }; - ALint state; - int i, j; - - if (openal_ready() == AL_TRUE && index < cache_size) { - // check if sound has already a source - if (the_sounds[index].source_index != -1) { - // it has a source, check it's not playing - alGetSourcei(Sources[the_sounds[index].source_index], AL_SOURCE_STATE, &state); - if (state != AL_PLAYING && state != AL_PAUSED) { - // it is not being played, so we can use it safely - needsSource = AL_FALSE; - } - // else it is being played, so we have to allocate a new source for this buffer - } - - if (needsSource) { -#ifdef DEBUG - fprintf(stderr,"(Bridge Debug) - looking for a source for sound %d\n", index); -#endif - for (i = 0; i < sources_number; i++) { - // let's iterate on Sources until we find a source that is not playing - alGetSourcei(Sources[i], AL_SOURCE_STATE, &state); - if (state != AL_PLAYING && state != AL_PAUSED) { - // let's iterate on the_sounds until we find the sound using that source - for (j = 0; j < cache_size; j++) { - if (the_sounds[j].source_index == i) { - the_sounds[j].source_index = -1; - break; - } - } - // here we know that no-one is using that source so we can use it - break; - } - } - - if (i == sources_number) { - // this means all sources are busy - } - - // set source properties that it will use when it's in playback - alSourcei (Sources[i], AL_BUFFER, the_sounds[index].buffer); - alSourcef (Sources[i], AL_PITCH, 1.0f); - alSourcef (Sources[i], AL_GAIN, 1.0f); - alSourcefv(Sources[i], AL_POSITION, SourcePosition); - alSourcefv(Sources[i], AL_VELOCITY, SourceVelocity); - alSourcei (Sources[i], AL_LOOPING, 0); - - if (AL_NO_ERROR != alGetError()) { - fprintf(stderr,"(Bridge ERROR) - failed to set Source properties\n"); - return; - } - the_sounds[index].source_index = i; - } - - alSourcePlay(Sources[the_sounds[index].source_index]); - - if (AL_NO_ERROR != alGetError()) { - fprintf(stderr,"(Bridge Warning) - failed to play sound %d\n", index); - return; - } - } -} - -void openal_toggleloop (uint32_t index) { - ALint loop; - - if (openal_ready() == AL_TRUE && index < cache_size) { - alGetSourcei (Sources[the_sounds[index].source_index], AL_LOOPING, &loop); - alSourcei (Sources[the_sounds[index].source_index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); - } -} - - -void openal_setvolume (uint32_t index, float gain) { - if (openal_ready() == AL_TRUE && index < cache_size) - alSourcef (Sources[the_sounds[index].source_index], AL_GAIN, gain); -} - - -void openal_setglobalvolume (float gain) { - if (openal_ready() == AL_TRUE) - alListenerf (AL_GAIN, gain); -} - -void openal_togglemute () { - ALfloat gain; - - if (openal_ready() == AL_TRUE) { - alGetListenerf (AL_GAIN, &gain); - if (gain > 0) { - old_gain = gain; - gain = 0; - } else - gain = old_gain; - - alListenerf (AL_GAIN, gain); - } -} - -// Fade in or out by calling a helper thread -void openal_fade (uint32_t index, uint16_t quantity, al_fade_t direction) { -#ifndef _WIN32 - pthread_t thread; -#else - HANDLE Thread; -#endif - fade_t *fade; - - if (openal_ready() == AL_TRUE && index < cache_size) { - fade = (fade_t*) Malloc(sizeof(fade_t)); - fade->index = index; - fade->quantity = quantity; - fade->type = direction; - -#ifndef _WIN32 - pthread_create(&thread, NULL, (void *)helper_fade, (void *)fade); - pthread_detach(thread); -#else - Thread = (HANDLE) _beginthread((void *)helper_fade, 0, (void *)fade); -#endif - } -} - -void openal_setposition (uint32_t index, float x, float y, float z) { - if (openal_ready() == AL_TRUE && index < cache_size) - alSource3f(Sources[the_sounds[index].source_index], AL_POSITION, x, y, z);; -} - -void helper_fade(void *tmp) { - ALfloat gain; - ALfloat target_gain; - fade_t *fade; - uint32_t index; - uint16_t quantity; - al_fade_t type; - - fade = tmp; - index = fade->index; - quantity = fade->quantity; - type = fade->type; - free (fade); - - if (type == AL_FADE_IN) { -#ifdef DEBUG - fprintf(stderr,"(Bridge Info) - Fade-in in progress [index %d quantity %d]", index, quantity); -#endif - - // save the volume desired after the fade - alGetSourcef(Sources[the_sounds[index].source_index], AL_GAIN, &target_gain); - if (target_gain > 1.0f || target_gain <= 0.0f) - target_gain = 1.0f; - - for (gain = 0.0f ; gain <= target_gain; gain += (float) quantity/10000) { -#ifdef TRACE - fprintf(stderr,"(Bridge Debug) - Fade-in set gain to %f\n", gain); -#endif - alSourcef(Sources[the_sounds[index].source_index], AL_GAIN, gain); - usleep(10000); - } - } else { - alGetSourcef(Sources[the_sounds[index].source_index], AL_GAIN, &target_gain); - - for (gain = target_gain; gain >= 0.00f; gain -= (float) quantity/10000) { -#ifdef TRACE - fprintf(stderr,"(Bridge Debug) - Fade-out set gain to %f\n", gain); -#endif - alSourcef(Sources[the_sounds[index].source_index], AL_GAIN, gain); - usleep(10000); - } - - if (AL_NO_ERROR != alGetError()) - fprintf(stderr,"(Bridge Warning) - Failed to set fade-out effect\n"); - - // stop that sound and reset its volume - alSourceStop (Sources[the_sounds[index].source_index]); - alSourcef (Sources[the_sounds[index].source_index], AL_GAIN, target_gain); - } - - if (AL_NO_ERROR != alGetError()) - fprintf(stderr,"(Bridge Warning) - Failed to set fade effect\n"); - -#ifndef _WIN32 - pthread_exit(NULL); -#else - _endthread(); -#endif -} - diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/commands.h --- a/misc/libopenalbridge/commands.h Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * commands.h - * Hedgewars - * - * Created by Vittorio on 13/06/10. - * Copyright 2010 __MyCompanyName__. All rights reserved. - * - */ - -#ifndef _OALB_COMMANDS_H -#define _OALB_COMMANDS_H - -#include "openalbridge_t.h" -#include "openalbridge.h" - - -#define openal_fadein(x,y) openal_fade(x,y,AL_FADE_IN) -#define openal_fadeout(x,y) openal_fade(x,y,AL_FADE_OUT) -#define openal_playsound_loop(x,y) openal_playsound(x) \ - if (y != 0) \ - openal_toggleloop(x); -#ifdef __CPLUSPLUS -extern "C" { -#endif - - // play, pause, stop a single sound source - void openal_pausesound (unsigned int index); - void openal_stopsound (unsigned int index); - - // play a sound and set whether it should loop or not (0/1) - void openal_playsound (unsigned int index); - - void openal_freesound (unsigned int index); - - // set or unset the looping property for a sound source - void openal_toggleloop (unsigned int index); - - // set position and volume of a sound source - void openal_setposition (unsigned int index, float x, float y, float z); - void openal_setvolume (unsigned int index, float gain); - - // set volume for all sounds (gain interval is [0-1]) - void openal_setglobalvolume (float gain); - - // mute or unmute all sounds - void openal_togglemute (void); - - // fade effect, - void openal_fade (unsigned int index, unsigned short int quantity, al_fade_t direction); - -#ifdef __CPLUSPLUS -} -#endif - -#endif /*_OALB_COMMANDS_H*/ diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/globals.h --- a/misc/libopenalbridge/globals.h Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* - * OpenAL Bridge - a simple portable library for OpenAL interface - * Copyright (c) 2009 Vittorio Giovara - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _OALB_GLOBALS_H -#define _OALB_GLOBALS_H - -#include -#include -#include "al.h" - -#ifndef _WIN32 -#include -#include -#else -#include -#endif - - -// 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. [Wu Yongwei] -#ifndef _SLEEP_H -#define _SLEEP_H -#ifdef _WIN32 -# if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__)) -# include -# define sleep(t) _sleep((t) * 1000) -# else -# define WIN32_LEAN_AND_MEAN -# include -# define sleep(t) Sleep((t) * 1000) -# endif -# ifndef _NEED_SLEEP_ONLY -# define msleep(t) Sleep(t) -# define usleep(t) Sleep((t) / 1000) -# endif -#else -# include -# ifndef _NEED_SLEEP_ONLY -# define msleep(t) usleep((t) * 1000) -# endif -#endif -#endif // _SLEEP_H - - -// check compiler requirements -#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) -#warning __BIG_ENDIAN__ or __LITTLE_ENDIAN__ not found, going to set __LITTLE_ENDIAN__ as default -#define __LITTLE_ENDIAN__ 1 -#endif - -/* use byteswap macros from the host system, hopefully optimized ones ;-) - * or define our own version, simple, stupid, straight-forward... */ -#ifdef HAVE_BYTESWAP_H -#include -#else -#define bswap_16(x) (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) -#define bswap_32(x) (((x & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | \ - ((x & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24) ) -#endif /* HAVE_BYTESWAP_H */ - -/* swap numbers accordingly to architecture automatically */ -#ifdef __LITTLE_ENDIAN__ -#define ENDIAN_LITTLE_32(x) x -#define ENDIAN_BIG_32(x) bswap_32(x) -#define ENDIAN_LITTLE_16(x) x -#define ENDIAN_BIG_16(x) bswap_16(x) -#elif __BIG_ENDIAN__ -#define ENDIAN_LITTLE_32(x) bswap_32(x) -#define ENDIAN_BIG_32(x) x -#define ENDIAN_LITTLE_16(x) bswap_16(x) -#define ENDIAN_BIG_16(x) x -#endif - -/* file format defines */ -#define OGG_FILE_FORMAT 0x4F676753 -#define WAV_FILE_FORMAT 0x52494646 -#define WAV_HEADER_SUBCHUNK2ID 0x64617461 - - -#endif /*_OALB_GLOBALS_H*/ diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/loaders.c --- a/misc/libopenalbridge/loaders.c Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,238 +0,0 @@ -/* -* OpenAL Bridge - a simple portable library for OpenAL interface -* Copyright (c) 2009 Vittorio Giovara -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License as published by -* the Free Software Foundation; version 2 of the License -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -*/ - -#include "loaders.h" -#include "wrappers.h" -#include "vorbis/vorbisfile.h" -#include "openalbridge_t.h" - - -int load_wavpcm (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) { - WAV_header_t WAVHeader; - FILE *wavfile; - int32_t t; - uint32_t n = 0; - uint8_t sub0, sub1, sub2, sub3; - - wavfile = Fopen(filename, "rb"); - - fread(&WAVHeader.ChunkID, sizeof(uint32_t), 1, wavfile); /*RIFF*/ - fread(&WAVHeader.ChunkSize, sizeof(uint32_t), 1, wavfile); - fread(&WAVHeader.Format, sizeof(uint32_t), 1, wavfile); /*WAVE*/ - -#ifdef DEBUG - fprintf(stderr, "ChunkID: %X\n", ENDIAN_BIG_32(WAVHeader.ChunkID)); - fprintf(stderr, "ChunkSize: %d\n", ENDIAN_LITTLE_32(WAVHeader.ChunkSize)); - fprintf(stderr, "Format: %X\n", ENDIAN_BIG_32(WAVHeader.Format)); -#endif - - fread(&WAVHeader.Subchunk1ID, sizeof(uint32_t), 1, wavfile); /*fmt */ - fread(&WAVHeader.Subchunk1Size, sizeof(uint32_t), 1, wavfile); - fread(&WAVHeader.AudioFormat, sizeof(uint16_t), 1, wavfile); - fread(&WAVHeader.NumChannels, sizeof(uint16_t), 1, wavfile); - fread(&WAVHeader.SampleRate, sizeof(uint32_t), 1, wavfile); - fread(&WAVHeader.ByteRate, sizeof(uint32_t), 1, wavfile); - fread(&WAVHeader.BlockAlign, sizeof(uint16_t), 1, wavfile); - fread(&WAVHeader.BitsPerSample, sizeof(uint16_t), 1, wavfile); - -#ifdef DEBUG - fprintf(stderr, "Subchunk1ID: %X\n", ENDIAN_BIG_32(WAVHeader.Subchunk1ID)); - fprintf(stderr, "Subchunk1Size: %d\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk1Size)); - fprintf(stderr, "AudioFormat: %d\n", ENDIAN_LITTLE_16(WAVHeader.AudioFormat)); - fprintf(stderr, "NumChannels: %d\n", ENDIAN_LITTLE_16(WAVHeader.NumChannels)); - fprintf(stderr, "SampleRate: %d\n", ENDIAN_LITTLE_32(WAVHeader.SampleRate)); - fprintf(stderr, "ByteRate: %d\n", ENDIAN_LITTLE_32(WAVHeader.ByteRate)); - fprintf(stderr, "BlockAlign: %d\n", ENDIAN_LITTLE_16(WAVHeader.BlockAlign)); - fprintf(stderr, "BitsPerSample: %d\n", ENDIAN_LITTLE_16(WAVHeader.BitsPerSample)); -#endif - - /*remove useless header chunks by looking for the WAV_HEADER_SUBCHUNK2ID integer */ - do { - t = fread(&sub0, sizeof(uint8_t), 1, wavfile); - if(sub0 == 0x64) { - t = fread(&sub1, sizeof(uint8_t), 1, wavfile); - if(sub1 == 0x61) { - t = fread(&sub2, sizeof(uint8_t), 1, wavfile); - if(sub2 == 0x74) { - t = fread(&sub3, sizeof(uint8_t), 1, wavfile); - if(sub3 == 0x61) { - WAVHeader.Subchunk2ID = WAV_HEADER_SUBCHUNK2ID; - break; - } - } - } - } - - if (t <= 0) { - // eof - fprintf(stderr,"(Bridge Error) - wrong WAV header\n"); - return -1; - } - } while (1); - - fread(&WAVHeader.Subchunk2Size, sizeof(uint32_t), 1, wavfile); - -#ifdef DEBUG - fprintf(stderr, "Subchunk2ID: %X\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk2ID)); - fprintf(stderr, "Subchunk2Size: %d\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size)); -#endif - - *data = (char*) Malloc (sizeof(char) * ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size)); - - /*read the actual sound data*/ - do { - n += fread(&((*data)[n]), sizeof(uint8_t), 4, wavfile); - } while (n < ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size)); - - fclose(wavfile); - -#ifdef DEBUG - fprintf(stderr,"(Bridge Info) - WAV data loaded\n"); -#endif - - /*set parameters for OpenAL*/ - /*Valid formats are AL_FORMAT_MONO8, AL_FORMAT_MONO16, AL_FORMAT_STEREO8, and AL_FORMAT_STEREO16*/ - if (ENDIAN_LITTLE_16(WAVHeader.NumChannels) == 1) { - if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 8) - *format = AL_FORMAT_MONO8; - else { - if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 16) - *format = AL_FORMAT_MONO16; - else { - fprintf(stderr,"(Bridge Error) - wrong WAV header [bitsample value]\n"); - return -2; - } - } - } else { - if (ENDIAN_LITTLE_16(WAVHeader.NumChannels) == 2) { - if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 8) - *format = AL_FORMAT_STEREO8; - else { - if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 16) - *format = AL_FORMAT_STEREO16; - else { - fprintf(stderr,"(Bridge Error) - wrong WAV header [bitsample value]\n"); - return -2; - } - } - } else { - fprintf(stderr,"(Bridge Error) - wrong WAV header [format value]\n"); - return -2; - } - } - - *bitsize = ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size); - *freq = ENDIAN_LITTLE_32(WAVHeader.SampleRate); - return 0; -} - - -int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) { - /*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */ - - /*ogg handle*/ - FILE *oggFile; - /*stream handle*/ - OggVorbis_File oggStream; - /*some formatting data*/ - vorbis_info *vorbisInfo; - /*length of the decoded data*/ - int64_t pcm_length; - /*other vars*/ - int section, result, size, endianness; -#ifdef DEBUG - int i; - /*other less useful data*/ - vorbis_comment *vorbisComment; -#endif - - oggFile = Fopen(filename, "rb"); - result = ov_open_callbacks(oggFile, &oggStream, NULL, 0, OV_CALLBACKS_DEFAULT); - if (result < 0) { - fprintf(stderr,"(Bridge Error) - ov_open_callbacks() failed with %X\n", result); - ov_clear(&oggStream); - return -1; - } - - /*load OGG header and determine the decoded data size*/ - vorbisInfo = ov_info(&oggStream, -1); - pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels; - -#ifdef DEBUG - vorbisComment = ov_comment(&oggStream, -1); - fprintf(stderr, "Version: %d\n", vorbisInfo->version); - fprintf(stderr, "Channels: %d\n", vorbisInfo->channels); - fprintf(stderr, "Rate (Hz): %ld\n", vorbisInfo->rate); - fprintf(stderr, "Bitrate Upper: %ld\n", vorbisInfo->bitrate_upper); - fprintf(stderr, "Bitrate Nominal: %ld\n", vorbisInfo->bitrate_nominal); - fprintf(stderr, "Bitrate Lower: %ld\n", vorbisInfo->bitrate_lower); - fprintf(stderr, "Bitrate Windows: %ld\n", vorbisInfo->bitrate_window); - fprintf(stderr, "Vendor: %s\n", vorbisComment->vendor); - fprintf(stderr, "PCM data size: %lld\n", pcm_length); - fprintf(stderr, "# comment: %d\n", vorbisComment->comments); - for (i = 0; i < vorbisComment->comments; i++) - fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]); -#endif - - /*allocates enough room for the decoded data*/ - *data = (char*) Malloc (sizeof(char) * pcm_length); - - /*there *should* not be ogg at 8 bits*/ - if (vorbisInfo->channels == 1) - *format = AL_FORMAT_MONO16; - else { - if (vorbisInfo->channels == 2) - *format = AL_FORMAT_STEREO16; - else { - fprintf(stderr,"(Bridge Error) - wrong OGG header [channel %d]\n", vorbisInfo->channels); - ov_clear(&oggStream); - return -2; - } - } - - size = 0; -#ifdef __LITTLE_ENDIAN__ - endianness = 0; -#elif __BIG_ENDIAN__ - endianness = 1; -#endif - while (size < pcm_length) { - /*ov_read decodes the ogg stream and storse the pcm in data*/ - result = ov_read (&oggStream, *data + size, pcm_length - size, endianness, 2, 1, §ion); - if (result > 0) { - size += result; - } else { - if (result == 0) - break; - else { - fprintf(stderr,"(Bridge Error) - End of file from OGG stream\n"); - ov_clear(&oggStream); - return -3; - } - } - } - - /*set the last fields*/ - *bitsize = size; - *freq = vorbisInfo->rate; - - /*cleaning time (ov_clear also closes file handler)*/ - ov_clear(&oggStream); - - return 0; -} diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/loaders.h --- a/misc/libopenalbridge/loaders.h Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * OpenAL Bridge - a simple portable library for OpenAL interface - * Copyright (c) 2009 Vittorio Giovara - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "globals.h" - -#ifndef _OALB_LOADERS_H -#define _OALB_LOADERS_H - -int load_wavpcm (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq); -int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq); - -#endif /*_OALB_LOADERS_H*/ diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/openalbridge.c --- a/misc/libopenalbridge/openalbridge.c Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,273 +0,0 @@ -/* -* OpenAL Bridge - a simple portable library for OpenAL interface -* Copyright (c) 2009 Vittorio Giovara -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License as published by -* the Free Software Foundation; version 2 of the License -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -*/ - -#include "openalbridge.h" -#include "globals.h" -#include "al.h" -#include "alc.h" -#include "wrappers.h" -#include "loaders.h" -#include "string.h" - -// Sources are points emitting sound, their number is limited, but a single source can play many buffers -// Buffers hold sound data and are unlimited -ALuint *Sources; -ALuint cache_size, cache_index, sources_number; -ALboolean instances_number; -al_sound_t *the_sounds; -ALint cache_pointer; - -// Initialize an OpenAL contex and allocate memory space for data and buffers -// It can be called twice to increase the cache size -int openal_init (void) { - ALCcontext *context; - ALCdevice *device; - int i; - - // reuse old context and resize the existing - if (openal_ready() == AL_TRUE) { - fprintf(stderr,"(Bridge Info) - already initialized\n"); - instances_number++; - return AL_TRUE; - } - - cache_pointer = 0; - instances_number++; - - // initial memory size - cache_size = 50; - - // open hardware device if present - device = alcOpenDevice(NULL); - sources_number = 16; - if (device == NULL) { - fprintf(stderr,"(Bridge Warning) - failed to open sound device, using software renderer\n"); - device = alcOpenDevice("Generic Software"); - sources_number = 32; - if (device == NULL) { - fprintf(stderr,"(Bridge ERROR) - failed to start software renderer, sound will be disabled\n"); - return -1; - } - } - - fprintf(stderr,"(Bridge Info) - output device: %s\n", alcGetString(device, ALC_DEVICE_SPECIFIER)); - - context = alcCreateContext(device, NULL); - alcMakeContextCurrent(context); - alcProcessContext(context); - - if (AL_NO_ERROR != alGetError()) { - fprintf(stderr,"(Bridge ERROR) - Failed to create a new contex\n"); - alcMakeContextCurrent(NULL); - alcDestroyContext(context); - alcCloseDevice(device); - return -2; - } - - Sources = (ALuint *)Malloc (sizeof(ALuint) * sources_number); - alGenSources(sources_number, Sources); - - // set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation - // Position, Velocity and Orientation of the listener - 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}; - - alListenerf (AL_GAIN, 1.0f ); - alListenerfv(AL_POSITION, ListenerPos); - alListenerfv(AL_VELOCITY, ListenerVel); - alListenerfv(AL_ORIENTATION, ListenerOri); - - if (AL_NO_ERROR != alGetError()) { - fprintf(stderr,"(Bridge ERROR) - Failed to set Listener properties\n"); - return -3; - } - - the_sounds = (al_sound_t *)Malloc (sizeof(al_sound_t) * cache_size); - for (i = 0; i < cache_size; i++) - the_sounds[i] = new_sound_el(); - - alGetError(); - return AL_TRUE; -} - - -// Stop all sounds, deallocate all memory and close OpenAL context -void openal_close (void) { - ALCcontext *context; - ALCdevice *device; - int i; - - if (instances_number == 0) { - fprintf(stderr,"(Bridge Warning) - OpenAL not initialized\n"); - return; - } - - instances_number--; - if (instances_number > 0) { - // release memory only when last session ends - return; - } - - for (i = 0; i < cache_size; i++) { - openal_unloadfile(i); - } - free(the_sounds); - - alSourceStopv (sources_number, Sources); - alDeleteSources (sources_number, Sources); - - free(Sources); - - context = alcGetCurrentContext(); - device = alcGetContextsDevice(context); - - alcMakeContextCurrent(NULL); - alcDestroyContext(context); - alcCloseDevice(device); - - fprintf(stderr,"(Bridge Info) - closed\n"); - - return; -} - - -ALboolean openal_ready (void) { - if (instances_number >= 1) - return AL_TRUE; - else - return AL_FALSE; -} - - -// Open a file, load into memory and allocate the Source buffer for playing -int openal_loadfile (const char *filename){ - ALenum format, error; - ALsizei bitsize, freq; - uint32_t fileformat; - al_sound_t sound_data; - int len, i, index = -1; - char *data; - FILE *fp; - - if (openal_ready() == AL_FALSE) { - fprintf(stderr,"(Bridge Warning) - not initialized\n"); - return -1; - } - - // if this sound is already loaded return the index from the_sounds - len = strlen(filename); - for (i = 0; i < cache_size; i++) { - if (the_sounds[i].filename != NULL && strncmp(the_sounds[i].filename, filename, len) == 0) { -#ifdef DEBUG - fprintf(stderr,"(Bridge Debug) - sound %d is already loaded\n", i); -#endif - return i; - } - // if we don't have memory available search for a free element - if (cache_pointer >= cache_size) - if (the_sounds[i].is_used == AL_FALSE) - index = i; - } - - if (index == -1 && cache_pointer >= cache_size) { - fprintf(stderr,"(Bridge Info) - No free spots found; doubling cache size\n", filename); - cache_size *= 2; - the_sounds = (al_sound_t *)Realloc (the_sounds, sizeof(al_sound_t) * cache_size); - for (i = cache_size - 50; i < cache_size; i++) - the_sounds[i] = new_sound_el(); - } else - index = ++cache_pointer; - - - // detect the file format, as written in the first 4 bytes of the header - fp = Fopen (filename, "rb"); - if (fp == NULL) { - fprintf(stderr,"(Bridge ERROR) - File %s not loaded\n", filename); - return -3; - } - - error = fread (&fileformat, sizeof(uint32_t), 1, fp); - fclose (fp); - if (error < 0) { - fprintf(stderr,"(Bridge ERROR) - File %s is too short\n", filename); - return -4; - } - - switch (ENDIAN_BIG_32(fileformat)) { - case OGG_FILE_FORMAT: - error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); - break; - case WAV_FILE_FORMAT: - error = load_wavpcm (filename, &format, &data, &bitsize, &freq); - break; - default: - fprintf(stderr,"(Bridge ERROR) - File format (%08X) not supported\n", ENDIAN_BIG_32(fileformat)); - return -5; - break; - } - - if (error != 0) { - fprintf(stderr,"(Bridge ERROR) - error loading file %s\n", filename); - if(data) - free(data); - return -6; - } - - // alGenBuffers happens here - sound_data = init_sound_el(filename); - - if (AL_NO_ERROR != alGetError()) { - fprintf(stderr,"(Bridge ERROR) - Failed to allocate memory for buffer %d\n", index); - free(data); - return -5; - } - - // copy pcm data in one buffer and free it - alBufferData(sound_data.buffer, format, data, bitsize, freq); - free(data); - - if (AL_NO_ERROR != alGetError()) { - fprintf(stderr,"(Bridge ERROR) - Failed to write data to buffer %d\n", index); - return -8; - } - - // clear any AL errors beforehand - alGetError(); - - fprintf(stderr,"(Bridge Info) - successfully loaded %s\n", filename); - - // returns the index of the source you just loaded, increments it and exits - the_sounds[index] = sound_data; - return index; -} - - -void openal_unloadfile (uint32_t index) { - ALint state; - - if (openal_ready() == AL_TRUE && index < cache_size && the_sounds[index].is_used == AL_TRUE) { - alGetSourcei (Sources[the_sounds[index].source_index], AL_SOURCE_STATE, &state); - if (state == AL_PLAYING || state == AL_PAUSED) - openal_stopsound(index); - - // free memory and - alDeleteBuffers (1, &the_sounds[index].buffer); - the_sounds[index] = new_sound_el(); - } -} diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/openalbridge.def --- a/misc/libopenalbridge/openalbridge.def Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -LIBRARY "openalbridge" -EXPORTS - openal_init - openal_close - openal_ready - openal_loadfile - openal_playsound - openal_pausesound - openal_stopsound - openal_playsound_loop - openal_stopsound_free - openal_freesound - openal_toggleloop - openal_setvolume - openal_setglobalvolume - openal_togglemute - openal_fade - openal_fadein - openal_fadeout - diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/openalbridge.h --- a/misc/libopenalbridge/openalbridge.h Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * OpenAL Bridge - a simple portable library for OpenAL interface - * Copyright (c) 2009 Vittorio Giovara - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _OALB_INTERFACE_H -#define _OALB_INTERFACE_H - -#include "openalbridge_t.h" -#include "commands.h" - -#ifdef __CPLUSPLUS -extern "C" { -#endif - - // init audio context and allocate memory - int openal_init (void); - - // close audio subsytem and free memory - void openal_close (void); - - // check if openal_init has been called - char openal_ready (void); - - // load an audio file into memory and map it to abuffer - int openal_loadfile (const char *filename); - - // unloads data from memory and marks a free spot - void openal_unloadfile (unsigned int index); - - /******* other functions continue in commands.h *******/ - -#ifdef __CPLUSPLUS -} -#endif - -#endif /*_OALB_INTERFACE_H*/ diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/openalbridge_t.h --- a/misc/libopenalbridge/openalbridge_t.h Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * OpenAL Bridge - a simple portable library for OpenAL interface - * Copyright (c) 2009 Vittorio Giovara - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include "al.h" - -#ifndef _OALB_INTERFACE_TYPES_H -#define _OALB_INTERFACE_TYPES_H - -enum al_fade_enum {AL_FADE_IN, AL_FADE_OUT}; -typedef enum al_fade_enum al_fade_t; - - -// data type to handle which source source is playing what -#pragma pack(1) -typedef struct _al_sound_t { - const char *filename; // name of the sound file - ALuint buffer; // actual sound content - uint32_t source_index; // index of the associated source - ALboolean is_used; // tells if the element can be overwritten -} al_sound_t; -#pragma pack() - - -// data type for passing data between threads -#pragma pack(1) -typedef struct _fade_t { - uint32_t index; - uint16_t quantity; - al_fade_t type; -} fade_t; -#pragma pack() - - -// data type for WAV header -#pragma pack(1) -typedef struct _WAV_header_t { - uint32_t ChunkID; - uint32_t ChunkSize; - uint32_t Format; - uint32_t Subchunk1ID; - uint32_t Subchunk1Size; - uint16_t AudioFormat; - uint16_t NumChannels; - uint32_t SampleRate; - uint32_t ByteRate; - uint16_t BlockAlign; - uint16_t BitsPerSample; - uint32_t Subchunk2ID; - uint32_t Subchunk2Size; -} WAV_header_t; -#pragma pack() - - -#ifdef __CPLUSPLUS -} -#endif - -#endif /*_OALB_INTERFACE_TYPES_H*/ diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/tester.c --- a/misc/libopenalbridge/tester.c Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -#include -#include "openalbridge.h" - -int main (int argc, int **argv) { - - openal_init(); - - openal_close(); - - return 0; -} diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/wrappers.c --- a/misc/libopenalbridge/wrappers.c Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* -* OpenAL Bridge - a simple portable library for OpenAL interface -* Copyright (c) 2009 Vittorio Giovara -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License as published by -* the Free Software Foundation; version 2 of the License -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -*/ - -#include "wrappers.h" -#include "openalbridge_t.h" - - -void *Malloc (size_t nbytes) { - void *aptr; - - if ((aptr = malloc(nbytes)) == NULL) { - fprintf(stderr,"(Bridge FATAL) - not enough memory\n"); - abort(); - } - - return aptr; -} - - -void *Realloc (void *aptr, size_t nbytes) { - aptr = realloc(aptr, nbytes); - - if (aptr == NULL) { - fprintf(stderr,"(Bridge FATAL) - not enough memory\n"); - abort(); - } - - return aptr; -} - - -FILE *Fopen (const char *fname, char *mode) { - FILE *fp; - - fp = fopen(fname,mode); - if (fp == NULL) - fprintf(stderr,"(Bridge Error) - can't open file %s in mode '%s'\n", fname, mode); - - return fp; -} - - -al_sound_t new_sound_el (void) { - al_sound_t sound; - - sound.filename = NULL; - sound.buffer = -1; - sound.source_index = -1; - sound.is_used = AL_FALSE; - - return sound; -} - -al_sound_t init_sound_el (const char *str) { - al_sound_t sound; - - sound.filename = str; - sound.source_index = -1; - sound.is_used = AL_TRUE; - alGenBuffers(1, &sound.buffer); - - return sound; -} diff -r 915436ff64ab -r b769a8e38cbd misc/libopenalbridge/wrappers.h --- a/misc/libopenalbridge/wrappers.h Thu Jul 25 23:20:06 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * OpenAL Bridge - a simple portable library for OpenAL interface - * Copyright (c) 2009 Vittorio Giovara - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _OALB_WRAPPERS_H -#define _OALB_WRAPPERS_H - -#include "globals.h" -#include "openalbridge_t.h" - -void *Malloc (size_t nbytes); -void *Realloc (void *aptr, size_t nbytes); -FILE *Fopen (const char *fname, char *mode); -void helper_fade (void *tmp); -al_sound_t new_sound_el (void); -al_sound_t init_sound_el (const char *str); - -#endif /*_OALB_WRAPPERS_H*/ diff -r 915436ff64ab -r b769a8e38cbd project_files/HedgewarsMobile/Hedgewars.xcodeproj/default.pbxuser --- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/default.pbxuser Thu Jul 25 23:20:06 2013 +0200 +++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/default.pbxuser Thu Jul 25 23:29:37 2013 +0200 @@ -11,9 +11,6 @@ activeExecutable = 617987D7114AA2CD00BA94A9 /* HedgewarsMobile */; activeSDKPreference = iphonesimulator3.2; activeTarget = 1D6058900D05DD3D006BFB54 /* HedgewarsMobile */; - addToTargets = ( - 61C3251C1179A300001E70B1 /* openalbridge */, - ); breakpoints = ( ); codeSenseManager = 617987E0114AA2EB00BA94A9 /* Code sense */; @@ -2774,9 +2771,6 @@ vrLen = 779; vrLoc = 123261; }; - 61C3251C1179A300001E70B1 /* openalbridge */ = { - activeExec = 0; - }; 61C325231179A314001E70B1 /* PBXTextBookmark */ = { isa = PBXTextBookmark; fRef = 6184DEA211795DBD00AF6EFA /* UIImageExtra.m */; @@ -2825,22 +2819,6 @@ sepNavVisRange = "{829, 414}"; }; }; - 61C3253E1179A336001E70B1 /* openalbridge.c */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {768, 7860}}"; - sepNavSelRange = "{4909, 0}"; - sepNavVisRange = "{4612, 631}"; - sepNavWindowFrame = "{{622, 369}, {1086, 797}}"; - }; - }; - 61C325401179A336001E70B1 /* openalbridge.h */ = { - uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {1027, 720}}"; - sepNavSelRange = "{2053, 0}"; - sepNavVisRange = "{3, 2114}"; - sepNavWindowFrame = "{{622, 369}, {1086, 797}}"; - }; - }; 61C325411179A336001E70B1 /* wrappers.c */ = { uiCtxt = { sepNavIntBoundsRect = "{{0, 0}, {1027, 2175}}"; @@ -2867,16 +2845,6 @@ vrLen = 274; vrLoc = 0; }; - 61C325691179A3A0001E70B1 /* PBXTextBookmark */ = { - isa = PBXTextBookmark; - fRef = 61C325401179A336001E70B1 /* openalbridge.h */; - name = "openalbridge.h: 1"; - rLen = 0; - rLoc = 0; - rType = 0; - vrLen = 684; - vrLoc = 0; - }; 61C325DD1179A993001E70B1 /* PBXTextBookmark */ = { isa = PBXTextBookmark; fRef = 61C3253B1179A336001E70B1 /* globals.h */;