more alsa - Alex
authorterminatorX <>
Tue, 17 Jul 2001 19:08:27 +0000 (19:08 +0000)
committerterminatorX <>
Tue, 17 Jul 2001 19:08:27 +0000 (19:08 +0000)
acconfig.h
configure.in
src/tX_audiodevice.cc
src/tX_audiodevice.h
src/tX_engine.cc
src/tX_global.c
src/tX_global.h

index 27a5dff22f8095d451bca4cbbdfa77d1a64d2c15..a2c8cf08b372488e9a94744f052fd50837279419 100644 (file)
 /* Exec xsetpointer instead of using Xlib-calls. */
 #undef USE_XSETPOINTER
 
-/* Do we have the ALSA-Lib?
-#undef HAVE_ALSALIB
-
-/* Do we have the ALSA-Headers? 
-#undef HAVE_ALSAHEADER*/
-
 /* Use ALSA*/
 #undef USE_ALSA
 
+/* Use OSS */
+#undef USE_OSS
index d6ca2f86a47f0096e71dbcc0b807d49f44ae3796..226b10e5e524f3458fce8652250f88b4ab1fae21 100644 (file)
@@ -14,7 +14,8 @@ dnl AC_ARG_ENABLE(3dnow,    [  --enable-3dnow          enables 3DNow! support. [
 dnl AC_ARG_ENABLE(benchmark,[  --enable-benchmark      creates a non-functional test version [default=no] ])
 AC_ARG_ENABLE(wav,          [  --enable-wav            enables the builtin wav-loader [default=yes] ])
 AC_ARG_ENABLE(xsetpointer,  [  --enable-xsetpointer    enables executing of xsetpointer [default=auto] ])
-AC_ARG_ENABLE(alsa,         [  --enable-alsa           use ALSA instead of OSS [default=auto] ])
+AC_ARG_ENABLE(alsa,         [  --enable-alsa           use ALSA for sound output [default=auto] ])
+AC_ARG_ENABLE(oss,          [  --enable-oss            use OSS for sound output [default=auto] ])
 
 dnl AC_ARG_ENABLE(dial,         [  --enable-dial           use dials instead of scales for effects [default=yes] ])
 dnl AC_ARG_ENABLE(bigdial,      [  --enable-bigdial        use BIG dials [default=yes] ])
@@ -36,7 +37,7 @@ dnl AM_PATH_GLIB(1.2.0, , AC_MSG_ERROR([** GLIB 1.2.0 not installed or broken **
 
 dnl Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/ioctl.h unistd.h)
+AC_CHECK_HEADERS(fcntl.h limits.h malloc.h unistd.h)
 AC_CHECK_HEADERS(ladspa.h,, AC_MSG_ERROR([** couldn't find ladspa.h - install the ladspa SDK - get it from http://www.ladspa.org **]))
 
 dnl Checks for typedefs, structures, and compiler characteristics.
@@ -78,6 +79,7 @@ if test "$enable_xsetpointer" != "no"; then
 fi
 
 using_alsa=no
+using_oss=no
 
 if test "$enable_alsa" != "no"; then
        AC_CHECK_LIB(asound, snd_ctl_open,alsalib=yes,alsalib=no)
@@ -99,12 +101,33 @@ if test "$enable_alsa" != "no"; then
        fi
 fi
 
+if test "$enable_oss" != "no"; then
+       AC_CHECK_HEADERS(sys/ioctl.h sys/soundcard.h,oss=yes,oss=no)
+       
+       if test "$oss" = "yes"; then
+               AC_DEFINE(USE_OSS)
+               using_oss=yes;
+       else
+               if test "$enable_oss" = "yes"; then
+                       AC_MSG_ERROR([** Couldn't find OSS header files. ***])
+               fi
+       fi
+fi
+
 if test "$using_alsa" = "yes"; then
-       AC_MSG_RESULT([** Using ALSA for sound output. **])
-else
-       AC_MSG_RESULT([** Using OSS for sound output. **])
+       AC_MSG_RESULT([termnatorX audiodevice: using ALSA.])
 fi
 
+if test "$using_oss" = "yes"; then
+       AC_MSG_RESULT([termnatorX audiodevice: using OSS.])
+fi
+
+if test "$using_alsa" != "yes"; then
+       if test "$using_oss" != "yes"; then
+               AC_MSG_ERROR([** Found neither OSS nor ALSA! **])
+       fi
+fi     
+       
 if test "$enable_wav" != "no";
 then
        AC_DEFINE(USE_BUILTIN_WAV)
@@ -131,13 +154,16 @@ if test "$enable_benchmark" = yes; then
        AC_DEFINE(CREATE_BENCHMARK)
 fi
 
-AC_MSG_CHECKING(whether to use dials)
-if test "$enable_dial" = no; then
-       AC_MSG_RESULT(no)
-else
-       AC_MSG_RESULT(yes)
+dnl AC_MSG_CHECKING(whether to use dials)
+dnl if test "$enable_dial" = no; then
+dnl    AC_MSG_RESULT(no)
+dnl else
+dnl    AC_MSG_RESULT(yes)
        AC_DEFINE(USE_DIAL)
-fi
+dnl fi
+
+AC_MSG_CHECKING(for necessary scratching skillz)
+AC_MSG_RESULT(yes)
 
 if test "$enable_bigdial" = yes; then
        AC_DEFINE(USE_DIAL)
index 2a3f1c4afce89d1401e10cefb577aaf532364311..8c117e12908831021d079e8675e3b1bce2f7d4f6 100644 (file)
 
 #include "tX_endian.h"
 
-int audiodevice :: dev_open(int dont_use_rt_buffsize)
+void tX_audiodevice :: init()
+{
+       samples_per_buffer=0;
+       set_buffersize_near(globals.audiodevice_buffersize);
+}
+
+
+void tX_audiodevice :: set_latency_near(int milliseconds)
+{
+       samples_per_buffer=(int) (((float) milliseconds) * 88.2);
+}
+
+int tX_audiodevice :: get_latency()
+{
+       return ((int) (((float) samples_per_buffer) / 88.2));
+}
+
+void tX_audiodevice :: set_buffersize_near(int samples)
+{
+       samples_per_buffer=samples;
+}
+
+int tX_audiodevice :: get_buffersize()
+{
+       return samples_per_buffer;
+}
+
+int tX_audiodevice :: open()
+{
+       fprintf(stderr, "tX: Error: tX_audiodevice::dev_open()\n");
+}
+
+int tX_audiodevice :: close()
+{
+       fprintf(stderr, "tX: Error: tX_audiodevice::dev_close()\n");
+}
+
+void tX_audiodevice :: play(int16_t* dummy)
+{
+       fprintf(stderr, "tX: Error: tX_audiodevice::play()\n");
+}
+
+#ifdef USE_OSS
+
+int tX_audiodevice_oss :: open(int dont_use_rt_buffsize)
 {
        int i=0;
        int p;
@@ -92,12 +136,7 @@ int audiodevice :: dev_open(int dont_use_rt_buffsize)
         return(i);     
 }
 
-int audiodevice :: getblocksize()
-{
-       return(blocksize);
-}
-
-int audiodevice :: dev_close()
+int tX_audiodevice_oss :: close()
 {
        void *dummy;
 
@@ -116,16 +155,44 @@ int audiodevice :: dev_close()
        return(0);      
 }
 
-audiodevice :: audiodevice()
+tX_audiodevice_oss :: tX_audiodevice_oss()
 {
        fd=0;
-       blocksize=0;
+
+       init();
 }
 
-void audiodevice :: eat(int16_t *buffer)
+void tX_audiodevice_oss :: play(int16_t *buffer)
 {
 #ifdef BIG_ENDIAN_MACHINE
        swapbuffer (buffer, samples);
 #endif
        write(fd, buffer, blocksize);   
 }
+
+#endif //USE_OSS
+
+#ifdef USE_ALSA
+
+int tX_audiodevice_alsa :: open(int dont_use_rt_buffsize)
+{
+}
+
+int tX_audiodevice_alsa :: close()
+{
+}
+
+tX_audiodevice_alsa :: tX_audiodevice_alsa()
+{
+       init();
+}
+
+void tX_audiodevice_alsa :: play(int16_t *buffer)
+{
+#ifdef BIG_ENDIAN_MACHINE
+       swapbuffer (buffer, samples);
+#endif
+       /***/
+}
+
+#endif //USE_ALSA
index 8c9ea5d6afd00f832a16545ce4cb2071efbe1111..c0cf8ac776b5c0fa8029d4bb38e6fd6de26ea7ee 100644 (file)
 
 #define NON_RT_BUFF 12
 
-
-class audiodevice
+class tX_audiodevice
 {
-       friend void* writer_thread(void *parm);
-       int fd;
-       int blocksize;
-       int samples;
-       clock_t lastclock;
-       clock_t rendercl;
-       clock_t writecl;
+       int samples_per_buffer;
+       
+       private:
+       void init();
        
        public:
-       int dev_open(int);
-       int dev_close();
+       void set_latency_near(int milliseconds);
+       int get_latency(); /* call only valid *after* open() */
        
-       int getblocksize();
+       void set_buffersize_near(int samples);
+       int get_buffersize(); /* call only valid *after* open() */
        
-       void eat(int16_t*);
+       virtual int open();
+       virtual int close();
+               
+       virtual void play(int16_t*); /* play blocked */
+};
+
+
+#ifdef USE_OSS
+
+class tX_audiodevice_oss : public tX_audiodevice
+{
+       public:
+       virtual int open();
+       virtual int close();
+               
+       virtual void play(int16_t*); /* play blocked */
        
-       audiodevice();
+       tX_audiodevice_oss();
+};
+
+#endif
+
+
+#ifdef USE_ALSA
+
+class tX_audiodevice_alsa : public tX_audiodevice
+{      
+       public:
+       virtual int open();
+       virtual int close();
+               
+       virtual void play(int16_t*); /* play blocked */
        
+       tX_audiodevice_alsa();
 };
 
 #endif
+
+#endif
index d83bd7a5c5766d9e34c021ec06daf78a2b393d64..8dea6590413c04562eb3db6fa799e9100cd2a938 100644 (file)
@@ -59,7 +59,7 @@ pthread_mutex_t pos_lock=PTHREAD_MUTEX_INITIALIZER;
 pthread_mutex_t run_lock=PTHREAD_MUTEX_INITIALIZER;
 
 tx_mouse *mouse=new tx_mouse();
-audiodevice *device=new audiodevice();
+tX_audiodevice *device=NULL;
 tx_tapedeck *tape=new tx_tapedeck();
 
 int engine_quit=0;
@@ -154,7 +154,7 @@ void *engine(void *nil)
                        new_grab_mouse=0;
                }
                
-               device->eat(temp);
+               device->play(temp);
                if (is_recording) tape->eat(temp);
                sequencer.step();
                temp=vtt_class::render_all_turntables();                                        
@@ -188,10 +188,33 @@ int run_engine()
        }
 
        pthread_mutex_lock(&run_lock);
+       
+       switch (globals.audiodevice_type)
+       {
+#ifdef USE_OSS 
+               case TX_AUDIODEVICE_TYPE_OSS:
+                       device=new tX_audiodevice_oss();
+                       break;
+#endif                 
 
-       if (device->dev_open(0))
+#ifdef USE_ALSA                        
+               case TX_AUDIODEVICE_TYPE_ALSA:
+                       device=new tX_audiodevice_alsa();
+                       break;
+#endif
+               
+               default:
+                       device=NULL;
+                       pthread_mutex_unlock(&run_lock);
+                       pthread_mutex_unlock(&thread_lock);
+                       return TX_ENG_ERR_DEVICE;
+       }
+       
+       if (device->open())
        {
-               device->dev_close();
+               device->close();
+               delete device;
+               device=NULL;            
                pthread_mutex_unlock(&run_lock);
                pthread_mutex_unlock(&thread_lock);
                return TX_ENG_ERR_DEVICE;
@@ -201,18 +224,20 @@ int run_engine()
        
        if (want_recording)
        {
-               if (!tape->start_record(globals.record_filename, device->getblocksize()))
+               if (!tape->start_record(globals.record_filename, device->get_buffersize()*sizeof(int16_t)))
                        is_recording=1;
                else
                {
-                       device->dev_close();
+                       device->close();
+                       delete device;
+                       device=NULL;                    
                        pthread_mutex_unlock(&run_lock);
                        pthread_mutex_unlock(&thread_lock);
                        return TX_ENG_ERR_TAPE;                 
                }
        }
 
-       vtt_class::set_mix_buffer_size(device->getblocksize()/sizeof(int16_t)/2);
+       vtt_class::set_mix_buffer_size(device->get_buffersize()/2); //mixbuffer is mono
        
        engine_quit=0;
 #ifdef USE_SCHEDULER   
@@ -247,7 +272,9 @@ int run_engine()
        
        if (!engine_thread)
        {
-               device->dev_close();
+               device->close();
+               delete device;          
+               device=NULL;
                pthread_mutex_unlock(&run_lock);
                pthread_mutex_unlock(&thread_lock);
                return(TX_ENG_ERR_THREAD);
@@ -292,7 +319,9 @@ int stop_engine()
        engine_thread=0;
        
        pthread_mutex_unlock(&thread_lock);
-       device->dev_close();
+       device->close();
+       delete device;
+       device=NULL;
        
        for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++)
        {
index 45b0e56250a09aef9917e99f7769cae39154586b..d168ab1a6d4908592ff7303f6a91673a1f377b89 100644 (file)
@@ -117,6 +117,17 @@ void load_globals()
                strcpy(globals.tables_filename, "");
                strcpy(globals.record_filename, "tX_record.wav");
                strcpy(globals.file_editor, "");
+               
+#ifdef USE_OSS
+               globals.audiodevice_type=TX_AUDIODEVICE_TYPE_OSS;               
+#else
+#ifdef USE_ALSA
+               globals.audiodevice_type=TX_AUDIODEVICE_TYPE_ALSA;
+#endif 
+#endif         
+               strcpy(globals.audiodevice_oss_devicename, "/dev/dsp");
+               globals.audiodevice_alsa_card=0;
+               globals.audiodevice_alsa_pcm=0;         
        }
 
        /* i'll have to keep these as they're in the code
index b11f0faf2b248f913205f8368fd11604b731d9f1..11c5b2d3afbf2e88cf4c171f7ed4909da5583fc2 100644 (file)
@@ -45,6 +45,9 @@ extern "C" {
 #define BUTTON_TYPE_TEXT 2
 #define BUTTON_TYPE_BOTH 3
 
+#define TX_AUDIODEVICE_TYPE_OSS 0
+#define TX_AUDIODEVICE_TYPE_ALSA 1
+
 typedef struct {
        char    audio_device[PATH_MAX];
        
@@ -98,6 +101,22 @@ typedef struct {
        int update_delay; 
        
        char *current_path;
+       
+       /* new audiodevice handling 
+          we have *all* variables for *all* audiodevice types -
+          even if support for them is not compiled in - to keep
+          the .terminatorX3rc.bin in sync.
+       */
+       
+       int audiodevice_type; // TX_AUDIODEVICE_TYPE_OSS etc.
+       int audiodevice_buffer; // buffer in samples
+       
+       /* OSS specific options */
+       int audiodevice_oss_devicename[PATH_MAX];
+       
+       /* ALSA specific options */
+       int audiodevice_alsa_card;
+       int audiodevice_alsa_pcm;               
 } tx_global;
 
 extern tx_global globals;