summaryrefslogtreecommitdiffstats
path: root/src/modules/module-equalizer-sink.c
diff options
context:
space:
mode:
authorJason Newton <jason@arcuid.wyred.org>2009-07-16 22:00:38 -0700
committerJason Newton <nevion@gmail.com>2009-09-29 23:50:52 -0700
commitd4fe5bfce988765fd51d291c61217ffef9df7698 (patch)
treefe1f12a5a28611b374713a9c4aa99ff198314fe3 /src/modules/module-equalizer-sink.c
parent182c9c7dcb3c7e6b8d273ab85e6f3e67070a4694 (diff)
module-equalizer-sink: attempt different buffering strategy
Diffstat (limited to 'src/modules/module-equalizer-sink.c')
-rwxr-xr-xsrc/modules/module-equalizer-sink.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/modules/module-equalizer-sink.c b/src/modules/module-equalizer-sink.c
index d4cec3cd..d6e28f3d 100755
--- a/src/modules/module-equalizer-sink.c
+++ b/src/modules/module-equalizer-sink.c
@@ -259,29 +259,11 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
if (!u->sink || !PA_SINK_IS_OPENED(u->sink->thread_info.state))
return -1;
- //output any buffered outputs first
- if(u->n_buffered_output>0){
- //pa_log("outputing %ld buffered samples",u->n_buffered_output);
- chunk->index = 0;
- size_t n_outputable=PA_MIN(u->n_buffered_output,u->max_output);
- chunk->length = n_outputable*fs;
- chunk->memblock = pa_memblock_new(i->sink->core->mempool, chunk->length);
- pa_memblockq_drop(u->memblockq, chunk->length);
- dst = (float*) pa_memblock_acquire(chunk->memblock);
- for(size_t j=0;j<u->channels;++j){
- pa_sample_clamp(PA_SAMPLE_FLOAT32NE, dst+j, fs, u->output_buffer[j], sizeof(float),n_outputable);
- memmove(u->output_buffer[j],u->output_buffer[j]+n_outputable,(u->n_buffered_output-n_outputable)*sizeof(float));
- }
- u->n_buffered_output-=n_outputable;
- pa_memblock_release(chunk->memblock);
- return 0;
- }
- pa_assert_se(u->n_buffered_output==0);
-
//collect the minimum number of samples
//TODO figure out a better way of buffering the needed
//number of samples, this doesn't seem to work correctly
- while(u->samples_gathered < u->R){
+ //most of the itme
+ if(u->samples_gathered < u->R){
//render some new fragments to our memblockq
size_t desired_samples=PA_MIN(u->R-u->samples_gathered,u->max_output);
while (pa_memblockq_peek(u->memblockq, &tchunk) < 0) {
@@ -295,7 +277,7 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
pa_log("got %ld samples, asked for %ld",tchunk.length/fs,desired_samples);
}
size_t n_samples=PA_MIN(tchunk.length/fs,u->R-u->samples_gathered);
- //TODO: figure out what to do with rest of the samples when there's too many (rare?)
+ pa_assert_se(n_samples<=u->R-u->samples_gathered);
src = (float*) ((uint8_t*) pa_memblock_acquire(tchunk.memblock) + tchunk.index);
for (size_t c=0;c<u->channels;c++) {
pa_sample_clamp(PA_SAMPLE_FLOAT32NE,u->input[c]+(u->window_size-u->R)+u->samples_gathered,sizeof(float), src+c, fs, n_samples);
@@ -304,12 +286,33 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
pa_memblock_release(tchunk.memblock);
pa_memblock_unref(tchunk.memblock);
}
+ //output any buffered outputs first
+ if(u->n_buffered_output>0){
+ //pa_log("outputing %ld buffered samples",u->n_buffered_output);
+ chunk->index = 0;
+ size_t n_outputable=PA_MIN(u->n_buffered_output,u->max_output);
+ chunk->length = n_outputable*fs;
+ chunk->memblock = pa_memblock_new(i->sink->core->mempool, chunk->length);
+ pa_memblockq_drop(u->memblockq, chunk->length);
+ dst = (float*) pa_memblock_acquire(chunk->memblock);
+ for(size_t j=0;j<u->channels;++j){
+ pa_sample_clamp(PA_SAMPLE_FLOAT32NE, dst+j, fs, u->output_buffer[j], sizeof(float),n_outputable);
+ memmove(u->output_buffer[j],u->output_buffer[j]+n_outputable,(u->n_buffered_output-n_outputable)*sizeof(float));
+ }
+ u->n_buffered_output-=n_outputable;
+ pa_memblock_release(chunk->memblock);
+ return 0;
+ }
+ pa_assert_se(u->n_buffered_output==0);
+
+ if(u->samples_gathered<u->R){
+ return -1;
+ }
//IT should be this guy if we're buffering like how its supposed to
//size_t n_outputable=PA_MIN(u->window_size-u->R,u->max_output);
//This one takes into account the actual data gathered but then the dsp
//stuff is wrong when the buffer "underruns"
- size_t n_outputable=PA_MIN(u->R,u->max_output);
-
+ size_t n_outputable=PA_MIN(u->R,u->max_output)*(u->R==u->samples_gathered);
chunk->index=0;
chunk->length=n_outputable*fs;
@@ -319,7 +322,6 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
pa_assert_se(u->fft_size>=u->window_size);
pa_assert_se(u->R<u->window_size);
- pa_assert_se(u->samples_gathered>=u->R);
size_t sample_rem=u->R-n_outputable;
//use a linear-phase sliding STFT and overlap-add method (for each channel)
for (size_t c=0;c<u->channels;c++) {
@@ -389,6 +391,7 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
//u->samplings++;
u->n_buffered_output+=sample_rem;
u->samples_gathered=0;
+end:
pa_memblock_release(chunk->memblock);
return 0;
}