Exemplo n.º 1
0
int AudioPlayer_AO::getPcmFormat( unsigned char * data, unsigned int length ) 
{
    struct wavinfo_t wavinfo;
    GetWavInfo( data, length, &wavinfo );

    // set the PCM format from wav header
    memset( &pcm_format, 0, sizeof(pcm_format) );

    pcm_format.bits         = wavinfo.width * 8;
    pcm_format.channels     = wavinfo.channels;
    pcm_format.rate         = wavinfo.rate;
    pcm_format.byte_format  = AO_FMT_LITTLE;

    return wavinfo.dataofs;
}
Exemplo n.º 2
0
/*
==============
S_EndLoadSound
==============
*/
qboolean S_EndLoadSound( sfx_t *sfx )
{
    wavinfo_t	info;
    byte*		data;
    ALuint		Buffer;

    assert(sfx->iFlags & SFX_FLAG_LOADING);
    sfx->iFlags &= ~SFX_FLAG_LOADING;

    // was the read successful?
    if (Sys_StreamIsError(sfx->iStreamHandle))
    {
#if defined(FINAL_BUILD)
        /*
        extern void ERR_DiscFail(bool);
        ERR_DiscFail(false);
        */
#endif
        Sys_StreamClose(sfx->iStreamHandle);
        Z_Free(sfx->pSoundData);
        sfx->iFlags |= SFX_FLAG_RESIDENT | SFX_FLAG_DEFAULT;
        return qfalse;
    }

    Sys_StreamClose(sfx->iStreamHandle);
    SND_TouchSFX(sfx);

    sfx->iLastTimeUsed = Com_Milliseconds()+1;	// why +1? Hmmm, leave it for now I guess

    // loading a WAV, presumably...
    data = (byte*)sfx->pSoundData;
    info = GetWavInfo( data );

    if (info.size == 0)
    {
        Z_Free(sfx->pSoundData);
        sfx->iFlags |= SFX_FLAG_RESIDENT | SFX_FLAG_DEFAULT;
        return qfalse;
    }

    sfx->iSoundLength = info.size;

    // make sure we have enough space for the sound
    SND_update(sfx);

    // Clear Open AL Error State
    alGetError();

    // Generate AL Buffer
    alGenBuffers(1, &Buffer);

    // Copy audio data to AL Buffer
    alBufferData(Buffer, info.format, data,
                 sfx->iSoundLength, info.rate);
    if (alGetError() != AL_NO_ERROR)
    {
        Z_Free(sfx->pSoundData);
        sfx->iFlags |= SFX_FLAG_UNLOADED;
        return qfalse;
    }

    sfx->Buffer = Buffer;

#ifdef _GAMECUBE
    Z_Free(sfx->pSoundData);
#endif
    sfx->iFlags |= SFX_FLAG_RESIDENT;

    return qtrue;
}