PulseAudio

Swap Pulse Audio in for all instance where OSS is used
Lots of other potentially things breaking
This commit is contained in:
lwvmobile
2022-02-08 00:26:14 -05:00
committed by GitHub
parent a4aab9a56d
commit 130afdc278
8 changed files with 1266 additions and 69 deletions

View File

@@ -17,67 +17,107 @@
#include "dsd.h"
pa_sample_spec ss;
pa_sample_spec tt;
pa_sample_spec zz;
pa_sample_spec cc;
void openPulseOutput(dsd_opts * opts)
{
ss.format = PA_SAMPLE_S16NE;
ss.channels = 1;
ss.rate = opts->pulse_raw_rate_out; //48000
tt.format = PA_SAMPLE_S16NE;
tt.channels = 1;
tt.rate = opts->pulse_digi_rate_out; //48000, switches to 8000 when using RTL dongle
//printf("digi rate out = %d\n", opts->pulse_digi_rate_out);
//ss
if (opts->monitor_input_audio == 1)
{
opts->pulse_raw_dev_out = pa_simple_new(NULL, "DSD FME", PA_STREAM_PLAYBACK, NULL, "Raw Audio Out", &ss, NULL, NULL, NULL);
}
//tt
opts->pulse_digi_dev_out = pa_simple_new(NULL, "DSD FME", PA_STREAM_PLAYBACK, NULL, "Digi Audio Out", &tt, NULL, NULL, NULL);
}
void openPulseInput(dsd_opts * opts)
{
zz.format = PA_SAMPLE_S16NE;
zz.channels = 1;
zz.rate = opts->pulse_raw_rate_in; //48000
cc.format = PA_SAMPLE_S16NE;
cc.channels = 1;
cc.rate = opts->pulse_digi_rate_in; //48000
//zz
if (opts->monitor_input_audio == 1)
{
opts->pulse_raw_dev_in = pa_simple_new(NULL, "DSD FME", PA_STREAM_RECORD, NULL, "Raw Audio In", &zz, NULL, NULL, NULL);
}
//cc
opts->pulse_digi_dev_in = pa_simple_new(NULL, "DSD FME", PA_STREAM_RECORD, NULL, "Digi Audio In", &cc, NULL, NULL, NULL);
}
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
*/
short obuf, outl, i, sample2, something;
something = state->samplesPerSymbol / 1; //this was 5 in OSS, changed to 1 for pulse audio, no idea how it affects Port Audio
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
//read (opts->audio_in_fd, &sample2, 2); //reading here seems to get same speed as gfsk modulation
pa_simple_read(opts->pulse_raw_dev_in, &sample2, 2, NULL );
obuf = sample2 / 4; //dividing here 'quietens' it down a little bit, helps with clicking and clipping
write (opts->audio_out_fd, (void*)&obuf, 2);
//write (opts->audio_out_fd, (void*)&obuf, 2);
pa_simple_write(opts->pulse_raw_dev_out, (void*)&obuf, 2, NULL);
}
}
#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++){
for (i=0; i < something * 5; i++){ //not sure if this should be 'something' or something * 5 like is was with OSS
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);
//write (opts->audio_out_fd, (void*)&obuf, 2);
pa_simple_write(opts->pulse_raw_dev_out, (void*)&obuf, 2, NULL);
}
}
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
//read (opts->audio_in_fd, &sample2, 2); //reading here seems to get same speed as gfsk modulation
pa_simple_read(opts->pulse_raw_dev_in, &sample2, 2, NULL );
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
Pa_StartStream( opts->audio_out_pa_stream ); //no promises this work
Pa_WriteStream( opts->audio_out_pa_stream, (void*)&obuf, 2); //no promises this 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++){
for (i=0; i < something * 5; i++){ //not sure if this should be 'something' or something * 5 like is was with OSS
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
Pa_StartStream( opts->audio_out_pa_stream ); //no promises this work
Pa_WriteStream( opts->audio_out_pa_stream, (void*)&obuf, 2); //no promises this 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
if (opts->audio_in_type == 1 || opts->audio_in_type == 3){ //only plays at 83% and sounds like s 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);}
//write (opts->audio_out_fd, (void*)&obuf, outl);
pa_simple_write(opts->pulse_raw_dev_out, (void*)&obuf, 2, NULL);
}
#ifdef USE_PORTAUDIO //no idea if this method will work, since I can't test it
if (opts->audio_out_type == 2){
@@ -342,7 +382,6 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state)
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;
@@ -357,9 +396,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)); //12
state->audio_out_idx = 0;
else{
pa_simple_flush(opts->pulse_raw_dev_out, NULL);
pa_simple_write(opts->pulse_digi_dev_out, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2), NULL); //Yay! It works.
state->audio_out_idx = 0; }
}
if (state->audio_out_idx2 >= 800000)
@@ -450,6 +490,12 @@ void
openAudioOutDevice (dsd_opts * opts, int speed)
{
// get info of device/file
/*
if(strncmp(opts->audio_out_dev, "pulse", 5) == 0)
{
opts->audio_out_type == 0;
}
*/
if(strncmp(opts->audio_out_dev, "pa:", 3) == 0)
{
opts->audio_out_type = 2;
@@ -462,21 +508,26 @@ openAudioOutDevice (dsd_opts * opts, int speed)
exit(1);
#endif
}
if(strncmp(opts->audio_in_dev, "pulse", 5) == 0)
{
opts->audio_in_type = 0;
}
else
{
struct stat stat_buf;
if(stat(opts->audio_out_dev, &stat_buf) != 0)
if(stat(opts->audio_out_dev, &stat_buf) != 0 && strncmp(opts->audio_out_dev, "pulse", 5 != 0)) //HERE
{
printf("Error, couldn't open %s\n", opts->audio_out_dev);
exit(1);
}
if( !(S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode)))
if( (!(S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode))) && strncmp(opts->audio_out_dev, "pulse", 5 != 0))
{
// this is not a device
printf("Error, %s is not a device. use -w filename for wav output.\n", opts->audio_out_dev);
exit(1);
}
/*
#ifdef SOLARIS
sample_info_t aset, aget;
@@ -484,7 +535,7 @@ openAudioOutDevice (dsd_opts * opts, int speed)
if (opts->audio_out_fd == -1)
{
printf ("Error, couldn't open %s\n", opts->audio_out_dev);
exit (1);
//exit (1);
}
// get current
@@ -514,7 +565,7 @@ openAudioOutDevice (dsd_opts * opts, int speed)
{
printf ("Error, couldn't open %s\n", opts->audio_out_dev);
opts->audio_out = 0;
exit(1);
//exit(1);
}
fmt = 0;
@@ -539,6 +590,7 @@ openAudioOutDevice (dsd_opts * opts, int speed)
}
#endif
*/
}
printf ("Audio Out Device: %s\n", opts->audio_out_dev);
}
@@ -559,7 +611,7 @@ openAudioInDevice (dsd_opts * opts)
if(opts->audio_in_file == NULL) {
printf ("Error, couldn't open stdin with libsndfile: %s\n", sf_strerror(NULL));
exit(1);
//exit(1);
}
}
else if(strncmp(opts->audio_in_dev, "pa:", 2) == 0)
@@ -585,6 +637,10 @@ openAudioInDevice (dsd_opts * opts)
else if(strncmp(opts->audio_in_dev, "rtl", 3) == 0)
{
opts->audio_in_type = 3;
}
else if(strncmp(opts->audio_in_dev, "pulse", 5) == 0)
{
opts->audio_in_type = 0;
}
else
{
@@ -610,8 +666,9 @@ openAudioInDevice (dsd_opts * opts)
}
else
{
// this is a device, use old handling
// this is a device, use old handling, pulse audio now
opts->audio_in_type = 0;
/*
#ifdef SOLARIS
sample_info_t aset, aget;
int rgain;
@@ -629,7 +686,7 @@ openAudioInDevice (dsd_opts * opts)
if (opts->audio_in_fd == -1)
{
printf ("Error, couldn't open %s\n", opts->audio_in_dev);
exit(1);
//exit(1);
}
// get current
@@ -652,7 +709,8 @@ openAudioInDevice (dsd_opts * opts)
exit (1);
}
#endif
*/
/*
#if defined(BSD) && !defined(__APPLE__)
int fmt;
@@ -692,6 +750,7 @@ openAudioInDevice (dsd_opts * opts)
printf ("ioctl setfmt error \n");
}
#endif
*/
}
}