From d98040895d2f8710a061fb04f6cef126801dca7e Mon Sep 17 00:00:00 2001 From: lwvmobile <59371473+lwvmobile@users.noreply.github.com> Date: Fri, 4 Feb 2022 18:01:33 -0500 Subject: [PATCH] Source Audio Monitoring (WIP) Add Source Audio Monitoring - But its a Work in Progress Seriously, though, depending on which setting you have on, it sounds terrible. Also, make ncurses no longer a requirement for the time being. Still want to work that into this version eventually. --- CMakeLists.txt | 16 ++-- include/dsd.h | 12 ++- src/dsd_audio.c | 171 ++++++++++++++++++++++--------------------- src/dsd_frame_sync.c | 46 ++++++++---- src/dsd_main.c | 73 ++++++------------ src/dsd_symbol.c | 22 +++++- src/rtl_sdr_fm.cpp | 8 +- 7 files changed, 185 insertions(+), 163 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cdf3e4a..8ad902c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,13 +9,19 @@ git_describe(GIT_TAG) find_package(LibSndFile REQUIRED) find_package(MBE REQUIRED) find_package(ITPP REQUIRED) -find_package(LibPortAudio) +find_package(LibPortAudio) #disabled for testing find_package(RTLSDR) -#more fucking around -find_package(Curses REQUIRED) +#more messing around +#find_package(Curses REQUIRED) + +#include_directories(SYSTEM ${LIBSNDFILE_INCLUDE_DIR} ${MBE_INCLUDE_DIR} ${ITPP_INCLUDE_DIR} ${CURSES_INCLUDE_DIR}) +#set(LIBS ${MBE_LIBRARY} ${LIBSNDFILE_LIBRARY} ${ITPP_LIBRARY} ${CURSES_LIBRARY}) include_directories(SYSTEM ${LIBSNDFILE_INCLUDE_DIR} ${MBE_INCLUDE_DIR} ${ITPP_INCLUDE_DIR} ${CURSES_INCLUDE_DIR}) -set(LIBS ${MBE_LIBRARY} ${LIBSNDFILE_LIBRARY} ${ITPP_LIBRARY} ${CURSES_LIBRARY}) +set(LIBS ${MBE_LIBRARY} ${LIBSNDFILE_LIBRARY} ${ITPP_LIBRARY}) + +#going to disable PortAudio, works just fine with padsp in Linux, +#hoping disabling this doesn't break OSX or cygwin, etc builds if(PORTAUDIO_FOUND) include_directories(SYSTEM ${PORTAUDIO_INCLUDE_DIRS}) @@ -57,7 +63,7 @@ if (HELP2MAN_FOUND) --version-string=${GIT_TAG} -o ${CMAKE_CURRENT_BINARY_DIR}/dsd.1 --no-info - $ + $ ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dsd.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) endif() diff --git a/include/dsd.h b/include/dsd.h index dd5ea03..83b5866 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -22,7 +22,7 @@ #include #include #include -#define __USE_XOPEN +#define __USE_XOPEN //compiler warning on this, needed for strptime, seems benign #include #include #include @@ -43,8 +43,8 @@ #include "p25p1_heuristics.h" -#define SAMPLE_RATE_IN 48000 -#define SAMPLE_RATE_OUT 8000 +#define SAMPLE_RATE_IN 48000 //48000 +#define SAMPLE_RATE_OUT 8000 //8000, #ifdef USE_PORTAUDIO #include "portaudio.h" @@ -142,6 +142,7 @@ typedef struct int rtl_squelch_level; int rtl_volume_multiplier; int rtl_udp_port; + int monitor_input_audio; } dsd_opts; typedef struct @@ -223,6 +224,10 @@ typedef struct // Heuristics state data for -P5 signals P25Heuristics inv_p25_heuristics; + //input sample buffer for monitoring Input + short input_sample_buffer; //HERE HERE + //float *input_sample_buffer; //HERE HERE + #ifdef TRACE_DSD char debug_prefix; char debug_prefix_2; @@ -291,6 +296,7 @@ void processDMRdata (dsd_opts * opts, dsd_state * state); void processDMRvoice (dsd_opts * opts, dsd_state * state); void processAudio (dsd_opts * opts, dsd_state * state); void playRawAudio (dsd_opts * opts, dsd_state * state); //added this one HERE HERE +void processRawAudio (dsd_opts * opts, dsd_state * state); //added this one HERE HERE void writeSynthesizedVoice (dsd_opts * opts, dsd_state * state); void playSynthesizedVoice (dsd_opts * opts, dsd_state * state); void openAudioOutDevice (dsd_opts * opts, int speed); diff --git a/src/dsd_audio.c b/src/dsd_audio.c index 5655a37..2182c43 100644 --- a/src/dsd_audio.c +++ b/src/dsd_audio.c @@ -17,6 +17,91 @@ #include "dsd.h" + +void playRawAudio(dsd_opts * opts, dsd_state * state) { + short obuf, outl, sample2, i, something; + something = state->samplesPerSymbol / 5; + /* //this method gets excellent results on gfsk provoice, but not at all on the others + if (opts->audio_in_type == 0 && opts->frame_provoice == 1){ //hack, but might as well for this particular type since its nearly perfect + read (opts->audio_in_fd, &sample2, 2); //reading here seems to get same speed as gfsk modulation + obuf = sample2; + } + #ifdef USE_PORTAUDIO + if (opts->audio_in_type == 2){ + Pa_ReadStream( opts->audio_in_pa_stream, &sample2, 1 ); //reading here seems to get same speed as gfsk modulation + obuf = sample2; + } + #endif + if (opts->audio_in_type == 3){ //can't seem to grab get_rtlsdr_sample here, can't share it with dsd_symbol.c + state->input_sample_buffer = state->lastsample; + } //grabbing this one from dsd_symbol.c but its already been processed + */ + if (opts->audio_in_type == 0 && opts->audio_out_type == 0){ //hack, but might as well for this particular type since its nearly perfect + for (i=0; i < something; i++){ + read (opts->audio_in_fd, &sample2, 2); //reading here seems to get same speed as gfsk modulation + obuf = sample2 / 4; //dividing here 'quietens' it down a little bit, helps with clicking and clipping + write (opts->audio_out_fd, (void*)&obuf, 2); + } + } + #ifdef USE_PORTAUDIO + if (opts->audio_in_type == 2 && opts->audio_out_type == 0){ //hack, but might as well for this particular type since its nearly perfect + for (i=0; i < something; i++){ + Pa_ReadStream( opts->audio_in_pa_stream, &sample2, 1 ); //reading here seems to get same speed as gfsk modulation + obuf = sample2 / 4; //dividing here 'quietens' it down a little bit, helps with clicking and clipping + write (opts->audio_out_fd, (void*)&obuf, 2); + } + } + if (opts->audio_in_type == 0 && opts->audio_out_type == 2){ //hack, but might as well for this particular type since its nearly perfect + for (i=0; i < something; i++){ + read (opts->audio_in_fd, &sample2, 2); //reading here seems to get same speed as gfsk modulation + obuf = sample2 / 4; //dividing here 'quietens' it down a little bit, helps with clicking and clipping + Pa_StartStream( opts->audio_out_pa_stream ); //no promises this shit'll work + Pa_WriteStream( opts->audio_out_pa_stream, (void*)&obuf, 2); //no promises this shit'll work + } + } + + if (opts->audio_in_type == 2 && opts->audio_out_type == 2){ //hack, but might as well for this particular type since its nearly perfect + for (i=0; i < something; i++){ + Pa_ReadStream( opts->audio_in_pa_stream, &sample2, 1 ); //reading here seems to get same speed as gfsk modulation + obuf = sample2 / 4; //dividing here 'quietens' it down a little bit, helps with clicking and clipping + Pa_StartStream( opts->audio_out_pa_stream ); //no promises this shit'll work + Pa_WriteStream( opts->audio_out_pa_stream, (void*)&obuf, 2); //no promises this shit'll work + } + } + #endif + //shouldn't need to use ifdef rtl here since audio_in_type will never set to 3 unless its there in main + if (opts->audio_in_type == 1 || opts->audio_in_type == 3){ //only plays at 83% and sounds like shit sadly, but can't get samples directly from sdr when its already being polled for samples + //also, can't get samples from stdin more than once either it seems, unless I borked it when I tried it earlier, so lumping it in here as well + for (i=0; i < something; i++) + { + obuf = state->input_sample_buffer; //dividing here 'quietens' it down a little bit, helps with clicking and clipping + outl = sizeof(obuf) ; //obuf length, I think its always equal to 2 + if (opts->audio_out_type == 0){ + write (opts->audio_out_fd, (void*)&obuf, outl);} + + #ifdef USE_PORTAUDIO //no idea if this method will work, since I can't test it + if (opts->audio_out_type == 2){ + short err; + err = Pa_IsStreamActive( opts->audio_out_pa_stream ); + if(err == 0) + { + err = Pa_StartStream( opts->audio_out_pa_stream ); + if( err != paNoError ){ + printf("Can't Start PA Stream"); + } + err = Pa_WriteStream( opts->audio_out_pa_stream, (void*)&obuf, outl ); + if( err != paNoError ){ + printf("Can't Write PA Stream"); + } + } + } + #endif + } // end for loop + } //end if statement + +} //end playRawAudio + + void processAudio (dsd_opts * opts, dsd_state * state) { @@ -213,85 +298,6 @@ writeSynthesizedVoice (dsd_opts * opts, dsd_state * state) */ } -//Test playing raw audio HERE -//get_rtlsdr_sample(&sample); -void -playRawAudio (dsd_opts * opts, dsd_state * state) -{ - ssize_t result; - //opts->audio_in_pa_stream = opts->audio_out_pa_stream; //no idea if this will work -> can't use PortAudio, it sucks the big one, use OSS/Alsa - //if (state->audio_out_idx > opts->delay) - if (1 == 1) //idk, just want it to continue - { - // output synthesized speech to sound card - if(opts->audio_out_type == 2) - { -#ifdef USE_PORTAUDIO - PaError err = paNoError; - do - { - long available = Pa_GetStreamWriteAvailable( opts->audio_out_pa_stream ); - if(available < 0) - err = available; - //printf("Frames available: %d\n", available); - if( err != paNoError ) - break; - if(available > SAMPLE_RATE_OUT * PA_LATENCY_OUT) - { - //It looks like this might not be needed for very small latencies. However, it's definitely needed for a bit larger ones. - //When PA_LATENCY_OUT == 0.500 I get output buffer underruns if I don't use this. With PA_LATENCY_OUT <= 0.100 I don't see those happen. - //But with PA_LATENCY_OUT < 0.100 I run the risk of choppy audio and stream errors. - printf("\nSyncing voice output stream\n"); - err = Pa_StopStream( opts->audio_out_pa_stream ); - if( err != paNoError ) - break; - } - - err = Pa_IsStreamActive( opts->audio_out_pa_stream ); - if(err == 0) - { - printf("Start voice output stream\n"); - err = Pa_StartStream( opts->audio_out_pa_stream ); - } - else if(err == 1) - { - err = paNoError; - } - if( err != paNoError ) - break; - - //printf("write stream %d\n", state->audio_out_idx); - err = Pa_WriteStream( opts->audio_out_pa_stream, (state->audio_out_buf_p - state->audio_out_idx), state->audio_out_idx ); - if( err != paNoError ) - break; - } while(0); - - if( err != paNoError ) - { - fprintf( stderr, "An error occured while using the portaudio output stream\n" ); - fprintf( stderr, "Error number: %d\n", err ); - fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); - } - -#endif - } - else - result = write (opts->audio_out_fd, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2)); - state->audio_out_idx = 0; - } - - if (state->audio_out_idx2 >= 800000) - { - state->audio_out_float_buf_p = state->audio_out_float_buf + 100; - state->audio_out_buf_p = state->audio_out_buf + 100; - memset (state->audio_out_float_buf, 0, 100 * sizeof (float)); - memset (state->audio_out_buf, 0, 100 * sizeof (short)); - state->audio_out_idx2 = 0; - } -} - -//end test raw audio - void playSynthesizedVoice (dsd_opts * opts, dsd_state * state) { @@ -306,7 +312,6 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state) PaError err = paNoError; do { - opts->audio_out_pa_stream = opts->audio_in_pa_stream; //just seeing if anythign sticks long available = Pa_GetStreamWriteAvailable( opts->audio_out_pa_stream ); if(available < 0) err = available; @@ -353,7 +358,10 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state) #endif } else - result = write (opts->audio_out_fd, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2)); + //short multiple = 12; + //probably going to need to do that void voodoo again here to get this to work to even see if it works in the grand scheme + //result = write (opts->audio_out_fd, ( (state->audio_out_buf_p - state->audio_out_idx) * 12 ), (state->audio_out_idx * 24) ); //HERE HERE work on way to boost output from 8000 to 48000 + result = write (opts->audio_out_fd, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2)); //12 state->audio_out_idx = 0; } @@ -484,7 +492,6 @@ openAudioOutDevice (dsd_opts * opts, int speed) // get current ioctl (opts->audio_out_fd, AUDIO_GETINFO, &aset); - aset.record.sample_rate = speed; aset.play.sample_rate = speed; aset.record.channels = 1; diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c index 0a77cd8..2d3da61 100644 --- a/src/dsd_frame_sync.c +++ b/src/dsd_frame_sync.c @@ -17,7 +17,7 @@ #include "dsd.h" #include -#include +//#include //borrowed from LEH for 'improved NXDN sync detection' int strncmperr(const char *s1, const char *s2, size_t size, int MaxErr) @@ -80,6 +80,9 @@ char * getDate(void) { return curr2; } +time_t last_sync_time; +short int time_set = 0; +//last_sync_time = time(NULL); void printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, char *modulation) @@ -89,7 +92,7 @@ printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, //erase(); //attron(COLOR_PAIR(4)); //for (short int i = 0; i < 7; i++) { - //printw("%s \n", FM_banner2[i]);} + //printw("%s \n", FM_banner2[i]);} //attroff(COLOR_PAIR(4)); if (opts->verbose > 0) @@ -105,19 +108,19 @@ printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, if (opts->verbose > 2) { printf ("o: %4i ", offset); - printw("o: %4i ", offset); + //printw("o: %4i ", offset); } if (opts->verbose > 1) { printf ("mod: %s ", modulation); - printw("mod: %s ", modulation); + //printw("mod: %s ", modulation); } if (opts->verbose > 2) { printf ("g: %f ", state->aout_gain); - printw("g: %f ", state->aout_gain); + //printw("g: %f ", state->aout_gain); } - refresh(); + //refresh(); } int @@ -565,6 +568,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) strncpy (synctest32, (synctest_p - 31), 32); if ((strcmp (synctest32, PROVOICE_SYNC) == 0) || (strcmp (synctest32, PROVOICE_EA_SYNC) == 0)) { + now = time(NULL); state->carrier = 1; state->offset = synctest_pos; state->max = ((state->max) + lmax) / 2; @@ -574,7 +578,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) //if (opts->errorbars == 1 && (time(NULL) - now) > 2 ) { printFrameSync (opts, state, " -ProVoice ", synctest_pos + 1, modulation); - now = time(NULL); + //now = time(NULL); } state->lastsynctype = 14; return (14); @@ -590,18 +594,21 @@ getFrameSync (dsd_opts * opts, dsd_state * state) //if (opts->errorbars == 1 && (time(NULL) - now) > 2 ) { printFrameSync (opts, state, " -ProVoice ", synctest_pos + 1, modulation); - now = time(NULL); + //now = time(NULL); //must be something I added, don't even remember why now } state->lastsynctype = 15; return (15); } - else { //HERE HERE - //printf("farts \n"); //well, this is the correct place to interject and have it playback raw audio if I can figure out how to make PA play raw audio damn it - //find something else to use that isn't PortAudio, need a way to send raw audio out from here when no frame sync + else + { + if (time_set == 0) + { + //state->lastsynctype = 99; //HERE HERE set last sync type to 99, special type + last_sync_time = time(NULL); + time_set == 1; + } } - - } - + } if ((opts->frame_nxdn96 == 1) || (opts->frame_nxdn48 == 1)) { strncpy (synctest18, (synctest_p - 17), 18); //seems like other sync tests do this as well @@ -616,7 +623,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) state->offset = synctest_pos; state->max = ((state->max) + lmax) / 2; state->min = ((state->min) + lmin) / 2; - //playRawAudio (opts, state); //test here HERE HERE + if (state->samplesPerSymbol == 20) { sprintf (state->ftype, " NXDN48 "); @@ -928,6 +935,15 @@ getFrameSync (dsd_opts * opts, dsd_state * state) return (-1); } } + + if ( (opts->monitor_input_audio == 1 && (time(NULL) - now) > 1 ) || (opts->monitor_input_audio == 1 && state->lastsynctype == -1) ) + { + //printf ("Playing Raw Audio - Should Keep Printing Over and over\n"); + playRawAudio(opts, state); //this is on line 21 in dsd_audio.c + //currently working on playRawAudio and samples grabbed in dsd_symbol, going to do it outside of the other big loop + + } + } return (-1); diff --git a/src/dsd_main.c b/src/dsd_main.c index 01e6354..df4a0c6 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -56,7 +56,7 @@ int pretty_colors() #include "pa_devs.h" //accidentally had this disabled when getting good NXDN, so if it breaks again, try disabling this short int butt = 1; #include -#include +//#include char * FM_banner[9] = { " CTRL + C twice to exit", " ██████╗ ██████╗██████╗    ███████╗███╗ ███╗███████╗", @@ -118,11 +118,6 @@ noCarrier (dsd_opts * opts, dsd_state * state) sprintf (state->algid, "________"); sprintf (state->keyid, "________________"); mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced); - //test below - //uint16_t sample; - //get_rtlsdr_sample(&sample); - //Pa_StartStream(sample); - //end test } void @@ -297,6 +292,7 @@ initState (dsd_state * state) void usage () { + printf ("\nFME build:%s", GIT_TAG); printf ("\n"); printf ("Usage: dsd [options] Live scanner mode\n"); printf (" or: dsd [options] -r Read/Play saved mbe data from file(s)\n"); @@ -318,11 +314,12 @@ usage () printf (" -i Audio input device (default is /dev/audio, - for piped stdin, rtl for rtl device)\n"); printf (" -o Audio output device (default is /dev/audio)\n"); printf (" -d Create mbe data files, use this directory\n"); - printf (" -r Read/Play saved mbe data from file(s)\n"); + printf (" -r Read/Play saved mbe data from file(s)\n"); printf (" -g Audio output gain (default = 0 = auto, disable = -1)\n"); printf (" -n Do not send synthesized speech to audio output device\n"); - printf (" -w Output synthesized speech to a .wav file\n"); + printf (" -w Output synthesized speech to a .wav file\n"); printf (" -a Display port audio devices\n"); + printf (" -W Monitor Source Audio When No Sync Detected (WIP!)\n"); printf ("\n"); printf ("RTL-SDR options:\n"); printf (" -c RTL-SDR Frequency\n"); @@ -342,9 +339,9 @@ usage () printf (" -fa Auto-detect frame type (default)\n"); printf (" -f1 Decode only P25 Phase 1\n"); printf (" -fd Decode only D-STAR\n"); - printf (" -fi Decode only NXDN48* (6.25 kHz) / IDAS*\n"); + printf (" -fi Decode only NXDN48* (6.25 kHz) / IDAS*\n"); printf (" -fn Decode only NXDN96 (12.5 kHz)\n"); - printf (" -fp Decode only ProVoice*\n"); + printf (" -fp Decode only ProVoice*\n"); printf (" -fr Decode only DMR/MOTOTRBO\n"); printf (" -fx Decode only X2-TDMA\n"); printf (" -l Disable DMR/MOTOTRBO and NXDN input filtering\n"); @@ -524,32 +521,6 @@ sigfun (int sig) #endif } -//LEH version of sigfun -/* -void sigfun (int sig) -{ - UNUSED_VARIABLE(sig); //what is this and where is it defined? - exitflag = 1; - signal (SIGINT, SIG_DFL); -} - -//another LEH thing to free allocated memory -void freeAllocatedMemory(dsd_opts * opts, dsd_state * state) -{ - UNUSED_VARIABLE(opts); - - // Free allocated memory // - free(state->prev_mp_enhanced); - free(state->prev_mp); - free(state->cur_mp); - free(state->audio_out_float_buf); - free(state->audio_out_buf); - free(state->dibit_buf); -} - -*/ -//end LEH version of sigfun - double atofs(char *s) { char last; @@ -603,7 +574,7 @@ main (int argc, char **argv) exitflag = 0; signal (SIGINT, sigfun); - while ((c = getopt (argc, argv, "haep:P:qstv:z:i:o:d:c:g:nw:B:C:R:f:m:u:x:A:S:M:G:D:L:V:U:rl")) != -1) + while ((c = getopt (argc, argv, "haep:P:qstv:z:i:o:d:c:g:nw:B:C:R:f:m:u:x:A:S:M:G:D:L:V:U:Wrl")) != -1) { opterr = 0; switch (c) @@ -667,27 +638,27 @@ main (int argc, char **argv) case 'G': //Set rtl device gain sscanf (optarg, "%d", &opts.rtl_gain_value); //multiple value by ten to make it consitent with the way rtl_fm really works - //opts->audio_in_type = 3; break; case 'L': //Set rtl squelch level sscanf (optarg, "%d", &opts.rtl_squelch_level); //set squelch by user to prevent false positives on NXDN and others - //opts->audio_in_type = 3; break; case 'V': //Set rtl squelch level sscanf (optarg, "%d", &opts.rtl_volume_multiplier); //set 'volume' multiplier for rtl-sdr samples - //opts->audio_in_type = 3; break; case 'U': //Set rtl squelch level sscanf (optarg, "%d", &opts.rtl_udp_port); //set udp port number for RTL remote - //opts->audio_in_type = 3; break; case 'D': //Set rtl device index number sscanf (optarg, "%d", &opts.rtl_dev_index); - //opts->audio_in_type = 3; + break; + + case 'W': //monitor_input_audio if no sync + opts.monitor_input_audio = 1; + printf ("Monitor Source Audio if no sync detected (WIP!)\n"); break; @@ -838,9 +809,9 @@ main (int argc, char **argv) state.rf_mod = 2; //was 2 //opts.symboltiming = 2400; //NXDN48 uses 2400 symbol rate printf ("Setting symbol rate to 2400 / second\n"); - printf ("Enabling only GFSK modulation optimizations.\n"); - printf ("Why are we using GFSK modulations? Isn't NXDN FSK4/C4FM??.\n"); - printf ("Well, it works now, so probably just the way DSD interprets symbols.\n"); + //printf ("Enabling only GFSK modulation optimizations.\n"); + //printf ("Why are we using GFSK modulations? Isn't NXDN FSK4/C4FM??.\n"); + //printf ("Well, it works now, so probably just the way DSD interprets symbols.\n"); printf ("Decoding only NXDN 4800 baud frames.\n"); } else if (optarg[0] == 'n') @@ -858,8 +829,8 @@ main (int argc, char **argv) state.rf_mod = 2; //printf ("Enabling only C4FM/FSK4 modulation optimizations. I really need a new FSK4 modulator\n"); printf ("Enabling only GFSK modulation optimizations.\n"); - printf ("Why are we using GFSK modulations? Isn't NXDN FSK4/C4FM??.\n"); - printf ("Well, it works now, so probably just the way DSD interprets symbols.\n"); + //printf ("Why are we using GFSK modulations? Isn't NXDN FSK4/C4FM??.\n"); + //printf ("Well, it works now, so probably just the way DSD interprets symbols.\n"); //opts.symboltiming = 4800; //NXDN96 uses 4800 symbol rate printf ("Decoding only NXDN 9600 baud frames.\n"); } @@ -1026,9 +997,10 @@ main (int argc, char **argv) openAudioOutDevice (&opts, SAMPLE_RATE_OUT); } openAudioInDevice (&opts); + /* setlocale(LC_ALL, ""); - //sleep(3); - //initscr(); //Initialize NCURSES screen window + sleep(3); + initscr(); //Initialize NCURSES screen window start_color(); init_pair(1, COLOR_YELLOW, COLOR_BLACK); //Yellow/Amber for frame sync/control channel, NV style init_pair(2, COLOR_RED, COLOR_BLACK); //Red for Terminated Calls @@ -1042,6 +1014,7 @@ main (int argc, char **argv) printw("%s \n", FM_banner[i]); } attroff(COLOR_PAIR(4)); refresh(); + */ printf("Press CTRL + C twice to close.\n"); //Kindly remind user to double tap CTRL + C } @@ -1064,6 +1037,6 @@ main (int argc, char **argv) liveScanner (&opts, &state); } cleanupAndExit (&opts, &state); - endwin(); + //endwin(); return (0); } diff --git a/src/dsd_symbol.c b/src/dsd_symbol.c index d34c7e6..93f24b9 100644 --- a/src/dsd_symbol.c +++ b/src/dsd_symbol.c @@ -20,14 +20,16 @@ int getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) { - short sample; + short sample, sample2; int i, sum, symbol, count; ssize_t result; sum = 0; count = 0; - for (i = 0; i < state->samplesPerSymbol; i++) + + for (i = 0; i < state->samplesPerSymbol; i++) //right HERE, this is how many samples it will grab, depending on samplesPerSymbol and also rf_mod messing with it too { + // timing control if ((i == 0) && (have_sync == 0)) { @@ -81,6 +83,8 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) // Read the new sample from the input if(opts->audio_in_type == 0) { result = read (opts->audio_in_fd, &sample, 2); + + } else if (opts->audio_in_type == 1) { result = sf_read_short(opts->audio_in_file, &sample, 1); @@ -98,6 +102,8 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) fprintf( stderr, "Error number: %d\n", err ); fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); } + + #endif } else if (opts->audio_in_type == 3) @@ -105,6 +111,8 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) #ifdef USE_RTLSDR // TODO: need to read demodulated stream here get_rtlsdr_sample(&sample); + + #endif } @@ -206,21 +214,24 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) } } } - if (state->samplesPerSymbol == 20) + + if (state->samplesPerSymbol == 20) //nxdn 4800 baud 2400 symbol rate { if ((i >= 9) && (i <= 11)) { sum += sample; count++; } + //state->input_sample_buffer = sum; //maybe find correct placement for this? } - if (state->samplesPerSymbol == 5) + if (state->samplesPerSymbol == 5) //provoice or gfsk { if (i == 2) { sum += sample; count++; } + //state->input_sample_buffer = sum; } else { @@ -231,6 +242,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) if ((i >= state->symbolCenter - 1) && (i <= state->symbolCenter + 2)) { sum += sample; + //state->input_sample_buffer = sum; count++; } @@ -273,6 +285,8 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) state->lastsample = sample; + //steal sample here for rtl input or stdin input + state->input_sample_buffer = sample; //sample or sum, honestly this seemt to be best place to grab this sadly, sounds terrible most everywhere else } // for symbol = (sum / count); diff --git a/src/rtl_sdr_fm.cpp b/src/rtl_sdr_fm.cpp index 301889f..521226f 100644 --- a/src/rtl_sdr_fm.cpp +++ b/src/rtl_sdr_fm.cpp @@ -728,7 +728,7 @@ int verbose_reset_buffer(rtlsdr_dev_t *dev) } //static void optimal_settings(struct fm_state *fm, int freq, int hopping) -static void optimal_settings(int freq, int rate) //why did you fuck with optimal settings? +static void optimal_settings(int freq, int rate) // { // giant ball of hacks // seems unable to do a single pass, 2:1 @@ -806,9 +806,9 @@ void dongle_init(struct dongle_state *s) s->gain = AUTO_GAIN; // tenths of a dB s->mute = 0; s->direct_sampling = 0; - s->offset_tuning = 0; //0 by default, but don't think it listens to proper frequency when 0, offset and tuned seem to be mixed up + s->offset_tuning = 0; // s->demod_target = &demod; - //s->dev_index = 1; //need to set dev_index from dsd_main as well... + } void demod_init(struct demod_state *s) @@ -943,7 +943,7 @@ static void *socket_thread_fn(void *arg) { while((n = read(sockfd,buffer,5)) != 0) { if(buffer[0] == 0) { new_freq = chars_to_int(buffer); - dongle.freq = new_freq; //not sure if still needed, or ever was needed lul + dongle.freq = new_freq; // optimal_settings(new_freq, demod.rate_in); rtlsdr_set_center_freq(dongle.dev, dongle.freq); //fprintf (stderr, "Tuning to: %d [Hz] (central freq: %d [Hz])\n", new_freq, new_freq + freq_offset);