Skip to content

Commit

Permalink
Added ALUT extension library to OpenAL
Browse files Browse the repository at this point in the history
  • Loading branch information
pelya committed Sep 2, 2011
1 parent 0b6f35e commit ec8c5a6
Show file tree
Hide file tree
Showing 15 changed files with 2,777 additions and 2 deletions.
6 changes: 4 additions & 2 deletions project/jni/openal/Android.mk
Expand Up @@ -9,8 +9,6 @@ APP_SUBDIRS := $(patsubst $(LOCAL_PATH)/%, %, $(shell find $(LOCAL_PATH)/src -ty
LOCAL_C_INCLUDES := $(foreach D, $(APP_SUBDIRS), $(LOCAL_PATH)/$(D)) $(LOCAL_PATH)/include
LOCAL_CFLAGS := -O3 -DHAVE_CONFIG_H -DAL_ALEXT_PROTOTYPES



LOCAL_CPP_EXTENSION := .cpp

LOCAL_SRC_FILES := $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.cpp))))
Expand All @@ -22,4 +20,8 @@ LOCAL_STATIC_LIBRARIES :=

LOCAL_LDLIBS := -llog

ifneq ($(CRYSTAX_R5_TOOLCHAIN),)
LOCAL_LDLIBS += -L$(NDK_PATH)/sources/crystax/libs/armeabi -lcrystax_static # I have no idea how could OpenAL link to C++ wide-char support lib
endif

include $(BUILD_SHARED_LIBRARY)
126 changes: 126 additions & 0 deletions project/jni/openal/include/AL/alut.h
@@ -0,0 +1,126 @@
#if !defined(AL_ALUT_H)
#define AL_ALUT_H

#if defined(_MSC_VER)
#include <alc.h>
#include <al.h>
#elif defined(__APPLE__)
#include <OpenAL/alc.h>
#include <OpenAL/al.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#endif

