* [FFmpeg-devel] [PATCH 2/6] avradio: Fill in missing bandwidth values at 80% of frequency
2023-07-04 22:22 [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound Michael Niedermayer
@ 2023-07-04 22:22 ` Michael Niedermayer
2023-07-04 22:22 ` [FFmpeg-devel] [PATCH 3/6] avradio/sdrdemux: Skip probing in the area outside the bandwidth Michael Niedermayer
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Michael Niedermayer @ 2023-07-04 22:22 UTC (permalink / raw)
To: FFmpeg development discussions and patches
The previous of 100% was a unrealistic default
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavradio/sdrdemux.c | 2 ++
libavradio/sdrinradio.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index cb5e7afb2f..39e2e54ee7 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1401,6 +1401,8 @@ static int sdrfile_initial_setup(AVFormatContext *s)
sdr->bandwidth = sdr->sdr_sample_rate;
sdr->fileheader_size = 40;
}
+ if (sdr->bandwidth >= sdr->sdr_sample_rate)
+ sdr->bandwidth = sdr->sdr_sample_rate * 4 / 5;
//After reading the first packet header we return to the begin so the packet can be read whole
avio_seek(s->pb, 0, SEEK_SET);
diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index 3a0b7f8ab4..c6f5742436 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -320,7 +320,7 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
// rtlsdr doesnt return a valid value
if (!sdr->bandwidth)
- sdr->bandwidth = sdr->sdr_sample_rate;
+ sdr->bandwidth = sdr->sdr_sample_rate * 4 / 5;
av_log(s, AV_LOG_INFO, "bandwidth %"PRId64"\n", sdr->bandwidth);
SoapySDRDevice_activateStream(soapy, soapyRxStream, 0, 0, 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] 7+ messages in thread
* [FFmpeg-devel] [PATCH 3/6] avradio/sdrdemux: Skip probing in the area outside the bandwidth
2023-07-04 22:22 [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound Michael Niedermayer
2023-07-04 22:22 ` [FFmpeg-devel] [PATCH 2/6] avradio: Fill in missing bandwidth values at 80% of frequency Michael Niedermayer
@ 2023-07-04 22:22 ` Michael Niedermayer
2023-07-04 22:23 ` [FFmpeg-devel] [PATCH 4/6] avradio/sdrdemux: adjust frequency precission in probing depending on modulation Michael Niedermayer
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Michael Niedermayer @ 2023-07-04 22:22 UTC (permalink / raw)
To: FFmpeg development discussions and patches
---
libavradio/sdrdemux.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 39e2e54ee7..90f6805c3b 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -394,6 +394,7 @@ static int probe_am(SDRContext *sdr)
int i;
int bandwidth_f = 6000;
int half_bw_i = bandwidth_f * (int64_t)sdr->block_size / sdr->sdr_sample_rate;
+ int border_i = (sdr->sdr_sample_rate - sdr->bandwidth) * sdr->block_size / sdr->sdr_sample_rate;
double avg = 0;
if (2*half_bw_i > 2*sdr->block_size)
@@ -408,6 +409,10 @@ static int probe_am(SDRContext *sdr)
avg += sdr->len2block[i + half_bw_i];
score = half_bw_i * mid / (avg - mid);
avg -= sdr->len2block[i - half_bw_i];
+
+ if (i < border_i || i > 2*sdr->block_size - border_i)
+ continue;
+
//TODO also check for symmetry in the spectrum
if (mid > 0 && score > AM_THRESHOLD &&
sdr->len2block[i - 1] < mid && sdr->len2block[i + 1] <= mid &&
@@ -703,6 +708,7 @@ static int probe_fm(SDRContext *sdr)
int half_bw_i = bandwidth_f * (int64_t)sdr->block_size / sdr->sdr_sample_rate;
double avg[2] = {0}, tri = 0;
float last_score[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
+ int border_i = (sdr->sdr_sample_rate - sdr->bandwidth) * sdr->block_size / sdr->sdr_sample_rate;
if (2*half_bw_i > 2*sdr->block_size)
return 0;
@@ -726,6 +732,8 @@ static int probe_fm(SDRContext *sdr)
last_score[2] = last_score[1];
last_score[1] = last_score[0];
last_score[0] = tri / (b * half_bw_i);
+ if (i < border_i || i > 2*sdr->block_size - border_i)
+ continue;
if (last_score[1] >= last_score[0] &&
last_score[1] > last_score[2] &&
--
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] 7+ messages in thread
* [FFmpeg-devel] [PATCH 4/6] avradio/sdrdemux: adjust frequency precission in probing depending on modulation
2023-07-04 22:22 [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound Michael Niedermayer
2023-07-04 22:22 ` [FFmpeg-devel] [PATCH 2/6] avradio: Fill in missing bandwidth values at 80% of frequency Michael Niedermayer
2023-07-04 22:22 ` [FFmpeg-devel] [PATCH 3/6] avradio/sdrdemux: Skip probing in the area outside the bandwidth Michael Niedermayer
@ 2023-07-04 22:23 ` Michael Niedermayer
2023-07-04 22:23 ` [FFmpeg-devel] [PATCH 5/6] avradio/sdrdemux: When searching for stations move in smaller steps Michael Niedermayer
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Michael Niedermayer @ 2023-07-04 22:23 UTC (permalink / raw)
To: FFmpeg development discussions and patches
for AM we can find the frequency very precissely, for FM currently not so
much
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavradio/sdrdemux.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 90f6805c3b..92b1e2b170 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -166,9 +166,10 @@ static int create_station(SDRContext *sdr, Station *candidate_station) {
return best_station_index;
}
for (i=0; i<sdr->nb_candidate_stations; i++) {
+ int freq_precission = modulation == AM ? 5 : 50;
double delta = fabs(sdr->candidate_station[i]->frequency - freq);
// Station already added, or we have 2 rather close stations
- if (modulation == sdr->candidate_station[i]->modulation && delta < 10 && sdr->candidate_station[i] != candidate_station) {
+ if (modulation == sdr->candidate_station[i]->modulation && delta < freq_precission && sdr->candidate_station[i] != candidate_station) {
nb_candidate_match++;
}
if (modulation != sdr->candidate_station[i]->modulation && delta < (bandwidth + sdr->candidate_station[i]->bandwidth)/2.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] 7+ messages in thread
* [FFmpeg-devel] [PATCH 5/6] avradio/sdrdemux: When searching for stations move in smaller steps
2023-07-04 22:22 [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound Michael Niedermayer
` (2 preceding siblings ...)
2023-07-04 22:23 ` [FFmpeg-devel] [PATCH 4/6] avradio/sdrdemux: adjust frequency precission in probing depending on modulation Michael Niedermayer
@ 2023-07-04 22:23 ` Michael Niedermayer
2023-07-04 22:23 ` [FFmpeg-devel] [PATCH 6/6] avradio/sdrdemux: slightly different normalization of FM scores Michael Niedermayer
2023-07-05 23:16 ` [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound Michael Niedermayer
5 siblings, 0 replies; 7+ messages in thread
From: Michael Niedermayer @ 2023-07-04 22:23 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Moving too quick can lead to missed stations
---
libavradio/sdrdemux.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 92b1e2b170..598dab8f18 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1216,7 +1216,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
// 2 blocks are needed with windowing to get a clean FFT output
// Thus > 3 is the minimum for the next frequency update if we want to do something reliable with the data
if (sdr->seek_direction && block_counter > 5) {
- sdr->wanted_freq = snap2band(sdr, sdr->wanted_freq, sdr->seek_direction*sdr->bandwidth);
+ sdr->wanted_freq = snap2band(sdr, sdr->wanted_freq, sdr->seek_direction*sdr->bandwidth*0.5);
}
if (sdr->wanted_freq != sdr->freq) {
//We could use a seperate MUTEX for the FIFO and for soapy
--
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] 7+ messages in thread
* [FFmpeg-devel] [PATCH 6/6] avradio/sdrdemux: slightly different normalization of FM scores
2023-07-04 22:22 [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound Michael Niedermayer
` (3 preceding siblings ...)
2023-07-04 22:23 ` [FFmpeg-devel] [PATCH 5/6] avradio/sdrdemux: When searching for stations move in smaller steps Michael Niedermayer
@ 2023-07-04 22:23 ` Michael Niedermayer
2023-07-05 23:16 ` [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound Michael Niedermayer
5 siblings, 0 replies; 7+ messages in thread
From: Michael Niedermayer @ 2023-07-04 22:23 UTC (permalink / raw)
To: FFmpeg development discussions and patches
This way teh scores now resemble station vs noise floor while before
they where "whatever"
This results in somewhat cleaner results from probing as well
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavradio/sdrdemux.c | 78 ++++++++++++++++++++++++-------------------
1 file changed, 43 insertions(+), 35 deletions(-)
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 598dab8f18..d3f0368d7d 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -72,7 +72,7 @@
#define AM_MAX23 0.06 //smaller causes failure on synthetic signals
#define AM_MAX4 0.02
-#define FM_THRESHOLD .8 //TODO adjust
+#define FM_THRESHOLD 50 //TODO adjust
//Least squares fit at 1khz points of frequency response shown by Frank McClatchie, FM SYSTEMS, INC. 800-235-6960
static double emphasis75us(int f)
@@ -707,53 +707,61 @@ static int probe_fm(SDRContext *sdr)
int bandwidth_f = 180*1000;
int bandwidth_p2 = 38*1000; //phase 2 bandwidth
int half_bw_i = bandwidth_f * (int64_t)sdr->block_size / sdr->sdr_sample_rate;
- double avg[2] = {0}, tri = 0;
float last_score[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
int border_i = (sdr->sdr_sample_rate - sdr->bandwidth) * sdr->block_size / sdr->sdr_sample_rate;
+ double noise_floor = FLT_MAX;
if (2*half_bw_i > 2*sdr->block_size)
return 0;
- for (i = 0; i<half_bw_i; i++) {
- avg[0] += sdr->len2block[i];
- tri += i*sdr->len2block[i];
- }
- for (; i<2*half_bw_i; i++) {
- avg[1] += sdr->len2block[i];
- tri += (2*half_bw_i-i)*sdr->len2block[i];
- }
+ for (int pass = 0; pass < 2; pass ++) {
+ double avg[2] = {0}, tri = 0;
+ for (i = 0; i<half_bw_i; i++) {
+ avg[0] += sdr->len2block[i];
+ tri += i*sdr->len2block[i];
+ }
+ for (; i<2*half_bw_i; i++) {
+ avg[1] += sdr->len2block[i];
+ tri += (2*half_bw_i-i)*sdr->len2block[i];
+ }
- for(i = half_bw_i; i<2*sdr->block_size - half_bw_i; i++) {
- double b = avg[0] + sdr->len2block[i];
- avg[0] += sdr->len2block[i] - sdr->len2block[i - half_bw_i];
- avg[1] -= sdr->len2block[i] - sdr->len2block[i + half_bw_i];
- b += avg[1];
- tri += avg[1] - avg[0];
+ for(i = half_bw_i; i<2*sdr->block_size - half_bw_i; i++) {
+ double b = avg[0] + sdr->len2block[i];
+ avg[0] += sdr->len2block[i] - sdr->len2block[i - half_bw_i];
+ avg[1] -= sdr->len2block[i] - sdr->len2block[i + half_bw_i];
+ b += avg[1];
+ tri += avg[1] - avg[0];
- last_score[2] = last_score[1];
- last_score[1] = last_score[0];
- last_score[0] = tri / (b * half_bw_i);
- if (i < border_i || i > 2*sdr->block_size - border_i)
- continue;
+ if (i < border_i || i > 2*sdr->block_size - border_i)
+ continue;
- if (last_score[1] >= last_score[0] &&
- last_score[1] > last_score[2] &&
- last_score[1] > FM_THRESHOLD) {
+ if (pass == 0) {
+ noise_floor = FFMIN(noise_floor, tri);
+ } else {
+ last_score[2] = last_score[1];
+ last_score[1] = last_score[0];
+ last_score[0] = tri / (noise_floor);
- float rmax = max_in_range(sdr, i-half_bw_i/4, i+half_bw_i/4);
- int lowcount = countbelow(sdr, i-half_bw_i/4, i+half_bw_i/4, rmax / 100);
- double peak_i;
+ if (last_score[1] >= last_score[0] &&
+ last_score[1] > last_score[2] &&
+ last_score[1] > FM_THRESHOLD) {
- if (lowcount / (half_bw_i*0.5) > 0.99)
- continue;
+ float rmax = max_in_range(sdr, i-half_bw_i/4, i+half_bw_i/4);
+ int lowcount = countbelow(sdr, i-half_bw_i/4, i+half_bw_i/4, rmax / 100);
+ double peak_i;
- // as secondary check, we could check that without the center 3 samples we are still having a strong signal FIXME
+ if (lowcount / (half_bw_i*0.5) > 0.99)
+ continue;
- peak_i = find_peak(sdr, last_score, 1, 3) + i - 1;
- if (peak_i < 0)
- continue;
- av_assert0(fabs(peak_i-i) < 2);
- create_candidate_station(sdr, FM, peak_i * 0.5 * sdr->sdr_sample_rate / sdr->block_size + sdr->block_center_freq - sdr->sdr_sample_rate/2, bandwidth_f, bandwidth_p2, last_score[1]);
+ // as secondary check, we could check that without the center 3 samples we are still having a strong signal FIXME
+
+ peak_i = find_peak(sdr, last_score, 1, 3) + i - 1;
+ if (peak_i < 0)
+ continue;
+ av_assert0(fabs(peak_i-i) < 2);
+ create_candidate_station(sdr, FM, peak_i * 0.5 * sdr->sdr_sample_rate / sdr->block_size + sdr->block_center_freq - sdr->sdr_sample_rate/2, bandwidth_f, bandwidth_p2, last_score[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] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound
2023-07-04 22:22 [FFmpeg-devel] [PATCH 1/6] avradio/sdrdemux: end on EOF dont wraparound Michael Niedermayer
` (4 preceding siblings ...)
2023-07-04 22:23 ` [FFmpeg-devel] [PATCH 6/6] avradio/sdrdemux: slightly different normalization of FM scores Michael Niedermayer
@ 2023-07-05 23:16 ` Michael Niedermayer
5 siblings, 0 replies; 7+ messages in thread
From: Michael Niedermayer @ 2023-07-05 23:16 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 617 bytes --]
On Wed, Jul 05, 2023 at 12:22:57AM +0200, Michael Niedermayer wrote:
> This is more usefull for testing
>
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> libavradio/sdrdemux.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
will apply patchset
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Frequently ignored answer#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
[-- 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] 7+ messages in thread