Ejemplo n.º 1
0
/*
================
VorbisStream::UploadData
================
*/
bool VorbisStream::UploadData( AudioStreamData *streamData, int buffer, uInt maxSize ) {
	VorbisStreamData *streamDataVorbis = static_cast<VorbisStreamData *>(streamData);

	if ( streamData->isDone )
		return false;

	DynBuffer<char> wavData(maxSize);
	int  size = 0;
	int  bitsteam, result;

	while( size < maxSize ) {
		result = ov_read( &streamDataVorbis->file, wavData.data + size, maxSize - size, 0, 2, 1, &bitsteam );

		if( result < 0 ) {
			//common->Warning("Vorbis read error: '%s'", ovErrorMessage( result ) );
			return false;
		}
		if( result > 0 )
			size += result;

		if( result == 0 )
			break;
	}

	if( size == 0 )
		return false;

	if( result == 0 ) {
		if ( !streamData->loop )
			streamData->isDone = true;
		else {
			ov_clear( &static_cast<VorbisStreamData *>(streamData)->file );
			streamData->pos = 0;
			if ( ov_open_callbacks( streamData, &static_cast<VorbisStreamData *>(streamData)->file, OG_NULL, 0, vorbisCallbacks ) != 0 ) {
				//common->Warning("Failed to read ogg file.");
				return false;
			}
		}
	}
	alBufferData( buffer, format, wavData.data, size, freq );

	return CheckAlErrors();
}
Ejemplo n.º 2
0
_Use_decl_annotations_
SingleSoundEffect AssetLoader::LoadSoundEffectFromFile(const char* filename) const
{
    char source[MAX_PATH];
    sprintf_s(source, "%s%s", GetConfig().ContentRoot, filename);

    SoundFileData data;

    LoadSoundFileData(source, &data);

    // The DirectXTK Audio stack requires the memory that describes the WAV data to be
    // in a unique_ptr.

    /*
    struct SoundFileDataDeleter
    {
        void operator() (void* p)
        {
            SoundFileData data;
            data.Data = (uint8_t*)p; // Let the proper free occur
            data.DataSize = 0;
            data.Format = nullptr;
            data.StartAudioData = nullptr;
            data.StartAudioDataSize = 0;

            FreeSoundFileData(&data);
        }
    };
    */

    //std::unique_ptr<uint8_t[], SoundFileDataDeleter> wavData(data.Data);
    std::unique_ptr<uint8_t[]> wavData(data.Data);
    std::shared_ptr<SoundEffect> soundEffect(new SoundEffect(&GetGame().GetAudioEngine(), wavData, data.Format, data.StartAudioData, data.StartAudioDataSize));

    return SingleSoundEffect(soundEffect);
}