Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-15-2004, 11:11 AM   #1
Registered: May 2003
Distribution: slackware-current
Posts: 34

Rep: Reputation: 15
Alsa capturing buffer underruns


I'm trying to write a simple alsa/gtk recording application in C that will record directly to an Ogg Vorbis file. (originally intended for recording my own dj sets)

It sort of "works" already. But I can't use the real-time scheduling when not running as root. It runs great as root, but as a normal user with normal scheduling I always get buffer underruns.

You can get the source at

Capturing is done in capt_alsa.c (capture_auto)

I've looked into asynchroneous capturing which might be the answer, but I couldn't find enough documentation to figure it out myself.

This is my first C application to span more than a file or two, so any other suggestion welcome too


Last edited by don_pingu; 09-16-2004 at 11:05 AM.
Old 09-15-2004, 11:32 AM   #2
Registered: May 2003
Distribution: slackware-current
Posts: 34

Original Poster
Rep: Reputation: 15
Erm, of course I'm talking about buffer OVERruns causing dropped samples Sorry about that.
Old 09-15-2004, 05:27 PM   #3
Registered: Jul 2003
Location: Bedford, UK
Distribution: Slackware 11.0, LFS 6.1
Posts: 519

Rep: Reputation: 30
I'm surprised to hear you're getting overruns. I wrote a program to play back modfiles and I never get buffer underruns, whether I have realtime scheduling priorities or not. Even if I'm compiling a kernel at the same time! And my program is seriously inefficient too.

When you say it records directly to an Ogg Vorbis, how have you implemented that? Do you write it as a wav (or equivalent) first and then run oggenc on it? (The obvious, and probably sensible way).
Old 09-16-2004, 11:00 AM   #4
Registered: May 2003
Distribution: slackware-current
Posts: 34

Original Poster
Rep: Reputation: 15
No no, I just use libvorbis and feed it the captured stream through a FIFO buffer. The whole idea is to save time (for having to encode it afterwards) and space (for the temporary wave).

Works great, but there's a problem with the capturing as I said. Appearently I can't get the capturing thread to make the snd_pcm_readi call in time (before the hardware (?) buffer is full). I'm using two threads besides the main one, one for capturing, one for encoding. Take a look at the source code if you like.

All help appreciated.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Capturing tool. mayankjohri Linux - Enterprise 0 01-30-2005 04:12 PM
Burning Linux Problems with Buffer underruns Rawr101 Linux - Software 1 10-31-2004 12:38 AM
Screen Capturing monohouse Linux - Software 3 10-30-2004 12:14 PM
Capturing X Events phrontist Linux - Software 1 10-28-2004 09:56 AM
Capturing video with Cinelerra works, capturing video with Xawtv doesn't! seaelf Slackware 0 06-27-2004 06:18 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:53 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration