simpleaudio: S16 format handling for backends
This commit is contained in:
parent
a65a20d274
commit
6671138471
|
@ -115,11 +115,22 @@ sa_alsa_open_stream(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( sa_format == SA_SAMPLE_FORMAT_FLOAT );
|
snd_pcm_format_t pcm_format;
|
||||||
|
|
||||||
|
switch ( sa->format ) {
|
||||||
|
case SA_SAMPLE_FORMAT_FLOAT:
|
||||||
|
pcm_format = SND_PCM_FORMAT_FLOAT;
|
||||||
|
break;
|
||||||
|
case SA_SAMPLE_FORMAT_S16:
|
||||||
|
pcm_format = SND_PCM_FORMAT_S16;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* set up ALSA hardware params */
|
/* set up ALSA hardware params */
|
||||||
error = snd_pcm_set_params(pcm,
|
error = snd_pcm_set_params(pcm,
|
||||||
SND_PCM_FORMAT_FLOAT,
|
pcm_format,
|
||||||
SND_PCM_ACCESS_RW_INTERLEAVED,
|
SND_PCM_ACCESS_RW_INTERLEAVED,
|
||||||
channels,
|
channels,
|
||||||
rate,
|
rate,
|
||||||
|
|
|
@ -92,11 +92,22 @@ sa_pulse_open_stream(
|
||||||
// FIXME - use source for something
|
// FIXME - use source for something
|
||||||
// just take the default pulseaudio source for now
|
// just take the default pulseaudio source for now
|
||||||
|
|
||||||
assert( sa_format == SA_SAMPLE_FORMAT_FLOAT );
|
pa_sample_format_t pa_format;
|
||||||
|
|
||||||
|
switch ( sa->format ) {
|
||||||
|
case SA_SAMPLE_FORMAT_FLOAT:
|
||||||
|
pa_format = PA_SAMPLE_FLOAT32;
|
||||||
|
break;
|
||||||
|
case SA_SAMPLE_FORMAT_S16:
|
||||||
|
pa_format = PA_SAMPLE_S16LE; // FIXME: handle S16BE
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* The sample type to use */
|
/* The sample type to use */
|
||||||
pa_sample_spec ss = {
|
pa_sample_spec ss = {
|
||||||
.format = PA_SAMPLE_FLOAT32,
|
.format = pa_format,
|
||||||
.rate = rate,
|
.rate = rate,
|
||||||
.channels = channels,
|
.channels = channels,
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,12 +44,23 @@ sa_sndfile_read( simpleaudio *sa, void *buf, size_t nframes )
|
||||||
{
|
{
|
||||||
SNDFILE *s = (SNDFILE *)sa->backend_handle;
|
SNDFILE *s = (SNDFILE *)sa->backend_handle;
|
||||||
int n;
|
int n;
|
||||||
if ((n = sf_readf_float(s, buf, nframes)) < 0) {
|
switch ( sa->format ) {
|
||||||
fprintf(stderr, "sf_read_float: ");
|
case SA_SAMPLE_FORMAT_FLOAT:
|
||||||
|
n = sf_readf_float(s, buf, nframes);
|
||||||
|
break;
|
||||||
|
case SA_SAMPLE_FORMAT_S16:
|
||||||
|
n = sf_readf_short(s, buf, nframes);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( n < 0 ) {
|
||||||
|
fprintf(stderr, "sf_read: ");
|
||||||
sf_perror(s);
|
sf_perror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//fprintf(stderr, "sf_readf_float: nframes=%ld n=%d\n", nframes, n);
|
// fprintf(stderr, "sf_read: nframes=%ld n=%d\n", nframes, n);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,11 +68,22 @@ sa_sndfile_read( simpleaudio *sa, void *buf, size_t nframes )
|
||||||
static ssize_t
|
static ssize_t
|
||||||
sa_sndfile_write( simpleaudio *sa, void *buf, size_t nframes )
|
sa_sndfile_write( simpleaudio *sa, void *buf, size_t nframes )
|
||||||
{
|
{
|
||||||
//fprintf(stderr, "sf_writef_float: nframes=%ld\n", nframes);
|
// fprintf(stderr, "sf_write: nframes=%ld\n", nframes);
|
||||||
SNDFILE *s = (SNDFILE *)sa->backend_handle;
|
SNDFILE *s = (SNDFILE *)sa->backend_handle;
|
||||||
int n;
|
int n;
|
||||||
if ((n = sf_writef_float(s, buf, nframes)) < 0) {
|
switch ( sa->format ) {
|
||||||
fprintf(stderr, "sf_read_float: ");
|
case SA_SAMPLE_FORMAT_FLOAT:
|
||||||
|
n = sf_writef_float(s, buf, nframes);
|
||||||
|
break;
|
||||||
|
case SA_SAMPLE_FORMAT_S16:
|
||||||
|
n = sf_writef_short(s, buf, nframes);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( n < 0 ) {
|
||||||
|
fprintf(stderr, "sf_write: ");
|
||||||
sf_perror(s);
|
sf_perror(s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -135,17 +157,27 @@ sa_sndfile_open_stream(
|
||||||
{
|
{
|
||||||
const char *path = stream_name;
|
const char *path = stream_name;
|
||||||
|
|
||||||
assert( sa_format == SA_SAMPLE_FORMAT_FLOAT );
|
int sf_format;
|
||||||
|
switch ( sa->format ) {
|
||||||
|
case SA_SAMPLE_FORMAT_FLOAT:
|
||||||
|
sf_format = SF_FORMAT_FLOAT;
|
||||||
|
break;
|
||||||
|
case SA_SAMPLE_FORMAT_S16:
|
||||||
|
sf_format = SF_FORMAT_PCM_16;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* setting for SA_STREAM_PLAYBACK (file write) */
|
/* setting for SA_STREAM_PLAYBACK (file write) */
|
||||||
SF_INFO sfinfo = {
|
SF_INFO sfinfo = {
|
||||||
.format = 0,
|
.format = sf_format,
|
||||||
.samplerate = rate,
|
.samplerate = rate,
|
||||||
.channels = channels,
|
.channels = channels,
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( sa_stream_direction == SA_STREAM_PLAYBACK )
|
if ( sa_stream_direction == SA_STREAM_PLAYBACK )
|
||||||
sfinfo.format = sndfile_format_from_path(path) | SF_FORMAT_PCM_16;
|
sfinfo.format = sndfile_format_from_path(path) | sf_format;
|
||||||
|
|
||||||
/* Create the recording stream */
|
/* Create the recording stream */
|
||||||
SNDFILE *s;
|
SNDFILE *s;
|
||||||
|
|
Loading…
Reference in New Issue