#if defined(__cplusplus)
extern "C" {
#endif

#if defined(_WIN32) && !defined(_XBOX)
#if defined (ALUT_BUILD_LIBRARY)
#define ALUT_API __declspec(dllexport)
#else
#define ALUT_API __declspec(dllimport)
#endif
#else
#if defined(ALUT_BUILD_LIBRARY) && defined(HAVE_GCC_VISIBILITY)
#define ALUT_API __attribute__((visibility("default")))
#else
#define ALUT_API extern
#endif
#endif

#if defined(_WIN32)
#define ALUT_APIENTRY __cdecl
#else
#define ALUT_APIENTRY
#endif

#if defined(__MWERKS_)
#pragma export on
#endif

/* Flag deprecated functions if possible (VisualC++ .NET and GCC >= 3.1.1). */
#if defined(_MSC_VER) && _MSC_VER >= 1300 && !defined(MIDL_PASS)
#define ALUT_ATTRIBUTE_DEPRECATED __declspec(deprecated)
#elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && (__GNUC_MINOR__ > 1 || (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ >= 1))))
#define ALUT_ATTRIBUTE_DEPRECATED __attribute__((deprecated))
#else
#define ALUT_ATTRIBUTE_DEPRECATED
#endif

#define ALUT_API_MAJOR_VERSION 1
#define ALUT_API_MINOR_VERSION 1

#define ALUT_ERROR_NO_ERROR 0
#define ALUT_ERROR_OUT_OF_MEMORY 0x200
#define ALUT_ERROR_INVALID_ENUM 0x201
#define ALUT_ERROR_INVALID_VALUE 0x202
#define ALUT_ERROR_INVALID_OPERATION 0x203
#define ALUT_ERROR_NO_CURRENT_CONTEXT 0x204
#define ALUT_ERROR_AL_ERROR_ON_ENTRY 0x205
#define ALUT_ERROR_ALC_ERROR_ON_ENTRY 0x206
#define ALUT_ERROR_OPEN_DEVICE 0x207
#define ALUT_ERROR_CLOSE_DEVICE 0x208
#define ALUT_ERROR_CREATE_CONTEXT 0x209
#define ALUT_ERROR_MAKE_CONTEXT_CURRENT 0x20A
#define ALUT_ERROR_DESTROY_CONTEXT 0x20B
#define ALUT_ERROR_GEN_BUFFERS 0x20C
#define ALUT_ERROR_BUFFER_DATA 0x20D
#define ALUT_ERROR_IO_ERROR 0x20E
#define ALUT_ERROR_UNSUPPORTED_FILE_TYPE 0x20F
#define ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE 0x210
#define ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA 0x211

#define ALUT_WAVEFORM_SINE 0x100
#define ALUT_WAVEFORM_SQUARE 0x101
#define ALUT_WAVEFORM_SAWTOOTH 0x102
#define ALUT_WAVEFORM_WHITENOISE 0x103
#define ALUT_WAVEFORM_IMPULSE 0x104

#define ALUT_LOADER_BUFFER 0x300
#define ALUT_LOADER_MEMORY 0x301

ALUT_API ALboolean ALUT_APIENTRY alutInit (int *argcp, char **argv);
ALUT_API ALboolean ALUT_APIENTRY alutInitWithoutContext (int *argcp, char **argv);
ALUT_API ALboolean ALUT_APIENTRY alutExit (void);

ALUT_API ALenum ALUT_APIENTRY alutGetError (void);
ALUT_API const char *ALUT_APIENTRY alutGetErrorString (ALenum error);

ALUT_API ALuint ALUT_APIENTRY alutCreateBufferFromFile (const char *fileName);
ALUT_API ALuint ALUT_APIENTRY alutCreateBufferFromFileImage (const ALvoid *data, ALsizei length);
ALUT_API ALuint ALUT_APIENTRY alutCreateBufferHelloWorld (void);
ALUT_API ALuint ALUT_APIENTRY alutCreateBufferWaveform (ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration);

ALUT_API ALvoid *ALUT_APIENTRY alutLoadMemoryFromFile (const char *fileName, ALenum *format, ALsizei *size, ALfloat *frequency);
ALUT_API ALvoid *ALUT_APIENTRY alutLoadMemoryFromFileImage (const ALvoid *data, ALsizei length, ALenum *format, ALsizei *size, ALfloat *frequency);
ALUT_API ALvoid *ALUT_APIENTRY alutLoadMemoryHelloWorld (ALenum *format, ALsizei *size, ALfloat *frequency);
ALUT_API ALvoid *ALUT_APIENTRY alutLoadMemoryWaveform (ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration, ALenum *format, ALsizei *size, ALfloat *freq);

ALUT_API const char *ALUT_APIENTRY alutGetMIMETypes (ALenum loader);

ALUT_API ALint ALUT_APIENTRY alutGetMajorVersion (void);
ALUT_API ALint ALUT_APIENTRY alutGetMinorVersion (void);

ALUT_API ALboolean ALUT_APIENTRY alutSleep (ALfloat duration);

/* Nasty Compatibility stuff, WARNING: THESE FUNCTIONS ARE STRONGLY DEPRECATED */
#if defined(__APPLE__)
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutLoadWAVFile (ALbyte *fileName, ALenum *format, void **data, ALsizei *size, ALsizei *frequency);
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutLoadWAVMemory (ALbyte *buffer, ALenum *format, void **data, ALsizei *size, ALsizei *frequency);
#else
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutLoadWAVFile (ALbyte *fileName, ALenum *format, void **data, ALsizei *size, ALsizei *frequency, ALboolean *loop);
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutLoadWAVMemory (ALbyte *buffer, ALenum *format, void **data, ALsizei *size, ALsizei *frequency, ALboolean *loop);
#endif
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutUnloadWAV (ALenum format, ALvoid *data, ALsizei size, ALsizei frequency);

#if defined(__MWERKS_)
#pragma export off
#endif

#if defined(__cplusplus)
}
#endif

#endif
4 changes: 4 additions & 0 deletions project/jni/openal/src/config.h
Expand Up @@ -34,6 +34,10 @@
/* Define if we have stdint.h */
#define HAVE_STDINT_H

#define HAVE_NANOSLEEP

#define HAVE_TIME_H

/* Define if we have the __int64 type */
#define HAVE___INT64

