Patchwork noaudio: use audio_pcm_sw_read() in no_read()

login
register
mail settings
Submitter Michael Walle
Date Jan. 3, 2011, 10:40 p.m.
Message ID <1294094404-20397-1-git-send-email-michael@walle.cc>
Download mbox | patch
Permalink /patch/77351/
State New
Headers show

Comments

Michael Walle - Jan. 3, 2011, 10:40 p.m.
Instead of returning a self-calculated empty buffer use the proper method
supplied by the audio subsystem. This will fix the return value of the
no_read() function which otherwise returns too many samples because
total_hw_samples_acquired isn't correctly accounted.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 audio/noaudio.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
malc - Jan. 3, 2011, 10:46 p.m.
On Mon, 3 Jan 2011, Michael Walle wrote:

> Instead of returning a self-calculated empty buffer use the proper method
> supplied by the audio subsystem. This will fix the return value of the
> no_read() function which otherwise returns too many samples because
> total_hw_samples_acquired isn't correctly accounted.

What and how is incorrectly accounted? FWIW the audio_pcm_sw_read will
perform useless resampling/mixing that's why custom code is used.

[..snip..]
Michael Walle - Jan. 3, 2011, 10:59 p.m.
On Mon, 3 Jan 2011, 23:46:34 malc wrote:
> On Mon, 3 Jan 2011, Michael Walle wrote:
> > Instead of returning a self-calculated empty buffer use the proper method
> > supplied by the audio subsystem. This will fix the return value of the
> > no_read() function which otherwise returns too many samples because
> > total_hw_samples_acquired isn't correctly accounted.
> 
> What and how is incorrectly accounted? FWIW the audio_pcm_sw_read will
> perform useless resampling/mixing that's why custom code is used.
total_hw_samples_acquired is never incremented (see audio_pcm_sw_read()). As a 
result the noaudio driver returns too many bytes per second.
malc - Jan. 4, 2011, 12:05 a.m.
On Mon, 3 Jan 2011, Michael Walle wrote:

> On Mon, 3 Jan 2011, 23:46:34 malc wrote:
> > On Mon, 3 Jan 2011, Michael Walle wrote:
> > > Instead of returning a self-calculated empty buffer use the proper method
> > > supplied by the audio subsystem. This will fix the return value of the
> > > no_read() function which otherwise returns too many samples because
> > > total_hw_samples_acquired isn't correctly accounted.
> > 
> > What and how is incorrectly accounted? FWIW the audio_pcm_sw_read will
> > perform useless resampling/mixing that's why custom code is used.
> total_hw_samples_acquired is never incremented (see audio_pcm_sw_read()). As a 
> result the noaudio driver returns too many bytes per second.
> 

Okay, then the simpler patch should just increment it by amount in "total"
variable.

Patch

diff --git a/audio/noaudio.c b/audio/noaudio.c
index 8015858..e720327 100644
--- a/audio/noaudio.c
+++ b/audio/noaudio.c
@@ -117,11 +117,7 @@  static int no_run_in (HWVoiceIn *hw)
 
 static int no_read (SWVoiceIn *sw, void *buf, int size)
 {
-    int samples = size >> sw->info.shift;
-    int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
-    int to_clear = audio_MIN (samples, total);
-    audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
-    return to_clear << sw->info.shift;
+    return audio_pcm_sw_read (sw, buf, size);
 }
 
 static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)