openalbridge/openalwrap.c
author koda
Tue, 30 Jun 2009 15:59:02 +0000
changeset 2215 1d78579e06c2
parent 2213 bd51bbf06033
child 2216 82e7da49c26a
permissions -rw-r--r--
regression of previous commit, stdint.h in use
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     1
/*
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     2
 * OpenAL Bridge - a simple portable library for OpenAL interface
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     4
 *
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     8
 *
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    13
 *
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    17
 */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    18
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
    19
#include "globals.h"
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
    20
#include "wrappers.h"
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
    21
#include "alc.h"
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
    22
#include "loaders.h"
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
    23
#include "endianness.h"
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    24
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    25
#ifdef __CPLUSPLUS
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    26
extern "C" {
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    27
#endif 
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    28
	
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    29
	/*Sources are points emitting sound*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    30
	ALuint *Sources;
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    31
	/*Buffers hold sound data*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    32
	ALuint *Buffers;
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    33
	/*index for Sources and Buffers*/
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
    34
	ALuint globalindex, globalsize, increment;
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    35
	/*Position of the source sound*/
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
    36
	ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    37
	/*Velocity of the source sound*/
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
    38
	ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    39
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    40
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    41
	ALint openal_close(void) {
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
    42
		/*Stop all sounds, deallocate all memory and close OpenAL */
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    43
		ALCcontext *context;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    44
		ALCdevice  *device;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    45
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    46
		alSourceStopv	(globalsize, Sources);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    47
		alDeleteSources (globalsize, Sources);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    48
		alDeleteBuffers (globalsize, Buffers);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    49
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    50
		free(Sources);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    51
		free(Buffers);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    52
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    53
		context = alcGetCurrentContext();
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    54
		device  = alcGetContextsDevice(context);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    55
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    56
		alcMakeContextCurrent(NULL);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    57
		alcDestroyContext(context);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    58
		alcCloseDevice(device);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    59
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    60
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    61
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    62
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
    63
	ALint openal_init(uint32_t memorysize) {	
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
    64
		/*Initialize an OpenAL contex and allocate memory space for data and buffers*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    65
		ALCcontext *context;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    66
		ALCdevice *device;
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
    67
		const ALCchar *default_device;
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    68
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    69
		/*Position of the listener*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    70
		ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    71
		/*Velocity of the listener*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    72
		ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    73
		/*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    74
		ALfloat ListenerOri[] = { 0.0, 0.0, -1.0,  0.0, 1.0, 0.0 };
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    75
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    76
		default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    77
		fprintf(stderr, "Using default device: %s\n", default_device);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    78
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    79
		if ((device = alcOpenDevice(default_device)) == NULL) {
2200
8192be6e3aef koda/Smaxx changes to openal for crossplatform building
nemo
parents: 2194
diff changeset
    80
			fprintf(stderr, "ERROR: Failed to open sound device\n");
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    81
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    82
		}
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
    83
		
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    84
		context = alcCreateContext(device, NULL);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    85
		alcMakeContextCurrent(context);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    86
		alcProcessContext(context);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    87
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    88
		if (AlGetError("ERROR %d: Creating a new contex\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    89
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    90
		
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    91
		/*allocate memory space for buffers and sources*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    92
		globalsize = memorysize;
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
    93
		increment = memorysize;
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
    94
		Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
    95
		Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    96
		
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
    97
		/*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    98
		alListenerf (AL_GAIN,		 1.0f		);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
    99
		alListenerfv(AL_POSITION,    ListenerPos);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   100
		alListenerfv(AL_VELOCITY,    ListenerVel);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   101
		alListenerfv(AL_ORIENTATION, ListenerOri);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   102
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   103
		if (AlGetError("ERROR %d: Setting Listener properties\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   104
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   105
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   106
		alGetError();  /* clear any AL errors beforehand */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   107
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   108
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   109
	
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   110
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   111
	uint8_t helper_realloc (void) {
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   112
		/*expands allocated memory when loading more sound files than expected*/
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   113
		globalsize += increment;
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   114
#ifdef DEBUG
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   115
		fprintf(stderr, "OpenAL: Realloc in process %d\n", globalsize);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   116
#endif
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   117
		Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   118
		Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize);
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   119
		
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   120
		return 0;
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   121
	}
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   122
	
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   123
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   124
	uint32_t openal_loadfile (const char *filename){
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   125
		/*Open a file, load into memory and allocate the Source buffer for playing*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   126
		ALenum format;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   127
		ALsizei bitsize;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   128
		ALsizei freq;
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   129
		char *data;
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   130
		uint32_t fileformat;
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   131
		ALenum error;
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   132
		FILE *fp;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   133
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   134
		
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   135
		/*when the buffers are all used, we can expand memory to accept new files*/
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   136
		if (globalindex == globalsize)
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   137
			helper_realloc();
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   138
		
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   139
		/*detect the file format, as written in the first 4 bytes of the header*/
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   140
		fp = Fopen (filename, "rb");
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   141
		if (fp == NULL)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   142
			return -1;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   143
		error = fread (&fileformat, sizeof(uint32_t), 1, fp);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   144
		fclose (fp);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   145
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   146
		if (error < 0) {
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   147
			fprintf(stderr, "ERROR: file %s is too short \n", filename);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   148
			return -2;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   149
		}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   150
		
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
   151
		/*prepare the buffer to receive data*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   152
		alGenBuffers(1, &Buffers[globalindex]);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   153
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   154
		if (AlGetError("ERROR %d: Allocating memory for buffers\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   155
			return -3;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   156
		
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
   157
		/*prepare the source to emit sound*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   158
		alGenSources(1, &Sources[globalindex]);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   159
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   160
		if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   161
			return -4;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   162
				
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   163
		
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
   164
		if (fileformat == 0x5367674F) /*check if ogg*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   165
			error = load_OggVorbis (filename, &format, &data, &bitsize, &freq);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   166
		else {
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
   167
			if (fileformat == 0x46464952) /*check if wav*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   168
				error = load_WavPcm (filename, &format, &data, &bitsize, &freq);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   169
			else {
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   170
				fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat));
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   171
				return -5;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   172
			}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   173
		}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   174
		
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
   175
		/*copy pcm data in one buffer*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   176
		alBufferData(Buffers[globalindex], format, data, bitsize, freq);
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
   177
		free(data);		/*deallocate data to save memory*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   178
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   179
		if (AlGetError("ERROR %d: Writing data to buffer\n") != AL_TRUE)
2210
1cb7118a77dd initial bugfix for volume setup
koda
parents: 2209
diff changeset
   180
			return -6;
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   181
			
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
   182
		/*set source properties that it will use when it's in playback*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   183
		alSourcei (Sources[globalindex], AL_BUFFER,   Buffers[globalindex]  );
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   184
		alSourcef (Sources[globalindex], AL_PITCH,    1.0f					);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   185
		alSourcef (Sources[globalindex], AL_GAIN,     1.0f					);
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   186
		alSourcefv(Sources[globalindex], AL_POSITION, SourcePos				);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   187
		alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel				);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   188
		alSourcei (Sources[globalindex], AL_LOOPING,  0						);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   189
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   190
		if (AlGetError("ERROR %d: Setting source properties\n") != AL_TRUE)
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   191
			return -7;
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   192
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   193
		alGetError();  /* clear any AL errors beforehand */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   194
		
2212
6b5da1a2765a -openalbridge headers cleaned
koda
parents: 2211
diff changeset
   195
		/*returns the index of the source you just loaded, increments it and exits*/
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   196
		return globalindex++;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   197
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   198
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   199
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   200
	ALint openal_toggleloop (uint32_t index){
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   201
		/*Set or unset looping mode*/
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   202
		ALint loop;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   203
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   204
		if (index >= globalsize) {
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   205
			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   206
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   207
		}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   208
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   209
		alGetSourcei (Sources[index], AL_LOOPING, &loop);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   210
		alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   211
		if (AlGetError("ERROR %d: Getting or setting loop property\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   212
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   213
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   214
		alGetError();  /* clear any AL errors beforehand */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   215
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   216
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   217
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   218
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   219
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   220
	ALint openal_setvolume (uint32_t index, uint8_t percentage) {
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   221
		/*Set volume for sound number index*/
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   222
		if (index >= globalindex) {
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   223
			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   224
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   225
		}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   226
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   227
		if (percentage > 100)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   228
			percentage = 100;
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   229
		alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   230
		if (AlGetError("ERROR %d: Setting volume for last sound\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   231
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   232
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   233
		alGetError();  /* clear any AL errors beforehand */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   234
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   235
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   236
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   237
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   238
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   239
	ALint openal_setglobalvolume (uint8_t percentage) {
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   240
		/*Set volume for all sounds*/		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   241
		if (percentage > 100)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   242
			percentage = 100;
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   243
		alListenerf (AL_GAIN, (float) percentage/100.0f);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   244
		if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   245
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   246
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   247
		alGetError();  /* clear any AL errors beforehand */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   248
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   249
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   250
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   251
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   252
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   253
	ALint openal_togglemute () {
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   254
		/*Mute or unmute sound*/
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   255
		ALfloat mute;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   256
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   257
		alGetListenerf (AL_GAIN, &mute);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   258
		if (mute > 0) 
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   259
			mute = 0;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   260
		else
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   261
			mute = 1.0;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   262
		alListenerf (AL_GAIN, mute);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   263
		if (AlGetError("ERROR %d: Setting mute property\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   264
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   265
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   266
		alGetError();  /* clear any AL errors beforehand */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   267
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   268
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   269
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   270
	
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   271
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   272
	ALint openal_fade(uint32_t index, uint16_t quantity, uint8_t direction) {
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   273
		/*Fade in or out by calling a helper thread*/
2194
1597710c6118 koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents: 2191
diff changeset
   274
#ifndef _WIN32
1597710c6118 koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents: 2191
diff changeset
   275
		pthread_t thread;
1597710c6118 koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents: 2191
diff changeset
   276
#else
1597710c6118 koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents: 2191
diff changeset
   277
		HANDLE Thread;
1597710c6118 koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents: 2191
diff changeset
   278
		DWORD threadID;
2209
2573d4ff78f9 - bugfix for segfault on fades
koda
parents: 2200
diff changeset
   279
#endif
2573d4ff78f9 - bugfix for segfault on fades
koda
parents: 2200
diff changeset
   280
		fade_t *fade;
2573d4ff78f9 - bugfix for segfault on fades
koda
parents: 2200
diff changeset
   281
		
2573d4ff78f9 - bugfix for segfault on fades
koda
parents: 2200
diff changeset
   282
		fade = (fade_t*) Malloc(sizeof(fade_t));
2200
8192be6e3aef koda/Smaxx changes to openal for crossplatform building
nemo
parents: 2194
diff changeset
   283
		fade->index = index;
8192be6e3aef koda/Smaxx changes to openal for crossplatform building
nemo
parents: 2194
diff changeset
   284
		fade->quantity = quantity;
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   285
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   286
		if (index >= globalindex) {
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   287
			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   288
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   289
		}
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   290
		
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   291
		if (direction == FADE_IN)
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   292
#ifndef _WIN32
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   293
			pthread_create(&thread, NULL, helper_fadein, (void*) fade);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   294
#else
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   295
			Thread = _beginthread(&helper_fadein, 0, (void*) fade);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   296
#endif
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   297
		else {
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   298
			if (direction == FADE_OUT)
2194
1597710c6118 koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents: 2191
diff changeset
   299
#ifndef _WIN32
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   300
				pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   301
#else
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   302
				Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   303
#endif	
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   304
			else {
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   305
				fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction);
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   306
				free(fade);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   307
				return AL_FALSE;
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   308
			}
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   309
		}
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   310
		
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   311
#ifndef _WIN32
2194
1597710c6118 koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents: 2191
diff changeset
   312
		pthread_detach(thread);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   313
#endif
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   314
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   315
		alGetError();  /* clear any AL errors beforehand */
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   316
		
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   317
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   318
	}
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   319
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   320
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   321
	ALint openal_fadeout(uint32_t index, uint16_t quantity) {
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   322
		/*wrapper for fadeout*/
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   323
		return openal_fade(index, quantity, FADE_OUT);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   324
	}
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   325
		
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   326
		
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   327
	ALint openal_fadein(uint32_t index, uint16_t quantity) {
2213
bd51bbf06033 -Smaxx's porting of the library to MSVC compilers
koda
parents: 2212
diff changeset
   328
		/*wrapper for fadein*/
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   329
		return openal_fade(index, quantity, FADE_IN);
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   330
	}
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   331
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   332
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   333
	ALint openal_playsound(uint32_t index){
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   334
		/*Play sound number index*/
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   335
		if (index >= globalindex) {
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   336
			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   337
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   338
		}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   339
		alSourcePlay(Sources[index]);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   340
		if (AlGetError("ERROR %d: Playing last sound\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   341
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   342
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   343
		alGetError();  /* clear any AL errors beforehand */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   344
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   345
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   346
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   347
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   348
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   349
	ALint openal_pausesound(uint32_t index){
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   350
		/*Pause sound number index*/
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   351
		if (index >= globalindex) {
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   352
			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   353
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   354
		}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   355
		alSourcePause(Sources[index]);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   356
		if (AlGetError("ERROR %d: Pausing last sound\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   357
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   358
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   359
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   360
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   361
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   362
	
2215
1d78579e06c2 regression of previous commit, stdint.h in use
koda
parents: 2213
diff changeset
   363
	ALint openal_stopsound(uint32_t index){
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   364
		/*Stop sound number index*/
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   365
		if (index >= globalindex) {
2211
288360b78f30 - fade in/out functions merged, but kept binary compatibility
koda
parents: 2210
diff changeset
   366
			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
2191
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   367
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   368
		}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   369
		alSourceStop(Sources[index]);
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   370
		if (AlGetError("ERROR %d: Stopping last sound\n") != AL_TRUE)
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   371
			return AL_FALSE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   372
		
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   373
		alGetError();  /* clear any AL errors beforehand */
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   374
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   375
		return AL_TRUE;
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   376
	}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   377
	
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   378
#ifdef __CPLUSPLUS
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   379
}
20c62f787a4d koda's OpenAL conversion:
unc0rr
parents:
diff changeset
   380
#endif