OpenAL documentation?

Posted By: Kartoffel

OpenAL documentation? - 06/02/17 16:22

I'm currently trying to port some code to OpenAL but I'm having a few problems.

I want to write generated data into a sound buffer. It works when using snd_buffer(...); but I don't know how to use the OpenAL-equivalent asnd_buffer(...);.

snd_buffer(); gives access to the sound data aswell as the DSBUFFERDESC (which is used in DirectSound8) but I don't know how to set the same parameters using asnd_buffer();.
In the manual I can't find anything about OpenAL and the header file (ackoal.h) doesn't help either (which is the reason why I'm asking here).

So how exactly does it work or is there some kind of documentation I can look up?
Posted By: jcl

Re: OpenAL documentation? - 06/12/17 08:03

Here's the source code of the asnd_buffer function:

Code:
#include "OpenAl.h"

int OpenAl::asnd_buffer(OpenAl::ASOUND *snd, void **pDesc, void ***ppSample) {
	//check whether the snd argument is valid
	if(OpenAl::helpFunctions::find(OpenAl::Settings::asoundStorage, snd) == false) {
		return -1;
	}

	//if snd is a streaming sound -> return
	if(snd->stream != 0) {
		*pDesc = 0;
		*ppSample = 0;
		return -2;
	}

	//assign the pointer to the pointer that points to the wave data
	*ppSample = &(snd->waveData);


	//search the dsbufferdescStorage for a matching pair, using the snd pointer
	std::map<OpenAl::ASOUND *, DSBUFFERDESC *>::iterator iteratorPosition =
		OpenAl::Settings::dsbufferdescStorage->find(snd);

	if(iteratorPosition != OpenAl::Settings::dsbufferdescStorage->end()) {
		//if a pair was found, store the pointer to the given pDesc variable
		*pDesc = (*iteratorPosition).second;
	} else {
		//else create such a pair, store it and save the pointer in the pDesc variable
		DSBUFFERDESC *tempBuffer = new DSBUFFERDESC;
		tempBuffer->lpwfxFormat = new WAVEFORMATEX;
		tempBuffer->lpwfxFormat->cbSize = 0;
		tempBuffer->lpwfxFormat->nAvgBytesPerSec = 0;
		tempBuffer->lpwfxFormat->nBlockAlign = 0;
		tempBuffer->lpwfxFormat->nChannels = 0;	//all sounds are mono, therefore this variable is useless
		tempBuffer->lpwfxFormat->nSamplesPerSec = snd->sampleRate;
		tempBuffer->lpwfxFormat->wBitsPerSample = 8 * OpenAl::getSizeOfOneSample(snd->format);

		tempBuffer->lpwfxFormat->wFormatTag = 0;

		tempBuffer->dwBufferBytes = snd->length;
		tempBuffer->dwFlags = 0;
		tempBuffer->dwReserved = 0;
		tempBuffer->dwSize = 0;
		tempBuffer->guid3DAlgorithm.Data1 = 0;
		tempBuffer->guid3DAlgorithm.Data2 = 0;
		tempBuffer->guid3DAlgorithm.Data3 = 0;
		tempBuffer->guid3DAlgorithm.Data4[0] = 'u';
		tempBuffer->guid3DAlgorithm.Data4[1] = 'n';
		tempBuffer->guid3DAlgorithm.Data4[2] = 'u';
		tempBuffer->guid3DAlgorithm.Data4[3] = 's';
		tempBuffer->guid3DAlgorithm.Data4[4] = 'e';
		tempBuffer->guid3DAlgorithm.Data4[5] = 'd';
		tempBuffer->guid3DAlgorithm.Data4[6] = ' ';
		tempBuffer->guid3DAlgorithm.Data4[7] = '!';

		OpenAl::Settings::dsbufferdescStorage->insert( std::pair<OpenAl::ASOUND *, DSBUFFERDESC *>(snd, tempBuffer) );

		*pDesc = tempBuffer;
	}

	return 0;
}

Posted By: Kartoffel

Re: OpenAL documentation? - 06/12/17 15:10

Oh, so the engine's asound implementation actually uses the same buffer descriptor that direct sound uses (DSBUFFERDESC).

This should be all I need, thank's a lot!
© 2024 lite-C Forums