SBPRO 16bit 44.1khz stereo (and some improvement to sb16
PATCH 1/1 SBPRO 16bit 44.1khz stereo (and some improvement to sb16
My brother grabbed my AWE32 for doing games with it, so I am been downgraded to my old sbpro I bought 7/8 years ago ;). Since I want to continue to use all software I was using in the past without having to hack it or LD_PRELOAD continously a write(2) and ioctl(2) wrapper that will convert in realtime all data that will go to the dsp, I hacked the kernel sb driver to handle a virtual sbpro mode at 16bit 44.1khz stereo. It will handle also 8bit 44.1khz stereo and hopefully all other various combination.
I also changed the sb16 full-duplex mode in order to do the signed <-> unsigned data conversion in hardware (obvious improvement) and to avoid a copy of the data from the tmp buffer to the kernel dma pool. I think this last could be an improvement because get_user should be reduced only to a movl in the fast path, and we was doing a movl also before while doing the conversion. But the reason I removed the buffer is just that I don't like a static buffer, if write(2) would be threaded (in the case we'll drop sometime in the future the big kernel lock) the static buffer would not be thread safe. This part of the patch (the sb16 part) is completly untested though and I would like to get feedback about it ;).
This patch is against 2.2.3 and is called sbpro-16bit-2.2.3-A.
Index: drivers/sound//audio.c
=================================RCS file: /var/cvs/linux/drivers/sound/audio.c,v retrieving revision 1.1.2.1
drivers/sound/audio.c renamed from audio.c +6 -6
@@ -249,12 +249,12 @@if (copy_from_user (dma_buf, &(buf)[p], l))return -EFAULT ; } -else audio_devs[dev]->d->copy_user (dev, - dma_buf,0 , - buf, p, - c, buf_size, - &used, &returned, - l); +else if (audio_devs[dev]->d->copy_user (dev, + dma_buf,0 , + buf, p, + c, buf_size, + &used, &returned)) +return -EFAULT ; l = returned;if (audio_devs[dev]->local_conversion &CNV_MU_LAW )
Index: drivers/sound//dev_table.h
=================================RCS file: /var/cvs/linux/drivers/sound/dev_table.h,v retrieving revision 1.1.2.1
drivers/sound/dev_table.h renamed from dev_table.h +5 -6
@@ -190,12 +190,11 @@int (*prepare_for_output) (int dev,int bufsize,int nbufs);void (*halt_io) (int dev);int (*local_qlen)(int dev); -void (*copy_user) (int dev, -char *localbuf,int localoffs, -const char *userbuf,int useroffs, -int max_in,int max_out, -int *used,int *returned, -int len); +int (*copy_user) (int dev, +char *localbuf,int localoffs, +const char *userbuf,int useroffs, +int max_in,int max_out, +int *used,int *returned);void (*halt_input) (int dev);void (*halt_output) (int dev);void (*trigger) (int dev,int bits);
Index: drivers/sound//sb_audio.c
=================================RCS file: /var/cvs/linux/drivers/sound/sb_audio.c,v retrieving revision 1.1.2.2
drivers/sound/sb_audio.c renamed from sb_audio.c +126 -39
261 lines not on this page · raw message
Forget to tell, I also changed the copy_user api to be enabled to segfault, and I removed a redundant field.
BTW, what about the alsa drivers? Are they going to replace OSS?
Andrea Arcangeli
Quoted 2 lines · Andrea Arcangeli
conversion. But the reason I removed the buffer is just that I don't like a static buffer, if write(2) would be threaded (in the case we'll drop
And I didn't thought that it can be just threaded if you run two sb16 in full-duplex mode and the userbuffer is in the swap...
Andrea Arcangeli
Quoted 1 line · Andrea Arcangeli
This patch is against 2.2.3 and is called sbpro-16bit-2.2.3-A.
I did some little improvement to the previous code. This patch is incremental and it's called sbpro-16bit-2.2.3-AB (AB because it's incremental to A ;).
Index: sb.h
=================================RCS file: /var/cvs/linux/drivers/sound/sb.h,v retrieving revision 1.1.2.4
drivers/sound/sb.h renamed from sb.h +2 -1
@@ -95,7 +95,8 @@/* State variables */ int opened;/* new audio fields for full duplex support */ -int fullduplex; + int fullduplex:1; + int double_speed:1;int duplex;int speed, bits, channels;volatile int irq_ok;
Index: sb_audio.c
=================================RCS file: /var/cvs/linux/drivers/sound/sb_audio.c,v retrieving revision 1.1.2.3
drivers/sound/sb_audio.c renamed from sb_audio.c +35 -29
136 lines not on this page · raw message
Andrea Arcangeli
Quoted 3 lines · Andrea Arcangeli
I did some little improvement to the previous code. This patch is incremental and it's called sbpro-16bit-2.2.3-AB (AB because it's incremental to A ;).
Oh well I have a final patch that is been tested also on the sb16 side. My -A and -B patches had a grave bug in the sb16 side.
So this new final patch (sbpro-16bit-2.2.3-C) is just been reported to works fine also with sb16 (and the sbpro side is tested by me ;), in both half-duplex and fullduplex mode by Edward S. Marshall <[email protected]>.
This new patch make the sb16_copy_to_user operation thread safe (if you have two sb16 both working in fullduplex you _need_ it) and it avoids us to do the signed<->unsigned conversion in software because now it's the sb16 that do that in hardware.
The second part of the patch is sbpro related. If you (like me) have an old sbpro you'll magically find yourself able to reproduce at 16bit 44.1khz stereo mode as you would using an sb16 :). Obviously the sound quality is bad, but at least everything works again ;)).
Last but not the least, the patch change the copy_user interface to make it able to report a segfault and it removes a field of overhead.
Index: linux/drivers/sound/audio.c
drivers/sound/audio.c renamed from drivers/sound/audio.c:1.1.1.1 +6 -6
@@ -249,12 +249,12 @@if (copy_from_user (dma_buf, &(buf)[p], l))return -EFAULT ; } -else audio_devs[dev]->d->copy_user (dev, - dma_buf,0 , - buf, p, - c, buf_size, - &used, &returned, - l); +else if (audio_devs[dev]->d->copy_user (dev, + dma_buf,0 , + buf, p, + c, buf_size, + &used, &returned)) +return -EFAULT ; l = returned;if (audio_devs[dev]->local_conversion &CNV_MU_LAW )
Index: linux/drivers/sound/dev_table.h
drivers/sound/dev_table.h renamed from drivers/sound/dev_table.h:1.1.1.1 +5 -6
@@ -190,12 +190,11 @@int (*prepare_for_output) (int dev,int bufsize,int nbufs);void (*halt_io) (int dev);int (*local_qlen)(int dev); -void (*copy_user) (int dev, -char *localbuf,int localoffs, -const char *userbuf,int useroffs, -int max_in,int max_out, -int *used,int *returned, -int len); +int (*copy_user) (int dev, +char *localbuf,int localoffs, +const char *userbuf,int useroffs, +int max_in,int max_out, +int *used,int *returned);void (*halt_input) (int dev);void (*halt_output) (int dev);void (*trigger) (int dev,int bits);
Index: linux/drivers/sound/sb.h
drivers/sound/sb.h renamed from drivers/sound/sb.h:1.1.1.4 +2 -1
@@ -95,7 +95,8 @@/* State variables */ int opened;/* new audio fields for full duplex support */ -int fullduplex; + int fullduplex:1; + int double_speed:1;int duplex;int speed, bits, channels;volatile int irq_ok;
Index: linux/drivers/sound/sb_audio.c
drivers/sound/sb_audio.c renamed from drivers/sound/sb_audio.c:1.1.1.2 +132 -39
273 lines not on this page · raw message
Andrea Arcangeli