mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-25 18:30:21 +00:00
Corrects logic for avoiding overwrite.
This commit is contained in:
parent
12c59ede09
commit
e0b75b6e3d
@ -46,16 +46,18 @@ void PCMSegmentEventSource::reset() {
|
||||
PCMSegment &PCMSegment::operator +=(const PCMSegment &rhs) {
|
||||
if(!rhs.number_of_bits) return *this;
|
||||
|
||||
assert(((rhs.number_of_bits+7) >> 3) == rhs.data.size());
|
||||
|
||||
if(number_of_bits&7) {
|
||||
auto target_number_of_bits = number_of_bits + rhs.number_of_bits;
|
||||
data.resize((target_number_of_bits + 7) >> 3);
|
||||
|
||||
std::size_t first_byte = number_of_bits >> 3;
|
||||
|
||||
int shift = number_of_bits&7;
|
||||
const int shift = number_of_bits&7;
|
||||
for(std::size_t source = 0; source < rhs.data.size(); ++source) {
|
||||
data[first_byte + source] |= rhs.data[source] >> shift;
|
||||
if(source*8 + static_cast<std::size_t>(shift) < rhs.number_of_bits)
|
||||
if(source*8 + static_cast<std::size_t>(8 - shift) < rhs.number_of_bits)
|
||||
data[first_byte + source + 1] = static_cast<uint8_t>(rhs.data[source] << (8-shift));
|
||||
}
|
||||
|
||||
@ -65,6 +67,8 @@ PCMSegment &PCMSegment::operator +=(const PCMSegment &rhs) {
|
||||
number_of_bits += rhs.number_of_bits;
|
||||
}
|
||||
|
||||
assert(((number_of_bits+7) >> 3) == data.size());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user