static void init(const char *fname) { ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f }; ALfloat position[] = { 0.0f, 0.0f, -4.0f }; ALuint boom; ALsizei size; ALsizei bits; ALsizei freq; ALsizei format; ALboolean err; int i = 0; alListenerfv(AL_POSITION, zeroes ); alGenBuffers( 1, &boom ); err = alutLoadWAV(fname, &wave, &format, &size, &bits, &freq); if(err == AL_FALSE) { fprintf(stderr, "Could not include %s\n", fname); exit(1); } alBufferData( boom, format, wave, size, freq ); free(wave); /* openal makes a local copy of wave data */ alGenSources(1, &rightSid); alSourcefv( rightSid, AL_POSITION, position ); alSourcei( rightSid, AL_BUFFER, boom ); alSourcei( rightSid, AL_LOOPING, AL_TRUE); return; }
/* Our own special magic version that fixes the filename. */ void alutLoadWAVFile_CFH(char *filename, ALenum *format, void **wave, unsigned int *size, ALsizei *freq) { char filename1[MAX_PATH]; ALsizei format1, size1, bits1, freq1; fix_filename(filename, filename1); alutLoadWAV(filename1, wave, &format1, &size1, &bits1, &freq1); *format = format1; *size = size1; *freq = freq1; }
static void init( const char *fname ) { ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f }; ALfloat back[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }; ALfloat position[] = { 2.0f, 0.0f, -4.0f }; ALuint boom; ALsizei size; ALsizei bits; ALsizei freq; ALsizei format; ALboolean err; int i; alListenerfv(AL_POSITION, zeroes ); alListenerfv(AL_VELOCITY, zeroes ); /* alListenerfv(AL_ORIENTATION, front ); */ alGenBuffers( 1, &boom ); err = alutLoadWAV(fname, &wave, &format, &size, &bits, &freq); if(err == AL_FALSE) { fprintf(stderr, "Could not include %s\n", fname); exit(1); } alBufferData( boom, format, wave, size, freq ); free(wave); /* openal makes a local copy of wave data */ alGenSources( NUMSOURCES ,&multis ); alSourcefv( multis, AL_POSITION, position ); alSourcefv( multis, AL_VELOCITY, zeroes ); alSourcefv( multis, AL_ORIENTATION, back ); alSourcef( multis, AL_GAIN_LINEAR_LOKI, 1.0); alQueuei( multis, AL_BUFFER, boom ); alQueuei( multis, AL_BUFFER, boom ); return; }
static void init( const char *fname ) { ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f }; ALfloat back[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }; ALfloat sourcepos[] = { 2.0f, 0.0f, 4.0f }; ALuint locutus; ALsizei size; ALsizei bits; ALsizei freq; ALsizei format; ALboolean err; alListenerfv(AL_POSITION, zeroes ); alListenerfv(AL_VELOCITY, zeroes ); alListenerfv(AL_ORIENTATION, front ); alGenBuffers( 1, &locutus); err = alutLoadWAV(fname, &wave, &format, &size, &bits, &freq); if(err == AL_FALSE) { fprintf(stderr, "Could not include %s\n", fname); exit(1); } alBufferData( locutus, format, wave, size, freq ); free(wave); /* openal makes a local copy of wave data */ alGenSources( 1, &reverb_sid); alSourcefv(reverb_sid, AL_POSITION, sourcepos ); alSourcefv(reverb_sid, AL_VELOCITY, zeroes ); alSourcefv(reverb_sid, AL_ORIENTATION, back ); alSourcei (reverb_sid, AL_BUFFER, locutus ); talReverbScale(reverb_sid, 0.35); talReverbDelay(reverb_sid, 1); return; }
static void init(const char *fname) { ALfloat weirdpos[] = { 300.0f, 0.0f, 0.0f }; ALfloat back[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }; ALfloat position[] = { 0.0f, 0.0f, 4.0f }; ALuint boom; ALsizei size; ALsizei bits; ALsizei freq; ALsizei format; ALboolean err; FILE* file = NULL; char* buffer = NULL; alListenerfv( AL_POSITION, weirdpos ); alGenBuffers( 1, &boom ); err = alutLoadWAV(fname, &wave, &format, &size, &bits, &freq); if(err == AL_FALSE) { fprintf(stderr, "Could not include %s\n", fname); exit(1); } alBufferData( boom, format, wave, size, freq ); free(wave); /* openal makes a local copy of wave data */ alGenSources( 1, &moving_source); alSourcei( moving_source, AL_BUFFER, boom ); alSourcei( moving_source, AL_LOOPING, AL_TRUE ); alSourcei( moving_source, AL_STREAMING, AL_TRUE ); alSourcei( moving_source, AL_SOURCE_RELATIVE, AL_TRUE ); alSourcefv( moving_source, AL_POSITION, position ); alSourcef( moving_source, AL_PITCH, 1.00 ); return; }
void CargaSonido ( char *fichero_wav, int identificador ){ /* Variables locales */ ALsizei size = NULL, freq = NULL, bits = NULL, format = NULL; ALenum format1 = NULL; static void *data = NULL; ALboolean loop = AL_FALSE; /* Generamos buffer, le asignamos un identificador y comprobamos errores */ alGenBuffers( 1, &buffer[identificador] ); if ( !alIsBuffer ( buffer[identificador] )){ fprintf ( logs, "error al crear los buffers\n"); exit(1); } /* Cargamos ficheros Wave */ #ifdef _LINUX alutLoadWAV ( fichero_wav, &data, &format, &size, &bits, &freq ); /* Cargamos en memoria */ alBufferData ( buffer[identificador], format, data, size, freq ); /* Almacenamos en buffer */ free (data); /* liberamos */ #endif #ifdef _WIN32 alutLoadWAVFile ( fichero_wav, &format1, &data, &size, &freq, &loop ); alBufferData ( buffer[identificador], format1, data, size, freq ); alutUnLoadWAV ( format1, data, size, freq ); #endif /* Generamos las fuentes de sonido y comprobamos errores */ alGenSources( 1, &source[identificador] ); if ( !alIsSource ( source[identificador])){ fprintf ( logs, "No se pueden crear las fuentes de sonido\n"); exit(1); } /* Pasamos el archivo wav del buffer a la fuente */ alSourcei ( source[identificador], AL_BUFFER, buffer[identificador]); }
static void init( const char *fname) { ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f }; ALfloat back[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }; ALuint boom; ALsizei size; ALsizei bits; ALsizei freq; ALsizei format; ALboolean err; start = time(NULL); alListenerfv(AL_POSITION, zeroes ); alListenerfv(AL_VELOCITY, zeroes ); alListenerfv(AL_ORIENTATION, front ); alGenBuffers( 1, &boom ); err = alutLoadWAV(fname, &wave, &format, &size, &bits, &freq); if(err == AL_FALSE) { fprintf(stderr, "Could not include %s\n", fname); exit(1); } alBufferData( boom, format, wave, size, freq ); free(wave); /* openal makes a local copy of wave data */ alGenSources( 1, &moving_source); alSourcef( moving_source, AL_GAIN_LINEAR_LOKI, 0.25 ); alSourcei( moving_source, AL_BUFFER, boom ); alSourcei( moving_source, AL_LOOPING, AL_TRUE); alSourcef( moving_source, AL_PITCH, 1.00); return; }
void SND_StartUp() { ALuint sources[SND_MAX_SRCNUM]; int i; /* int attr[] = { ALC_FREQUENCY, 22050, 0 }; */ if( sst_isup ) { __warning( "sound is already up\n" ); return; } if( !((sh_var_t *)SHP_GetVar( "sound" ))->ivalue ) { __named_message( "\tsound disabled\n" ); sst_isup = 0; return; } Vec3dInit( snd_origin, 0.0, 0.0, 0.0 ); alc_ctx = alcCreateContext( NULL ); alcMakeContextCurrent( alc_ctx ); // init listener alListenerfv( AL_POSITION, zeroes ); alListenerfv( AL_VELOCITY, zeroes ); { alListenerfv( AL_ORIENTATION, front ); } // init sources memset( srcs, 0, SND_MAX_SRCNUM * sizeof( snd_source_t )); al_srcnum = alGenSources( SND_MAX_SRCNUM, sources ); if( al_srcnum != SND_MAX_SRCNUM ) { __warning( "got only %d sources\n", al_srcnum ); } for( i = 0; i < al_srcnum; i++ ) { srcs[i].al_source = sources[i]; printf( "source %d: %d\n", i, srcs[i].al_source ); // alSource3f( srcs[i].al_source, AL_POSITION, 0.0, 0.0, 0.0 ); } alAttenuationScale( 0.7 ); snd_num = 0; sst_isup = 1; // if( 1 ) { ALuint sources[2]; ALuint boom, l2; ALsizei size; ALsizei bits; ALsizei freq; ALsizei format; void *wave = NULL; ALuint left = 0; ALuint right = 0; __named_message( "test...\n" ); if( alGenBuffers( 1, &boom ) != 1 ) { fprintf( stderr, "aldemo: couldn't generate buffers\n" ); exit( 1 ); } alutLoadWAV( "boom.wav", &wave, &format, &size, &bits, &freq); alBufferData( boom, format, wave, size, freq ); alSource3f( boom, AL_POSITION, -5.0, 0.0, 0.0 ); alSourcefv( boom, AL_VELOCITY, zeroes ); alSourcefv( boom, AL_ORIENTATION, back ); alSourcei( boom, AL_BUFFER, boom ); alSourcei( boom, AL_LOOPING, AL_FALSE ); alSourcePlay( boom ); alAttenuationScale(0.7); } }
int main(int argc, char *argv[]) { ALuint freq; ALenum format; ALvoid *data; ALsizei i, size; thread_id thread1, thread2; status_t status; /* listener parameters */ ALfloat listenerOrientation[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }; ALfloat listenerPosition[] = { 0.0f, 0.0f, 0.0f }; ALfloat listenerVelocity[] = { 0.0f, 0.0f, 0.0f }; /* source parameters */ ALfloat sourcePosition[] = { 0.0f, 0.0f, 1.0f }; ALfloat sourceVelocity[] = { 0.0f, 0.0f, 0.0f }; ALfloat sourcePitch = 1.0f; ALfloat sourceGain = 1.0f; /* initialize */ print("Main: initialize"); alInit((ALint *) &argc, (ALubyte **) argv); /* create context */ print("Main: create context"); context = alcCreateContext(22050, AL_FORMAT_STEREO16, 2048); /* lock the context */ print("Main: make current"); alcMakeCurrent(context); /* create buffers and sources */ if (alGenBuffers(kNumBuffers, buffer) != kNumBuffers) quit("Can't create buffers"); if (alGenSources(kNumSources, source) != kNumSources) quit("Can't create sources"); /* load buffers with data */ alutLoadWAV(kWaveFileName, &format, &data, &size, &freq); for (i = 0; i < kNumBuffers; i++) { alBufferData(buffer[i], format, data, size, freq); } free(data); /* initialize listener */ alListenerfv(AL_POSITION, listenerPosition); alListenerfv(AL_VELOCITY, listenerVelocity); alListenerfv(AL_ORIENTATION, listenerOrientation); /* initialize sources */ for (i = 0; i < kNumSources; i++) { alSourcefv(source[i], AL_POSITION, sourcePosition); alSourcefv(source[i], AL_VELOCITY, sourceVelocity); alSourcef(source[i], AL_PITCH, sourcePitch); alSourcef(source[i], AL_GAIN, sourceGain); alSourcei(source[i], AL_BUFFER, buffer[i % kNumBuffers]); alSourcei(source[i], AL_LOOPING, AL_TRUE); } /* start the sources */ print("Main: play"); for (i = 0; i < kNumSources; i++) alSourcePlay(source[i]); /* release the context */ print("Main: release current"); alcMakeCurrent(NULL); /* spawn two threads */ print("Main: spawn thread 1"); thread1 = spawn_thread(threadFunc1, "thread 1", B_NORMAL_PRIORITY, NULL); print("Main: spawn thread 2"); thread2 = spawn_thread(threadFunc2, "thread 2", B_NORMAL_PRIORITY, NULL); /* resume the threads */ print("Main: resume thread 1"); resume_thread(thread1); print("Main: resume thread 2"); resume_thread(thread2); /* acquire context, snooze and release context */ print("Main: make current"); alcMakeCurrent(context); print("Main: snooze..."); snooze(500000); print("Main: release current"); alcMakeCurrent(NULL); /* wait until the threads end */ print("Main: wait thread 1"); wait_for_thread(thread1, &status); if (status != 0) print("Main: thread 1 failed?"); print("Main: wait thread 2"); wait_for_thread(thread2, &status); if (status != 0) print("Main: thread 2 failed?"); /* acquire the context */ print("Main: make current"); alcMakeCurrent(context); /* delete buffers and sources */ print("Main: delete sources"); alDeleteSources(kNumSources, source); print("Main: delete buffers"); alDeleteBuffers(kNumBuffers, buffer); /* release the context */ print("Main: release current"); alcMakeCurrent(NULL); /* shutdown */ print("Main: delete context"); alcDeleteContext(context); /* bye */ print("Main: bye"); alExit(); return 0; }
int main(int argc, char *argv[]) { ALenum format; ALsizei size, freq; ALvoid *data; /* setup camera position and orientation */ cameraAngle = 0.0f; cameraPosition[0] = 0.0f; cameraPosition[1] = 0.8f; cameraPosition[2] = 0.0f; cameraOrientation[0] = cos(2.0 * M_PI * cameraAngle / 360.0); cameraOrientation[1] = 0.0f; cameraOrientation[2] = sin(2.0 * M_PI * cameraAngle / 360.0); cameraOrientation[3] = 0.0f; cameraOrientation[4] = 1.0f; cameraOrientation[5] = 0.0f; /* setup radar and phase position */ radarPosition[0] = 5.0f; radarPosition[1] = 0.0f; radarPosition[2] = 0.0f; phaserPosition[0] = 2.0f; phaserPosition[1] = 0.0f; phaserPosition[2] = 0.0f; radarLightAngle = 0.0f; phaserPlaying = AL_FALSE; /* initialize GLUT */ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowPosition(200, 100); glutInitWindowSize(320, 240); glutCreateWindow("XL Demo"); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutSpecialFunc(special); glutReshapeFunc(reshape); glutIdleFunc(idle); glEnable(GL_CULL_FACE); /* initialize ALUT */ alutInit(&argc, argv); /* set up the buffers */ alGenBuffers(1, &radarBuffer); alGenBuffers(1, &phaserBuffer); alutLoadWAV(kRadarFileName, &format, &data, &size, &freq); alBufferData(radarBuffer, format, data, size, freq); free(data); alutLoadWAV(kPhaserFileName, &format, &data, &size, &freq); alBufferData(phaserBuffer, format, data, size, freq); free(data); /* set up the sources */ alGenSources(1, &radarSource); alGenSources(1, &phaserSource); alSourcefv(radarSource, AL_POSITION, radarPosition); alSourcef(radarSource, AL_GAIN, 1.0f); alSourcef(radarSource, AL_PITCH, 1.0f); alSourcei(radarSource, AL_BUFFER, radarBuffer); alSourcei(radarSource, AL_LOOPING, AL_TRUE); alSourcefv(phaserSource, AL_POSITION, phaserPosition); alSourcef(phaserSource, AL_GAIN, 1.0f); alSourcef(phaserSource, AL_PITCH, 1.0f); alSourcei(phaserSource, AL_BUFFER, phaserBuffer); alSourcei(phaserSource, AL_LOOPING, AL_FALSE); /* start the radar */ alSourcePlay(radarSource); /* GLUT event loop */ glutMainLoop(); /* shutdown alut */ alutExit(); return 0; }
int main(int argc, char *argv[]) { ALuint buffer[kNumBuffers], source[kNumSources]; ALuint freq; ALenum format; ALvoid *data; ALsizei i, size; /* listener parameters */ ALfloat listenerOrientation[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }; ALfloat listenerPosition[] = { 0.0f, 0.0f, 0.0f }; ALfloat listenerVelocity[] = { 0.0f, 0.0f, 0.0f }; /* source parameters */ ALfloat sourcePosition[] = { 0.0f, 0.0f, 1.0f }; ALfloat sourceVelocity[] = { 0.0f, 0.0f, 0.0f }; ALfloat sourcePitch = 1.0f; ALfloat sourceGain = 1.0f; /* initialize */ alutInit(&argc, argv); /* create buffers and sources */ if (alGenBuffers(kNumBuffers, buffer) != kNumBuffers) quit("Can't create buffers"); if (alGenSources(kNumSources, source) != kNumSources) quit("Can't create sources"); /* load buffers with data */ alutLoadWAV(kWaveFileName, &format, &data, &size, &freq); for (i = 0; i < kNumBuffers; i++) { alBufferData(buffer[i], format, data, size, freq); } free(data); /* initialize listener */ alListenerfv(AL_POSITION, listenerPosition); alListenerfv(AL_VELOCITY, listenerVelocity); alListenerfv(AL_ORIENTATION, listenerOrientation); /* initialize sources */ for (i = 0; i < kNumSources; i++) { alSourcefv(source[i], AL_POSITION, sourcePosition); alSourcefv(source[i], AL_VELOCITY, sourceVelocity); alSourcef(source[i], AL_PITCH, sourcePitch); alSourcef(source[i], AL_GAIN, sourceGain); alSourcei(source[i], AL_BUFFER, buffer[i % kNumBuffers]); alSourcei(source[i], AL_LOOPING, AL_TRUE); } /* test pitch range [0.5, 2.0] */ printf("Test range\n"); for (sourcePitch = -1.0f; sourcePitch < 3.0f; sourcePitch += 0.1f) { for (i = 0; i < kNumSources; i++) { alSourcef(source[i], AL_PITCH, sourcePitch); if (alGetError() != AL_NO_ERROR) { if (sourcePitch >= 0.5f && sourcePitch <= 2.0f) quit("Pitch change failed"); } else { if (!(sourcePitch >= 0.5f && sourcePitch <= 2.0f)) quit("Pitch out of range accepted"); } } } /* start the sources, pitch shift up, down and stop all */ printf("Play\n"); for (i = 0; i < kNumSources; i++) { alSourcePlay(source[i]); } printf("Pitch Up "); for (sourcePitch = 0.5f; sourcePitch < 2.0f; sourcePitch += 0.005f) { for (i = 0; i < kNumSources; i++) alSourcef(source[i], AL_PITCH, sourcePitch); printf("."); fflush(stdout); delay(20); } delay(2000); printf("\n"); printf("Pitch Down "); for (sourcePitch = 2.0f; sourcePitch > 0.5f; sourcePitch -= 0.005f) { for (i = 0; i < kNumSources; i++) alSourcef(source[i], AL_PITCH, sourcePitch); printf("."); fflush(stdout); delay(20); } delay(2000); printf("\n"); printf("Stop\n"); for (i = 0; i < kNumSources; i++) alSourceStop(source[i]); /* delete buffers and sources */ alDeleteSources(kNumSources, source); alDeleteBuffers(kNumBuffers, buffer); /* shutdown */ alutExit(); return 0; }