* [FFmpeg-devel] [PATCH 02/12] avradio/avformat/sdrdemux: Move Software AGC into buffer thread
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 03/12] avradio/avdevice/sdrindev: Soapy / RTLSDR ignores gain in direct sampling mode Michael Niedermayer
` (11 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
This allows the AGC to act with less latency
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdr.h | 1 -
libavformat/sdrdemux.c | 77 ++++++++++++++++++++++++------------------
2 files changed, 44 insertions(+), 34 deletions(-)
diff --git a/libavformat/sdr.h b/libavformat/sdr.h
index 1f2d3a49ab..1bf8fbef79 100644
--- a/libavformat/sdr.h
+++ b/libavformat/sdr.h
@@ -161,7 +161,6 @@ typedef struct SDRContext {
float agc_max_headroom;
float agc_max_headroom_time;
int agc_low_time;
- atomic_int wanted_gain;
int sdr_adcc;
int64_t bandwidth;
int64_t last_pts;
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 4bde431e17..e5ee4e80f5 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1475,6 +1475,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
unsigned block_counter = 0;
int64_t local_wanted_freq = 0;
int64_t last_wanted_freq = 0;
+ float wanted_gain = (sdr->min_gain + sdr->max_gain) / 2;
float agc_gain = 0;
sdr->remaining_file_block_size = 0;
@@ -1485,7 +1486,6 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
FIFOElement fifo_element;
int remaining, ret;
int empty_blocks, full_blocks;
- float wanted_gain = atomic_load(&sdr->wanted_gain) / 65536.0;
int64_t wanted_freq = atomic_load(&sdr->wanted_freq);
int seek_direction = atomic_load(&sdr->seek_direction);
@@ -1551,6 +1551,49 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
remaining -= ret;
}
+ if (sdr->sdr_gain == GAIN_SW_AGC) {
+ float inmax = 0;
+ int inmax1 = 0;
+ // We only check 25% of the data to safe computations
+ int start = 3*sdr->block_size / 4;
+ int end = 5*sdr->block_size / 4;
+ if (sdr->sample_size == 2) {
+ const int8_t *halfblock = fifo_element.halfblock;
+ for (int i = start; i < end; i++) {
+ int v = FFMAX(FFABS(halfblock[i]), FFABS(halfblock[i]));
+ inmax1 = FFMAX(inmax1, v);
+ }
+ } else if (sdr->sample_size == 4) {
+ const int16_t *halfblock = fifo_element.halfblock;
+ for (int i = start; i < end; i++) {
+ int v = FFMAX(FFABS(halfblock[i]), FFABS(halfblock[i]));
+ inmax1 = FFMAX(inmax1, v);
+ }
+ } else {
+ const float *halfblock = fifo_element.halfblock;
+ for (int i = start; i < end; i++) {
+ float v = fmaxf(fabsf(halfblock[i]), fabsf(halfblock[i]));
+ inmax = fmaxf(inmax, v);
+ }
+ }
+ inmax = fmaxf(inmax, inmax1 / sdr->sample_scale);
+
+ if (inmax > 1.0 - sdr->agc_min_headroom && wanted_gain > sdr->min_gain) {
+ //according to docs this is a dB scale, in reality it beheaves differnt to that
+ //Because of this we will try to just make small changes and not assume too much
+ wanted_gain = FFMIN(wanted_gain, FFMAX(agc_gain - 1.0, agc_gain * 0.9));
+
+ sdr->agc_low_time = 0;
+ } else if (inmax < 1.0 - sdr->agc_max_headroom && wanted_gain < sdr->max_gain) {
+ sdr->agc_low_time += sdr->block_size;
+ if (sdr->agc_low_time > sdr->agc_max_headroom_time * sdr->sdr_sample_rate) {
+ sdr->agc_low_time = 0;
+ wanted_gain = FFMAX(wanted_gain, FFMIN(agc_gain + 1.0, agc_gain * 1.1));
+ }
+ } else
+ sdr->agc_low_time = 0;
+ }
+
inject_block_into_fifo(sdr, sdr->full_block_fifo, &fifo_element, "block fifo overflow, discarding block\n");
}
av_assert0(atomic_load(&sdr->close_requested) == 1);
@@ -1724,7 +1767,6 @@ int avpriv_sdr_common_init(AVFormatContext *s)
atomic_init(&sdr->close_requested, 0);
atomic_init(&sdr->seek_direction, 0);
atomic_init(&sdr->wanted_freq, sdr->user_wanted_freq);
- atomic_init(&sdr->wanted_gain, lrint((sdr->min_gain + sdr->max_gain) * 65536 / 2));
ret = pthread_mutex_init(&sdr->mutex, NULL);
if (ret) {
av_log(s, AV_LOG_ERROR, "pthread_mutex_init failed: %s\n", strerror(ret));
@@ -2021,37 +2063,6 @@ process_next_block:
}
}
- float smaller_block_gain = FFMIN(fifo_element[0].gain, fifo_element[1].gain);
- float bigger_block_gain = FFMAX(fifo_element[0].gain, fifo_element[1].gain);
-
- if (sdr->sdr_gain == GAIN_SW_AGC) {
- float inmax = 0;
- float wanted_gain = atomic_load(&sdr->wanted_gain) / 65536.0;
- // We only check 25% of the data to safe computations
- int start = 3*sdr->block_size / 4;
- int end = 5*sdr->block_size / 4;
- for (i = start; i < end; i++) {
- float v = fmaxf(fabsf(sdr->windowed_block[i].re), fabsf(sdr->windowed_block[i].im));
- inmax = fmaxf(inmax, v);
- }
-
- if (inmax > 1.0 - sdr->agc_min_headroom && wanted_gain > sdr->min_gain) {
- //according to docs this is a dB scale, in reality it beheaves differnt to that
- //Because of this we will try to just make small changes and not assume too much
- wanted_gain = FFMIN(wanted_gain, FFMAX(smaller_block_gain - 1.0, smaller_block_gain * 0.9));
-
- sdr->agc_low_time = 0;
- } else if (inmax < 1.0 - sdr->agc_max_headroom && wanted_gain < sdr->max_gain) {
- sdr->agc_low_time += sdr->block_size;
- if (sdr->agc_low_time > sdr->agc_max_headroom_time * sdr->sdr_sample_rate) {
- sdr->agc_low_time = 0;
- wanted_gain = FFMAX(wanted_gain, FFMIN(bigger_block_gain + 1.0, bigger_block_gain * 1.1));
- }
- } else
- sdr->agc_low_time = 0;
- atomic_store(&sdr->wanted_gain, (int)lrint(wanted_gain * 65536));
- }
-
inject_block_into_fifo(sdr, sdr->empty_block_fifo, &fifo_element[0], "Cannot pass next buffer, freeing it\n");
#ifdef SYN_TEST //synthetic test signal
static int64_t synp=0;
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 03/12] avradio/avdevice/sdrindev: Soapy / RTLSDR ignores gain in direct sampling mode
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 02/12] avradio/avformat/sdrdemux: Move Software AGC into buffer thread Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 04/12] avradio/avformat/sdrdemux: only update agc_gain on success Michael Niedermayer
` (10 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavdevice/sdrindev.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libavdevice/sdrindev.c b/libavdevice/sdrindev.c
index f07bd6b154..8766fc2f34 100644
--- a/libavdevice/sdrindev.c
+++ b/libavdevice/sdrindev.c
@@ -88,6 +88,10 @@ static int sdrindev_set_gain_callback(SDRContext *sdr, float gain)
}
if (sdr->sdr_gain != GAIN_SDR_AGC) {
+ if (sdr->current_direct_samp && !strcmp(sdr->current_direct_samp, "2")) {
+ return -1; // soapy ignores gain in direct sampling mode
+ }
+
ret = SoapySDRDevice_setGain(soapy, SOAPY_SDR_RX, 0, gain);
if (ret) {
av_log(avfmt, AV_LOG_WARNING, "Failed to set gain to %f (%s)\n", gain, SoapySDRDevice_lastError());
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 04/12] avradio/avformat/sdrdemux: only update agc_gain on success
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 02/12] avradio/avformat/sdrdemux: Move Software AGC into buffer thread Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 03/12] avradio/avdevice/sdrindev: Soapy / RTLSDR ignores gain in direct sampling mode Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 05/12] avradio/avformat/sdrdemux: delay station search on AGC adjust Michael Niedermayer
` (9 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index e5ee4e80f5..fa45d30a3d 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1533,8 +1533,10 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
fabs(wanted_gain - agc_gain) > 0.001 &&
sdr->set_gain_callback
) {
- sdr->set_gain_callback(sdr, wanted_gain);
- agc_gain = wanted_gain;
+ int ret = sdr->set_gain_callback(sdr, wanted_gain);
+ if (ret >= 0) {
+ agc_gain = wanted_gain;
+ }
}
pthread_mutex_unlock(&sdr->mutex);
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 05/12] avradio/avformat/sdrdemux: delay station search on AGC adjust
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (2 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 04/12] avradio/avformat/sdrdemux: only update agc_gain on success Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 06/12] avradio/avformat/sdrdemux: run clip check on the correct samples Michael Niedermayer
` (8 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index fa45d30a3d..44a6489bd2 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1536,6 +1536,8 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
int ret = sdr->set_gain_callback(sdr, wanted_gain);
if (ret >= 0) {
agc_gain = wanted_gain;
+ if (block_counter)
+ block_counter = 1;
}
}
pthread_mutex_unlock(&sdr->mutex);
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 06/12] avradio/avformat/sdrdemux: run clip check on the correct samples
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (3 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 05/12] avradio/avformat/sdrdemux: delay station search on AGC adjust Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 07/12] avradio/avformat/sdrdemux: Avoid uninitialized memory on mono -> stereo switch Michael Niedermayer
` (7 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 44a6489bd2..69349add7b 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1153,10 +1153,9 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
sst->out_buf[2*i+0] =
sst->out_buf[2*i+1] = m;
}
-
- if (fabs(sst->out_buf[i]) > clip) {
- av_log(sdr->avfmt, AV_LOG_WARNING, "CLIP %f\n", sst->out_buf[i]);
- clip = fabs(sst->out_buf[i]) * 1.1;
+ if (fmax(fabs(sst->out_buf[2*i+0]), fabs(sst->out_buf[2*i+1])) > clip) {
+ av_log(sdr->avfmt, AV_LOG_WARNING, "CLIP %f %f\n", sst->out_buf[2*i+0], sst->out_buf[2*i+1]);
+ clip = fmax(fabs(sst->out_buf[2*i+0]), fabs(sst->out_buf[2*i+1])) * 1.1;
}
}
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 07/12] avradio/avformat/sdrdemux: Avoid uninitialized memory on mono -> stereo switch
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (4 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 06/12] avradio/avformat/sdrdemux: run clip check on the correct samples Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 08/12] avradio/avformat/sdrdemux: set wanted gain also when manually set Michael Niedermayer
` (6 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 69349add7b..8f0f4657f3 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1150,6 +1150,8 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
sst->out_buf[2*i+0] = m + q;
sst->out_buf[2*i+1] = m - q;
} else {
+ newbuf[2*i+1] = 0;
+
sst->out_buf[2*i+0] =
sst->out_buf[2*i+1] = m;
}
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 08/12] avradio/avformat/sdrdemux: set wanted gain also when manually set
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (5 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 07/12] avradio/avformat/sdrdemux: Avoid uninitialized memory on mono -> stereo switch Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 09/12] avradio/avformat/sdrdemux: dont use a fuction name as local variable Michael Niedermayer
` (5 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 8f0f4657f3..3f3390049c 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1476,7 +1476,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
unsigned block_counter = 0;
int64_t local_wanted_freq = 0;
int64_t last_wanted_freq = 0;
- float wanted_gain = (sdr->min_gain + sdr->max_gain) / 2;
+ float wanted_gain = sdr->sdr_gain < 0 ? (sdr->min_gain + sdr->max_gain) / 2 : sdr->sdr_gain;
float agc_gain = 0;
sdr->remaining_file_block_size = 0;
@@ -1530,7 +1530,8 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
//And theres not much else we can do, an error message was already printed by ff_sdr_set_freq() in that case
block_counter = 0; // we just changed the frequency, do not trust the next blocks content
}
- if (sdr->sdr_gain == GAIN_SW_AGC &&
+ if (sdr->sdr_gain != GAIN_SDR_AGC &&
+ sdr->sdr_gain != GAIN_DEFAULT &&
fabs(wanted_gain - agc_gain) > 0.001 &&
sdr->set_gain_callback
) {
@@ -1539,6 +1540,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
agc_gain = wanted_gain;
if (block_counter)
block_counter = 1;
+ av_log(avfmt, AV_LOG_DEBUG, "GAIN changed %f\n", wanted_gain);
}
}
pthread_mutex_unlock(&sdr->mutex);
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 09/12] avradio/avformat/sdrdemux: dont use a fuction name as local variable
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (6 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 08/12] avradio/avformat/sdrdemux: set wanted gain also when manually set Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 10/12] avradio/avformat/sdrdemux: fix off by 2 FM bandwidth error Michael Niedermayer
` (4 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 3f3390049c..0e327f4860 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1043,13 +1043,13 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
double carrier19_i_exact;
int W= 5;
double dc = 0, dcw = 0;
- int len2 = FFMIN(index, 2*sdr->block_size - index);
+ int lenmax = FFMIN(index, 2*sdr->block_size - index);
av_assert0(!st || (sst == station->stream && sst->station == station));
//If only some of the bandwidth is available, just try with less
- if (len2 < len && len2 > len/2)
- len = len2;
+ if (lenmax < len && lenmax > len/2)
+ len = lenmax;
if (index + len >= 2*sdr->block_size ||
index - len < 0 ||
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 10/12] avradio/avformat/sdrdemux: fix off by 2 FM bandwidth error
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (7 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 09/12] avradio/avformat/sdrdemux: dont use a fuction name as local variable Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 11/12] avradio/avformat/sdrdemux: fix FM block size Michael Niedermayer
` (3 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Also adjust related parameters
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 8 ++++----
tests/ref/fate/sdr-am | 25 ++++++++++++-------------
tests/ref/fate/sdr-fm | 14 +++++++-------
3 files changed, 23 insertions(+), 24 deletions(-)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 0e327f4860..a40346ff31 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -704,7 +704,7 @@ static int demodulate_am(SDRContext *sdr, Station *station, AVStream *st, AVPack
double freq = station->frequency;
int64_t bandwidth = station->bandwidth;
int index = lrint(F2INDEX(freq));
- int len = (bandwidth * 2ll * sdr->block_size + sdr->sdr_sample_rate/2) / sdr->sdr_sample_rate;
+ int len = (bandwidth * 1ll * sdr->block_size + sdr->sdr_sample_rate/2) / sdr->sdr_sample_rate;
float *newbuf;
float scale;
int sample_rate = sdr->sdr_sample_rate * (int64_t)sdr->am_block_size / sdr->block_size;
@@ -1030,7 +1030,7 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
double freq = station->frequency;
int64_t bandwidth = station->bandwidth;
int index = lrint(F2INDEX(freq));
- int len = (bandwidth * 2ll * sdr->block_size + sdr->sdr_sample_rate/2) / sdr->sdr_sample_rate;
+ int len = (bandwidth * 1ll * sdr->block_size + sdr->sdr_sample_rate/2) / sdr->sdr_sample_rate;
float *newbuf;
float scale;
int sample_rate = sdr->sdr_sample_rate * (int64_t)sdr->fm_block_size / sdr->block_size;
@@ -1687,11 +1687,11 @@ int avpriv_sdr_common_init(AVFormatContext *s)
av_log(s, AV_LOG_INFO, "Block size %d\n", sdr->block_size);
sdr->block_time = sdr->block_size / (double)sdr->sdr_sample_rate;
- sdr->am_bandwidth = 6 * 1000;
+ sdr->am_bandwidth = 12 * 1000;
sdr->fm_bandwidth = 180 * 1000;
sdr->fm_bandwidth_p2 = 16.5 * 1000; // Officially Stereo Broadcast FM has 15khz audio bandwidth
- sdr->am_block_size = find_block_size(sdr, sdr->am_bandwidth);
+ sdr->am_block_size = find_block_size(sdr, sdr->am_bandwidth / 2);
sdr->fm_block_size = find_block_size(sdr, sdr->fm_bandwidth);
sdr->fm_block_size_p2 = find_block_size(sdr, sdr->fm_bandwidth_p2);
diff --git a/tests/ref/fate/sdr-am b/tests/ref/fate/sdr-am
index e2ae353902..992ec1936d 100644
--- a/tests/ref/fate/sdr-am
+++ b/tests/ref/fate/sdr-am
@@ -30,18 +30,17 @@
#channel_layout_name 5: stereo
0, 0, 0, 1, 320000, 0x816a0964
0, 1, 1, 1, 320000, 0x140ce2da
-1, 2048, 2048, 1024, 2048, 0x4d31ff0f
-2, 2048, 2048, 1024, 2048, 0x3cd002ad
-3, 2048, 2048, 1024, 2048, 0x8bdd034d
-4, 2048, 2048, 1024, 2048, 0xc6430169
-1, 3072, 3072, 1024, 2048, 0xb307000d
-2, 3072, 3072, 1024, 2048, 0x3f6d01d4
-3, 3072, 3072, 1024, 2048, 0x2de9fde9
-4, 3072, 3072, 1024, 2048, 0xad7efe6f
+1, 2048, 2048, 1024, 2048, 0x3cd002ad
+2, 2048, 2048, 1024, 2048, 0x8bdd034d
+3, 2048, 2048, 1024, 2048, 0xc6430169
+1, 3072, 3072, 1024, 2048, 0x3f6d01d4
+2, 3072, 3072, 1024, 2048, 0x2de9fde9
+3, 3072, 3072, 1024, 2048, 0xad7efe6f
+4, 3072, 3072, 1024, 2048, 0x2c18fef7
5, 3072, 3072, 1024, 2048, 0x9c840168
-1, 4096, 4096, 1024, 2048, 0x7e7cfe03
-2, 4096, 4096, 1024, 2048, 0x6561fc7b
-3, 4096, 4096, 1024, 2048, 0xdcd6ff8d
-4, 4096, 4096, 1024, 2048, 0xedac0493
+1, 4096, 4096, 1024, 2048, 0x6561fc7b
+2, 4096, 4096, 1024, 2048, 0xdcd6ff8d
+3, 4096, 4096, 1024, 2048, 0xedac0493
+4, 4096, 4096, 1024, 2048, 0x7e7cfe03
5, 4096, 4096, 1024, 2048, 0x970a0066
-0, 3, 3, 1, 320000, 0x6ea8fa49
+0, 3, 3, 1, 320000, 0x76d901a2
diff --git a/tests/ref/fate/sdr-fm b/tests/ref/fate/sdr-fm
index 3ae5adc2c0..97a2320a2a 100644
--- a/tests/ref/fate/sdr-fm
+++ b/tests/ref/fate/sdr-fm
@@ -15,11 +15,11 @@
#channel_layout_name 2: stereo
0, 0, 0, 1, 320000, 0xf553af75
0, 1, 1, 1, 320000, 0xeabc15b3
-1, 8196, 8196, 4096, 8192, 0x585d090e
-2, 8196, 8196, 4096, 8192, 0xb966fb19
-1, 12292, 12292, 4096, 8192, 0x6d8ffe6e
-2, 12292, 12292, 4096, 8192, 0x51d1fb50
+1, 8196, 8196, 4096, 8192, 0x4af5090c
+2, 8196, 8196, 4096, 8192, 0x8e43fafd
+1, 12292, 12292, 4096, 8192, 0x39fbfe6a
+2, 12292, 12292, 4096, 8192, 0x7febfb59
0, 3, 3, 1, 320000, 0xf8b7b144
-1, 16388, 16388, 4096, 8192, 0x8c000600
-2, 16388, 16388, 4096, 8192, 0x335ff20c
-0, 4, 4, 1, 320000, 0xab42bbc7
+1, 16388, 16388, 4096, 8192, 0x886a05fe
+2, 16388, 16388, 4096, 8192, 0x0b2cf20d
+0, 4, 4, 1, 320000, 0xf3a3bf66
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 11/12] avradio/avformat/sdrdemux: fix FM block size
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (8 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 10/12] avradio/avformat/sdrdemux: fix off by 2 FM bandwidth error Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 12/12] avradio/avformat/sdrdemux: replace heuristic FM scaling by logic Michael Niedermayer
` (2 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
as we copied twice the bandwith needed previously, we now also
need only half the block size.
Done in a seperate patch for easier bisection
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 2 +-
tests/ref/fate/sdr-fm | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index a40346ff31..bda7387213 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1692,7 +1692,7 @@ int avpriv_sdr_common_init(AVFormatContext *s)
sdr->fm_bandwidth_p2 = 16.5 * 1000; // Officially Stereo Broadcast FM has 15khz audio bandwidth
sdr->am_block_size = find_block_size(sdr, sdr->am_bandwidth / 2);
- sdr->fm_block_size = find_block_size(sdr, sdr->fm_bandwidth);
+ sdr->fm_block_size = find_block_size(sdr, sdr->fm_bandwidth / 2);
sdr->fm_block_size_p2 = find_block_size(sdr, sdr->fm_bandwidth_p2);
sdr->windowed_block = av_malloc(sizeof(*sdr->windowed_block) * 2 * sdr->block_size);
diff --git a/tests/ref/fate/sdr-fm b/tests/ref/fate/sdr-fm
index 97a2320a2a..ef76e4f584 100644
--- a/tests/ref/fate/sdr-fm
+++ b/tests/ref/fate/sdr-fm
@@ -15,11 +15,11 @@
#channel_layout_name 2: stereo
0, 0, 0, 1, 320000, 0xf553af75
0, 1, 1, 1, 320000, 0xeabc15b3
-1, 8196, 8196, 4096, 8192, 0x4af5090c
-2, 8196, 8196, 4096, 8192, 0x8e43fafd
-1, 12292, 12292, 4096, 8192, 0x39fbfe6a
-2, 12292, 12292, 4096, 8192, 0x7febfb59
+1, 8196, 8196, 4096, 8192, 0xdd0d10be
+2, 8196, 8196, 4096, 8192, 0x98c4f547
+1, 12292, 12292, 4096, 8192, 0xaf58fbdc
+2, 12292, 12292, 4096, 8192, 0x6d53f60a
0, 3, 3, 1, 320000, 0xf8b7b144
-1, 16388, 16388, 4096, 8192, 0x886a05fe
-2, 16388, 16388, 4096, 8192, 0x0b2cf20d
+1, 16388, 16388, 4096, 8192, 0x03640b38
+2, 16388, 16388, 4096, 8192, 0x1216e352
0, 4, 4, 1, 320000, 0xf3a3bf66
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* [FFmpeg-devel] [PATCH 12/12] avradio/avformat/sdrdemux: replace heuristic FM scaling by logic
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (9 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 11/12] avradio/avformat/sdrdemux: fix FM block size Michael Niedermayer
@ 2023-07-30 22:11 ` Michael Niedermayer
2023-07-30 22:26 ` [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Paul B Mahol
2023-09-08 13:24 ` Michael Niedermayer
12 siblings, 0 replies; 17+ messages in thread
From: Michael Niedermayer @ 2023-07-30 22:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavformat/sdrdemux.c | 4 +++-
tests/ref/fate/sdr-fm | 12 ++++++------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index bda7387213..f8590a2e18 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1135,7 +1135,9 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
if (!newbuf)
return AVERROR(ENOMEM);
- scale = 5 / (M_PI * 2*sdr->fm_block_size);
+ //ATAN gives us +-PI the following 2 transforms scale by the given values, we reverse this here
+ scale = 1.0 / (M_PI * sqrt(2*sdr->fm_block_size * 2*sdr->fm_block_size_p2));
+
for(i = 0; i<sdr->fm_block_size_p2; i++) {
float m, q;
diff --git a/tests/ref/fate/sdr-fm b/tests/ref/fate/sdr-fm
index ef76e4f584..526f53a2bd 100644
--- a/tests/ref/fate/sdr-fm
+++ b/tests/ref/fate/sdr-fm
@@ -15,11 +15,11 @@
#channel_layout_name 2: stereo
0, 0, 0, 1, 320000, 0xf553af75
0, 1, 1, 1, 320000, 0xeabc15b3
-1, 8196, 8196, 4096, 8192, 0xdd0d10be
-2, 8196, 8196, 4096, 8192, 0x98c4f547
-1, 12292, 12292, 4096, 8192, 0xaf58fbdc
-2, 12292, 12292, 4096, 8192, 0x6d53f60a
+1, 8196, 8196, 4096, 8192, 0x12b50769
+2, 8196, 8196, 4096, 8192, 0xeb93fbff
+1, 12292, 12292, 4096, 8192, 0xba21feb7
+2, 12292, 12292, 4096, 8192, 0x3ef2fc7b
0, 3, 3, 1, 320000, 0xf8b7b144
-1, 16388, 16388, 4096, 8192, 0x03640b38
-2, 16388, 16388, 4096, 8192, 0x1216e352
+1, 16388, 16388, 4096, 8192, 0xdea20516
+2, 16388, 16388, 4096, 8192, 0x7538f52b
0, 4, 4, 1, 320000, 0xf3a3bf66
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (10 preceding siblings ...)
2023-07-30 22:11 ` [FFmpeg-devel] [PATCH 12/12] avradio/avformat/sdrdemux: replace heuristic FM scaling by logic Michael Niedermayer
@ 2023-07-30 22:26 ` Paul B Mahol
2023-08-10 21:03 ` Michael Niedermayer
2023-09-08 13:24 ` Michael Niedermayer
12 siblings, 1 reply; 17+ messages in thread
From: Paul B Mahol @ 2023-07-30 22:26 UTC (permalink / raw)
To: FFmpeg development discussions and patches
NAK to whole set.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable
2023-07-30 22:26 ` [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Paul B Mahol
@ 2023-08-10 21:03 ` Michael Niedermayer
2023-08-10 23:03 ` Paul B Mahol
0 siblings, 1 reply; 17+ messages in thread
From: Michael Niedermayer @ 2023-08-10 21:03 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Jean-Baptiste Kempf
[-- Attachment #1.1: Type: text/plain, Size: 1086 bytes --]
Hi Paul
also CC-ing jb as he seemed interrested in teh subject
On Mon, Jul 31, 2023 at 12:26:50AM +0200, Paul B Mahol wrote:
> NAK to whole set.
I suggest you lift that NAK.
If you do i would apply this set of bugfixes and after that
look into, if its possible to factorize the SDR code out.
I first would do so within the same lib but once its more
seperated, maybe we can seperate the SDR code and move it
into a seperate libavradio leaving the input device/demuxer
as a user of that lib.
That would be a seperate lib and API used by a module
in libavdevice/libavformat as it was suggestes by jb
I dont know how well that refactorization would work out. I may
have looked at this from the wrong side
but as long as you block this patchset the code is stuck in
libavformat and libavdevice
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable
2023-08-10 21:03 ` Michael Niedermayer
@ 2023-08-10 23:03 ` Paul B Mahol
0 siblings, 0 replies; 17+ messages in thread
From: Paul B Mahol @ 2023-08-10 23:03 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Jean-Baptiste Kempf
On Thu, Aug 10, 2023 at 11:03 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:
> Hi Paul
>
> also CC-ing jb as he seemed interrested in teh subject
>
> On Mon, Jul 31, 2023 at 12:26:50AM +0200, Paul B Mahol wrote:
> > NAK to whole set.
>
> I suggest you lift that NAK.
>
NAK is here to stay forever, until:
All SDR related work/patches/files/posts are moved out FFmpeg's
FATE/mailing lists/Twitter.
> If you do i would apply this set of bugfixes and after that
> look into, if its possible to factorize the SDR code out.
> I first would do so within the same lib but once its more
> seperated, maybe we can seperate the SDR code and move it
> into a seperate libavradio leaving the input device/demuxer
> as a user of that lib.
> That would be a seperate lib and API used by a module
> in libavdevice/libavformat as it was suggestes by jb
>
> I dont know how well that refactorization would work out. I may
> have looked at this from the wrong side
> but as long as you block this patchset the code is stuck in
> libavformat and libavdevice
>
> thx
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Into a blind darkness they enter who follow after the Ignorance,
> they as if into a greater darkness enter who devote themselves
> to the Knowledge alone. -- Isha Upanishad
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable
2023-07-30 22:11 [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Michael Niedermayer
` (11 preceding siblings ...)
2023-07-30 22:26 ` [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable Paul B Mahol
@ 2023-09-08 13:24 ` Michael Niedermayer
2023-09-09 10:34 ` Paul B Mahol
12 siblings, 1 reply; 17+ messages in thread
From: Michael Niedermayer @ 2023-09-08 13:24 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 539 bytes --]
On Mon, Jul 31, 2023 at 12:11:20AM +0200, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> libavformat/sdr.h | 1 -
> libavformat/sdrdemux.c | 7 ++++---
> 2 files changed, 4 insertions(+), 4 deletions(-)
I will apply this patchset (of mostly bugfixes) in a few days unless there are
technical objections
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
There will always be a question for which you do not know the correct answer.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 17+ messages in thread