Skip to content

Commit

Permalink
Merge pull request #90 from pothosware/fix-cs16cs8-scale
Browse files Browse the repository at this point in the history
Fix scaling in CS16-CS8 conversion
  • Loading branch information
zuckschwerdt authored Jan 21, 2024
2 parents 3aadac6 + ffcae2d commit cd756d7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client/ClientStreamData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ void ClientStreamData::convertRecvBuffs(void * const *buffs, const size_t numEle
case CONVERT_CS16_CS8:
///////////////////////////
{
// note that we expect CS8 scaleFactor to be power of 2, usually 128
const int scale = 32768/int(scaleFactor);
for (size_t i = 0; i < recvBuffs.size(); i++)
{
auto in = (int8_t *)recvBuffs[i];
auto out = (int16_t *)buffs[i];
for (size_t j = 0; j < numElems*2; j++)
{
out[j] = int16_t(in[j]);
out[j] = int16_t(in[j])*scale;
}
}
}
Expand Down Expand Up @@ -236,13 +238,15 @@ void ClientStreamData::convertSendBuffs(const void * const *buffs, const size_t
case CONVERT_CS16_CS8:
///////////////////////////
{
// note that we expect CS16 scaleFactor to be a power of 2, usually 2048
const int scale = int(scaleFactor + 1)/128; // round e.g. 2047.0 and 32767.0
for (size_t i = 0; i < sendBuffs.size(); i++)
{
auto in = (int16_t *)buffs[i];
auto out = (int8_t *)sendBuffs[i];
for (size_t j = 0; j < numElems*2; j++)
{
out[j] = int8_t(in[j]);
out[j] = int8_t(in[j]/scale);
}
}
}
Expand Down

0 comments on commit cd756d7

Please sign in to comment.