Skip to content

Commit cb0ea52

Browse files
committed
Fix potential issue on hydrasdr_set_decimation_mode() to re-apply samplerate on mode change
1 parent 296dc3e commit cb0ea52

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

libhydrasdr/src/hydrasdr_shared.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,10 +1618,16 @@ int hydrasdr_generic_get_hardware_samplerate(struct hydrasdr_device* dev, uint32
16181618

16191619
/*
16201620
* Set decimation mode (LOW_BANDWIDTH or HIGH_DEFINITION)
1621+
*
1622+
* If a sample rate is already configured, re-apply it with the new mode
1623+
* so that the decimation pipeline is immediately reconfigured.
1624+
* On failure, the previous mode is restored for consistency.
16211625
*/
16221626
int hydrasdr_generic_set_decimation_mode(struct hydrasdr_device* dev, uint32_t mode)
16231627
{
16241628
hydrasdr_streaming_t* stream;
1629+
uint32_t prev_mode;
1630+
int result;
16251631

16261632
if (!dev || !dev->private_data) {
16271633
return HYDRASDR_ERROR_INVALID_PARAM;
@@ -1633,7 +1639,24 @@ int hydrasdr_generic_set_decimation_mode(struct hydrasdr_device* dev, uint32_t m
16331639
}
16341640

16351641
stream = (hydrasdr_streaming_t*)dev->private_data;
1642+
prev_mode = stream->decimation_mode;
1643+
1644+
if (mode == prev_mode) {
1645+
return HYDRASDR_SUCCESS;
1646+
}
1647+
16361648
stream->decimation_mode = mode;
1649+
1650+
/* Re-apply current sample rate with new mode */
1651+
if (stream->effective_samplerate > 0) {
1652+
result = hydrasdr_generic_set_samplerate(dev,
1653+
stream->effective_samplerate);
1654+
if (result != HYDRASDR_SUCCESS) {
1655+
stream->decimation_mode = prev_mode;
1656+
return result;
1657+
}
1658+
}
1659+
16371660
return HYDRASDR_SUCCESS;
16381661
}
16391662

0 commit comments

Comments
 (0)