1
0

Free loaded data after alBufferData() (#147)

https://github.com/kcat/openal-soft/blob/master/examples/alplay.c#L266
This commit is contained in:
Deve 2023-09-21 23:14:00 +02:00 committed by GitHub
parent 6cc875cc32
commit 5b9ca22c57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,7 +109,6 @@ struct SoundBuffer
ALenum format; ALenum format;
ALsizei freq; ALsizei freq;
ALuint buffer_id; ALuint buffer_id;
std::vector<char> buffer;
}; };
SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile, SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
@ -120,6 +119,7 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
long bytes; long bytes;
char array[BUFFER_SIZE]; // Local fixed size array char array[BUFFER_SIZE]; // Local fixed size array
vorbis_info *pInfo; vorbis_info *pInfo;
std::vector<char> buffer;
SoundBuffer *snd = new SoundBuffer; SoundBuffer *snd = new SoundBuffer;
@ -151,12 +151,12 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
} }
// Append to end of buffer // Append to end of buffer
snd->buffer.insert(snd->buffer.end(), array, array + bytes); buffer.insert(buffer.end(), array, array + bytes);
} while (bytes > 0); } while (bytes > 0);
alGenBuffers(1, &snd->buffer_id); alGenBuffers(1, &snd->buffer_id);
alBufferData(snd->buffer_id, snd->format, alBufferData(snd->buffer_id, snd->format,
&(snd->buffer[0]), snd->buffer.size(), &buffer[0], buffer.size(),
snd->freq); snd->freq);
ALenum error = alGetError(); ALenum error = alGetError();
@ -170,6 +170,7 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
// << filename_for_logging << " loaded" << std::endl; // << filename_for_logging << " loaded" << std::endl;
// Clean up! // Clean up!
buffer.clear();
ov_clear(oggFile); ov_clear(oggFile);
return snd; return snd;