Éloi Rivard | 19 Oct 23:24 2014

"underrun occured" issue


I am a developper of GNU denemo ( http://denemo.org ) and I met some troubles with Portmidi. In short, denemo produces a constant error message flow:

ALSA lib pcm.c:7843:(snd_pcm_recover) underrun occurred

I don't know the cause of this but I can only fix this with the environment var "PULSE_LATENCY_MSEC=30"

I though maybe it is due to a bad portaudio initialization from denemo ? Looking at this source code, do you see something wrong/chocking ?


You can also have a look at our bug report:

Thanks for your help
Portaudio mailing list
Portaudio <at> music.columbia.edu
Pradeep Kumar | 10 Oct 00:26 2014

Periodic noise in playback


I'm using portaudio in my application both for audio and video playback.
For long time it was working fine. But recently I'm facing a strange issue.
I'm hearing some periodic low click noise during playback which was not there earlier. However when I pause my playback and again resume the noise disappear for sometime (5-7 seconds) but comes back again. And this is consistence whenever I pause or start my playback. So the noise is coming after duration of playback.
I know something has changed which is causing this issue but I'm not able to figure it out. I tried many change like changing the buffer size,flags Pa_OpenStream and many other changes but the noise is still there.

Please suggest what could be doing wrong.

Thanks and Regards,
Portaudio mailing list
Portaudio <at> music.columbia.edu
John Clements | 1 Oct 00:37 2014

brute-force approach to paTerminate?

I have a set of bindings for portaudio for Racket, an environment where it’s inconvenient[*] to pass
state between threads in order to properly ensure that paInitialize happens once at the beginning of
execution, and paTerminate is called at the end of execution. Indeed, if multiple user programs are
running simultaneously, it’s not even clear definition is the best one to use for the “end of execution”.

In light of this, I came up with this gross hack:

;; initialize unless it's already been initialized.
(define (pa-maybe-initialize)
  (cond [(pa-initialized?) (void)]
        [else (pa-initialize)]))

;; has portaudio been initialized?
(define (pa-initialized?)
  (not (= (pa-get-host-api-count/raw) pa-not-initialized-error)))

;; terminate until pa-initialized returns false
(define (pa-terminate-completely)
  (let loop ([count terminate-absurd-threshold])
    (cond ([< count 0] (error 'pa-terminate-completely 
                              "terminated more than ~s times and initialized? still returns true."
          [(pa-initialized?) (pa-terminate)
                             (loop (- count 1))]
          [else #t])))

;; the number of times to try terminating before giving up:
(define terminate-absurd-threshold 1000000)

That is: call pa-maybe-initialize at the beginning of each user thread that uses portaudio, and attach
pa-terminate-completely to the end of a user thread.

Can anyone comment on the possible race conditions inherent in this approach? Yes, it makes you hold your
nose, but will it lead to core dumps?

Many thanks!

John Clements

[*] I should add that a new feature called ‘plumbers’ may help with this; before I invest time in
rewriting code (and potentially introducing more bugs), I want to evaluate the stability of the solution
that I currently have.
Garth Hjelte | 26 Sep 21:40 2014

Multiple SoundFonts

In the API:

>The synthesizer can load any number of SoundFonts. The loaded SoundFonts are treated as a stack, where
each new loaded SoundFont is placed at the top of the stack. When selecting presets by bank and program
numbers, SoundFonts are searched beginning at the top of the stack. In the case where there are presets in
different SoundFonts with identical bank and program numbers, the preset from the most recently loaded
SoundFont is used. The fluid_synth_program_select() can be used for unambiguously selecting a preset
or bank offsets could be applied to each SoundFont with fluid_synth_set_bank_offset(), to try and
ensure that each preset has unique bank and program numbers. 

I just want to make sure I got this right. I want to use multiple SoundFonts, but I'm not in a position to dicker
around with the BankNum setting in the SoundFonts I create, they'll always be set to 0.

So this is where fluid_synth_set_bank_offset() comes in handy, right? For each SF loaded I'd do something
like this;

fluid_synth_set_bank_offset(synth, sfont_id[MySoundFontIndex], MySoundFontIndex);

So then to switch to a new soundfont for NoteOn, I do this:

fluid_synth_program_select(synth, MIDIChannel, BankNum, PresetNum);

Then every fluid_synth_noteon() call, the Preset that's played is the SoundFont represented by the
BankNum, and the PresetNum in that Bank, right?

In other words I'm switching SoundFont's by switching BankNum's, without hardchanging the BankNum in the
SF's. All SF's that I use (I create them from scratch on the fly) will have one Bank with BankNum=0.

(Perhaps there's other ways of toggling between SF's, I just thought this may be the best way for me. Any
suggestions are welcome.)

But is this correct; is this how fluid_synth_set_bank_offset works?  

Garth Hjelte
Sampler User
Dinesh Iyer | 25 Sep 22:24 2014

Speaker Configuration in DirectSound

Hi all,
I apologize for the multiple emails but each question is unrelated to the other and thought that this would be better for tracking and searching.

Since the March 26, 2011 version of PortAudio, in DirectSound, the maximum number of channels for a device is being guessed based on the speaker configuration. The code for this is in pa_win_ds.c (line 863- 895) in the AddOutputDeviceInfoFromDirectSound function.

This was not done earlier and the check unfortunately breaks a use case of mine.

I am shipping a demo as part of my application that uses 5.1 surround audio. This demo uses the default device. It used to work for customers even if the default device on their system had a maximum of only two channels, say a USB headset. This demo not does not work now. 

I will be happy to update my dmeo but many of our users have built applications using this behaviour and so it is very difficult to add this restriction all of a sudden.

The only workaround that I see is to comment out the specified lines of code. Are there any other suggested workarounds?


Portaudio mailing list
Portaudio <at> music.columbia.edu
Dinesh Iyer | 25 Sep 22:04 2014

Audio Latency degradation with latest PortAudio

Hi all,
I am upgrading to PortAudio Jan 30, 2014 from March 26, 2011 release and I am noticing a degradation in audio latency that I can get from the new version of the library with ASIO and CoreAudio.

On CoreAudio, I was able to run at a buffersize of 32 samples <at> 44100 Hz without any sample drops with the older version of the library. However, with the new version, I need to bump the buffersize upto 48 or 64 samples to be able to run without any sample drops. This affects the latency.

I am facing the same latency issue with ASIO too. I was able to run my Steinberg UR22 at 64 samples without any drops but now I have to bump it up.

I have also noticed that on Mac, it takes around 0.5 seconds for the paCallback to be fired the first time after calling PaStartStream. In my setup, I am playing back and recording data to measure roundtrip latency. I start playback before starting recording. I am dumping out time stamps in my code and I notice that the first call to paCallback for recording always occurs ~0.5 seconds after calling PaStartStream. I have observed this in both versions of the library.

Portaudio mailing list
Portaudio <at> music.columbia.edu
Dinesh Iyer | 24 Sep 17:08 2014

Playing back 24-bit audio using DirectSound results in distorted output

I am in the process of upgrading to the latest version of PortAudio Jan 30, 2014 and I noticed that when I attempt to play audio using DirectSound the output appears to be distorted. The issue appears to be in the conversion for 24-bit -> 16-bit data. This is being done because in OpenStream, the native format appears to be listed as paInt16.

PaSampleFormat nativeOutputFormats = paInt16;
        /* PaSampleFormat nativeOutputFormats = paUInt8 | paInt16 | paInt24 | paInt32 | paFloat32; */

        hostOutputSampleFormat =
            PaUtil_SelectClosestAvailableFormat( nativeOutputFormats, outputParameters->sampleFormat );

However, when I change this to paInt16 | paInt24, the playback works without any distortions.

You can find the text file containing the samples in the link below:

There are no distortions when I attempt to playback data at 8-bit, 16-bit, 32-bit but only for 24-bit.

Why is the sample format hardcoded to paInt16? Is the change I made an appropriate fix?

Portaudio mailing list
Portaudio <at> music.columbia.edu
tompoe | 20 Sep 07:40 2014

SOLVED: low level static with Portaudio

Fiddled, and found my HDM1 sound volume was excessive.  Once I lowered 
to 50%, static disappeared.  I'm hard of hearing, so my normal volume on 
television channels is usually much higher. Thanks, much.  And, by the 
way, am impressed with Portaudio.  Good work, people.
Thanks, Tom
tompoe | 20 Sep 07:26 2014

low level static when using portaudio

Writing as a user:  I installed Linuxmint17 on a desktop.  I installed 
GUVCviewer for webcam recording.  I'm getting low level static output.  
Is this a familiar issue?  Does not appear to be connected to volume 
level.  Any help appreciated.
Thanks, Tom
Dinesh Iyer | 11 Sep 18:19 2014

PortAudio crash when attempting play audio using NComputing Virtual Desktop client

Hi all,
I am connecting to a Windows 2008 Server R2 system using an NComputing Virtual Desktop Client (vSpace client). The Windows 2008 Server does not have any sound devices. So I am playing the sound on my machine. This is similar to "Play sound on this computer" option using Windows Remote Desktop.

The screenshot of my Control Panel Sound Setting is below:

When I play a file using Windows Media Player or a youtube video on 2008 Server, I am able to hear the sound clearly on my system.

When I use Audacity to play a wav file, the sound was delivered but its completely distorted.

With my application, which uses portaudio March 26, 2011 (I am in the process of upgrading), my application crashes. I am adding a crash trace below:

[0] 0x000007fef1bd6dae C:\\Program Files\\myApp\\bin\\libportaudio.dll+00028078 Pa_Sleep+00001550\u8232 \u8232 
[1] 0x000007fee5d4f27e C:\\Windows\\system32\\dsound.dll+00193150 DllCanUnloadNow+00010430
[2] 0x000007fee5d522ca C:\\Windows\\system32\\dsound.dll+00205514 DllCanUnloadNow+00022794
[3] 0x000007fee5d50654 C:\\Windows\\system32\\dsound.dll+00198228 DllCanUnloadNow+00015508
[4] 0x000007fef1bd6ea5 C:\\Program Files\\myApp\\bin\\libportaudio.dll+00028325 Pa_Sleep+00001797
[5] 0x000007fef1bd8d5f C:\\Program Files\\myApp\\bin\\libportaudio.dll+00036191 Pa_Sleep+00009663
[6] 0x000007fef1bd2ea6 C:\\Program Files\\myApp\\bin\\libportaudio.dll+00011942 Pa_GetVersionText+00000422
[7] 0x000007fef1bd3007 C:\\Program Files\\myApp\\bin\\libportaudio.dll+00012295 Pa_Initialize+00000039

Are there known issues between PortAudio and NComputing clients?

Portaudio mailing list
Portaudio <at> music.columbia.edu
Rob | 5 Sep 23:01 2014

Portaudio bug?

In the past I encountered a problem with an application that uses portaudio (fldigi).
Now I have seen that it occurs in other applications as well and apparently is a portaudio bug.

I use a Linux system with Alsa sound.  The problem is not dependent on Linux version or distribution.

Whenever fldigi is started, other running programs that use Alsa sound directly (not via portaudio)
are affected.  The least symptom I see is that they get no input from the soundcard anymore.
Maybe the soundcard settings are affected as well.

When using a system with multiple soundcards and multiple applications running, it is a real nuisance.
After starting a program that uses portaudio, some of the other programs have to be restarted.

At first I neglected a problem thinking that it may be a bug in fldigi.   But now I noticed that exactly
the same thing happens when the example program pa_devs from the distribution is started.

I also noticed that often not all input sound devices are listed in the enumeration of portaudio.
These issues may be related.   It may be that something is done during enumeration that both
kicks off the existing program and prematurely terminates the enumeration of input devices.
(the list of output devices is complete)

Is this behaviour by design?  Isn't portaudio supposed to leave the other sound apps untouched,
especially when starting an application for which the soundcard already has been configured?