NSoundSystem::NSoundSystem() { ALCsizei Count; const char** DeviceNames = alureGetDeviceNames(true,&Count); for (int i=0;i<Count;i++) { GetGame()->GetLog()->Send("ALURE",2,std::string("Found device: ") + DeviceNames[i] + "."); } bool Found = false; for (int i=0;i<Count;i++) { if (alureInitDevice(DeviceNames[0],NULL) != AL_FALSE) { GetGame()->GetLog()->Send("ALURE",2,std::string("Using device: ") + DeviceNames[0] + "."); Found = true; break; } } if (!Found) { GetGame()->GetLog()->Send("ALURE",0,"Failed to use any sound devices!"); alureFreeDeviceNames(DeviceNames); return; } alureFreeDeviceNames(DeviceNames); alListener3f(AL_POSITION,0,0,0); alListener3f(AL_VELOCITY,0,0,0); alListener3f(AL_ORIENTATION,0,0,-1); }
bool initSoundStuff (HWND hwnd) { if(!alureInitDevice(NULL, NULL)) { debugOut( "Failed to open OpenAL device: %s\n", alureGetErrorString()); return 1; } int a; for (a = 0; a < MAX_SAMPLES; a ++) { soundCache[a].stream = NULL; soundCache[a].playing = false; soundCache[a].fileLoaded = -1; soundCache[a].looping = false; intpointers[a] = a; } for (a = 0; a < MAX_MODS; a ++) { modCache[a].stream = NULL; modCache[a].playing = false; } if (! alureUpdateInterval(0.01)) { debugOut("Failed to set Alure update interval: %s\n", alureGetErrorString()); return 1; } return soundOK = true; }
AudioDevice::AudioDevice() { if(!alureInitDevice(NULL, NULL)) { std::cerr << "Error: OpenAl cannot initialize Device" << std::endl; } AL_CHECK(); std::cout << "initialized audio device" << std::endl; }
bool audio_on() { if(!alureInitDevice(NULL, NULL)) { err("audio", "could not initiate"); return false; } fluid_set_log_function(FLUID_WARN, dumberror, NULL); fluid_set_log_function(FLUID_ERR, dumberror, NULL); fluid_set_log_function(FLUID_INFO, dumberror, NULL); fluid_set_log_function(FLUID_DBG, dumberror, NULL); alureUpdateInterval(0.05); atexit(audio_off); alure_state = 1; return true; }
int is::Audio::init() { // Grab available devices and print them. int deviceCount; const char** deviceNames = alureGetDeviceNames( true, &deviceCount ); if ( !deviceCount ) { os->printf( "ERR OpenAL failed to find any usable devices for audio playback!\n" ); alureFreeDeviceNames( deviceNames ); audio->checkErrorSimple(); return 1; } os->printf( "INF OpenAL detected the following devices for audio:\n" ); for ( int i=0; i<deviceCount; i++ ) { os->printf( "INF %.\n", deviceNames[i] ); } // Attempt to use any device starting from the first. int i = 0; while ( alureInitDevice( deviceNames[i], NULL ) == AL_FALSE && i < deviceCount ) { audio->checkErrorSimple(); i++; } if ( i == deviceCount ) { os->printf( "ERR OpenAL failed to find any usable devices for audio playback!\n" ); alureFreeDeviceNames( deviceNames ); return 1; } os->printf( "INF OpenAL: Using %.\n", deviceNames[i] ); alureFreeDeviceNames( deviceNames ); // Initialize the listener alListener3f( AL_POSITION, 0.f, 0.f, 0.f ); alListener3f( AL_VELOCITY, 0.f, 0.f, 0.f ); float ori[6] = { 0, 0, -1, 0, 1, 0 }; alListenerfv( AL_ORIENTATION, ori ); audio->checkErrorSimple(); lua->doFolder( "data/sounds" ); return 0; }
void Init(int frequency, int resolution, int sources) { (void)resolution; --sources; // one spare source for music ALCint attribs[] = { ALC_FREQUENCY, frequency, /*ALC_MONO_SOURCES, sources, ALC_STEREO_SOURCES, 1,*/ 0 }; alureInitDevice(NULL, attribs); soundSources = new ALuint[sources]; alGenSources(sources, soundSources); alGenSources(1, &musicSource); //alGenBuffers(2, musicBufs); soundSourceCount = sources; alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); alSpeedOfSound(1400.0); alDopplerFactor(0.7); alureUpdateInterval(0.03333f); }
void Init(int frequency, int resolution, int sources) { (void)resolution; --sources; // one spare source for music ALCint attribs[] = { ALC_FREQUENCY, frequency, /*ALC_MONO_SOURCES, sources, ALC_STEREO_SOURCES, 1,*/ 0 }; if (AL_FALSE == alureInitDevice(NULL, attribs)) { LOG("Sound", LOG_ERROR, "ALURE init failure"); exit(1); } soundSources = new ALuint[sources]; alGenSources(sources, soundSources); alGenSources(1, &musicSource); alGenBuffers(2, musicBufs); soundSourceCount = sources; alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); alSpeedOfSound(1400.0); alDopplerFactor(0.7); alureUpdateInterval(0.03333f); #ifndef NDEBUG if (alGetError()) LOG("Sound", LOG_ERROR, "OpenAL init failure"); const ALchar* err = alureGetErrorString(); if (strcmp(err, "No error")) { LOG("Sound", LOG_ERROR, "ALURE init failure: %s", err); exit(1); } #endif }
int main () { if (!alureInitDevice(NULL, NULL)) { std::fprintf(stderr, "Failed to open OpenAL device: %s\n", alureGetErrorString()); return 1; } alGenSources(1, &src); if (alGetError() != AL_NO_ERROR) { std::fprintf(stderr, "Failed to create OpenAL source!\n"); alureShutdownDevice(); return 1; } // Seeting Blip Buffer synth.treble_eq( -18.0f ); synth.volume (0.80); synth.output (&blipbuf); // Init Blip Buffer with a buffer of 250ms (second paramter is time in ms) if ( blipbuf.set_sample_rate( SR, 1000 / 4 ) ) { std::fprintf(stderr, "Failed to create Blip Buffer! Our of Memory\n"); alureShutdownDevice(); return 1; } blipbuf.clock_rate( blipbuf.sample_rate() ); blipbuf.bass_freq(300); // Equalization like a TV speaker stream = alureCreateStreamFromCallback (StreamCB, nullptr, AL_FORMAT_MONO16, SR, SR/2, 0, nullptr); if(!stream) { std::fprintf(stderr, "Error creating stream! %s\n", alureGetErrorString()); alDeleteSources(1, &src); alureShutdownDevice(); return 1; } if (!alurePlaySourceStream(src, stream, 4, 0, eos_callback, NULL)) { std::fprintf(stderr, "Failed to play stream: %s\n", alureGetErrorString()); isdone = 1; } alureUpdateInterval(0.005f); // Should be a independint thread playing the stream while(!isdone) { freq -= 1; if (freq < 1) { freq = 600; } alureSleep(0.02f); } alureStopSource(src, AL_FALSE); alDeleteSources(1, &src); alureDestroyStream(stream, 0, NULL); alureShutdownDevice(); return 0; }
UBOOL UOpenALAudioSubsystem::Init() { guard(UOpenALAudioSubsystem::Init); INT Rate = GetActualOutputRate(); // OpenAL / ALURE initialization ALCint ContextAttrs[] = { ALC_FREQUENCY, Rate, 0 }; if( alureInitDevice( NULL, ContextAttrs ) == AL_FALSE ) appErrorf( TEXT("Couldn't initialize OpenAL: %s"), alureGetErrorString() ); alDistanceModel( AL_LINEAR_DISTANCE_CLAMPED ); CheckALErrorFlag( TEXT("alDistanceModel") ); alDopplerFactor( DopplerFactor ); CheckALErrorFlag( TEXT("alDopplerFactor") ); // Metre per second to units per second, where units per meter is 52.5. // Taken from: http://wiki.beyondunreal.com/Legacy:General_Scale_And_Dimensions alSpeedOfSound( 343.3f * 52.5f ); CheckALErrorFlag( TEXT("alSpeedOfSound") ); ALuint* NewSources = new ALuint[NumSources + 1]; Sources = new FAudioSource[NumSources]; alGenSources( NumSources + 1, NewSources ); CheckALErrorFlag( TEXT("alGenSources") ); MusicSource = NewSources[0]; for( INT i=0; i<NumSources; i++ ) Sources[i].Id = NewSources[i+1]; delete[] NewSources; // Fix the music source to 0 values alSource3f( MusicSource, AL_POSITION, 0.f, 0.f, 0.f ); alSource3f( MusicSource, AL_VELOCITY, 0.f, 0.f, 0.f ); alSource3f( MusicSource, AL_DIRECTION, 0.f, 0.f, 0.f ); alSourcef( MusicSource, AL_ROLLOFF_FACTOR, 0.f ); alSourcei( MusicSource, AL_SOURCE_RELATIVE, AL_TRUE ); SetVolumes(); CheckALErrorFlag( TEXT("SetVolumes") ); // MikMod initialization //kipz - remove this because it breaks on new mikmod //MikMod_RegisterDriver( &MusicDriver ); MikMod_RegisterAllDrivers(); // Register only formats that are known to be supported by UT. // Taken from: http://wiki.beyondunreal.com/Music MikMod_RegisterLoader( &load_mod ); MikMod_RegisterLoader( &load_s3m ); MikMod_RegisterLoader( &load_stm ); MikMod_RegisterLoader( &load_it ); MikMod_RegisterLoader( &load_xm ); MikMod_RegisterLoader( &load_far ); MikMod_RegisterLoader( &load_669 ); md_mixfreq = Rate; if ( HighQualityMusic ) md_mode |= DMODE_HQMIXER; if( MikMod_Init( "" ) ) appErrorf( TEXT("Couldn't initialize MikMod: %s"), MikMod_strerror( MikMod_errno ) ); // Initialized! USound::Audio = this; UMusic::Audio = this; Initialized = 1; return 1; unguard; }