possible fix for alsa-oss fopen() [Patch]
Hi,
i attached to this email a patch which blatantly rips parts out of the artsdsp program from the KDE artsd. Namely the file stdioemu.c which provides the mechanism to hook fopen and related functions. See the email by James Courtier-Dutton with subject "Possible solution for the alsa-oss fopen problem" for details. The changes to alsa-oss.c are minimal. See patch..
I also uploaded a tarball to
http://www.affenbande.org/~tapas/alsa-oss-1.0.5-artsdsp-rip.tar.bz2
The relevant parts of artsdsp.c and stdioemu.c are both LGPL. I copied the file stdioemu.c unchanged including the copyright notice.
Please test it and tell me, if it works for you.. A test case is the following command:
aoss sox ~/test.wav -t ossdsp -w -s /dev/dsp
and define your pcm.dsp0 device in the .asoundrc to something which differs from normal output. I use a ladspa plugin for this:
pcm.dsp0 {type plug slave.pcm "ladspa"}
pcm.ladspa {
type ladspa
slave.pcm "plughw:0,0"
path "/usr/lib/ladspa"
plugins [ {label delay_5s input { controls [0.8 0.3] } } ]
}you need the delay_5s plugin for this test, of course.. Now, with the attached patch i get a nice delay on my test.wav playback with sox.. With the original alsa-oss, sox is not interceptable and therefore does not play the delay. Teamspeak seems to work with aoss now, too...
If your soundcard does not do hw mixing, a good test case is to use
pcm.dsp {type plug slave.pcm "dmix"}
and try two instances of the aoss sox command..
Florian Schmidt
Signature · 1 line
Palimm Palimm!
alsa/alsa-oss.c +22 -0
@@ -73,6 +73,8 @@void *(*_mmap)(void *addr,size_t len,int prot,int flags,int fd,off_t offset);int (*_munmap)(void * addr,size_t len); +FILE *(*_fopen)(const char *path,const char *mode); + typedef struct ops { int (*close)(int fd); ssize_t (*write)(int fd, const void *buf, size_t n);
@@ -630,6 +632,24 @@return count1; } +static int is_sound_device (const char *pathname) +{ +if (!pathname)return 0 ; +if (strcmp (pathname,"/dev/dsp" ) ==0 )return 1 ; +if (strcmp (pathname,"/dev/sound/dsp" ) ==0 )return 1 ; +return 0 ; +} + + +#include "stdioemu.c" + +FILE *fopen (const char * path,const char *mode) { +if (!is_sound_device (path)) +return _fopen (path, mode); + +return fake_fopen (path, mode); +} +#if 1 # define strong_alias (name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((alias (#name)));
@@ -643,6 +663,7 @@strong_alias (munmap, __munmap);strong_alias (poll, __poll);strong_alias (select, __select); +strong_alias (fopen, __fopen);#else int dup (int fd) {
@@ -712,4 +733,5 @@ _munmap =dlsym (RTLD_NEXT ,"munmap" ); _select =dlsym (RTLD_NEXT ,"select" ); _poll =dlsym (RTLD_NEXT ,"poll" ); + _fopen =dlsym (RTLD_NEXT ,"fopen" ); }
alsa/stdioemu.c +96 -0
96 lines not on this page · raw message
Quoted 1 line · On Fri, 11 Jun 2004 01:27:53 +0200 Florian Schmidt <[email protected]> wrote:
pcm.dsp {type plug slave.pcm "dmix"}
pcm.dsp0, of course
Signature · 6 lines
Palimm Palimm! ------------------------------------------------------- This SF.Net email is sponsored by the new InstallShield X.
Quoted 1 line
From Windows to Linux, servers to mobile, InstallShield X is the
one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504
On Fri, 11 Jun 2004 01:27:53 +0200
Florian Schmidt <[email protected]> wrote:
minor fix [now dsp0, dsp1, etc. should be covered, too.. a little hacky though]
http://www.affenbande.org/~tapas/alsa-oss-1.0.5-artsdsp-rip.tar.bz2
http://www.affenbande.org/~tapas/alsa-oss-fopen.patch
Florian Schmidt
Signature · 1 line
Palimm Palimm!
alsa/alsa-oss.c +22 -0
@@ -73,6 +73,8 @@void *(*_mmap)(void *addr,size_t len,int prot,int flags,int fd,off_t offset);int (*_munmap)(void * addr,size_t len); +FILE *(*_fopen)(const char *path,const char *mode); + typedef struct ops { int (*close)(int fd); ssize_t (*write)(int fd, const void *buf, size_t n);
@@ -630,6 +632,24 @@return count1; } +static int is_sound_device (const char *pathname) +{ +if (!pathname)return 0 ; +if (strncmp (pathname,"/dev/dsp" ,8 ) ==0 )return 1 ; +if (strncmp (pathname,"/dev/sound/dsp" ,14 ) ==0 )return 1 ; +return 0 ; +} + + +#include "stdioemu.c" + +FILE *fopen (const char * path,const char *mode) { +if (!is_sound_device (path)) +return _fopen (path, mode); + +return fake_fopen (path, mode); +} +#if 1 # define strong_alias (name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((alias (#name)));
@@ -643,6 +663,7 @@strong_alias (munmap, __munmap);strong_alias (poll, __poll);strong_alias (select, __select); +strong_alias (fopen, __fopen);#else int dup (int fd) {
@@ -712,4 +733,5 @@ _munmap =dlsym (RTLD_NEXT ,"munmap" ); _select =dlsym (RTLD_NEXT ,"select" ); _poll =dlsym (RTLD_NEXT ,"poll" ); + _fopen =dlsym (RTLD_NEXT ,"fopen" ); }
alsa/stdioemu.c +96 -0
96 lines not on this page · raw message
Quoted 7 lines · On Fri, 11 Jun 2004 20:06:01 +0200 Florian Schmidt <[email protected]> wrote:
On Fri, 11 Jun 2004 01:27:53 +0200
Florian Schmidt <[email protected]> wrote:minor fix [now dsp0, dsp1, etc. should be covered, too.. a little hacky though]
http://www.affenbande.org/~tapas/alsa-oss-1.0.5-artsdsp-rip.tar.bz2
http://www.affenbande.org/~tapas/alsa-oss-fopen.patch
anybody out there?
flo
Signature · 6 lines
Palimm Palimm! ------------------------------------------------------- This SF.Net email is sponsored by the new InstallShield X.
Quoted 1 line
From Windows to Linux, servers to mobile, InstallShield X is the
one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504
Quoted 7 lines · On Mon, 14 Jun 2004 14:55:32 +0200 Florian Schmidt <[email protected]> wrote:
Quoted 4 lines
minor fix [now dsp0, dsp1, etc. should be covered, too.. a little hacky though]
http://www.affenbande.org/~tapas/alsa-oss-1.0.5-artsdsp-rip.tar.bz2
http://www.affenbande.org/~tapas/alsa-oss-fopen.patchanybody out there?
hmm, i know it's a little hacky, but here it works fine. So please let me know, what's wrong with it. License issues? Sorry, i'm not a telepathic so i have to ask..
Flo
Signature · 9 lines
Palimm Palimm! ------------------------------------------------------- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
At Tue, 15 Jun 2004 19:24:36 +0200,
Quoted 9 lines · Florian Schmidt
Quoted 5 lines · On Mon, 14 Jun 2004 14:55:32 +0200 Florian Schmidt <[email protected]> wrote:
Quoted 4 lines
minor fix [now dsp0, dsp1, etc. should be covered, too.. a little hacky though]
http://www.affenbande.org/~tapas/alsa-oss-1.0.5-artsdsp-rip.tar.bz2
http://www.affenbande.org/~tapas/alsa-oss-fopen.patch
Quoted 6 lines
Quoted 2 lines
anybody out there?
hmm, i know it's a little hacky, but here it works fine. So please let me know, what's wrong with it. License issues? Sorry, i'm not a telepathic so i have to ask..
sorry, just lack of time...
it's also GPL, so the license should be ok.
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
On Wed, 16 Jun 2004 11:32:11 +0200
Takashi Iwai <[email protected]> wrote:
http://www.affenbande.org/~tapas/alsa-oss-1.0.5-artsdsp-rip.tar.bz2
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
anybody out there?
hmm, i know it's a little hacky, but here it works fine. So please let me know, what's wrong with it. License issues? Sorry, i'm not a telepathic so i have to ask..
sorry, just lack of time...
it's also GPL, so the license should be ok.
Ah, ok, sorry to be so noisy.. Take your time and have look at it when your time allows.
Thanks
Flo
Signature · 9 lines
Palimm Palimm! ------------------------------------------------------- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
At Wed, 16 Jun 2004 12:19:04 +0200,
Quoted 14 lines · Florian Schmidt
On Wed, 16 Jun 2004 11:32:11 +0200
Takashi Iwai <[email protected]> wrote:http://www.affenbande.org/~tapas/alsa-oss-1.0.5-artsdsp-rip.tar.bz2
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
anybody out there?
hmm, i know it's a little hacky, but here it works fine. So please let me know, what's wrong with it. License issues? Sorry, i'm not a telepathic so i have to ask..
Quoted 5 lines
Quoted 2 lines
sorry, just lack of time...
it's also GPL, so the license should be ok.Ah, ok, sorry to be so noisy.. Take your time and have look at it when your time allows.
I confirmed that it works fine.
Now committed to cvs now. Sorry for the delay!
thanks,
Takashi
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com