Fix crash on unaligned volume scale
Volume scaling would potentially crash when handling unaligned blocks of samples, and also handled them completely wrong. It should be counting up single samples until the buffer is aligned to a multiple of 16 bytes, and it should not exceed the intended count. BUG: It was not only counting the unaligned samples backwards, it was ignoring the real sample count. Fixes #380 Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
1c95771ed0
commit
42ea824972
1 changed files with 6 additions and 4 deletions
|
@ -76,15 +76,17 @@ void scale_by_volume(float *buffer, size_t count, float volume) {
|
|||
if(volume != 1.0) {
|
||||
size_t unaligned = (uintptr_t)buffer & 15;
|
||||
if(unaligned) {
|
||||
size_t count3 = unaligned >> 2;
|
||||
while(count3 > 0) {
|
||||
size_t count_unaligned = (16 - unaligned) / sizeof(float);
|
||||
while(count > 0 && count_unaligned > 0) {
|
||||
*buffer++ *= volume;
|
||||
count3--;
|
||||
count_unaligned--;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
vDSP_vsmul(buffer, 1, &volume, buffer, 1, count);
|
||||
if(count) {
|
||||
vDSP_vsmul(buffer, 1, &volume, buffer, 1, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue