Re: Question about OpenAl Versions

Chris Robinson <[email protected]>
Newsgroups gmane.comp.lib.openal
Message-ID <[email protected]>
On Monday, November 15, 2010 7:34:21 pm Bruce Clay wrote:
> if (deviceName.length() > 0)
> {
> 	mCurrCaptureDevice = alcCaptureOpenDevice (deviceName.c_str(),
> sampleRate, audioFormat, sampleBufSize);
> }
> else
> {
> 	mCurrCaptureDevice = alcCaptureOpenDevice (NULL, sampleRate,
> audioFormat, sampleBufSize);
> }
> 
> int error = alGetError();

This won't do what you expect. alGetError only returns the last error from the 
current context, and opening a capture device doesn't use a context. The way 
to check for an error would be to look for a NULL return value, then use 
alcGetError(NULL) to get the error code.

> formatChunk.format = WAVE_FORMAT_PCM;
> formatChunk.numChannels = numChannels;
> formatChunk.samplesPerSec = sampleRate;
> formatChunk.avgBytesPerSec = sampleRate * numChannels * bitsPerSample / 8;
> formatChunk.blockAlign = numChannels * bitsPerSample / 8;
> formatChunk.bitsPerSample = bitsPerSample;
> 
> fwrite(FORMAT_TAG, strlen(FORMAT_TAG), 1, fdes);
> 
> fieldLen = sizeof(formatChunk);
> 
> fwrite(&fieldLen, sizeof(fieldLen), 1, fdes);
> 
> fwrite(&formatChunk, fieldLen, 1, fdes);

It's not a good idea to write whole structs and integers to a file, since it 
assumes a particular endianess and structure padding, which may not always be 
true. It's better to read/write each field separately, using wrappers so 16- 
and 32-bit values are properly handled.

> unsigned long currPos = ftell(fdes);
> 
> chunkSize = currPos - mStartChunkPos;
> 
> fseek(fdes, mStartChunkPos + sizeof(chunkSize), SEEK_SET);
> 
> fwrite(&chunkSize, chunkSize, 1, fdes);

That last bit doesn't look right. The chunk size is only 4 bytes, not 
'chunkSize' bytes. But again, it's better to use dedicated functions to write 
16- and 32-bit values, to help avoid problems like this:

size_t fwrite32le(unsigned int value, FILE *fdes)
{
    unsigned char buf[4] = {
        value&0xff, (value>>8)&0xff, (value>>16)&0xff, (value>>24)&0xff
    };
    return fwrite(buf, 4, 1, fdes);
}

size_t fwrite16le(unsigned short value, FILE *fdes)
{
    unsigned char buf[2] = {
        value&0xff, (value>>8)&0xff
    };
    return fwrite(buf, 2, 1, fdes);
}
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.