--- src/d_array.c | 2 +- src/d_osc.c | 2 +- src/s_audio.c | 62 +++++++++++++++++++++ src/s_audio_audiounit.c | 43 +++++++++++++++ src/s_audio_esd.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++ src/s_file.c | 4 +- src/s_loader.c | 4 +- src/s_main.c | 23 ++++++++ src/s_stuff.h | 27 +++++++++ src/x_misc.c | 2 +- 10 files changed, 298 insertions(+), 6 deletions(-) create mode 100644 src/s_audio_audiounit.c create mode 100644 src/s_audio_esd.c
diff --git a/src/d_array.c b/src/d_array.c index 1624aa3..c0aab61 100644 --- a/src/d_array.c +++ b/src/d_array.c @@ -506,7 +506,7 @@ static void tabread4_tilde_setup(void) #include <machine/endian.h> #endif
-#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) +#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || defined(ANDROID) #include <endian.h> #endif
diff --git a/src/d_osc.c b/src/d_osc.c index 582a0b2..25e490d 100644 --- a/src/d_osc.c +++ b/src/d_osc.c @@ -19,7 +19,7 @@ #include <machine/endian.h> #endif
-#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) +#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || defined(ANDROID) #include <endian.h> #endif
diff --git a/src/s_audio.c b/src/s_audio.c index 7545558..5582d44 100644 --- a/src/s_audio.c +++ b/src/s_audio.c @@ -362,6 +362,16 @@ void sys_close_audio(void) mmio_close_audio(); else #endif +#ifdef USEAPI_AUDIOUNIT + if (sys_audioapiopened == API_AUDIOUNIT) + audiounit_close_audio(); + else +#endif +#ifdef USEAPI_ESD + if (sys_audioapiopened == API_ESD) + esd_close_audio(); + else +#endif post("sys_close_audio: unknown API %d", sys_audioapiopened); sys_inchannels = sys_outchannels = 0; sys_audioapiopened = -1; @@ -426,6 +436,18 @@ void sys_reopen_audio( void) chindev, naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate); else #endif +#ifdef USEAPI_AUDIOUNIT + if (sys_audioapi == API_AUDIOUNIT) + outcome = audiounit_open_audio((naudioindev > 0 ? chindev[0] : 0), + (naudioindev > 0 ? choutdev[0] : 0), rate); + else +#endif +#ifdef USEAPI_ESD + if (sys_audioapi == API_ALSA) + outcome = esd_open_audio(naudioindev, audioindev, naudioindev, + chindev, naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate); + else +#endif if (sys_audioapi == API_NONE) ; else post("unknown audio API specified"); @@ -497,6 +519,16 @@ int sys_send_dacs(void) return (mmio_send_dacs()); else #endif +#ifdef USEAPI_AUDIOUNIT + if (sys_audioapi == API_AUDIOUNIT) + return (audiounit_send_dacs()); + else +#endif +#ifdef USEAPI_ESD + if (sys_audioapi == API_ESD) + return (esd_send_dacs()); + else +#endif post("unknown API"); return (0); } @@ -580,6 +612,20 @@ static void audio_getdevs(char *indevlist, int *nindevs, } else #endif +#ifdef USEAPI_AUDIOUNIT + if (sys_audioapi == API_AUDIOUNIT) + { + } + else +#endif +#ifdef USEAPI_ESD + if (sys_audioapi == API_ESD) + { + esd_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti, + maxndev, devdescsize); + } + else +#endif { /* this shouldn't happen once all the above get filled in. */ int i; @@ -781,6 +827,16 @@ void sys_listdevs(void ) sys_listaudiodevs(); else #endif +#ifdef USEAPI_AUDIOUNIT + if (sys_audioapi == API_AUDIOUNIT) + sys_listaudiodevs(); + else +#endif +#ifdef USEAPI_ESD + if (sys_audioapi == API_ESD) + sys_listaudiodevs(); + else +#endif post("unknown API");
sys_listmididevs(); @@ -876,6 +932,12 @@ void sys_get_audio_apis(char *buf) #ifdef USEAPI_JACK sprintf(buf + strlen(buf), "{jack %d} ", API_JACK); n++; #endif +#ifdef USEAPI_AUDIOUNIT + sprintf(buf + strlen(buf), "{AudioUnit %d} ", API_AUDIOUNIT); n++; +#endif +#ifdef USEAPI_ESD + sprintf(buf + strlen(buf), "{ESD %d} ", API_ESD); n++; +#endif strcat(buf, "}"); /* then again, if only one API (or none) we don't offer any choice. */ if (n < 2) diff --git a/src/s_audio_audiounit.c b/src/s_audio_audiounit.c new file mode 100644 index 0000000..d9d7f66 --- /dev/null +++ b/src/s_audio_audiounit.c @@ -0,0 +1,43 @@ + +/* ------------- routines for Apple AudioUnit in AudioToolbox -------------- */ +#ifdef USEAPI_AUDIOUNIT + +/* this is currently a placeholder file while we decide which one of three implementations of this API we use */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "m_pd.h" +#include "s_stuff.h" +#include <AudioToolbox/AudioToolbox.h> + +pthread_mutex_t audiounit_mutex; +pthread_cond_t audiounit_sem; + +int audiounit_open_audio(int inchans, int outchans, int rate) +{ + return 0; +} + +void audiounit_close_audio(void) +{ +} + +int audiounit_send_dacs(void) +{ + return 0; +} + +void audiounit_getdevs(char *indevlist, int *nindevs, + char *outdevlist, int *noutdevs, int *canmulti, + int maxndev, int devdescsize) +{ + post("device getting not implemented for AudioUnit yet\n"); +} + +void audiounit_listdevs( void) +{ + post("device listing not implemented for AudioUnit yet\n"); +} + +#endif /* AUDIOUNIT */ diff --git a/src/s_audio_esd.c b/src/s_audio_esd.c new file mode 100644 index 0000000..ce0f117 --- /dev/null +++ b/src/s_audio_esd.c @@ -0,0 +1,135 @@ +/* Copyright (c) 2006 Guenter Geiger, +* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +#ifdef USEAPI_ESD + +#include <stdio.h> +#include <string.h> /* memset */ +#include <esd.h> +#include "m_pd.h" +#include "s_stuff.h" +#include "m_fixed.h" + +/* exported variables */ + +float sys_dacsr; + + +/* private data */ + +static int esd_socket_out; +static int esd_channels_out; + +static int esd_socket_in; +static int esd_channels_in; + + +int esd_open_audio(int nindev, int *indev, int nchin, int *chin, + int noutdev, int *outdev, int nchout, int *chout, int rate) +{ + + esd_format_t format = ESD_BITS16 | ESD_STEREO | ESD_STREAM | ESD_PLAY; + + indev[0] = 0; + nindev = 1; + + outdev[0] = 0; + noutdev = 1; + + rate = sys_dacsr = ESD_DEFAULT_RATE; + + if (*chout == 2) { + esd_socket_out = esd_play_stream_fallback(format, ESD_DEFAULT_RATE, NULL, "pd"); + if (esd_socket_out <= 0) { + fprintf (stderr, "Error at esd open: %d\n", esd_socket_out); + esd_channels_out = *chout = 0; + return 0; + } + esd_channels_out = *chout = 2; + } + + if (*chin == 2) { + esd_socket_in = esd_record_stream_fallback(format, ESD_DEFAULT_RATE, NULL, "pd-in"); + if (esd_socket_in <= 0) { + fprintf (stderr, "Error at esd open: %d\n", esd_socket_in); + esd_channels_in = *chin = 0; + return 0; + } + esd_channels_in = *chin = 2; + } + return (0); +} + +void esd_close_audio( void) +{ + close(esd_socket_out); + close(esd_socket_in); +} + + +#define DEFDACBLKSIZE 64 +#define MAXCHANS 2 + +static short buf[DEFDACBLKSIZE*MAXCHANS]; + +int esd_send_dacs(void) +{ + t_sample* fp1,*fp2; + short* sp; + int i,j; + + /* Do input */ + + if (esd_channels_in) { + read(esd_socket_in,buf,DEFDACBLKSIZE*esd_channels_out*2); + for (i = DEFDACBLKSIZE, fp1 = sys_soundin, + sp = (short *)buf; i--; fp1++, sp += esd_channels_in) { + for (j=0, fp2 = fp1; j<esd_channels_in; j++, fp2 += DEFDACBLKSIZE) + { + int s = INVSCALE16(sp[j]); + *fp2 = s; + } + } + } + + /* Do output */ + + if (esd_channels_out) { + for (i = DEFDACBLKSIZE, fp1 = sys_soundout, + sp = (short *)buf; i--; fp1++, sp += esd_channels_out) { + for (j=0, fp2 = fp1; j<esd_channels_out; j++, fp2 += DEFDACBLKSIZE) + { + int s = SCALE16(*fp2); + if (s > 32767) s = 32767; + else if (s < -32767) s = -32767; + sp[j] = s; + } + } + + write(esd_socket_out,buf,DEFDACBLKSIZE*esd_channels_out*2); + } + + memset(sys_soundin,0,DEFDACBLKSIZE*esd_channels_out*2); + memset(sys_soundout,0,DEFDACBLKSIZE*esd_channels_out*4); + + return (SENDDACS_YES); +} + +void esd_listdevs( void) +{ + post("device listing not implemented for ESD yet\n"); +} + +void esd_getdevs(char *indevlist, int *nindevs, + char *outdevlist, int *noutdevs, int *canmulti, + int maxndev, int devdescsize) +{ + int i, ndev; + *canmulti = 1; /* supports multiple devices */ + sprintf(indevlist, "ESD device"); + sprintf(outdevlist, "ESD device"); + *nindevs = *noutdevs = 1; +} + +#endif diff --git a/src/s_file.c b/src/s_file.c index 2fca46c..874ebc2 100644 --- a/src/s_file.c +++ b/src/s_file.c @@ -36,7 +36,7 @@ int sys_defeatrt; t_symbol *sys_flags = &s_; void sys_doflags( void);
-#if defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD_kernel__) || defined(__GNU__) +#if defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD_kernel__) || defined(__GNU__) || defined(ANDROID)
static char *sys_prefbuf; static int sys_prefbufsize; @@ -417,7 +417,7 @@ void sys_loadpreferences( void) #if defined(__linux__) || defined(__CYGWIN__) sys_hipriority = !geteuid(); #else -#ifdef _WIN32 +#if defined(_WIN32) || defined(ANDROID) sys_hipriority = 0; #else sys_hipriority = 1; diff --git a/src/s_loader.c b/src/s_loader.c index 28dd4ce..0b4ff4a 100644 --- a/src/s_loader.c +++ b/src/s_loader.c @@ -44,7 +44,7 @@ static char sys_dllextent[] = ".l_ia64", sys_dllextent2[] = ".pd_linux"; # else static char sys_dllextent[] = ".l_i386", sys_dllextent2[] = ".pd_linux"; # endif -#elif defined __APPLE__ +#elif defined(__APPLE__) # ifndef MACOSX3 static char sys_dllextent[] = ".d_fat", sys_dllextent2[] = ".pd_darwin"; # else @@ -52,6 +52,8 @@ static char sys_dllextent[] = ".d_ppc", sys_dllextent2[] = ".pd_darwin"; # endif #elif defined(_WIN32) || defined(__CYGWIN__) static char sys_dllextent[] = ".m_i386", sys_dllextent2[] = ".dll"; +#elif defined(ANDROID) +static char sys_dllextent[] = ".l_arm", sys_dllextent2[] = ".pd_linux"; #endif
/* maintain list of loaded modules to avoid repeating loads */ diff --git a/src/s_main.c b/src/s_main.c index 1b06b7d..efb69db 100644 --- a/src/s_main.c +++ b/src/s_main.c @@ -345,6 +345,15 @@ static char *(usagemessage[]) = { #ifdef USEAPI_MMIO "-mmio -- use MMIO audio API (default for Windows)\n", #endif + +#ifdef USEAPI_AUDIOUNIT +"-audiounit -- use Apple AudioUnit API\n", +#endif + +#ifdef USEAPI_ESD +"-esd -- use Enlightenment Sound Daemon (ESD) API\n", +#endif + " (default audio API for this platform: ", API_DEFSTRING, ")\n\n",
"\nMIDI configuration flags:\n", @@ -645,6 +654,20 @@ int sys_argparse(int argc, char **argv) argc--; argv++; } #endif +#ifdef USEAPI_AUDIOUNIT + else if (!strcmp(*argv, "-audiounit")) + { + sys_set_audio_api(API_AUDIOUNIT); + argc--; argv++; + } +#endif +#ifdef USEAPI_ESD + else if (!strcmp(*argv, "-esd")) + { + sys_set_audio_api(API_ESD); + argc--; argv++; + } +#endif else if (!strcmp(*argv, "-nomidiin")) { sys_nmidiin = 0; diff --git a/src/s_stuff.h b/src/s_stuff.h index 5e8b5e3..47a7987 100644 --- a/src/s_stuff.h +++ b/src/s_stuff.h @@ -182,6 +182,8 @@ void sys_setalarm(int microsec); #define API_PORTAUDIO 4 #define API_JACK 5 #define API_SGI 6 +#define API_AUDIOUNIT 7 +#define API_ESD 8
#if defined(__linux__) || defined(__FreeBSD_kernel__) # define API_DEFAULT API_OSS @@ -192,8 +194,13 @@ void sys_setalarm(int microsec); # define API_DEFSTRING "MMIO" #endif #ifdef __APPLE__ +# ifdef __arm__ +# define API_DEFAULT API_AUDIOUNIT +# define API_DEFSTRING "AudioUnit" +# else # define API_DEFAULT API_PORTAUDIO # define API_DEFSTRING "portaudio" +# endif /* __arm__ */ #endif #ifdef IRIX # define API_DEFAULT API_SGI @@ -269,6 +276,26 @@ void mmio_getdevs(char *indevlist, int *nindevs, char *outdevlist, int *noutdevs, int *canmulti, int maxndev, int devdescsize);
+int audiounit_open_audio(int naudioindev, int *audioindev, int nchindev, + int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, + int *choutdev, int rate); +void audiounit_close_audio(void); +int audiounit_send_dacs(void); +void audiounit_listdevs(void); +void audiounit_getdevs(char *indevlist, int *nindevs, + char *outdevlist, int *noutdevs, int *canmulti, + int maxndev, int devdescsize); + +int esd_open_audio(int naudioindev, int *audioindev, int nchindev, + int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, + int *choutdev, int rate); +void esd_close_audio(void); +int esd_send_dacs(void); +void esd_listdevs(void); +void esd_getdevs(char *indevlist, int *nindevs, + char *outdevlist, int *noutdevs, int *canmulti, + int maxndev, int devdescsize); + void sys_listmididevs(void); void sys_set_midi_api(int whichapi); void sys_set_audio_api(int whichapi); diff --git a/src/x_misc.c b/src/x_misc.c index 2865d3f..13090f0 100644 --- a/src/x_misc.c +++ b/src/x_misc.c @@ -23,7 +23,7 @@ #if defined (__APPLE__) || defined (__FreeBSD__) #define CLOCKHZ CLK_TCK #endif -#if defined (__linux__) || defined (__CYGWIN__) +#if defined (__linux__) || defined (__CYGWIN__) || defined (ANDROID) #define CLOCKHZ sysconf(_SC_CLK_TCK) #endif #if defined (__FreeBSD_kernel__) || defined(__GNU__)