Audio::Audio(const int _buffAl,const char* dir): buffAl(_buffAl) { load=false; ALFWInit(); // Initialize Framework if (!ALFWInitOpenAL()) { if (!ALFWInitOpenAL()) { ALFWprintf("Failed to initialize OpenAL\n"); ALFWShutdown(); return; } } // Generate an AL Buffer alGenBuffers(buffAl, &uiBuffer ); if (!ALFWLoadWaveToBuffer((char*)ALFWaddMediaPath(dir), uiBuffer)) { ALFWprintf("Failed to load %s\n", ALFWaddMediaPath(dir)); return; } load=true; lastTime = 0; }
BOOL XOpenAL::Init() { ALFWInit(); if (!ALFWInitOpenAL()) { XLOG_ALERT( "Failed to initialize OpenAL" ); ALFWShutdown(); return FALSE; } return TRUE; }
GLboolean OpenALInit() { // Initialize Framework ALFWInit(); if (!ALFWInitOpenAL()) { ALFWprintf("Failed to initialize OpenAL\n"); ALFWShutdown(); return false; } else { return true; } }
EdenSound_t *EdenSoundLoad(const char *pathname) { EdenSound_t *sound = NULL; #ifdef EDEN_HAVE_OPENAL // One-time initialisation. if (refCount == 0) { #ifdef EDEN_HAVE_OPENAL ALFWInit(); if (!ALFWInitOpenAL()) { ALFWprintf("Failed to initialize OpenAL\n"); ALFWShutdown(); } #endif // EDEN_HAVE_OPENAL } if (!(sound = (EdenSound_t *)calloc(1, sizeof(EdenSound_t)))) { EDEN_LOGe("Out of memory!\n"); return (NULL); } #ifdef EDEN_HAVE_OPENAL alGenBuffers(1, &sound->uiBuffer); #ifdef _WIN32 if (!ALFWLoadWaveToBuffer(pathname, sound->uiBuffer)) { EDEN_LOGe("Failed to load .wav file '%s'.\n", pathname); } #endif #ifdef __APPLE__ if (!ALFWLoadFileToBuffer(pathname, sound->uiBuffer)) { EDEN_LOGe("Failed to load audio file '%s'.\n", pathname); } #endif alGenSources(1, &sound->uiSource); alSourcei(sound->uiSource, AL_BUFFER, sound->uiBuffer); #endif // EDEN_HAVE_OPENAL refCount++; #endif // EDEN_HAVE_OPENAL return (sound); }
CGameEngine::CGameEngine(SampleViewer * s) { sampleViewer = s; m_bShowTexture = false; //GetApp()->MessageBox((const char *)glGetString(GL_EXTENSIONS)); GLUtil()->Init(); m_fFont.Init(GetGameApp()->GetHDC()); m_nPolygonMode = GL_FILL; m_3DCamera.SetPosition(CDoubleVector(0, 0, 25)); m_vLight = CVector(1000, 1000, 1000); m_vLightDirection = m_vLight / m_vLight.Magnitude(); CTexture::InitStaticMembers(238653, 256); m_nSamples = 4; // Number of sample rays to use in integral equation m_Kr = 0.0025f; // Rayleigh scattering constant m_Kr4PI = m_Kr*4.0f*PI; m_Km = 0.0025f; // Mie scattering constant m_Km4PI = m_Km*4.0f*PI; m_ESun = 15.0f; // Sun brightness constant m_g = -0.75f; // The Mie phase asymmetry factor m_fInnerRadius = 10.0f; m_fOuterRadius = 10.15f; m_fScale = 1 / (m_fOuterRadius - m_fInnerRadius); m_fWavelength[0] = 0.650f; // 650 nm for red m_fWavelength[1] = 0.570f; // 570 nm for green m_fWavelength[2] = 0.475f; // 475 nm for blue m_fWavelength4[0] = powf(m_fWavelength[0], 4.0f); m_fWavelength4[1] = powf(m_fWavelength[1], 4.0f); m_fWavelength4[2] = powf(m_fWavelength[2], 4.0f); m_fRayleighScaleDepth = 0.25f; m_fMieScaleDepth = 0.1f; m_pbOpticalDepth.MakeOpticalDepthBuffer(m_fInnerRadius, m_fOuterRadius, m_fRayleighScaleDepth, m_fMieScaleDepth); m_sphereInner.Init(m_fInnerRadius, 50, 50); m_sphereOuter.Init(m_fOuterRadius, 100, 100); headFront = headBack = headLeft = headRight = handLeft = handRight = false; skip = jointIdx = 0; float initialH_x = initialRH_x = initialH_z = initialRH_z = 0; // Initialize Framework ALFWInit(); ALFWprintf("PlayStatic Test Application\n"); if (!ALFWInitOpenAL()) { sprintf(g_ALError, "Failed to initialize OpenAL\n"); ALFWShutdown(); } // http://stackoverflow.com/questions/3169009/passing-arguments-to-beginthread-whats-wrong t *arg1; arg1 = (t *)malloc(sizeof(t)); sprintf(arg1->wavFile, "media/white_16.wav"); _beginthread( PlayWavLoop, 0, (void*) arg1); t *arg2; arg2 = (t *)malloc(sizeof(t)); sprintf(arg2->wavFile, "media/bass_808_1.wav"); _beginthread( PlayWavLoop, 0, (void*) arg2); startFly = false; }
MOboolean moSoundManager::Init() { if (!m_pResourceManager) return false; moResource::Init(); #ifdef MO_WIN32 #ifdef MO_USING_ALFW ALenum eBufferFormat = 0; ALFWInit(); if (!ALFWInitOpenAL()) { ALFWprintf("Failed to initialize OpenAL\n"); ALFWShutdown(); return 0; } // For this example, we are going to play a 5.1 test file ... /*eBufferFormat = alGetEnumValue("AL_FORMAT_51CHN16"); if (!eBufferFormat) { ALFWprintf("No support for 5.1 playback!\n"); ALFWShutdownOpenAL(); ALFWShutdown(); return 0; } */ if (ALFWIsXRAMSupported()) { //continue } if (ALFWIsEFXSupported()) { //esto deberia configurarse desde el config moSoundEffect* pneweffect = new moSoundEffect(); /* ALuint genfxid; if (pneweffect) { alGenEffects(1, &genfxid); pneweffect->m_EffectId = genfxid; alEffecti(pneweffect->m_EffectId, AL_EFFECT_TYPE, AL_EFFECT_COMPRESSOR); m_effects_array.Add(pneweffect); } pneweffect = new moSoundEffect(); genfxid; if (pneweffect) { alGenEffects(1, &genfxid); pneweffect->m_EffectId = genfxid; alEffecti(pneweffect->m_EffectId, AL_EFFECT_TYPE, AL_EFFECT_EQUALIZER); m_effects_array.Add(pneweffect); }*/ } #endif #endif #ifdef MO_LINUX #endif m_sounds_array.Init( 0, NULL ); m_bInitialized = true; return m_bInitialized; }
int main() { ALuint uiBuffers[NUMBUFFERS]; ALuint uiSource; ALuint uiBuffer; ALint iState; CWaves * pWaveLoader = NULL; WAVEID WaveID; ALint iLoop; ALint iBuffersProcessed, iTotalBuffersProcessed, iQueuedBuffers; WAVEFORMATEX wfex; unsigned long ulDataSize = 0; unsigned long ulFrequency = 0; unsigned long ulFormat = 0; unsigned long ulBufferSize; unsigned long ulBytesWritten; void * pData = NULL; // Initialize Framework ALFWInit(); ALFWprintf("PlayStream Test Application\n"); if (!ALFWInitOpenAL()) { ALFWprintf("Failed to initialize OpenAL\n"); ALFWShutdown(); return 0; } // Generate some AL Buffers for streaming alGenBuffers( NUMBUFFERS, uiBuffers ); // Generate a Source to playback the Buffers alGenSources( 1, &uiSource ); // Create instance of WaveLoader class pWaveLoader = new CWaves(); if ((pWaveLoader) && (SUCCEEDED(pWaveLoader->OpenWaveFile(ALFWaddMediaPath(TEST_WAVE_FILE), &WaveID)))) { pWaveLoader->GetWaveSize(WaveID, &ulDataSize); pWaveLoader->GetWaveFrequency(WaveID, &ulFrequency); pWaveLoader->GetWaveALBufferFormat(WaveID, &alGetEnumValue, &ulFormat); // Queue 250ms of audio data pWaveLoader->GetWaveFormatExHeader(WaveID, &wfex); ulBufferSize = wfex.nAvgBytesPerSec >> 2; // IMPORTANT : The Buffer Size must be an exact multiple of the BlockAlignment ... ulBufferSize -= (ulBufferSize % wfex.nBlockAlign); if (ulFormat != 0) { pData = malloc(ulBufferSize); if (pData) { // Set read position to start of audio data pWaveLoader->SetWaveDataOffset(WaveID, 0); // Fill all the Buffers with audio data from the wavefile for (iLoop = 0; iLoop < 4; iLoop++) { if (SUCCEEDED(pWaveLoader->ReadWaveData(WaveID, pData, ulBufferSize, &ulBytesWritten))) { alBufferData(uiBuffers[iLoop], ulFormat, pData, ulBytesWritten, ulFrequency); alSourceQueueBuffers(uiSource, 1, &uiBuffers[iLoop]); } } // Start playing source alSourcePlay(uiSource); iTotalBuffersProcessed = 0; while (!ALFWKeyPress()) { Sleep( SERVICE_UPDATE_PERIOD ); // Request the number of OpenAL Buffers have been processed (played) on the Source iBuffersProcessed = 0; alGetSourcei(uiSource, AL_BUFFERS_PROCESSED, &iBuffersProcessed); // Keep a running count of number of buffers processed (for logging purposes only) iTotalBuffersProcessed += iBuffersProcessed; ALFWprintf("Buffers Processed %d\r", iTotalBuffersProcessed); // For each processed buffer, remove it from the Source Queue, read next chunk of audio // data from disk, fill buffer with new data, and add it to the Source Queue while (iBuffersProcessed) { // Remove the Buffer from the Queue. (uiBuffer contains the Buffer ID for the unqueued Buffer) uiBuffer = 0; alSourceUnqueueBuffers(uiSource, 1, &uiBuffer); // Read more audio data (if there is any) pWaveLoader->ReadWaveData(WaveID, pData, ulBufferSize, &ulBytesWritten); if (ulBytesWritten) { // Copy audio data to Buffer alBufferData(uiBuffer, ulFormat, pData, ulBytesWritten, ulFrequency); // Queue Buffer on the Source alSourceQueueBuffers(uiSource, 1, &uiBuffer); } iBuffersProcessed--; } // Check the status of the Source. If it is not playing, then playback was completed, // or the Source was starved of audio data, and needs to be restarted. alGetSourcei(uiSource, AL_SOURCE_STATE, &iState); if (iState != AL_PLAYING) { // If there are Buffers in the Source Queue then the Source was starved of audio // data, so needs to be restarted (because there is more audio data to play) alGetSourcei(uiSource, AL_BUFFERS_QUEUED, &iQueuedBuffers); if (iQueuedBuffers) { alSourcePlay(uiSource); } else { // Finished playing break; } } } // Stop the Source and clear the Queue alSourceStop(uiSource); alSourcei(uiSource, AL_BUFFER, 0); // Release temporary storage free(pData); pData = NULL; } else { ALFWprintf("Out of memory\n"); } } else { ALFWprintf("Unknown Audio Buffer format\n"); } // Close Wave Handle pWaveLoader->DeleteWaveFile(WaveID); }
int main() { ALCdevice *pDevice; ALCcontext *pContext; ALCdevice *pCaptureDevice; const ALCchar *szDefaultCaptureDevice; ALint iSamplesAvailable; FILE *pFile; ALchar Buffer[BUFFERSIZE]; WAVEHEADER sWaveHeader; ALint iDataSize = 0; ALint iSize; // NOTE : This code does NOT setup the Wave Device's Audio Mixer to select a recording input // or a recording level. // Initialize Framework ALFWInit(); ALFWprintf("Capture Application\n"); if (!ALFWInitOpenAL()) { ALFWprintf("Failed to initialize OpenAL\n"); ALFWShutdown(); return 0; } // Check for Capture Extension support pContext = alcGetCurrentContext(); pDevice = alcGetContextsDevice(pContext); if (alcIsExtensionPresent(pDevice, "ALC_EXT_CAPTURE") == AL_FALSE) { ALFWprintf("Failed to detect Capture Extension\n"); ALFWShutdownOpenAL(); ALFWShutdown(); return 0; } // Get list of available Capture Devices const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); if (pDeviceList) { ALFWprintf("\nAvailable Capture Devices are:-\n"); while (*pDeviceList) { ALFWprintf("%s\n", pDeviceList); pDeviceList += strlen(pDeviceList) + 1; } } // Get the name of the 'default' capture device szDefaultCaptureDevice = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); ALFWprintf("\nDefault Capture Device is '%s'\n\n", szDefaultCaptureDevice); // Open the default Capture device to record a 22050Hz 16bit Mono Stream using an internal buffer // of BUFFERSIZE Samples (== BUFFERSIZE * 2 bytes) pCaptureDevice = alcCaptureOpenDevice(szDefaultCaptureDevice, 22050, AL_FORMAT_MONO16, BUFFERSIZE); if (pCaptureDevice) { ALFWprintf("Opened '%s' Capture Device\n\n", alcGetString(pCaptureDevice, ALC_CAPTURE_DEVICE_SPECIFIER)); // Create / open a file for the captured data pFile = fopen(OUTPUT_WAVE_FILE, "wb"); // Prepare a WAVE file header for the captured data sprintf(sWaveHeader.szRIFF, "RIFF"); sWaveHeader.lRIFFSize = 0; sprintf(sWaveHeader.szWave, "WAVE"); sprintf(sWaveHeader.szFmt, "fmt "); sWaveHeader.lFmtSize = sizeof(WAVEFORMATEX); sWaveHeader.wfex.nChannels = 1; sWaveHeader.wfex.wBitsPerSample = 16; sWaveHeader.wfex.wFormatTag = WAVE_FORMAT_PCM; sWaveHeader.wfex.nSamplesPerSec = 22050; sWaveHeader.wfex.nBlockAlign = sWaveHeader.wfex.nChannels * sWaveHeader.wfex.wBitsPerSample / 8; sWaveHeader.wfex.nAvgBytesPerSec = sWaveHeader.wfex.nSamplesPerSec * sWaveHeader.wfex.nBlockAlign; sWaveHeader.wfex.cbSize = 0; sprintf(sWaveHeader.szData, "data"); sWaveHeader.lDataSize = 0; fwrite(&sWaveHeader, sizeof(WAVEHEADER), 1, pFile); // Start audio capture alcCaptureStart(pCaptureDevice); // Record for two seconds or until a key is pressed DWORD dwStartTime = timeGetTime(); while (!ALFWKeyPress() && (timeGetTime() <= (dwStartTime + 2000))) { // Release some CPU time ... Sleep(1); // Find out how many samples have been captured alcGetIntegerv(pCaptureDevice, ALC_CAPTURE_SAMPLES, 1, &iSamplesAvailable); ALFWprintf("Samples available : %d\r", iSamplesAvailable); // When we have enough data to fill our BUFFERSIZE byte buffer, grab the samples if (iSamplesAvailable > (BUFFERSIZE / sWaveHeader.wfex.nBlockAlign)) { // Consume Samples alcCaptureSamples(pCaptureDevice, Buffer, BUFFERSIZE / sWaveHeader.wfex.nBlockAlign); // Write the audio data to a file fwrite(Buffer, BUFFERSIZE, 1, pFile); // Record total amount of data recorded iDataSize += BUFFERSIZE; } } // Stop capture alcCaptureStop(pCaptureDevice); // Check if any Samples haven't been consumed yet alcGetIntegerv(pCaptureDevice, ALC_CAPTURE_SAMPLES, 1, &iSamplesAvailable); while (iSamplesAvailable) { if (iSamplesAvailable > (BUFFERSIZE / sWaveHeader.wfex.nBlockAlign)) { alcCaptureSamples(pCaptureDevice, Buffer, BUFFERSIZE / sWaveHeader.wfex.nBlockAlign); fwrite(Buffer, BUFFERSIZE, 1, pFile); iSamplesAvailable -= (BUFFERSIZE / sWaveHeader.wfex.nBlockAlign); iDataSize += BUFFERSIZE; } else { alcCaptureSamples(pCaptureDevice, Buffer, iSamplesAvailable); fwrite(Buffer, iSamplesAvailable * sWaveHeader.wfex.nBlockAlign, 1, pFile); iDataSize += iSamplesAvailable * sWaveHeader.wfex.nBlockAlign; iSamplesAvailable = 0; } } // Fill in Size information in Wave Header fseek(pFile, 4, SEEK_SET); iSize = iDataSize + sizeof(WAVEHEADER) - 8; fwrite(&iSize, 4, 1, pFile); fseek(pFile, 42, SEEK_SET); fwrite(&iDataSize, 4, 1, pFile); fclose(pFile); ALFWprintf("\nSaved captured audio data to '%s'\n", OUTPUT_WAVE_FILE); // Close the Capture Device alcCaptureCloseDevice(pCaptureDevice); } // Close down OpenAL ALFWShutdownOpenAL(); // Close down the Framework ALFWShutdown(); return 0; }