openalbridge/openalwrap.c
changeset 2209 2573d4ff78f9
parent 2200 8192be6e3aef
child 2210 1cb7118a77dd
equal deleted inserted replaced
2208:7d1a084d11ab 2209:2573d4ff78f9
   282 		unsigned int quantity; 
   282 		unsigned int quantity; 
   283 		
   283 		
   284 		fade = tmp;
   284 		fade = tmp;
   285 		index = fade->index;
   285 		index = fade->index;
   286 		quantity = fade->quantity;
   286 		quantity = fade->quantity;
       
   287 		free(fade);
       
   288 
       
   289 #ifdef DEBUG
       
   290 		fprintf(stderr, "Fade-out: index %d quantity %d", index, quantity);
       
   291 #endif
   287 		
   292 		
   288 		alGetSourcef(Sources[index], AL_GAIN, &gain);
   293 		alGetSourcef(Sources[index], AL_GAIN, &gain);
   289 		
   294 		
   290 		for ( ; gain >= 0.00f; gain -= (float) quantity/10000){
   295 		for ( ; gain >= 0.00f; gain -= (float) quantity/10000){
   291 #ifdef DEBUG
   296 #ifdef DEBUG
   292 			fprintf(stderr, "Fade-out: Set gain to %f\n", gain);
   297 			fprintf(stderr, "Fade-out: Set gain to %f\n", gain);
   293 #endif
   298 #endif
   294 			alSourcef(Sources[index], AL_GAIN, gain);
   299 			alSourcef(Sources[index], AL_GAIN, gain);
   295 			usleep(10000);
   300 			usleep(10000);
   296 		}
   301 		}
   297 		
   302 
   298 		AlGetError("ERROR %d: Setting fade out volume\n");
   303 		AlGetError("ERROR %d: Setting fade out volume\n");
   299 		
   304 		
   300 		//stop that sound and reset its gain
   305 		//stop that sound and reset its gain
   301 		alSourceStop (Sources[index]);
   306 		alSourceStop (Sources[index]);
   302 		alSourcef (Sources[index], AL_GAIN, 1.0f);	
   307 		alSourcef (Sources[index], AL_GAIN, 1.0f);	
   303 		
   308 		
   304 #ifndef _WIN32
   309 #ifndef _WIN32
   305 		pthread_exit(NULL);
   310 		pthread_exit(NULL);
   306 #else
   311 #else
   307 		free(fade);
       
   308 		_endthread();
   312 		_endthread();
   309 #endif
   313 #endif
   310 	}
   314 	}
   311 	
   315 	
   312 	ALint openal_fadeout(int index, unsigned int quantity) {
   316 	ALint openal_fadeout(int index, unsigned int quantity) {
   313 #ifndef _WIN32
   317 #ifndef _WIN32
   314 		pthread_t thread;
   318 		pthread_t thread;
   315 		fade_t fade;
       
   316 		fade.index = index;
       
   317 		fade.quantity = quantity;
       
   318 #else
   319 #else
   319 		HANDLE Thread;
   320 		HANDLE Thread;
   320 		DWORD threadID;
   321 		DWORD threadID;
   321 		fade_t *fade = malloc(sizeof(fade_t));
   322 #endif
       
   323 		fade_t *fade; 
       
   324 		
       
   325 		if (index >= globalindex) {
       
   326 			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)", index, globalindex);
       
   327 			return AL_FALSE;
       
   328 		}
       
   329 		
       
   330 		fade = (fade_t*) Malloc(sizeof(fade_t));
   322 		fade->index = index;
   331 		fade->index = index;
   323 		fade->quantity = quantity;
   332 		fade->quantity = quantity;
   324 #endif
   333 		
   325 
   334 #ifndef _WIN32
   326 		if (index >= globalindex) {
   335 		pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
   327 			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)", index, globalindex);
       
   328 			return AL_FALSE;
       
   329 		}
       
   330 		
       
   331 		
       
   332 #ifndef _WIN32
       
   333 		pthread_create(&thread, NULL, helper_fadeout, (void*) &fade);
       
   334 		pthread_detach(thread);
   336 		pthread_detach(thread);
   335 #else
   337 #else
   336 		Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
   338 		Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
   337 #endif
   339 #endif
   338 		
   340 		
   353 			unsigned int quantity; 
   355 			unsigned int quantity; 
   354 			
   356 			
   355 			fade = tmp;
   357 			fade = tmp;
   356 			index = fade->index;
   358 			index = fade->index;
   357 			quantity = fade->quantity;
   359 			quantity = fade->quantity;
       
   360 			free (fade);
   358 			
   361 			
   359 			gain = 0.0f;
   362 			gain = 0.0f;
   360 			alSourcef(Sources[index], AL_GAIN, gain);
   363 			alSourcef(Sources[index], AL_GAIN, gain);
   361 			alSourcePlay(Sources[index]);
   364 			alSourcePlay(Sources[index]);
   362 			
   365 			
   366 #endif
   369 #endif
   367 				alSourcef(Sources[index], AL_GAIN, gain);
   370 				alSourcef(Sources[index], AL_GAIN, gain);
   368 				usleep(10000);
   371 				usleep(10000);
   369 			}
   372 			}
   370 			
   373 			
   371 			if (AlGetError("ERROR %d: Setting fade in volume\n") != AL_TRUE)
   374 			AlGetError("ERROR %d: Setting fade in volume\n");
   372 				return AL_FALSE;
       
   373 			
   375 			
   374 #ifndef _WIN32
   376 #ifndef _WIN32
   375 			pthread_exit(NULL);
   377 			pthread_exit(NULL);
   376 #else
   378 #else
   377 			free(fade);
       
   378 			_endthread();
   379 			_endthread();
   379 #endif
   380 #endif
   380 		}
   381 		}
   381 			
   382 			
   382 		
   383 		
   383 	ALint openal_fadein(int index, unsigned int quantity) {
   384 	ALint openal_fadein(int index, unsigned int quantity) {
   384 #ifndef _WIN32
   385 #ifndef _WIN32
   385 		pthread_t thread;
   386 		pthread_t thread;
   386 		fade_t fade;
       
   387 		fade.index = index;
       
   388 		fade.quantity = quantity;
       
   389 #else
   387 #else
   390 		HANDLE Thread;
   388 		HANDLE Thread;
   391 		DWORD threadID;
   389 		DWORD threadID;
   392 		fade_t *fade = malloc(sizeof(fade_t));
   390 #endif
       
   391 		fade_t *fade;
       
   392 		
       
   393 		fade = (fade_t*) Malloc(sizeof(fade_t));
   393 		fade->index = index;
   394 		fade->index = index;
   394 		fade->quantity = quantity;
   395 		fade->quantity = quantity;
   395 #endif
       
   396 		
   396 		
   397 		if (index >= globalindex) {
   397 		if (index >= globalindex) {
   398 			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)", index, globalindex);
   398 			fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)", index, globalindex);
   399 			return AL_FALSE;
   399 			return AL_FALSE;
   400 		}
   400 		}
   401 				
   401 				
   402 #ifndef _WIN32
   402 #ifndef _WIN32
   403 		pthread_create(&thread, NULL, helper_fadein, (void*) &fade);
   403 		pthread_create(&thread, NULL, helper_fadein, (void*) fade);
   404 		pthread_detach(thread);
   404 		pthread_detach(thread);
   405 #else
   405 #else
   406 		Thread = _beginthread(&helper_fadein, 0, (void*) fade);
   406 		Thread = _beginthread(&helper_fadein, 0, (void*) fade);
   407 #endif
   407 #endif
   408 		
   408