#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;
}