Add stdout option for audio output

This commit is contained in:
ars-ka0s 2023-01-17 01:25:08 -06:00
parent 58652df5b9
commit f1fcb8cd95
2 changed files with 205 additions and 162 deletions

View File

@ -129,6 +129,7 @@ static struct adev_s {
int outbuf_len; int outbuf_len;
enum audio_in_type_e g_audio_in_type; enum audio_in_type_e g_audio_in_type;
enum audio_out_type_e g_audio_out_type;
int udp_sock; /* UDP socket for receiving data */ int udp_sock; /* UDP socket for receiving data */
@ -453,9 +454,20 @@ int audio_open (struct audio_s *pa)
} }
/* /*
* Output device. Only "soundcard" is supported at this time. * Output device. Only "soundcard" and "stdout" are supported at this time.
*/ */
if (strcasecmp(pa->adev[a].adevice_out, "stdout") == 0 || strcmp(pa->adev[a].adevice_out, "-") == 0) {
adev[a].g_audio_out_type = AUDIO_OUT_TYPE_STDOUT;
} else {
adev[a].g_audio_out_type = AUDIO_OUT_TYPE_SOUNDCARD;
}
switch (adev[a].g_audio_out_type) {
case AUDIO_OUT_TYPE_STDOUT:
adev[a].outbuf_size_in_bytes = 1024;
break;
case AUDIO_OUT_TYPE_SOUNDCARD:
#if USE_ALSA #if USE_ALSA
err = snd_pcm_open (&(adev[a].audio_out_handle), audio_out_name, SND_PCM_STREAM_PLAYBACK, 0); err = snd_pcm_open (&(adev[a].audio_out_handle), audio_out_name, SND_PCM_STREAM_PLAYBACK, 0);
@ -498,7 +510,7 @@ int audio_open (struct audio_s *pa)
return (-1); return (-1);
} }
#endif #endif
}
/* /*
* Finally allocate buffer for each direction. * Finally allocate buffer for each direction.
*/ */
@ -1333,6 +1345,29 @@ int audio_put (int a, int c)
int audio_flush (int a) int audio_flush (int a)
{ {
switch (adev[a].g_audio_out_type) {
case AUDIO_OUT_TYPE_STDOUT:;
int res;
unsigned char *ptr;
int len;
ptr = adev[a].outbuf_ptr;
len = adev[a].outbuf_len;
while (len > 0) {
res = write(STDOUT_FILENO, ptr, (size_t) len);
if (res <= 0) {
text_color_set(DW_COLOR_INFO);
dw_printf ("\nError writing to stdout. Exiting.\n");
exit (0);
}
ptr += res;
len -= res;
}
adev[a].outbuf_len = 0;
return 0;
case AUDIO_OUT_TYPE_SOUNDCARD:;
#if USE_ALSA #if USE_ALSA
int k; int k;
unsigned char *psound; unsigned char *psound;
@ -1504,7 +1539,8 @@ int audio_flush (int a)
adev[a].outbuf_len = 0; adev[a].outbuf_len = 0;
return (0); return (0);
#endif #endif
}
return (0);
} /* end audio_flush */ } /* end audio_flush */
@ -1546,9 +1582,12 @@ int audio_flush (int a)
void audio_wait (int a) void audio_wait (int a)
{ {
audio_flush (a); audio_flush (a);
if (adev[a].g_audio_out_type == AUDIO_OUT_TYPE_STDOUT) {
return;
}
#if USE_ALSA #if USE_ALSA
/* For playback, this should wait for all pending frames */ /* For playback, this should wait for all pending frames */

View File

@ -43,6 +43,10 @@ enum audio_in_type_e {
AUDIO_IN_TYPE_SDR_UDP, AUDIO_IN_TYPE_SDR_UDP,
AUDIO_IN_TYPE_STDIN }; AUDIO_IN_TYPE_STDIN };
enum audio_out_type_e {
AUDIO_OUT_TYPE_SOUNDCARD,
AUDIO_OUT_TYPE_STDOUT };
/* For option to try fixing frames with bad CRC. */ /* For option to try fixing frames with bad CRC. */
typedef enum retry_e { typedef enum retry_e {