laforge
/
openbts-osmo
Archived
1
0
Fork 0

transceiver: minor cleanup of sample type sizing in uhd

A small simplification of buffer indexing and sizing.

Signed-off-by: Thomas Tsou <ttsou@vt.edu>
master
Thomas Tsou 11 years ago
parent 331755f458
commit 0b974109a8
  1. 16
      public-trunk/Transceiver52M/UHDDevice.cpp

@ -792,6 +792,8 @@ ssize_t smpl_buf::avail_smpls(uhd::time_spec_t timespec) const
ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp)
{
int type_sz = 2 * sizeof(short);
// Check for valid read
if (timestamp < time_start)
return ERROR_TIMESTAMP;
@ -810,11 +812,11 @@ ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp)
// Read it
if (read_start + num_smpls < buf_len) {
size_t numBytes = len * 2 * sizeof(short);
size_t numBytes = len * type_sz;
memcpy(buf, data + read_start, numBytes);
} else {
size_t first_cp = (buf_len - read_start) * 2 * sizeof(short);
size_t second_cp = len * 2 * sizeof(short) - first_cp;
size_t first_cp = (buf_len - read_start) * type_sz;
size_t second_cp = len * type_sz - first_cp;
memcpy(buf, data + read_start, first_cp);
memcpy((char*) buf + first_cp, data, second_cp);
@ -836,6 +838,8 @@ ssize_t smpl_buf::read(void *buf, size_t len, uhd::time_spec_t ts)
ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp)
{
int type_sz = 2 * sizeof(short);
// Check for valid write
if ((len == 0) || (len >= buf_len))
return ERROR_WRITE;
@ -847,11 +851,11 @@ ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp)
// Write it
if ((write_start + len) < buf_len) {
size_t numBytes = len * 2 * sizeof(short);
size_t numBytes = len * type_sz;
memcpy(data + write_start, buf, numBytes);
} else {
size_t first_cp = (buf_len - write_start) * 2 * sizeof(short);
size_t second_cp = len * 2 * sizeof(short) - first_cp;
size_t first_cp = (buf_len - write_start) * type_sz;
size_t second_cp = len * type_sz - first_cp;
memcpy(data + write_start, buf, first_cp);
memcpy(data, (char*) buf + first_cp, second_cp);