From: Daniel Elstner Date: Tue, 18 Feb 2014 22:41:33 +0000 (+0100) Subject: decode: Fix mixup of bytes vs samples X-Git-Tag: pulseview-0.2.0~62 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c2d4e9df36b9c19c691ff6fcb57066fd84a652e3;p=pulseview.git decode: Fix mixup of bytes vs samples (DecoderStack::decode_proc): The final argument to srd_session_send() is a byte count, not a sample count. (LogicSnapshot::get_samples): Multiply start_sample by the unit size to get the byte offset into the buffer. --- diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 74ad7d36..e667693e 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -260,8 +260,9 @@ void DecoderStack::decode_proc(shared_ptr data) const shared_ptr &snapshot = snapshots.front(); const int64_t sample_count = snapshot->get_sample_count(); + const unsigned int unit_size = snapshot->unit_size(); const unsigned int chunk_sample_count = - DecodeChunkLength / snapshot->unit_size(); + DecodeChunkLength / unit_size; // Create the session srd_session_new(&session); @@ -305,8 +306,8 @@ void DecoderStack::decode_proc(shared_ptr data) i + chunk_sample_count, sample_count); snapshot->get_samples(chunk, i, chunk_end); - if (srd_session_send(session, i, i + sample_count, - chunk, chunk_end - i) != SRD_OK) { + if (srd_session_send(session, i, i + sample_count, chunk, + (chunk_end - i) * unit_size) != SRD_OK) { _error_message = tr("Decoder reported an error"); break; } diff --git a/pv/data/logicsnapshot.cpp b/pv/data/logicsnapshot.cpp index 444fa9ec..797a00bc 100644 --- a/pv/data/logicsnapshot.cpp +++ b/pv/data/logicsnapshot.cpp @@ -164,7 +164,7 @@ void LogicSnapshot::get_samples(uint8_t *const data, lock_guard lock(_mutex); const size_t size = (end_sample - start_sample) * _unit_size; - memcpy(data, (const uint8_t*)_data + start_sample, size); + memcpy(data, (const uint8_t*)_data + start_sample * _unit_size, size); } void LogicSnapshot::reallocate_mipmap_level(MipMapLevel &m)