diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2019-12-05 17:24:30 +0100 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2019-12-08 17:26:44 +0100 |
commit | 150a77b69d7a91a300540606b4eccf382e0caf08 (patch) | |
tree | 429558100bc964c534e5317f04ba118765e4ae3b | |
parent | c2f14834e5ae683cc944c6c0b398d83caed656a9 (diff) |
Add support for AM to libmobile and libsdr
-rw-r--r-- | src/amps/Makefile.am | 1 | ||||
-rw-r--r-- | src/anetz/Makefile.am | 1 | ||||
-rw-r--r-- | src/bnetz/Makefile.am | 1 | ||||
-rw-r--r-- | src/bnetz/dialer.c | 2 | ||||
-rw-r--r-- | src/cnetz/Makefile.am | 1 | ||||
-rw-r--r-- | src/datenklo/datenklo.c | 2 | ||||
-rw-r--r-- | src/imts/Makefile.am | 1 | ||||
-rw-r--r-- | src/imts/dialer.c | 2 | ||||
-rw-r--r-- | src/jolly/Makefile.am | 1 | ||||
-rw-r--r-- | src/jtacs/Makefile.am | 1 | ||||
-rw-r--r-- | src/libam/am.c | 4 | ||||
-rw-r--r-- | src/libmncc/mncc_console.c | 2 | ||||
-rw-r--r-- | src/libmobile/sender.c | 25 | ||||
-rw-r--r-- | src/libmobile/sender.h | 11 | ||||
-rw-r--r-- | src/libsdr/sdr.c | 92 | ||||
-rw-r--r-- | src/libsdr/sdr.h | 2 | ||||
-rw-r--r-- | src/libsound/sound.h | 2 | ||||
-rw-r--r-- | src/libsound/sound_alsa.c | 2 | ||||
-rw-r--r-- | src/nmt/Makefile.am | 1 | ||||
-rw-r--r-- | src/r2000/Makefile.am | 1 | ||||
-rw-r--r-- | src/radio/main.c | 4 | ||||
-rw-r--r-- | src/radio/radio.c | 4 | ||||
-rw-r--r-- | src/tacs/Makefile.am | 1 | ||||
-rw-r--r-- | src/test/Makefile.am | 2 | ||||
-rw-r--r-- | src/tv/Makefile.am | 3 | ||||
-rw-r--r-- | src/tv/main.c | 4 |
26 files changed, 121 insertions, 52 deletions
diff --git a/src/amps/Makefile.am b/src/amps/Makefile.am index c64ccef..a1156d0 100644 --- a/src/amps/Makefile.am +++ b/src/amps/Makefile.am @@ -55,6 +55,7 @@ endif if HAVE_SDR amps_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/anetz/Makefile.am b/src/anetz/Makefile.am index 76dbb4a..58f5f0a 100644 --- a/src/anetz/Makefile.am +++ b/src/anetz/Makefile.am @@ -44,6 +44,7 @@ endif if HAVE_SDR anetz_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/bnetz/Makefile.am b/src/bnetz/Makefile.am index ecb611e..17e8044 100644 --- a/src/bnetz/Makefile.am +++ b/src/bnetz/Makefile.am @@ -61,6 +61,7 @@ endif if HAVE_SDR bnetz_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/bnetz/dialer.c b/src/bnetz/dialer.c index 15289e0..396eb3c 100644 --- a/src/bnetz/dialer.c +++ b/src/bnetz/dialer.c @@ -346,7 +346,7 @@ int main(int argc, char *argv[]) #ifdef HAVE_ALSA /* init sound */ - audio = sound_open(audiodev, NULL, NULL, 1, 0.0, samplerate, latspl, 1.0, 4000.0); + audio = sound_open(audiodev, NULL, NULL, NULL, 1, 0.0, samplerate, latspl, 1.0, 4000.0, 2.0); if (!audio) { PDEBUG(DBNETZ, DEBUG_ERROR, "No sound device!\n"); goto exit; diff --git a/src/cnetz/Makefile.am b/src/cnetz/Makefile.am index c644dd6..28ae31a 100644 --- a/src/cnetz/Makefile.am +++ b/src/cnetz/Makefile.am @@ -44,6 +44,7 @@ endif if HAVE_SDR cnetz_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/datenklo/datenklo.c b/src/datenklo/datenklo.c index c5c893e..4de7ced 100644 --- a/src/datenklo/datenklo.c +++ b/src/datenklo/datenklo.c @@ -1395,7 +1395,7 @@ int datenklo_open_audio(datenklo_t *datenklo, const char *audiodev, int latency, #ifdef HAVE_ALSA /* init sound */ - datenklo->audio = sound_open(audiodev, NULL, NULL, channels, 0.0, datenklo->samplerate, datenklo->latspl, 1.0, 4000.0); + datenklo->audio = sound_open(audiodev, NULL, NULL, NULL, channels, 0.0, datenklo->samplerate, datenklo->latspl, 1.0, 4000.0, 2.0); if (!datenklo->audio) { PDEBUG(DDATENKLO, DEBUG_ERROR, "No sound device!\n"); return -EIO; diff --git a/src/imts/Makefile.am b/src/imts/Makefile.am index c9f7dce..4b6d622 100644 --- a/src/imts/Makefile.am +++ b/src/imts/Makefile.am @@ -52,6 +52,7 @@ endif if HAVE_SDR imts_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/imts/dialer.c b/src/imts/dialer.c index c53a03f..a279141 100644 --- a/src/imts/dialer.c +++ b/src/imts/dialer.c @@ -307,7 +307,7 @@ int main(int argc, char *argv[]) #ifdef HAVE_ALSA /* init sound */ - audio = sound_open(audiodev, NULL, NULL, 1, 0.0, samplerate, latspl, 1.0, 4000.0); + audio = sound_open(audiodev, NULL, NULL, NULL, 1, 0.0, samplerate, latspl, 1.0, 4000.0, 2.0); if (!audio) { PDEBUG(DBNETZ, DEBUG_ERROR, "No sound device!\n"); goto exit; diff --git a/src/jolly/Makefile.am b/src/jolly/Makefile.am index 85d5fc5..a225935 100644 --- a/src/jolly/Makefile.am +++ b/src/jolly/Makefile.am @@ -38,6 +38,7 @@ endif if HAVE_SDR jollycom_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/jtacs/Makefile.am b/src/jtacs/Makefile.am index 33ed68c..23f0e76 100644 --- a/src/jtacs/Makefile.am +++ b/src/jtacs/Makefile.am @@ -38,6 +38,7 @@ endif if HAVE_SDR jtacs_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/libam/am.c b/src/libam/am.c index e9367d9..d5c50b6 100644 --- a/src/libam/am.c +++ b/src/libam/am.c @@ -111,8 +111,8 @@ void am_modulate_complex(am_mod_t *mod, sample_t *amplitude, int num, float *bas else if (phase >= 65536.0) phase -= 65536.0; } else { - *baseband++ = cos(phase) * vector; - *baseband++ = sin(phase) * vector; + *baseband++ += cos(phase) * vector; + *baseband++ += sin(phase) * vector; phase += rot; if (phase < 0.0) phase += 2.0 * M_PI; diff --git a/src/libmncc/mncc_console.c b/src/libmncc/mncc_console.c index cfe7979..06d5778 100644 --- a/src/libmncc/mncc_console.c +++ b/src/libmncc/mncc_console.c @@ -299,7 +299,7 @@ int console_open_audio(int __attribute__((unused)) latspl) #ifdef HAVE_ALSA /* open sound device for call control */ /* use factor 1.4 of speech level for complete range of sound card */ - console.sound = sound_open(console.audiodev, NULL, NULL, 1, 0.0, console.samplerate, latspl, 1.4, 4000.0); + console.sound = sound_open(console.audiodev, NULL, NULL, NULL, 1, 0.0, console.samplerate, latspl, 1.4, 4000.0, 2.0); if (!console.sound) { PDEBUG(DSENDER, DEBUG_ERROR, "No sound device!\n"); return -EIO; diff --git a/src/libmobile/sender.c b/src/libmobile/sender.c index 31d1dd0..cdd1fae 100644 --- a/src/libmobile/sender.c +++ b/src/libmobile/sender.c @@ -183,36 +183,38 @@ int sender_open_audio(int latspl) channels++; } double tx_f[channels], rx_f[channels], paging_frequency = 0.0; + int am[channels]; for (i = 0, inst = master; inst; i++, inst = inst->slave) { tx_f[i] = inst->sendefrequenz; rx_f[i] = inst->empfangsfrequenz; + am[i] = inst->am; if (inst->ruffrequenz) paging_frequency = inst->ruffrequenz; } if (master->write_rx_wave) { - rc = wave_create_record(&master->wave_rx_rec, master->write_rx_wave, master->samplerate, channels, master->max_deviation); + rc = wave_create_record(&master->wave_rx_rec, master->write_rx_wave, master->samplerate, channels, (master->max_deviation) ?: 1.0); if (rc < 0) { PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); return rc; } } if (master->write_tx_wave) { - rc = wave_create_record(&master->wave_tx_rec, master->write_tx_wave, master->samplerate, channels, master->max_deviation); + rc = wave_create_record(&master->wave_tx_rec, master->write_tx_wave, master->samplerate, channels, (master->max_deviation) ?: 1.0); if (rc < 0) { PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); return rc; } } if (master->read_rx_wave) { - rc = wave_create_playback(&master->wave_rx_play, master->read_rx_wave, &master->samplerate, &channels, master->max_deviation); + rc = wave_create_playback(&master->wave_rx_play, master->read_rx_wave, &master->samplerate, &channels, (master->max_deviation) ?: 1.0); if (rc < 0) { PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); return rc; } } if (master->read_tx_wave) { - rc = wave_create_playback(&master->wave_tx_play, master->read_tx_wave, &master->samplerate, &channels, master->max_deviation); + rc = wave_create_playback(&master->wave_tx_play, master->read_tx_wave, &master->samplerate, &channels, (master->max_deviation) ?: 1.0); if (rc < 0) { PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); return rc; @@ -220,7 +222,7 @@ int sender_open_audio(int latspl) } /* open device */ - master->audio = master->audio_open(master->audiodev, tx_f, rx_f, channels, paging_frequency, master->samplerate, latspl, master->max_deviation, master->max_modulation); + master->audio = master->audio_open(master->audiodev, tx_f, rx_f, am, channels, paging_frequency, master->samplerate, latspl, (master->max_deviation) ?: 1.0, master->max_modulation, master->modulation_index); if (!master->audio) { PDEBUG(DSENDER, DEBUG_ERROR, "No device for transceiver!\n"); return -EIO; @@ -293,6 +295,19 @@ void sender_set_fm(sender_t *sender, double max_deviation, double max_modulation PDEBUG_CHAN(DSENDER, DEBUG_DEBUG, "Deviation at speech level: %.1f kHz\n", speech_deviation / 1000.0); } +/* set amplitude modulation and parameters */ +void sender_set_am(sender_t *sender, double max_modulation, double speech_level, double max_display, double modulation_index) +{ + sender->am = 1; + sender->max_deviation = 0; + sender->max_modulation = max_modulation; + sender->speech_deviation = speech_level; + sender->max_display = max_display; + sender->modulation_index = modulation_index; + + PDEBUG_CHAN(DSENDER, DEBUG_DEBUG, "Modulation degree: %.0f %%, Maximum modulation: %.1f kHz\n", modulation_index / 100.0, max_modulation / 1000.0); +} + static void gain_samples(sample_t *samples, int length, double gain) { int i; diff --git a/src/libmobile/sender.h b/src/libmobile/sender.h index a2721f1..0e2ffcb 100644 --- a/src/libmobile/sender.h +++ b/src/libmobile/sender.h @@ -33,16 +33,18 @@ typedef struct sender { double empfangsfrequenz; /* receiver frequency */ double ruffrequenz; /* special paging frequency used for B-Netz */ - /* fm levels */ - double max_deviation; /* max frequency deviation */ + /* FM/AM levels */ + int am; /* use AM instead of FM */ + double max_deviation; /* max frequency deviation / level */ double max_modulation; /* max frequency modulated */ - double speech_deviation; /* deviation of 1000 Hz reference tone at speech level */ + double speech_deviation; /* deviation / level of 1000 Hz reference tone at speech level */ + double modulation_index; /* AM modulation index */ double max_display; /* level of displaying wave form */ /* audio */ void *audio; char audiodev[64]; /* audio device name (alsa or sdr) */ - void *(*audio_open)(const char *, double *, double *, int, double, int, int, double, double); + void *(*audio_open)(const char *, double *, double *, int *, int, double, int, int, double, double, double); int (*audio_start)(void *); void (*audio_close)(void *); int (*audio_write)(void *, sample_t **, uint8_t **, int, enum paging_signal *, int *, int); @@ -93,6 +95,7 @@ extern int cant_recover; int sender_create(sender_t *sender, const char *kanal, double sendefrequenz, double empfangsfrequenz, const char *audiodev, int use_sdr, int samplerate, double rx_gain, int pre_emphasis, int de_emphasis, const char *write_rx_wave, const char *write_tx_wave, const char *read_rx_wave, const char *read_tx_wave, int loopback, enum paging_signal paging_signal); void sender_destroy(sender_t *sender); void sender_set_fm(sender_t *sender, double max_deviation, double max_modulation, double speech_deviation, double max_display); +void sender_set_am(sender_t *sender, double max_modulation, double speech_deviation, double max_display, double modulation_index); int sender_open_audio(int latspl); int sender_start_audio(void); void process_sender_audio(sender_t *sender, int *quit, int latspl); diff --git a/src/libsdr/sdr.c b/src/libsdr/sdr.c index 2270d8a..eb627f2 100644 --- a/src/libsdr/sdr.c +++ b/src/libsdr/sdr.c @@ -30,6 +30,7 @@ enum paging_signal; #include <unistd.h> #include "../libsample/sample.h" #include "../libfm/fm.h" +#include "../libam/am.h" #include "../libtimer/timer.h" #include "../libmobile/sender.h" #include "sdr_config.h" @@ -71,8 +72,11 @@ typedef struct sdr_thread { typedef struct sdr_chan { double tx_frequency; /* frequency used */ double rx_frequency; /* frequency used */ - fm_mod_t mod; /* modulator instance */ - fm_demod_t demod; /* demodulator instance */ + int am; /* use AM instead of FM */ + fm_mod_t fm_mod; /* modulator instance */ + fm_demod_t fm_demod; /* demodulator instance */ + am_mod_t am_mod; /* modulator instance */ + am_demod_t am_demod; /* demodulator instance */ dispmeasparam_t *dmp_rf_level; dispmeasparam_t *dmp_freq_offset; dispmeasparam_t *dmp_deviation; @@ -94,9 +98,10 @@ typedef struct sdr { wave_rec_t wave_tx_rec; wave_play_t wave_rx_play; wave_play_t wave_tx_play; - float *modbuff; /* buffer for FM transmodulation */ + float *modbuff; /* buffer for transmodulation */ sample_t *modbuff_I; sample_t *modbuff_Q; + sample_t *modbuff_carrier; sample_t *wavespl0; /* sample buffer for wave generation */ sample_t *wavespl1; } sdr_t; @@ -131,7 +136,7 @@ static void show_spectrum(const char *direction, double halfbandwidth, double ce PDEBUG(DSDR, DEBUG_INFO, "Frequency P = %.4f MHz (Paging Frequency)\n", paging_frequency / 1e6); } -void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_frequency, double *rx_frequency, int channels, double paging_frequency, int samplerate, int latspl, double max_deviation, double max_modulation) +void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_frequency, double *rx_frequency, int *am, int channels, double paging_frequency, int samplerate, int latspl, double max_deviation, double max_modulation, double modulation_index) { sdr_t *sdr; int threads = 1, oversample = 1; /* always use threads */ @@ -231,6 +236,11 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); goto error; } + sdr->modbuff_carrier = calloc(sdr->latspl, sizeof(*sdr->modbuff_carrier)); + if (!sdr->modbuff_carrier) { + PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + goto error; + } sdr->wavespl0 = calloc(sdr->latspl, sizeof(*sdr->wavespl0)); if (!sdr->wavespl0) { PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); @@ -297,7 +307,14 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq double tx_offset; tx_offset = sdr->chan[c].tx_frequency - tx_center_frequency; PDEBUG(DSDR, DEBUG_DEBUG, "Frequency #%d: TX offset: %.6f MHz\n", c, tx_offset / 1e6); - rc = fm_mod_init(&sdr->chan[c].mod, samplerate, tx_offset, sdr->amplitude); + sdr->chan[c].am = am[c]; + if (am[c]) { + double gain, bias; + gain = modulation_index / 2.0; + bias = 1.0 - gain; + rc = am_mod_init(&sdr->chan[c].am_mod, samplerate, tx_offset, sdr->amplitude * gain, sdr->amplitude * bias); + } else + rc = fm_mod_init(&sdr->chan[c].fm_mod, samplerate, tx_offset, sdr->amplitude); if (rc < 0) goto error; } @@ -305,7 +322,7 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq double tx_offset; tx_offset = sdr->chan[sdr->paging_channel].tx_frequency - tx_center_frequency; PDEBUG(DSDR, DEBUG_DEBUG, "Paging Frequency: TX offset: %.6f MHz\n", tx_offset / 1e6); - rc = fm_mod_init(&sdr->chan[sdr->paging_channel].mod, samplerate, tx_offset, sdr->amplitude); + rc = fm_mod_init(&sdr->chan[sdr->paging_channel].fm_mod, samplerate, tx_offset, sdr->amplitude); if (rc < 0) goto error; } @@ -400,7 +417,11 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq double rx_offset; rx_offset = sdr->chan[c].rx_frequency - rx_center_frequency; PDEBUG(DSDR, DEBUG_DEBUG, "Frequency #%d: RX offset: %.6f MHz\n", c, rx_offset / 1e6); - rc = fm_demod_init(&sdr->chan[c].demod, samplerate, rx_offset, bandwidth); + sdr->chan[c].am = am[c]; + if (am[c]) + rc = am_demod_init(&sdr->chan[c].am_demod, samplerate, rx_offset, bandwidth, 1.0 / modulation_index); + else + rc = fm_demod_init(&sdr->chan[c].fm_demod, samplerate, rx_offset, bandwidth / 2.0); if (rc < 0) goto error; } @@ -428,8 +449,10 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq if (!sender) continue; sdr->chan[c].dmp_rf_level = display_measurements_add(&sender->dispmeas, "RF Level", "%.1f dB", DISPLAY_MEAS_AVG, DISPLAY_MEAS_LEFT, -96.0, 0.0, -INFINITY); - sdr->chan[c].dmp_freq_offset = display_measurements_add(&sender->dispmeas, "Freq. Offset", "%+.2f KHz", DISPLAY_MEAS_AVG, DISPLAY_MEAS_CENTER, -max_deviation / 1000.0 * 2.0, max_deviation / 1000.0 * 2.0, 0.0); - sdr->chan[c].dmp_deviation = display_measurements_add(&sender->dispmeas, "Deviation", "%.2f KHz", DISPLAY_MEAS_PEAK2PEAK, DISPLAY_MEAS_LEFT, 0.0, max_deviation / 1000.0 * 1.5, max_deviation / 1000.0); + if (!am[c]) { + sdr->chan[c].dmp_freq_offset = display_measurements_add(&sender->dispmeas, "Freq. Offset", "%+.2f KHz", DISPLAY_MEAS_AVG, DISPLAY_MEAS_CENTER, -max_modulation / 1000.0 * 2.0, max_modulation / 1000.0 * 2.0, 0.0); + sdr->chan[c].dmp_deviation = display_measurements_add(&sender->dispmeas, "Deviation", "%.2f KHz", DISPLAY_MEAS_PEAK2PEAK, DISPLAY_MEAS_LEFT, 0.0, max_deviation / 1000.0 * 1.5, max_deviation / 1000.0); + } } } @@ -700,6 +723,7 @@ void sdr_close(void *inst) free(sdr->modbuff); free(sdr->modbuff_I); free(sdr->modbuff_Q); + free(sdr->modbuff_carrier); free(sdr->wavespl0); free(sdr->wavespl1); wave_destroy_record(&sdr->wave_rx_rec); @@ -710,11 +734,13 @@ void sdr_close(void *inst) int c; for (c = 0; c < sdr->channels; c++) { - fm_mod_exit(&sdr->chan[c].mod); - fm_demod_exit(&sdr->chan[c].demod); + fm_mod_exit(&sdr->chan[c].fm_mod); + fm_demod_exit(&sdr->chan[c].fm_demod); + am_mod_exit(&sdr->chan[c].am_mod); + am_demod_exit(&sdr->chan[c].am_demod); } if (sdr->paging_channel) - fm_mod_exit(&sdr->chan[sdr->paging_channel].mod); + fm_mod_exit(&sdr->chan[sdr->paging_channel].fm_mod); free(sdr->chan); } free(sdr); @@ -747,9 +773,12 @@ int sdr_write(void *inst, sample_t **samples, uint8_t **power, int num, enum pag for (c = 0; c < channels; c++) { /* switch to paging channel, if requested */ if (on[c] && sdr->paging_channel) - fm_modulate_complex(&sdr->chan[sdr->paging_channel].mod, samples[c], power[c], num, buff); - else - fm_modulate_complex(&sdr->chan[c].mod, samples[c], power[c], num, buff); + fm_modulate_complex(&sdr->chan[sdr->paging_channel].fm_mod, samples[c], power[c], num, buff); + else if (sdr->chan[c].am) { + if (power[c][0]) + am_modulate_complex(&sdr->chan[c].am_mod, samples[c], num, buff); + } else + fm_modulate_complex(&sdr->chan[c].fm_mod, samples[c], power[c], num, buff); } } else { buff = (float *)samples; @@ -914,7 +943,10 @@ int sdr_read(void *inst, sample_t **samples, int num, int channels, double *rf_l if (channels) { for (c = 0; c < channels; c++) { - fm_demodulate_complex(&sdr->chan[c].demod, samples[c], count, buff, sdr->modbuff_I, sdr->modbuff_Q); + if (sdr->chan[c].am) + am_demodulate_complex(&sdr->chan[c].am_demod, samples[c], count, buff, sdr->modbuff_I, sdr->modbuff_Q, sdr->modbuff_carrier); + else + fm_demodulate_complex(&sdr->chan[c].fm_demod, samples[c], count, buff, sdr->modbuff_I, sdr->modbuff_Q); sender_t *sender = get_sender_by_empfangsfrequenz(sdr->chan[c].rx_frequency); if (!sender || !count) continue; @@ -928,20 +960,22 @@ int sdr_read(void *inst, sample_t **samples, int num, int channels, double *rf_l avg = log10(avg) * 20; display_measurements_update(sdr->chan[c].dmp_rf_level, avg, 0.0); rf_level_db[c] = avg; - min = 0.0; - max = 0.0; - avg = 0.0; - for (s = 0; s < count; s++) { - avg += samples[c][s]; - if (s == 0 || samples[c][s] > max) - max = samples[c][s]; - if (s == 0 || samples[c][s] < min) - min = samples[c][s]; + if (!sdr->chan[c].am) { + min = 0.0; + max = 0.0; + avg = 0.0; + for (s = 0; s < count; s++) { + avg += samples[c][s]; + if (s == 0 || samples[c][s] > max) + max = samples[c][s]; + if (s == 0 || samples[c][s] < min) + min = samples[c][s]; + } + avg /= (double)count; + display_measurements_update(sdr->chan[c].dmp_freq_offset, avg / 1000.0, 0.0); + /* use half min and max, because we want the deviation above/below (+-) center frequency. */ + display_measurements_update(sdr->chan[c].dmp_deviation, min / 2.0 / 1000.0, max / 2.0 / 1000.0); } - avg /= (double)count; - display_measurements_update(sdr->chan[c].dmp_freq_offset, avg / 1000.0, 0.0); - /* use half min and max, because we want the deviation above/below (+-) center frequency. */ - display_measurements_update(sdr->chan[c].dmp_deviation, min / 2.0 / 1000.0, max / 2.0 / 1000.0); } } diff --git a/src/libsdr/sdr.h b/src/libsdr/sdr.h index aadc5d7..daaed7c 100644 --- a/src/libsdr/sdr.h +++ b/src/libsdr/sdr.h @@ -2,7 +2,7 @@ enum paging_signal; int sdr_start(void *inst); -void *sdr_open(const char *audiodev, double *tx_frequency, double *rx_frequency, int channels, double paging_frequency, int samplerate, int latspl, double max_deviation, double max_modulation); +void *sdr_open(const char *audiodev, double *tx_frequency, double *rx_frequency, int *am, int channels, double paging_frequency, int samplerate, int latspl, double max_deviation, double max_modulation, double modulation_index); void sdr_close(void *inst); int sdr_write(void *inst, sample_t **samples, uint8_t **power, int num, enum paging_signal *paging_signal, int *on, int channels); int sdr_read(void *inst, sample_t **samples, int num, int channels, double *rf_level_db); diff --git a/src/libsound/sound.h b/src/libsound/sound.h index 850832d..6440a3c 100644 --- a/src/libsound/sound.h +++ b/src/libsound/sound.h @@ -1,7 +1,7 @@ enum paging_signal; -void *sound_open(const char *audiodev, double *tx_frequency, double *rx_frequency, int channels, double paging_frequency, int samplerate, int latspl, double max_deviation, double max_modulation); +void *sound_open(const char *audiodev, double *tx_frequency, double *rx_frequency, int *am, int channels, double paging_frequency, int samplerate, int latspl, double max_deviation, double max_modulation, double modulation_index); int sound_start(void *inst); void sound_close(void *inst); int sound_write(void *inst, sample_t **samples, uint8_t **power, int num, enum paging_signal *paging_signal, int *on, int channels); diff --git a/src/libsound/sound_alsa.c b/src/libsound/sound_alsa.c index dc1dfcd..21199c9 100644 --- a/src/libsound/sound_alsa.c +++ b/src/libsound/sound_alsa.c @@ -131,7 +131,7 @@ static int sound_prepare(sound_t *sound) return 0; } -void *sound_open(const char *audiodev, double __attribute__((unused)) *tx_frequency, double __attribute__((unused)) *rx_frequency, int channels, double __attribute__((unused)) paging_frequency, int samplerate, int __attribute((unused)) latspl, double max_deviation, double __attribute__((unused)) max_modulation) +void *sound_open(const char *audiodev, double __attribute__((unused)) *tx_frequency, double __attribute__((unused)) *rx_frequency, int __attribute__((unused)) *am, int channels, double __attribute__((unused)) paging_frequency, int samplerate, int __attribute((unused)) latspl, double max_deviation, double __attribute__((unused)) max_modulation, double __attribute__((unused)) modulation_index) { sound_t *sound; int rc, rc_rec, rc_play; diff --git a/src/nmt/Makefile.am b/src/nmt/Makefile.am index 5f15ff4..4bfd766 100644 --- a/src/nmt/Makefile.am +++ b/src/nmt/Makefile.am @@ -51,6 +51,7 @@ endif if HAVE_SDR nmt_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/r2000/Makefile.am b/src/r2000/Makefile.am index 120221b..0fd8fdd 100644 --- a/src/r2000/Makefile.am +++ b/src/r2000/Makefile.am @@ -39,6 +39,7 @@ endif if HAVE_SDR radiocom2000_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/radio/main.c b/src/radio/main.c index 4f87fea..fc876a7 100644 --- a/src/radio/main.c +++ b/src/radio/main.c @@ -383,9 +383,11 @@ int main(int argc, char *argv[]) } double tx_frequencies[1], rx_frequencies[1]; + int am[1]; tx_frequencies[0] = frequency; rx_frequencies[0] = frequency; - sdr = sdr_open(NULL, tx_frequencies, rx_frequencies, 1, 0.0, samplerate, latspl, 0.0, 0.0); + am[0] = 0; + sdr = sdr_open(NULL, tx_frequencies, rx_frequencies, am, 1, 0.0, samplerate, latspl, 0.0, 0.0, 0.0); if (!sdr) goto error; sdr_start(sdr); diff --git a/src/radio/radio.c b/src/radio/radio.c index ee85805..c1be7e7 100644 --- a/src/radio/radio.c +++ b/src/radio/radio.c @@ -98,7 +98,7 @@ int radio_init(radio_t *radio, int latspl, int samplerate, const char *tx_wave_f /* open audio device */ radio->tx_audio_samplerate = 48000; radio->tx_audio_channels = (stereo) ? 2 : 1; - radio->tx_sound = sound_open(tx_audiodev, NULL, NULL, radio->tx_audio_channels, 0.0, radio->tx_audio_samplerate, radio->latspl, 1.0, 0.0); + radio->tx_sound = sound_open(tx_audiodev, NULL, NULL, NULL, radio->tx_audio_channels, 0.0, radio->tx_audio_samplerate, radio->latspl, 1.0, 0.0, 2.0); if (!radio->tx_sound) { rc = -EIO; PDEBUG(DRADIO, DEBUG_ERROR, "Failed to open sound device!\n"); @@ -164,7 +164,7 @@ int radio_init(radio_t *radio, int latspl, int samplerate, const char *tx_wave_f if (radio->tx_sound && !strcmp(tx_audiodev, rx_audiodev)) radio->rx_sound = radio->tx_sound; else - radio->rx_sound = sound_open(rx_audiodev, NULL, NULL, radio->rx_audio_channels, 0.0, radio->rx_audio_samplerate, radio->latspl, 1.0, 0.0); + radio->rx_sound = sound_open(rx_audiodev, NULL, NULL, NULL, radio->rx_audio_channels, 0.0, radio->rx_audio_samplerate, radio->latspl, 1.0, 0.0, 2.0); if (!radio->rx_sound) { rc = -EIO; PDEBUG(DRADIO, DEBUG_ERROR, "Failed to open sound device!\n"); diff --git a/src/tacs/Makefile.am b/src/tacs/Makefile.am index 08cb381..478730e 100644 --- a/src/tacs/Makefile.am +++ b/src/tacs/Makefile.am @@ -39,6 +39,7 @@ endif if HAVE_SDR tacs_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a \ $(top_builddir)/src/libfft/libfft.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 141d88d..dd65ec6 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -81,6 +81,7 @@ test_dms_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ $(top_builddir)/src/libfft/libfft.a \ $(top_builddir)/src/libfm/libfm.a \ + $(top_builddir)/src/libam/libam.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) endif @@ -115,6 +116,7 @@ test_sms_LDADD += \ $(top_builddir)/src/libsdr/libsdr.a \ $(top_builddir)/src/libfft/libfft.a \ $(top_builddir)/src/libfm/libfm.a \ + $(top_builddir)/src/libam/libam.a \ $(UHD_LIBS) \ $(SOAPY_LIBS) endif diff --git a/src/tv/Makefile.am b/src/tv/Makefile.am index d14baad..2131067 100644 --- a/src/tv/Makefile.am +++ b/src/tv/Makefile.am @@ -31,7 +31,8 @@ osmotv_LDADD = \ if HAVE_SDR osmotv_LDADD += \ - $(top_builddir)/src/libsdr/libsdr.a + $(top_builddir)/src/libsdr/libsdr.a \ + $(top_builddir)/src/libam/libam.a endif osmotv_LDADD += \ diff --git a/src/tv/main.c b/src/tv/main.c index fea842d..e4e7a85 100644 --- a/src/tv/main.c +++ b/src/tv/main.c @@ -321,9 +321,11 @@ static void tx_bas(sample_t *sample_bas, __attribute__((__unused__)) sample_t *s } double tx_frequencies[1], rx_frequencies[1]; + int am[1]; tx_frequencies[0] = frequency; rx_frequencies[0] = frequency; - sdr = sdr_open(NULL, tx_frequencies, rx_frequencies, 1, 0.0, samplerate, latspl, 0.0, 0.0); + am[0] = 0; + sdr = sdr_open(NULL, tx_frequencies, rx_frequencies, am, 1, 0.0, samplerate, latspl, 0.0, 0.0, 0.0); if (!sdr) goto error; sdr_start(sdr); |