Example #1
0
void alBufferi(ALuint buffer, ALenum param, ALint value)
{
    DEBUGLOGCALL(LCF_OPENAL);
    AudioBuffer* ab = audiocontext.getBuffer(buffer);
    if (ab == nullptr) {
        ALSETERROR(AL_INVALID_NAME);
        return;
    }

    std::lock_guard<std::mutex> lock(audiocontext.mutex);

    switch(param) {
        case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
            debuglog(LCF_OPENAL, "  Set block alignment ", value);
            ab->blockSamples = value;
            ab->update();
            break;
        default:
            debuglog(LCF_OPENAL, "  Operation not supported");
            return;
    }
}
Example #2
0
void alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
{
    debuglog(LCF_OPENAL, __func__, " call - copy buffer data of format ", format, ", size ", size, " and frequency ", freq, " into buffer ", buffer);
	AudioBuffer* ab = audiocontext.getBuffer(buffer);
    if (ab == nullptr) {
        ALSETERROR(AL_INVALID_NAME);
        return;
    }

    std::lock_guard<std::mutex> lock(audiocontext.mutex);
    
    /* Fill the buffer informations */
    ab->size = size;
    ab->frequency = freq;
    switch(format) {
        case AL_FORMAT_MONO8:
            ab->format = SAMPLE_FMT_U8;
            ab->nbChannels = 1;
            break;
        case AL_FORMAT_MONO16:
            ab->format = SAMPLE_FMT_S16;
            ab->nbChannels = 1;
            break;
        case AL_FORMAT_STEREO8:
            ab->format = SAMPLE_FMT_U8;
            ab->nbChannels = 2;
            break;
        case AL_FORMAT_STEREO16:
            ab->format = SAMPLE_FMT_S16;
            ab->nbChannels = 2;
            break;
        case AL_FORMAT_MONO_FLOAT32:
            ab->format = SAMPLE_FMT_FLT;
            ab->nbChannels = 1;
            break;
        case AL_FORMAT_STEREO_FLOAT32:
            ab->format = SAMPLE_FMT_FLT;
            ab->nbChannels = 2;
            break;
        case AL_FORMAT_MONO_DOUBLE_EXT:
            ab->format = SAMPLE_FMT_DBL;
            ab->nbChannels = 1;
            break;
        case AL_FORMAT_STEREO_DOUBLE_EXT:
            ab->format = SAMPLE_FMT_DBL;
            ab->nbChannels = 2;
            break;
        case AL_FORMAT_MONO_MSADPCM_SOFT:
            ab->format = SAMPLE_FMT_MSADPCM;
            ab->nbChannels = 1;
            if (ab->blockSamples == 0)
                ab->blockSamples = 64;
            break;
        case AL_FORMAT_STEREO_MSADPCM_SOFT:
            ab->format = SAMPLE_FMT_MSADPCM;
            ab->nbChannels = 2;
            if (ab->blockSamples == 0)
                ab->blockSamples = 64;
            break;
        default:
            debuglog(LCF_OPENAL | LCF_ERROR, "Unsupported format: ", format);
            return;
    }

    ab->update();

    /* Check for size validity */
    if (! ab->checkSize()) {
        ALSETERROR(AL_INVALID_VALUE);
        return;
    }

    /* Copy the data into our buffer */
    ab->samples.clear();
    ab->samples.insert(ab->samples.end(), &((uint8_t*)data)[0], &((uint8_t*)data)[size]);

}