The patch below adds digital audio extraction to XMMS's cdaudio input
plugin.

Previously, you could only play CDs with XMMS on OpenBSD through the
analog output of the CD drive.  This doesn't work if
* your drive's analog output isn't connected to the sound card,
* you have a newish optical drive that just doesn't have an analog output,
* you send audio digitally over S/PDIF to an amplifier.

To enable:

Options -> Preferences
  -> Audio I/O Plugins tab
     CD Audio Player
     -> Configure
        -> Device tab
           [x] Digital audio extraction

This is equivalent to cdio(1)'s "cdplay" command and in fact I have
pinched the code from there.  The error handling is a bit dubious
since I have no clue what error conditions are possible, but the
code that calls read_audio_data() is also quite limited in this
respect.

Works for me for playing unscratched Red Book CDs and even a
DTS CD.

Index: Makefile
===================================================================
RCS file: /cvs/ports/audio/xmms/Makefile,v
retrieving revision 1.61
diff -u -p -r1.61 Makefile
--- Makefile    16 Jan 2009 04:15:46 -0000      1.61
+++ Makefile    7 Feb 2009 22:56:01 -0000
@@ -9,7 +9,7 @@ SHARED_ONLY=            Yes
 
 VERSION=               1.2.11
 DISTNAME=              xmms-${VERSION}
-PKGNAME-main=          xmms-${VERSION}p4
+PKGNAME-main=          xmms-${VERSION}p5
 PKGNAME-vorbis=                xmms-vorbis-${VERSION}p0
 PKGNAME-mikmod=                xmms-mikmod-${VERSION}p0
 PKGNAME-mp3=           xmms-mp3-${VERSION}p0
Index: patches/patch-Input_cdaudio_cdaudio_c
===================================================================
RCS file: /cvs/ports/audio/xmms/patches/patch-Input_cdaudio_cdaudio_c,v
retrieving revision 1.4
diff -u -p -r1.4 patch-Input_cdaudio_cdaudio_c
--- patches/patch-Input_cdaudio_cdaudio_c       8 Dec 2007 21:54:57 -0000       
1.4
+++ patches/patch-Input_cdaudio_cdaudio_c       7 Feb 2009 22:56:01 -0000
@@ -1,6 +1,6 @@
 $OpenBSD: patch-Input_cdaudio_cdaudio_c,v 1.4 2007/12/08 21:54:57 ajacoutot 
Exp $
---- Input/cdaudio/cdaudio.c.orig       Fri Nov 23 16:18:35 2007
-+++ Input/cdaudio/cdaudio.c    Fri Nov 23 16:20:02 2007
+--- Input/cdaudio/cdaudio.c.orig       Fri Nov 16 22:51:24 2007
++++ Input/cdaudio/cdaudio.c    Sat Feb  7 23:13:08 2009
 @@ -819,6 +819,10 @@ static int get_current_frame(void)
  {
        struct ioc_read_subchannel subchnl;
@@ -12,3 +12,42 @@ $OpenBSD: patch-Input_cdaudio_cdaudio_c,
        subchnl.address_format = CD_MSF_FORMAT;
        subchnl.data_format = CD_CURRENT_POSITION;
        subchnl.track = 0;
+@@ -891,6 +895,38 @@ int read_audio_data(int fd, int pos, int num, void *bu
+       return num;             
+ }
+ # endif /* CDIOCREADAUDIO */
++#endif
++
++#ifdef __OpenBSD__
++int read_audio_data(int fd, int pos, int num, void *buf)
++{
++      scsireq_t scr;
++      int lba;
++
++      memset(&scr, 0, sizeof(scr));
++
++      lba = pos - CDDA_MSF_OFFSET;
++      scr.cmd[0] = 0xbe;                      /* READ CD */
++      scr.cmd[2] = (lba >> 24) & 0xff;
++      scr.cmd[3] = (lba >> 16) & 0xff;
++      scr.cmd[4] = (lba >> 8) & 0xff;
++      scr.cmd[5] = lba & 0xff;
++      scr.cmd[6] = (num >> 16) & 0xff;
++      scr.cmd[7] = (num >> 8) & 0xff;
++      scr.cmd[8] = num & 0xff;
++      scr.cmd[9] = 0x10;
++
++      scr.flags = SCCMD_ESCAPE | SCCMD_READ;
++      scr.databuf = buf;
++      scr.datalen = num * CD_FRAMESIZE_RAW;
++      scr.cmdlen = 12;
++      scr.timeout = 120000;
++      scr.senselen = SENSEBUFLEN;
++
++      if (ioctl(fd, SCIOCCOMMAND, &scr) == -1 || scr.retsts != SCCMD_OK)
++              return 0;
++      return num;
++}
+ #endif
+ 
+ #ifdef XMMS_CDROM_BSD_NETBSD /* NetBSD, OpenBSD */
Index: patches/patch-Input_cdaudio_cdaudio_h
===================================================================
RCS file: patches/patch-Input_cdaudio_cdaudio_h
diff -N patches/patch-Input_cdaudio_cdaudio_h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-Input_cdaudio_cdaudio_h       7 Feb 2009 22:56:01 -0000
@@ -0,0 +1,16 @@
+$OpenBSD$
+--- Input/cdaudio/cdaudio.h.orig       Sat Feb  7 22:44:27 2009
++++ Input/cdaudio/cdaudio.h    Sat Feb  7 22:56:20 2009
+@@ -65,7 +65,11 @@
+ #include <sys/cdrio.h>
+ #endif
+ 
+-#if defined(CDROMREADAUDIO) || defined(CDIOCREADAUDIO) || defined(CDROMCDDA) 
|| defined(CDRIOCSETBLOCKSIZE)
++#ifdef __OpenBSD__
++#include <sys/scsiio.h>
++#endif
++
++#if defined(CDROMREADAUDIO) || defined(CDIOCREADAUDIO) || defined(CDROMCDDA) 
|| defined(CDRIOCSETBLOCKSIZE) || defined(SCIOCCOMMAND)
+ # define CDDA_HAS_READAUDIO
+ #endif
+ 
-- 
Christian "naddy" Weisgerber                          [email protected]

Reply via email to