Subject: debugging help: nas enabled mpg123 sounds slow and scratchy?
To: None <nas@radscan.com, netbsd-help@netbsd.org>
From: Scott Presnell <srp@tworoads.net>
List: netbsd-help
Date: 02/28/2003 10:45:23
Hi NAS and/or NetBSD folks,
	I'm hoping for some debugging hints here:

I'm running NetBSD 1.5.2 with NAS 1.6 as compiled from the
NetBSD package system, and I'm trying mpg123-nas also
from the package system (Paul: I'll say upfront that I've
tried w/ and /wo your audio_nas.c patches)

For testing/benchmark purposes auplay (playing via NAS)
plays .wavs as nice as audioplay (which plays directly to
/dev/audio0)

However NAS enabled mpg123 sounds slow (to be clear, pitch
is right, time/beat is longer), and there is a fair bit of
popping (like a very badly scratched LP). Normal mpg123
(using /dev/audio0) works just fine...

If I add verbose logging, I can see that mpg123+nas bursts
frames, while mpg123-nas has a steady, slower, stream (this
is right, right?)

Since auplay seems to work right, I'm guessing mpg123+nas
is at fault, but I'm not sure where to look first.

Anyone else had this problem?  Thanks for any pointers...

	- Scott

I've included data from mpg123, nasd, and my audio driver.

% ./mpg123+nas -vv ...
Audio capabilities:
         |  s16  |  u16  |  u8   |  s8   | ulaw  | alaw  |
  --------------------------------------------------------
   8000  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |
  11025  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |
  12000  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |
  16000  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |
  22050  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |
  24000  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |
  32000  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |
  44100  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |
  48000  |  M/S  |       |  M/S  |  M/S  |  M/S  |       |

Using memory mapped IO for this stream.
Title  : I Have the Touch                Artist: Peter Gabriel
Album  : Peter Gabriel 4 (Security)      Year  :    0
Comment: Created by Grip                 Genre : Rock

Directory: /usr/share/mp3/Peter Gabriel/Peter Gabriel 4 Security/
Playing MPEG stream from I Have the Touch.mp3 ...
MPEG 1.0, Layer: III, Freq: 44100, mode: Joint-Stereo, modext: 0, BPF : 418
Channels: 2, copyright: No, original: Yes, CRC: No, emphasis: 0.
Bitrate: 128 Kbits/s, Extension value: 0
Audio: 1:1 conversion, rate: 44100, encoding: signed 16 bit, channels: 2
Frame#   752 [ 9843], Time: 00:19.64 [04:17.12], ^C^\Quit(core dumped)

% /usr/X11R6/bin/nasd -aa -d 999
serverReset();
setTimer(rate = 0);
closeDevice: out
closeDevice: output device already closed
closeDevice: mixer
closeDevice: mixerdevice already closed
  done.
AuInitPhysicalDevices();
Init: will close device when finished with stream.
Init: will initialize mixer device options.
setTimer(rate = 0);
createServerComponents(...);
serverReset();
setTimer(rate = 0);
closeDevice: out
closeDevice: output device already closed
closeDevice: mixer
closeDevice: mixerdevice already closed
  done.
AuInitPhysicalDevices();
Init: will close device when finished with stream.
Init: will initialize mixer device options.
setTimer(rate = 0);
createServerComponents(...);
setSampleRate(rate = 44100);
setTimer(rate = 44100);
enableProcessFlow();
openDevice
openDevice OUT /dev/audio0 mode 1
setupSoundcard(...);
++ Setting up Output device
+++ requesting wordsize of 16, got 16
+++ requesting 2 channel(s), got 2 channel(s)
+++ Requesting minimum sample rate of 5000, got 5000
+++ Requesting maximum sample rate of 44100, got 44100
openDevice: input device already open
setSampleRate(rate = 44100);
setTimer(rate = 44100);
enableProcessFlow() - set SIGALRM handler to 
intervalProcdisableProcessFlow() - starting
closeDevice: out
closeDevice OUT /dev/audio0 mode 1
closeDevice: mixer
disableProcessFlow() - done;
serverReset();
setTimer(rate = 0);
closeDevice: out
closeDevice: output device already closed
closeDevice: mixer
closeDevice: mixerdevice already closed
  done.
