Skip to content

Commit 767c2e9

Browse files
committed
Swap to correct endianness
1 parent 2d2d09b commit 767c2e9

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

ch32v305/src/feature/fm_audio_out/fm_audio_out.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ bool fm_audio_out_process_i2s_words_isr(volatile uint16_t const *src_words, size
175175
frame_count = word_count / 4U;
176176
for(i = 0U; i < frame_count; ++i)
177177
{
178-
uint16_t i_hi = src_words[i * 4U + 1U];
179-
uint16_t i_lo = src_words[i * 4U + 0U];
180-
uint16_t q_hi = src_words[i * 4U + 3U];
181-
uint16_t q_lo = src_words[i * 4U + 2U];
178+
uint16_t i_hi = src_words[i * 4U + 0U];
179+
uint16_t i_lo = src_words[i * 4U + 1U];
180+
uint16_t q_hi = src_words[i * 4U + 2U];
181+
uint16_t q_lo = src_words[i * 4U + 3U];
182182
int32_t i_now = (int32_t)(((uint32_t)i_hi << 16) | (uint32_t)i_lo);
183183
int32_t q_now = (int32_t)(((uint32_t)q_hi << 16) | (uint32_t)q_lo);
184184

ch32v305/src/hw/i2s_hw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void i2s_process_buf(volatile uint16_t const *src_words)
9999
uint32_t coincidences = 0;
100100
for(size_t i = 0; i < I2S_RX_DMA_CHUNK_WORDS - 4; i += 2U)
101101
{
102-
uint32_t sample_32 = ((uint32_t)src_words[i + 1U] << 16) | src_words[i];
102+
uint32_t sample_32 = ((uint32_t)src_words[i] << 16) | src_words[i + 1U];
103103
bool first_two_bits_same = (sample_32 >> 31) == ((sample_32 >> 30) & 1);
104104
bool last_bit_different = (sample_32 >> 31) != (sample_32 & 1);
105105
coincidences += first_two_bits_same && last_bit_different;
@@ -325,7 +325,7 @@ bool i2s_needs_reset(void)
325325
if ((s_i2s_reset_coincidences < s_i2s_coincidences_samples / 2 - thres) ||
326326
(s_i2s_reset_coincidences > s_i2s_coincidences_samples / 2 + thres)) {
327327
// Is bitslipped, request reset outside the ISR.
328-
uint32_t sample_32 = ((uint32_t)s_rx_dma_buf[1] << 16) | s_rx_dma_buf[0];
328+
uint32_t sample_32 = ((uint32_t)s_rx_dma_buf[0] << 16) | s_rx_dma_buf[1];
329329
printf("coincidences: %ld/%ld, thres: %ld, sample: %08lX\n", s_i2s_reset_coincidences, s_i2s_coincidences_samples, thres, sample_32);
330330
ret = true;
331331
}

ui/src/lib/data.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const IQ_FIXED_POINT_SCALE = 1 / 0x80000000
88
const BYTES_PER_MB = 1000 * 1000
99

1010
function decodeSlotSample(view, offset) {
11-
return view.getInt32(offset, true) * IQ_FIXED_POINT_SCALE
11+
const hiWord = view.getUint16(offset, true)
12+
const loWord = view.getUint16(offset + 2, true)
13+
const sample = ((hiWord << 16) | loWord) >> 0
14+
return sample * IQ_FIXED_POINT_SCALE
1215
}
1316

1417
function decodeIqFrames(dataView) {

0 commit comments

Comments
 (0)