simpleaudio: handle any audio sample rate
This commit is contained in:
parent
500208ba81
commit
22317f54fc
|
@ -285,6 +285,9 @@ main( int argc, char*argv[] )
|
||||||
|
|
||||||
simpleaudio * (*simpleaudio_open_system_audio)() = NULL;
|
simpleaudio * (*simpleaudio_open_system_audio)() = NULL;
|
||||||
|
|
||||||
|
unsigned int sample_rate = 48000;
|
||||||
|
unsigned int nchannels = 1; // FIXME: only works with one channel
|
||||||
|
|
||||||
/* configure the default system audio mechanism */
|
/* configure the default system audio mechanism */
|
||||||
#if USE_PULSEAUDIO
|
#if USE_PULSEAUDIO
|
||||||
simpleaudio_open_system_audio = simpleaudio_open_stream_pulseaudio;
|
simpleaudio_open_system_audio = simpleaudio_open_stream_pulseaudio;
|
||||||
|
@ -511,6 +514,7 @@ main( int argc, char*argv[] )
|
||||||
tx_interactive = 0;
|
tx_interactive = 0;
|
||||||
#if USE_SNDFILE
|
#if USE_SNDFILE
|
||||||
sa_out = simpleaudio_open_stream_sndfile(SA_STREAM_PLAYBACK,
|
sa_out = simpleaudio_open_stream_sndfile(SA_STREAM_PLAYBACK,
|
||||||
|
sample_rate, nchannels,
|
||||||
filename);
|
filename);
|
||||||
#endif
|
#endif
|
||||||
if ( ! sa_out )
|
if ( ! sa_out )
|
||||||
|
@ -519,6 +523,7 @@ main( int argc, char*argv[] )
|
||||||
|
|
||||||
if ( ! sa_out )
|
if ( ! sa_out )
|
||||||
sa_out = simpleaudio_open_system_audio(SA_STREAM_PLAYBACK,
|
sa_out = simpleaudio_open_system_audio(SA_STREAM_PLAYBACK,
|
||||||
|
sample_rate, nchannels,
|
||||||
program_name, "output audio");
|
program_name, "output audio");
|
||||||
if ( ! sa_out )
|
if ( ! sa_out )
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -540,7 +545,9 @@ main( int argc, char*argv[] )
|
||||||
simpleaudio *sa = NULL;
|
simpleaudio *sa = NULL;
|
||||||
if ( filename ) {
|
if ( filename ) {
|
||||||
#if USE_SNDFILE
|
#if USE_SNDFILE
|
||||||
sa = simpleaudio_open_stream_sndfile(SA_STREAM_RECORD, filename);
|
sa = simpleaudio_open_stream_sndfile(SA_STREAM_RECORD,
|
||||||
|
sample_rate, nchannels,
|
||||||
|
filename);
|
||||||
#endif
|
#endif
|
||||||
if ( ! sa )
|
if ( ! sa )
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -548,15 +555,11 @@ main( int argc, char*argv[] )
|
||||||
|
|
||||||
if ( ! sa )
|
if ( ! sa )
|
||||||
sa = simpleaudio_open_system_audio(SA_STREAM_RECORD,
|
sa = simpleaudio_open_system_audio(SA_STREAM_RECORD,
|
||||||
|
sample_rate, nchannels,
|
||||||
program_name, "input audio");
|
program_name, "input audio");
|
||||||
if ( !sa )
|
if ( !sa )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
unsigned int sample_rate = simpleaudio_get_rate(sa);
|
|
||||||
unsigned int nchannels = simpleaudio_get_channels(sa);
|
|
||||||
|
|
||||||
assert( nchannels == 1 );
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare the input sample chunk rate
|
* Prepare the input sample chunk rate
|
||||||
|
|
|
@ -43,7 +43,7 @@ simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur)
|
||||||
|
|
||||||
if ( tone_freq != 0 ) {
|
if ( tone_freq != 0 ) {
|
||||||
|
|
||||||
float wave_nsamples = 48000.0 / tone_freq; // FIXME rate
|
float wave_nsamples = simpleaudio_get_rate(sa_out) / tone_freq;
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
for ( i=0; i<nsamples_dur; i++ )
|
for ( i=0; i<nsamples_dur; i++ )
|
||||||
|
|
|
@ -104,13 +104,10 @@ static const struct simpleaudio_backend simpleaudio_backend_alsa = {
|
||||||
|
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_alsa(
|
simpleaudio_open_stream_alsa(
|
||||||
// unsigned int rate, unsigned int channels,
|
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
unsigned int rate, unsigned int channels,
|
||||||
char *app_name, char *stream_name )
|
char *app_name, char *stream_name )
|
||||||
{
|
{
|
||||||
unsigned int rate = 48000;
|
|
||||||
unsigned int channels = 1;
|
|
||||||
|
|
||||||
snd_pcm_t *pcm;
|
snd_pcm_t *pcm;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,8 @@ static const struct simpleaudio_backend simpleaudio_backend_pulse = {
|
||||||
|
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_pulseaudio(
|
simpleaudio_open_stream_pulseaudio(
|
||||||
// unsigned int rate, unsigned int channels,
|
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
unsigned int rate, unsigned int channels,
|
||||||
char *app_name, char *stream_name )
|
char *app_name, char *stream_name )
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
@ -100,10 +100,8 @@ simpleaudio_open_stream_pulseaudio(
|
||||||
/* The sample type to use */
|
/* The sample type to use */
|
||||||
pa_sample_spec ss = {
|
pa_sample_spec ss = {
|
||||||
.format = PA_SAMPLE_FLOAT32,
|
.format = PA_SAMPLE_FLOAT32,
|
||||||
// .rate = rate,
|
.rate = rate,
|
||||||
.rate = 48000,
|
.channels = channels,
|
||||||
// .channels = channels,
|
|
||||||
.channels = 1,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pa_buffer_attr attr = {
|
pa_buffer_attr attr = {
|
||||||
|
|
|
@ -135,13 +135,14 @@ sndfile_format_from_path( const char *path )
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_sndfile(
|
simpleaudio_open_stream_sndfile(
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
unsigned int rate, unsigned int channels,
|
||||||
char *path )
|
char *path )
|
||||||
{
|
{
|
||||||
/* setting for SA_STREAM_PLAYBACK (file write) */
|
/* setting for SA_STREAM_PLAYBACK (file write) */
|
||||||
SF_INFO sfinfo = {
|
SF_INFO sfinfo = {
|
||||||
.format = 0,
|
.format = 0,
|
||||||
.samplerate = 48000,
|
.samplerate = rate,
|
||||||
.channels = 1,
|
.channels = channels,
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( sa_stream_direction == SA_STREAM_PLAYBACK )
|
if ( sa_stream_direction == SA_STREAM_PLAYBACK )
|
||||||
|
|
|
@ -38,19 +38,20 @@ enum {
|
||||||
|
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_pulseaudio(
|
simpleaudio_open_stream_pulseaudio(
|
||||||
// unsigned int rate, unsigned int channels,
|
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
unsigned int rate, unsigned int channels,
|
||||||
char *app_name, char *stream_name );
|
char *app_name, char *stream_name );
|
||||||
|
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_alsa(
|
simpleaudio_open_stream_alsa(
|
||||||
// unsigned int rate, unsigned int channels,
|
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
unsigned int rate, unsigned int channels,
|
||||||
char *app_name, char *stream_name );
|
char *app_name, char *stream_name );
|
||||||
|
|
||||||
simpleaudio *
|
simpleaudio *
|
||||||
simpleaudio_open_stream_sndfile(
|
simpleaudio_open_stream_sndfile(
|
||||||
int sa_stream_direction,
|
int sa_stream_direction,
|
||||||
|
unsigned int rate, unsigned int channels,
|
||||||
char *path );
|
char *path );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue