From 16b60d5ca0c9f50b0f1b156237334b8210ea6f20 Mon Sep 17 00:00:00 2001 From: Yasser Yassine Date: Tue, 19 Mar 2024 20:36:21 +0000 Subject: [PATCH] A2B: Fix get & set with upstream direction --- communication/message/a2bmessage.cpp | 7 +++---- test/a2bencoderdecodertest.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/communication/message/a2bmessage.cpp b/communication/message/a2bmessage.cpp index c43bf23..4c12567 100644 --- a/communication/message/a2bmessage.cpp +++ b/communication/message/a2bmessage.cpp @@ -59,7 +59,7 @@ size_t A2BMessage::getSampleOffset(Direction dir, uint8_t channel, size_t frame) size_t sampleOffset = static_cast(frameSize * frame + 2 * channel * getBytesPerChannel()); if(dir == Direction::Upstream) { - sampleOffset++; + sampleOffset += getBytesPerChannel(); } return sampleOffset; @@ -152,7 +152,6 @@ PCMSample A2BMessage::getChannelSample(Direction dir, uint8_t channel, size_t fr void A2BMessage::setChannelSample(Direction dir, uint8_t channel, size_t frame, PCMSample sampleToSet, PCMType pcmType) { size_t sampleOffset = getSampleOffset(dir, channel, frame); - uint8_t* audioData = data.data(); uint32_t& uSample = *reinterpret_cast(&sampleToSet); // Align the bytes towards the most significant bit by multiplying using @@ -168,10 +167,10 @@ void A2BMessage::setChannelSample(Direction dir, uint8_t channel, size_t frame, if(channelSize16) { // Read the 2 most significant bytes of the sample - SAMPLE_TO_BYTES_16(audioData, sampleOffset, uSample) + SAMPLE_TO_BYTES_16(data, sampleOffset, uSample) } else { // Read the entire sample - SAMPLE_TO_BYTES_32(audioData, sampleOffset, uSample); + SAMPLE_TO_BYTES_32(data, sampleOffset, uSample); } } diff --git a/test/a2bencoderdecodertest.cpp b/test/a2bencoderdecodertest.cpp index 64307e6..946c7c1 100644 --- a/test/a2bencoderdecodertest.cpp +++ b/test/a2bencoderdecodertest.cpp @@ -71,6 +71,21 @@ TEST_F(A2BEncoderDecoderTest, PacketEncoderTest) packetEncoder->encode(*packetizer, bytestream, messagePtr); EXPECT_EQ(bytestream, testBytes); + + message.setChannelSample( + icsneo::A2BMessage::Direction::Upstream, + static_cast(1u), + 0u, + -102, + icsneo::PCMType::L16 + ); + + EXPECT_EQ(message.getChannelSample( + icsneo::A2BMessage::Direction::Upstream, + static_cast(1u), + 0u, + icsneo::PCMType::L16 + ), -102); } TEST_F(A2BEncoderDecoderTest, PacketDecoderTest)