Пример #1
0
CGameEngine::~CGameEngine()
{
	GLUtil()->Cleanup();

	ALFWShutdownOpenAL();
	ALFWShutdown();
}
Пример #2
0
MOboolean moSoundManager::Finish() {
	for(MOuint i=0; i<m_sounds_array.Count(); i++) {
		//moSound* psound = m_sounds_array[i];
		//if (psound) delete psound;
		//psound = NULL;
	}
	m_sounds_array.Empty();

	for(MOuint i=0; i<m_effects_array.Count(); i++) {
		//moSoundEffect* psoundeffect = m_effects_array[i];
		//if (psoundeffect) delete psoundeffect;
		//psoundeffect = NULL;
	}
	m_effects_array.Empty();

	#ifdef MO_WIN32
    #ifdef MO_USING_ALFW
    if (m_bInitialized) {
          ALFWShutdownOpenAL();
          ALFWShutdown();
    }
    #endif
	#endif
	return true;
}
Пример #3
0
Audio::~Audio(void)
{
	alSourceStop(uiSource);
    alDeleteSources(buffAl, &uiSource);
	alDeleteBuffers(buffAl, &uiBuffer);
	ALFWShutdownOpenAL();
	ALFWShutdown();
}
Пример #4
0
void EdenSoundUnload(EdenSound_t **sound_p)
{
    if (!sound_p) return;
    if (!(*sound_p)) return;
    
#ifdef EDEN_HAVE_OPENAL
    alSourceStop((*sound_p)->uiSource);
    alDeleteSources(1, &(*sound_p)->uiSource);
    alDeleteBuffers(1, &(*sound_p)->uiBuffer);
#endif // EDEN_HAVE_OPENAL
    
    free(*sound_p);
    *sound_p = NULL;

    // One-time cleanup.
    refCount--;
    if (refCount == 0) {
#ifdef EDEN_HAVE_OPENAL
        ALFWShutdownOpenAL();
        ALFWShutdown();
#endif // EDEN_HAVE_OPENAL
    }
}
Пример #5
0
void XOpenAL::Destroy()
{
	ALFWShutdownOpenAL();
	ALFWShutdown();
}
Пример #6
0
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;
}