simpleaudio: get_framesize
This commit is contained in:
parent
07a8ca158b
commit
39bee9adf1
|
@ -38,7 +38,9 @@ simpleaudio_tone_reset()
|
||||||
void
|
void
|
||||||
simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur)
|
simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur)
|
||||||
{
|
{
|
||||||
float *buf = malloc(nsamples_dur * sizeof(float));
|
unsigned int framesize = simpleaudio_get_framesize(sa_out);
|
||||||
|
|
||||||
|
float *buf = malloc(nsamples_dur * framesize);
|
||||||
assert(buf);
|
assert(buf);
|
||||||
|
|
||||||
if ( tone_freq != 0 ) {
|
if ( tone_freq != 0 ) {
|
||||||
|
@ -54,7 +56,7 @@ simpleaudio_tone(simpleaudio *sa_out, float tone_freq, size_t nsamples_dur)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
bzero(buf, nsamples_dur*sizeof(float));
|
bzero(buf, nsamples_dur * framesize);
|
||||||
sa_tone_cphase = 0.0;
|
sa_tone_cphase = 0.0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,9 +162,10 @@ simpleaudio_open_stream_alsa(
|
||||||
}
|
}
|
||||||
sa->rate = rate;
|
sa->rate = rate;
|
||||||
sa->channels = channels;
|
sa->channels = channels;
|
||||||
|
sa->samplesize = sizeof(float);
|
||||||
sa->backend = &simpleaudio_backend_alsa;
|
sa->backend = &simpleaudio_backend_alsa;
|
||||||
sa->backend_handle = pcm;
|
sa->backend_handle = pcm;
|
||||||
sa->backend_framesize = sizeof(float);
|
sa->backend_framesize = sa->channels * sa->samplesize;
|
||||||
|
|
||||||
return sa;
|
return sa;
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,11 +136,12 @@ simpleaudio_open_stream_pulseaudio(
|
||||||
}
|
}
|
||||||
sa->rate = ss.rate;
|
sa->rate = ss.rate;
|
||||||
sa->channels = ss.channels;
|
sa->channels = ss.channels;
|
||||||
|
sa->samplesize = sizeof(float);
|
||||||
sa->backend = &simpleaudio_backend_pulse;
|
sa->backend = &simpleaudio_backend_pulse;
|
||||||
sa->backend_handle = s;
|
sa->backend_handle = s;
|
||||||
sa->backend_framesize = pa_frame_size(&ss);
|
sa->backend_framesize = pa_frame_size(&ss);
|
||||||
|
|
||||||
assert( sa->backend_framesize == ss.channels * sizeof(float) );
|
assert( sa->backend_framesize == sa->channels * sa->samplesize );
|
||||||
|
|
||||||
return sa;
|
return sa;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,9 +167,10 @@ simpleaudio_open_stream_sndfile(
|
||||||
}
|
}
|
||||||
sa->rate = sfinfo.samplerate;
|
sa->rate = sfinfo.samplerate;
|
||||||
sa->channels = sfinfo.channels;
|
sa->channels = sfinfo.channels;
|
||||||
|
sa->samplesize = sizeof(float);
|
||||||
sa->backend = &simpleaudio_backend_sndfile;
|
sa->backend = &simpleaudio_backend_sndfile;
|
||||||
sa->backend_handle = s;
|
sa->backend_handle = s;
|
||||||
sa->backend_framesize = sa->channels * sizeof(float);
|
sa->backend_framesize = sa->channels * sa->samplesize;
|
||||||
|
|
||||||
return sa;
|
return sa;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,18 @@ simpleaudio_get_channels( simpleaudio *sa )
|
||||||
return sa->channels;
|
return sa->channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
simpleaudio_get_framesize( simpleaudio *sa )
|
||||||
|
{
|
||||||
|
return sa->backend_framesize;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
simpleaudio_get_samplesize( simpleaudio *sa )
|
||||||
|
{
|
||||||
|
return sa->samplesize;
|
||||||
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
simpleaudio_read( simpleaudio *sa, float *buf, size_t nframes )
|
simpleaudio_read( simpleaudio *sa, float *buf, size_t nframes )
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,6 +64,12 @@ simpleaudio_get_rate( simpleaudio *sa );
|
||||||
unsigned int
|
unsigned int
|
||||||
simpleaudio_get_channels( simpleaudio *sa );
|
simpleaudio_get_channels( simpleaudio *sa );
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
simpleaudio_get_framesize( simpleaudio *sa );
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
simpleaudio_get_samplesize( simpleaudio *sa );
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
simpleaudio_read( simpleaudio *sa, float *buf, size_t nframes );
|
simpleaudio_read( simpleaudio *sa, float *buf, size_t nframes );
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ struct simpleaudio {
|
||||||
unsigned int rate;
|
unsigned int rate;
|
||||||
unsigned int channels;
|
unsigned int channels;
|
||||||
void * backend_handle;
|
void * backend_handle;
|
||||||
|
unsigned int samplesize;
|
||||||
unsigned int backend_framesize;
|
unsigned int backend_framesize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue