openalbridge/openalwrap.c
changeset 2257 7eb31efcfb9b
parent 2220 110266ba2ef7
child 2259 ca42efdce3ce
equal deleted inserted replaced
2256:30797f3a4321 2257:7eb31efcfb9b
     1 /*
     1 /*
     2  * OpenAL Bridge - a simple portable library for OpenAL interface
     2  * OpenAL Bridge - a simple portable library for OpenAL interface
     3  * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
     3  * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU Lesser General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
     9  * This program is distributed in the hope that it will be useful,
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    12  * GNU Lesser General Public License for more details.
    13  *
    13  *
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU Lesser General Public License
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18 
    18 
    19 #include "globals.h"
    19 #include "globals.h"
    30 	ALuint *Sources;
    30 	ALuint *Sources;
    31 	/*Buffers hold sound data*/
    31 	/*Buffers hold sound data*/
    32 	ALuint *Buffers;
    32 	ALuint *Buffers;
    33 	/*index for Sources and Buffers*/
    33 	/*index for Sources and Buffers*/
    34 	ALuint globalindex, globalsize, increment;
    34 	ALuint globalindex, globalsize, increment;
    35 	/*Position of the source sound*/
       
    36 	ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };
       
    37 	/*Velocity of the source sound*/
       
    38 	ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };
       
    39 	
    35 	
    40 	ALint openalReady = AL_FALSE;
    36 	ALint openalReady = AL_FALSE;
    41 	
    37 	
    42 	ALint openal_close(void) {
    38 	ALint openal_close(void) {
    43 		/*Stop all sounds, deallocate all memory and close OpenAL */
    39 		/*Stop all sounds, deallocate all memory and close OpenAL */
   142 	}
   138 	}
   143 	
   139 	
   144 	
   140 	
   145 	int openal_loadfile (const char *filename){
   141 	int openal_loadfile (const char *filename){
   146 		/*Open a file, load into memory and allocate the Source buffer for playing*/
   142 		/*Open a file, load into memory and allocate the Source buffer for playing*/
       
   143                 ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/
       
   144                 ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/
   147 		ALenum format;
   145 		ALenum format;
   148 		ALsizei bitsize;
   146 		ALsizei bitsize;
   149 		ALsizei freq;
   147 		ALsizei freq;
   150 		char *data;
   148 		char *data;
   151 		uint32_t fileformat;
   149 		uint32_t fileformat;
   186 		if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE)
   184 		if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE)
   187 			return -4;
   185 			return -4;
   188 				
   186 				
   189 		
   187 		
   190 		if (fileformat == 0x5367674F) /*check if ogg*/
   188 		if (fileformat == 0x5367674F) /*check if ogg*/
   191 			error = load_OggVorbis (filename, &format, &data, &bitsize, &freq);
   189 			error = load_oggvorbis (filename, &format, &data, &bitsize, &freq);
   192 		else {
   190 		else {
   193 			if (fileformat == 0x46464952) /*check if wav*/
   191 			if (fileformat == 0x46464952) /*check if wav*/
   194 				error = load_WavPcm (filename, &format, &data, &bitsize, &freq);
   192 				error = load_wavpcm (filename, &format, &data, &bitsize, &freq);
   195 			else {
   193 			else {
   196 				fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat));
   194 				fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat));
   197 				return -5;
   195 				return -5;
   198 			}
   196 			}
   199 		}
   197 		}