Raw Signal Wav File Saving; #163

This commit is contained in:
lwvmobile
2023-09-05 11:28:50 -04:00
parent d917f85926
commit 6e7f2962f0
4 changed files with 44 additions and 12 deletions

View File

@@ -534,7 +534,7 @@ void openWavOutFileRaw (dsd_opts * opts, dsd_state * state)
info.samplerate = 48000; //8000
info.channels = 1;
info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 | SF_ENDIAN_LITTLE;
opts->wav_out_raw = sf_open (opts->wav_out_file_raw, SFM_RDWR, &info);
opts->wav_out_raw = sf_open (opts->wav_out_file_raw, SFM_WRITE, &info);
if (opts->wav_out_raw == NULL)
{
fprintf (stderr,"Error - could not open raw wav output file %s\n", opts->wav_out_file_raw);

View File

@@ -1136,6 +1136,7 @@ usage ()
printf (" -r <files> Read/Play saved mbe data from file(s)\n");
printf (" -g <num> Audio output gain (default = 0 = auto, disable = -1)\n");
printf (" -w <file> Output synthesized speech to a .wav file, legacy auto modes only.\n");
printf (" -6 <file> Output raw audio .wav file (48K/1). (WARNING! Large File Sizes 1 Hour ~= 360 MB)\n");
printf (" -8 Enable Experimental Source Audio Monitor (OSS at 48k1 and Pulse Audio)\n");
printf (" (Its recommended to use Squelch in SDR++ or GQRX, etc, if monitoring mixed analog/digital)\n");
printf (" -P Enable Per Call WAV file saving in XDMA and NXDN decoding classes\n");
@@ -1839,6 +1840,13 @@ main (int argc, char **argv)
openWavOutFile (&opts, &state);
break;
case '6':
strncpy(opts.wav_out_file_raw, optarg, 1023);
opts.wav_out_file_raw[1023] = '\0';
fprintf (stderr,"Writing raw audio to file %s\n", opts.wav_out_file_raw);
openWavOutFileRaw (&opts, &state);
break;
case 'f':
if (optarg[0] == 'a')
{

View File

@@ -2345,9 +2345,9 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{
printw ("| Writing MBE data files to directory %s\n", opts->mbe_out_dir);
}
if (opts->wav_out_file_raw[0] != 0 && opts->audio_in_type == 0)
if (opts->wav_out_raw)
{
printw ("| Appending Raw Sig Audio WAV to file %s\n", opts->wav_out_file_raw);
printw ("| Raw Audio Output: %s\n", opts->wav_out_file_raw);
}
if (opts->symbol_out_file[0] != 0 && opts->symbol_out == 1)
{

View File

@@ -265,7 +265,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
}
//Source Audio Monitoring
if (have_sync == 0 && opts->monitor_input_audio == 1)
if (have_sync == 0)
{
//sanity check to prevent an overflow
if (state->analog_sample_counter > 959)
@@ -276,18 +276,18 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
if (state->analog_sample_counter == 960)
{
//get an rms value if not using the rtl built in version
if (opts->audio_in_type != 3)
if (opts->audio_in_type != 3 && opts->monitor_input_audio == 1)
opts->rtl_rms = raw_rms(state->analog_out, 960, 1);
//debug
// opts->rtl_rms = 101;
//make it a little quieter
for (int x = 0; x < 960; x++)
state->analog_out[x] /= 4;
// for (int x = 0; x < 960; x++)
// state->analog_out[x] /= 4;
//seems to be working now, but RMS values are lower on actual analog signal than on no signal but noise
if ( opts->rtl_rms > opts->rtl_squelch_level )
if ( (opts->rtl_rms > opts->rtl_squelch_level) && (opts->monitor_input_audio == 1) )
{
if (opts->audio_out_type == 0)
pa_simple_write(opts->pulse_raw_dev_out, state->analog_out, 960*2, NULL);
@@ -301,17 +301,41 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
state->last_vc_sync_time = time(NULL);
}
//raw wav file saving -- only write when not NXDN, dPMR, or M17 due to noise that can cause tons of false positives when no sync
if (opts->wav_out_raw != NULL && opts->frame_nxdn48 == 0 && opts->frame_nxdn96 == 0 && opts->frame_dpmr == 0 && opts->frame_m17 == 0)
{
sf_write_short(opts->wav_out_raw, state->analog_out, 960);
sf_write_sync (opts->wav_out_raw);
}
memset (state->analog_out, 0, sizeof(state->analog_out));
state->analog_sample_counter = 0;
}
}
if (have_sync == 1 && opts->monitor_input_audio == 1)
if (have_sync == 1)
{
//zero out and reset counter
memset (state->analog_out, 0, sizeof(state->analog_out));
state->analog_sample_counter = 0;
//sanity check to prevent an overflow
if (state->analog_sample_counter > 959)
state->analog_sample_counter = 959;
state->analog_out[state->analog_sample_counter++] = sample;
if (state->analog_sample_counter == 960)
{
//raw wav file saving -- file size on this blimps pretty fast 1 min ~= 6 MB; 1 hour ~= 360 MB;
if (opts->wav_out_raw != NULL)
{
sf_write_short(opts->wav_out_raw, state->analog_out, 960);
sf_write_sync (opts->wav_out_raw);
}
//zero out and reset counter
memset (state->analog_out, 0, sizeof(state->analog_out));
state->analog_sample_counter = 0;
}
}
if (opts->use_cosine_filter)