Expand Down
13 changes: 13 additions & 0 deletions project/jni/openal/src/freealut/README
@@ -0,0 +1,13 @@
The files in this directory contain the code of the ALUT library. They typically
compile to make 'libalut.so' on *nix platforms or to 'alut.dll' for Windows
platforms.

There is also a header file 'alut.h' in ../include/AL which gets installed into
$(includedir)/AL/alut.h on *nix platforms and someplace else entirely on
Windows platforms.

The file 'helloworld.wav' is the original voice recording of Steve Baker saying
this immortal phrase. It is converted into a large hexadecimal data block inside
alutWaveform.c - but this file is retained in version control just in case
anyone ever feels like re-doing it. The format is 16bit PCM, 1 channel, 44.1kHz
sample rate.
147 changes: 147 additions & 0 deletions project/jni/openal/src/freealut/alutBufferData.c
@@ -0,0 +1,147 @@
#include "alutInternal.h"

struct BufferData_struct
{
ALvoid *data;
size_t length;
ALint numChannels;
ALint bitsPerSample;
ALfloat sampleFrequency;
};

BufferData *
_alutBufferDataConstruct (ALvoid *data, size_t length, ALint numChannels,
ALint bitsPerSample, ALfloat sampleFrequency)
{
BufferData *bufferData = (BufferData *) _alutMalloc (sizeof (BufferData));
if (bufferData == NULL)
{
return NULL;
}

bufferData->data = data;
bufferData->length = length;
bufferData->numChannels = numChannels;
bufferData->bitsPerSample = bitsPerSample;
bufferData->sampleFrequency = sampleFrequency;

return bufferData;
}

ALboolean
_alutBufferDataDestroy (BufferData *bufferData)
{
if (bufferData->data != NULL)
{
free (bufferData->data);
}
free (bufferData);
return AL_TRUE;
}

ALvoid *
_alutBufferDataGetData (const BufferData *bufferData)
{
return bufferData->data;
}

void
_alutBufferDataDetachData (BufferData *bufferData)
{
bufferData->data = NULL;
}

size_t
_alutBufferDataGetLength (const BufferData *bufferData)
{
return bufferData->length;
}

static ALint
getNumChannels (const BufferData *bufferData)
{
return bufferData->numChannels;
}

static ALint
getBitsPerSample (const BufferData *bufferData)
{
return bufferData->bitsPerSample;
}

ALfloat
_alutBufferDataGetSampleFrequency (const BufferData *bufferData)
{
return bufferData->sampleFrequency;
}

/****************************************************************************
* The utility functions below do not know the internal BufferData
* representation.
****************************************************************************/

ALboolean
_alutGetFormat (const BufferData *bufferData, ALenum *format)
{
if (!_alutFormatConstruct
(getNumChannels (bufferData), getBitsPerSample (bufferData), format))
{
_alutSetError (ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE);
return AL_FALSE;
}
return AL_TRUE;
}

static ALuint
generateBuffer (void)
{
ALuint buffer;
alGenBuffers (1, &buffer);
if (alGetError () != AL_NO_ERROR)
{
_alutSetError (ALUT_ERROR_GEN_BUFFERS);
return AL_NONE;
}
return buffer;
}

static ALboolean
passBufferData (BufferData *bufferData, ALuint bid)
{
ALenum format;
size_t size;
ALfloat frequency;
if (!_alutGetFormat (bufferData, &format))
{
return AL_FALSE;
}
/* GCC is a bit picky about casting function calls, so we do it in two
steps... */
size = _alutBufferDataGetLength (bufferData);
frequency = _alutBufferDataGetSampleFrequency (bufferData);
alBufferData (bid, format, _alutBufferDataGetData (bufferData),
(ALsizei) size, (ALsizei) frequency);
if (alGetError () != AL_NO_ERROR)
{
_alutSetError (ALUT_ERROR_BUFFER_DATA);
return AL_FALSE;
}
return AL_TRUE;
}

ALuint
_alutPassBufferData (BufferData *bufferData)
{
ALuint buffer = generateBuffer ();
if (buffer == AL_NONE)
{
return AL_NONE;
}

if (!passBufferData (bufferData, buffer))
{
return AL_NONE;
}

return buffer;
}

0 comments on commit ec8c5a6

Please sign in to comment.