AuInitPhysicalDevices();


I enclude dmesg for my audio card, and audioctl output:

eap0 at pci2 dev 12 function 0: Ensoniq CT5880 CT5880C (rev. 0x02)
eap0: interrupting at irq 10
eap0: SigmaTel STAC9708 codec; 18 bit DAC, 18 bit ADC, Rockwell 3D

% audioctl -a
name=Ensoniq AudioPCI
version=
config=eap
encodings=ulinear:8,mulaw:8*,alaw:8*,slinear:8*,slinear_le:16,ulinear_le:16*,slinear_be:16*,ulinear_be:16*
properties=full_duplex,mmap,independent
full_duplex=0
fullduplex=0
blocksize=2048
hiwat=3
lowat=1
monitor_gain=0
mode=
play.rate=44100
play.channels=2
play.precision=16
play.encoding=slinear_le
play.gain=127
play.balance=32
play.port=0x0
play.avail_ports=0x0
play.seek=0
play.samples=0
play.eof=0
play.pause=0
play.error=0
play.waiting=0
play.open=0
play.active=0
play.buffer_size=65536
record.rate=44100
record.channels=2
record.precision=16
record.encoding=slinear_le
record.gain=191
record.balance=32
record.port=0x2
record.avail_ports=0x7
record.seek=0
record.samples=0
record.eof=0
record.pause=0
record.error=0
record.waiting=0
record.open=0
record.active=0
record.buffer_size=65536
record.errors=0

% auinfo
Audio Server:           ?localhost:8000
Version Number:         2.2
Vendor:                 Network Audio System Release 1.6 - VoxWare
Vendor Release:         1
Min Sample Rate:        5000
Max Sample Rate:        44100
Max Tracks:             32
Number of Formats:      7
Formats:                ULAW8  LinearUnsigned8  LinearSigned8
                         LinearSigned16MSB  LinearUnsigned16MSB
                         LinearSigned16LSB  LinearUnsigned16LSB
Number of Elem Types:   12
Element Types:          ImportClient  ImportDevice  ImportBucket
                         ImportWaveForm  Bundle  MultiplyConstant 
AddConstant
                         Sum  ExportClient  ExportDevice  ExportBucket
                         ExportMonitor
Number of Wave Forms:   2
Wave Forms:             Square  Sine
Number of Actions:      3
Actions:                ChangeState  SendNotify  Noop
Number of Devices:      3
     Device 0:
         Changable:      Gain  LineMode
         ID:             0x23
         Kind:           PhysicalInput
         Use:            Import
         Format:         LinearUnsigned8
         Num Tracks:     2
         Access:         Import  List
         Description:    "Stereo Channel Input"
         Min Rate:       5000
         Max Rate:       44100
         Location:       Left  Right  External
         Gain Percent:   50
         Num Children:   0
     Device 1:
         Changable:      Gain
         ID:             0x22
         Kind:           PhysicalOutput
         Use:            Export
         Format:         LinearSigned16LSB
         Num Tracks:     2
         Access:         Export  List
         Description:    "Stereo Channel Output"
         Min Rate:       5000
         Max Rate:       44100
         Location:       Center  Internal
         Gain Percent:   50
         Num Children:   1
         Children:       0x21
     Device 2:
         Changable:      Gain
         ID:             0x21
         Kind:           PhysicalOutput
         Use:            Export
         Format:         LinearSigned16LSB
         Num Tracks:     1
         Access:         Export  List
         Description:    "Mono Channel Output"
         Min Rate:       5000
         Max Rate:       44100
         Location:       Center  Internal
         Gain Percent:   50
         Num Children:   0
Number of Buckets:      0