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