SoundDataSetSample: only allowed on raw; and check frames instead of blob size

This commit is contained in:
Nevyn Bengtsson 2020-12-15 10:15:24 +01:00 committed by Bjorn
parent 5df40bb103
commit eee1d09cc4
1 changed files with 2 additions and 2 deletions

View File

@ -191,8 +191,8 @@ size_t lovrSoundDataStreamAppendSound(SoundData *dest, SoundData *src) {
}
void lovrSoundDataSetSample(SoundData* soundData, size_t index, float value) {
size_t byteIndex = index * SampleFormatBytesPerFrame(soundData->channels, soundData->format);
lovrAssert(byteIndex < soundData->blob->size, "Sample index out of range");
lovrAssert(soundData->blob && soundData->read == lovrSoundDataReadRaw, "Source SoundData must have static PCM data and not be a stream");
lovrAssert(index < soundData->frames, "Sample index out of range");
switch (soundData->format) {
case SAMPLE_I16: ((int16_t*) soundData->blob->data)[index] = value * SHRT_MAX; break;
case SAMPLE_F32: ((float*) soundData->blob->data)[index] = value; break;