From 9249b7a9436ba8eaf341832a8a3f04008b98455b Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Sun, 24 Mar 2024 12:28:26 -0400 Subject: [PATCH] Simply Mono Short Playback; --- include/dsd.h | 2 + src/dpmr_voice.c | 2 +- src/dsd_audio2.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++- src/dsd_mbe.c | 8 +-- src/dsd_mbe2.c | 4 +- src/nxdn_voice.c | 2 +- src/p25p1_ldu1.c | 18 +++---- src/p25p1_ldu2.c | 18 +++---- src/provoice.c | 8 +-- src/ysf.c | 6 +-- 10 files changed, 158 insertions(+), 34 deletions(-) diff --git a/include/dsd.h b/include/dsd.h index c9db9d9..d9622c2 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -994,6 +994,8 @@ void agf (dsd_opts * opts, dsd_state * state, float samp[160], int slot); //floa void agsm (dsd_opts * opts, dsd_state * state, short * input, int len); //short gain control for analog things void analog_gain (dsd_opts * opts, dsd_state * state, short * input, int len); //manual gain handling for analong things //new short stuff +void playSynthesizedVoiceMS (dsd_opts * opts, dsd_state * state); //short mono mix +void playSynthesizedVoiceMSR (dsd_opts * opts, dsd_state * state); //short mono mix R (needed for OSS 48k input/output) void playSynthesizedVoiceSS (dsd_opts * opts, dsd_state * state); //short stereo mix void playSynthesizedVoiceSS3 (dsd_opts * opts, dsd_state * state); //short stereo mix 3v2 DMR void playSynthesizedVoiceSS4 (dsd_opts * opts, dsd_state * state); //short stereo mix 4v2 P25p2 diff --git a/src/dpmr_voice.c b/src/dpmr_voice.c index 54a7c53..8981c1b 100644 --- a/src/dpmr_voice.c +++ b/src/dpmr_voice.c @@ -478,7 +478,7 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state) { processMbeFrame (opts, state, NULL, ambe_fr[i], NULL); if (opts->floating_point == 0) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1) playSynthesizedVoiceFM(opts, state); } diff --git a/src/dsd_audio2.c b/src/dsd_audio2.c index e472fd9..a9b5c1a 100644 --- a/src/dsd_audio2.c +++ b/src/dsd_audio2.c @@ -724,6 +724,128 @@ void playSynthesizedVoiceFM (dsd_opts * opts, dsd_state * state) } +//Mono - Short (SB16LE) - Drop-in replacement for playSyntesizedVoice, but easier to manipulate +void playSynthesizedVoiceMS (dsd_opts * opts, dsd_state * state) +{ + int i; + size_t len = state->audio_out_idx; + + //debug + // fprintf (stderr, " L LEN: %d", len); + + short mono_samp[len]; + memset (mono_samp, 0, len*sizeof(short)); + + if (opts->slot1_on == 0) + goto MS_END; + + if (len == 160) + { + for (i = 0; i < len; i++) + mono_samp[i] = state->s_l[i]; + } + else if (len == 960) + { + state->audio_out_buf_p -= 960; //rewind first + for (i = 0; i < len; i++) + { + mono_samp[i] = *state->audio_out_buf_p; + state->audio_out_buf_p++; + } + } + + if (opts->use_hpf_d == 1) + hpf_dL(state, state->s_l, len); + + if (opts->audio_out_type == 0) //Pulse Audio + pa_simple_write(opts->pulse_digi_dev_out, mono_samp, len*2, NULL); + + if (opts->audio_out_type == 8) //UDP Audio + udp_socket_blaster (opts, state, len*2, mono_samp); + + if (opts->audio_out_type == 1 || opts->audio_out_type == 2 || opts->audio_out_type == 5) //STDOUT or OSS + write (opts->audio_out_fd, mono_samp, len*2); + + MS_END: + + //run cleanup since we pulled stuff from processAudio + state->audio_out_idx = 0; + + //set short temp buffer to baseline + memset (state->s_l, 0, sizeof(state->s_l)); + + 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; + } + +} + +//Mono - Short (SB16LE) - Drop-in replacement for playSyntesizedVoiceR, but easier to manipulate +void playSynthesizedVoiceMSR (dsd_opts * opts, dsd_state * state) +{ + int i; + size_t len = state->audio_out_idxR; + + //debug + // fprintf (stderr, " R LEN: %d", len); + + short mono_samp[len]; + memset (mono_samp, 0, len*sizeof(short)); + + if (opts->slot2_on == 0) + goto MS_ENDR; + + if (len == 160) + { + for (i = 0; i < len; i++) + mono_samp[i] = state->s_r[i]; + } + else if (len == 960) + { + state->audio_out_buf_pR -= 960; //rewind first + for (i = 0; i < len; i++) + { + mono_samp[i] = *state->audio_out_buf_pR; + state->audio_out_buf_pR++; + } + } + + if (opts->use_hpf_d == 1) + hpf_dR(state, mono_samp, len); + + if (opts->audio_out_type == 0) //Pulse Audio + pa_simple_write(opts->pulse_digi_dev_out, mono_samp, len*2, NULL); + + if (opts->audio_out_type == 8) //UDP Audio + udp_socket_blaster (opts, state, len*2, mono_samp); + + if (opts->audio_out_type == 1 || opts->audio_out_type == 2 || opts->audio_out_type == 5) //STDOUT or OSS + write (opts->audio_out_fd, mono_samp, len*2); + + MS_ENDR: + + //run cleanup since we pulled stuff from processAudioR + state->audio_out_idxR = 0; + + //set short temp buffer to baseline + memset (state->s_r, 0, sizeof(state->s_r)); + + if (state->audio_out_idx2R >= 800000) + { + state->audio_out_float_buf_pR = state->audio_out_float_bufR + 100; + state->audio_out_buf_pR = state->audio_out_bufR + 100; + memset (state->audio_out_float_bufR, 0, 100 * sizeof (float)); + memset (state->audio_out_bufR, 0, 100 * sizeof (short)); + state->audio_out_idx2R = 0; + } + +} + //Stereo Mix - Short (SB16LE) -- When Playing Short FDMA samples when setup for stereo output void playSynthesizedVoiceSS (dsd_opts * opts, dsd_state * state) { @@ -731,7 +853,7 @@ void playSynthesizedVoiceSS (dsd_opts * opts, dsd_state * state) int i; int encL; short stereo_samp1[320]; //8k 2-channel stereo interleave mix - memset (stereo_samp1, 1, sizeof(stereo_samp1)); + memset (stereo_samp1, 0, sizeof(stereo_samp1)); //enc checkdown for whether or not to fill the stereo sample or not for playback or writing encL = 0; diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index d1d58e9..07075c8 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -134,7 +134,7 @@ void playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv) if (opts->audio_out == 1 && opts->floating_point == 0) { - playSynthesizedVoice (opts, state); + playSynthesizedVoiceMS (opts, state); } if (opts->floating_point == 1) { @@ -174,7 +174,7 @@ void playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv) if (opts->audio_out == 1 && opts->floating_point == 0) { - playSynthesizedVoice (opts, state); + playSynthesizedVoiceMS (opts, state); } if (opts->floating_point == 1) { @@ -1084,7 +1084,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } if (opts->audio_out == 1 && opts->floating_point == 0 && opts->audio_out_type == 5 && opts->slot1_on == 1) //for OSS 48k 1 channel configs -- relocate later if possible { - playSynthesizedVoice (opts, state); //it may be more beneficial to move this to each individual decoding type to handle, but ultimately, let's just simpifly mbe handling instead + playSynthesizedVoiceMS (opts, state); //it may be more beneficial to move this to each individual decoding type to handle, but ultimately, let's just simpifly mbe handling instead } } @@ -1161,7 +1161,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } if (opts->audio_out == 1 && opts->floating_point == 0 && opts->audio_out_type == 5 && opts->slot2_on == 1) //for OSS 48k 1 channel configs -- relocate later if possible { - playSynthesizedVoiceR (opts, state); + playSynthesizedVoiceMSR (opts, state); } } diff --git a/src/dsd_mbe2.c b/src/dsd_mbe2.c index 76dc0fe..55dcebb 100644 --- a/src/dsd_mbe2.c +++ b/src/dsd_mbe2.c @@ -115,7 +115,7 @@ void soft_mbe (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char amb PrintAMBEData (opts, state, ambe_d); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) playSynthesizedVoiceFM(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) @@ -138,7 +138,7 @@ void soft_mbe (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char amb PrintAMBEData (opts, state, ambe_d); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) playSynthesizedVoiceFM(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) diff --git a/src/nxdn_voice.c b/src/nxdn_voice.c index 927ff65..326151f 100644 --- a/src/nxdn_voice.c +++ b/src/nxdn_voice.c @@ -93,7 +93,7 @@ void nxdn_voice (dsd_opts * opts, dsd_state * state, int voice, uint8_t dbuf[182 memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l)); if (opts->floating_point == 0 ) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1) playSynthesizedVoiceFM(opts, state); } diff --git a/src/p25p1_ldu1.c b/src/p25p1_ldu1.c index 7c784ed..2950a71 100644 --- a/src/p25p1_ldu1.c +++ b/src/p25p1_ldu1.c @@ -60,7 +60,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -74,7 +74,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -95,7 +95,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -116,7 +116,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -137,7 +137,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -158,7 +158,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -179,7 +179,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -200,7 +200,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -261,7 +261,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) diff --git a/src/p25p1_ldu2.c b/src/p25p1_ldu2.c index dec7113..54cd32e 100644 --- a/src/p25p1_ldu2.c +++ b/src/p25p1_ldu2.c @@ -65,7 +65,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -79,7 +79,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -100,7 +100,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -121,7 +121,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -142,7 +142,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -163,7 +163,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -184,7 +184,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) playSynthesizedVoiceFM(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 2) @@ -203,7 +203,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) @@ -264,7 +264,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif process_IMBE (opts, state, &status_count); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1) diff --git a/src/provoice.c b/src/provoice.c index b24f4e6..a348ba9 100644 --- a/src/provoice.c +++ b/src/provoice.c @@ -214,12 +214,12 @@ void processProVoice (dsd_opts * opts, dsd_state * state) processMbeFrame (opts, state, NULL, NULL, imbe7100_fr1); if (opts->floating_point == 0) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1) playSynthesizedVoiceFM(opts, state); processMbeFrame (opts, state, NULL, NULL, imbe7100_fr2); if (opts->floating_point == 0) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1) playSynthesizedVoiceFM(opts, state); @@ -392,12 +392,12 @@ void processProVoice (dsd_opts * opts, dsd_state * state) processMbeFrame (opts, state, NULL, NULL, imbe7100_fr1); if (opts->floating_point == 0) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1) playSynthesizedVoiceFM(opts, state); processMbeFrame (opts, state, NULL, NULL, imbe7100_fr2); if (opts->floating_point == 0) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1) playSynthesizedVoiceFM(opts, state); diff --git a/src/ysf.c b/src/ysf.c index a94bbd3..8ed1910 100644 --- a/src/ysf.c +++ b/src/ysf.c @@ -737,7 +737,7 @@ void ysf_ehr (dsd_opts * opts, dsd_state * state, uint8_t dbuf[180], int start, writeSynthesizedVoice (opts, state); if (opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if(opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); @@ -1027,7 +1027,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) if (opts->wav_out_f != NULL) writeSynthesizedVoice (opts, state); if (opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if(opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); @@ -1147,7 +1147,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) writeSynthesizedVoice (opts, state); if (opts->pulse_digi_out_channels == 1) - playSynthesizedVoice(opts, state); + playSynthesizedVoiceMS(opts, state); if(opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state);