simpleaudio: get_framesize

This commit is contained in:
Kamal Mostafa 2012-08-11 20:40:20 -07:00
parent 07a8ca158b
commit 39bee9adf1
7 changed files with 29 additions and 5 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 )
{

View File

@ -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 );

View File

@ -36,6 +36,7 @@ struct simpleaudio {
unsigned int rate;
unsigned int channels;
void * backend_handle;
unsigned int samplesize;
unsigned int backend_framesize;
};