Re: setup 3d audio
Chris Robinson <[email protected]>
| Newsgroups | gmane.comp.lib.openal |
|---|---|
| Message-ID | <[email protected]> |
On Monday 03 May 2010 5:24:17 am coolbreeze wrote:
> I tested with a mono sound but it is too noisy,
> i find a tutorial but they use alut to load files and its depreciated...
>
> maybe the problem is when i init openAL? or when i load the file ? with
> libsndfile
...
> switch (device_type)
> {
> case ASS_DEFAULT_DEVICE:
> d->device=alcOpenDevice(NULL);
> break;
> case ASS_PULSEAUDIO_DEVICE:
> d->device=alcOpenDevice("PulseAudio Software");
> break;
> case ASS_ALSA_DEVICE:
> d->device=alcOpenDevice("ALSA Software");
> break;
> case ASS_OSS_DEVICE:
> d->device=alcOpenDevice("OSS Software");
> break;
> case ASS_PORTAUDIO_DEVICE:
> d->device=alcOpenDevice("PortAudio Software");
> break;
> default:
> break;
> }
...
Not related to the problem, but you shouldn't rely on specific device strings
like this. They are implementation-defined, and subject to change. Not that I
have any immediate plans to change them, but just saying.
> if (sf_read_short(file, audio->data_samples,audio->nbr_samples) <
> audio->nbr_samples) return ASS_FALSE;
IIRC, sf_read_short takes and returns the number of frames, not samples. So
you'd want to use audio->file_info.frames instead of audio->nbr_samples.
You'll also want to be careful because not all file formats will have a known
(or correct) frame count. In general, you'll want to read in a loop until it
has no more to give. Eg:
ALshort *data = NULL;
ALsizei datasize = 0;
ALsizei totalsize = 0;
int todo;
do {
todo = (totalsize-datasize) / audio->file_info.channels;
if(todo == 0)
{
ALshort *temp;
totalsize = (totalsize ? totalsize<<1 : 65536);
temp = realloc(data, totalsize*sizeof(ALshort));
if(!temp)
{
free(data);
return false;
}
data = temp;
todo = (totalsize-datasize) / audio->file_info.channels;
}
todo = sf_read_short(file, data+datasize, todo);
datasize += todo;
} while(todo > 0);
data = realloc(data, datasize*sizeof(ALshort));
alBufferData(bID, format, data, datasize*sizeof(ALshort), samplerate);
free(data);
...
C++ would benefit from using std::vector<ALshort>, but that's how you'd do it
in C.
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal