Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Windows 7, Boost and LLVM 3 part 2

This is a major commit (too big sorry!) that touches nearly every file
in the repo.  There are three signficiant changes represented here:

Firstly there are changes to the extempore lang type system to support
upcoming changes in llvm 3.0+.  These are generally behind the scenes
changes but do slightly effect the syntax and semantics of bind-type.

By default extempore still builds (and expects) against the LLVM 2.8
and 2.9 branches.  Also the examples/extempore_lang.scm file is
for the 2.8 and 2.9 branches.  If you want to use LLVM 3.0+ you will
need to compile against a build of the LLVM 3.0+ branch (still in beta)
and set the EXT_LLVM_3 flag:

./all -DEXT_LLVM_3

Additionally there is a patch required to make the LLVM 3.0 branch
compatible.  You'll need to install this patch before you build
LLVM 3.0.  The LLVM src code patch is supplied as a download option
from github: click on downloads on the main extempore github page
and download the llvm 3 patch.

The second major change is to promote cross platform compatibility
by utilizing the boost libraries.  I'm not much of a fan of boost
to be honest but it seems to be the best of a bad bunch of options
at the moment.  This change largely effects networking and threading
code.  As there is quite a lot of threading and networking code
in extempore this change touches on many parts of the system and
potentially adds new bugs/instability.  I hope this is isn't the
case but ...

By default Extempore will still compile with the old code in place
(i.e. pthreads and unix sockets).  If you want to compile against
the boost libraries (instead if pthreads and unix sockets) you
need to set the EXT_BOOST property.

./all -DEXT_BOOST

or if you want boost and LLVM 3

./all -DEXT_BOOST -DEXT_LLVM_3

Finally the boost changes have been made in large part to support
Windows.  Or more specifically 64bit Windows 7 - I'm not going to bother
supporting anything ealier.  It MAY work on other Windows systems,
but I'm not going to be bother testing on them.  Everything currently
works nicely on Windows 7 64bit.  I'm am using this at work at the moment
and so can confirm that it is operational and stable.

There is NO official build support for Windows at the moment.  I will
put a zip file containing my extremetly hacky MSVS 2010 project up
on github (in downloads - same as patch file) for those who want to
build their own.  You will also obviously need to install and build
the Boost, LLVM and PortAudio libraries yourself.  If someone would
like to put together a nice cmake project for all of this that would
be wonderful - until that happens your on your own ;)

Because it's a hastle to build all of this on windows I have also put
a pre-built extempore binary for windows in github downloads.  this
is for convenience only.
  • Loading branch information...
commit 3a52ed0f2625c2528f3a7cfceb878b717887bfb9 1 parent b5ffd5c
@digego authored
Showing with 2,939 additions and 1,945 deletions.
  1. +73 −33 INSTALL
  2. +10 −41 README
  3. +1 −0  all.bash
  4. 0  build/mergedep.pl
  5. +1 −1  config/linux.make
  6. +5 −0 examples/extempore_lang.scm
  7. +25 −18 examples/horde3d_knight.scm
  8. +19 −28 examples/opengl_101.scm
  9. +3 −3 include/AudioDevice.h
  10. +12 −3 include/EXTCondition.h
  11. +0 −1  include/EXTMonitor.h
  12. +9 −0 include/EXTMutex.h
  13. +12 −1 include/EXTThread.h
  14. +33 −12 include/OSC.h
  15. +10 −10 include/Scheme.h
  16. +13 −4 include/SchemeFFI.h
  17. +31 −17 include/SchemeProcess.h
  18. +9 −0 include/SchemeREPL.h
  19. +5 −0 include/UNIV.h
  20. +4 −2 libs/dsp_library.scm
  21. +34 −35 libs/horde3d_lib.scm
  22. +3 −6 runtime/code.ir
  23. +140 −137 src/AudioDevice.cpp
  24. +28 −2 src/EXTCondition.cpp
  25. +44 −8 src/EXTLLVM.cpp
  26. +1 −3 src/EXTMonitor.cpp
  27. +42 −6 src/EXTMutex.cpp
  28. +36 −7 src/EXTThread.cpp
  29. +5 −3 src/Extempore.cpp
  30. +749 −758 src/OSC.cpp
  31. +55 −15 src/Scheme.cpp
  32. +547 −66 src/SchemeFFI.cpp
  33. +872 −712 src/SchemeProcess.cpp
  34. +69 −3 src/SchemeREPL.cpp
  35. +12 −7 src/TaskScheduler.cpp
  36. +24 −1 src/UNIV.cpp
  37. +3 −2 top.make
View
106 INSTALL
@@ -7,53 +7,58 @@ Prerequisites
Extempore has some library dependencies.
On linux and OSX:
- - LLVM (version 2.8)
- - pthread
+ - LLVM (version 2.8, 2.9 or 3.0)
+ - pthread (if not using boost)
+ OR boost (if not using pthread)
- pcre (Perl Compatible Regular Expressions)
- - glfw (a light weight opengl lib)
On linux you will also need:
- portaudio
- mesa GL (opengl)
- - glut
- (optionally jack)
On OSX you also need the following frameworks:
- opengl
- coreaudio
- cocoa
- - glut
+
+On Windows 7
+ - LLVM (version 2.8, 2.9 or 3.0)
+ - pcre
+ - boost
+ - portaudio
Most of these are pretty standard and you will probably already have
them on your system (or they will be easy to install). The three that
you are most likely to need to download, compile and install yourself
-are PCRE, GLFW and LLVM (version 2.8). You can find them here:
+are PCRE, PORTAUDIO and LLVM. You can find them here:
PCRE you can get from:
http://www.pcre.org/
- GLFW you can get from:
- http://www.glfw.org/
+ PORTAUDIO you can get from:
+ http://www.portaudio.com
LLVM you can get from:
http://www.llvm.org/
-PCRE and GLFW should build from the most recent source and should
-"just work". LLVM must be version 2.8. All three should build fine
-with standard defaults - although you do need to provide an install
-location for LLVM. So a simple './configure', then 'make' and then
-'make install' should be sufficient for PCRE and GLFW. LLVM will just
-require an additional build location, so something like './configure
---prefix=~/Documents/ext_llvm' then 'make -j2' and then 'make install'
+PCRE and PortAudio should build from the most recent source and should
+"just work". LLVM must be version 2.8,2.9,3.0. All three should
+build fine with standard defaults - although you do need to provide an
+install location for LLVM. So a simple './configure', then 'make' and
+then 'make install' should be sufficient for PCRE and PORTAUDIO. LLVM
+will require an additional build location, so something like
+'./configure --prefix=~/Documents/ext_llvm' then 'make -j2' and then
+'make install'.
-PCRE and GLFW should be installed in the usual locations
+PCRE and PortAudio should be installed in the usual locations
(i.e. somewhere that gcc can find). LLVM is a special case. You'll
need to do ONE of either (a) copy config/llvm.bash.sample to
config/llvm.bash and edit it according to the prefix install location
you set for LLVM. OR (b) set the EXT_LLVM_DIR shell variable to point
to the prefix install location for LLVM. Make sure you download
-version 2.8 of LLVM!
-(i.e. $ export EXT_LLVM_DIR=~/Documents/ext_llvm)
+version 2.8, 2.9 or 3.0 of LLVM! (i.e. $ export
+EXT_LLVM_DIR=~/Documents/ext_llvm)
Once all of the library dependencies for your platform are installed,
you can build extempore using:
@@ -62,6 +67,21 @@ you can build extempore using:
Voila ... you should be done.
+There are a couple of extra build arguments that you may need to use
+
+1) If you are building against LLVM version 3.0+ you to define
+EXT_LLVM_3.
+
+2) If you wish to build against the boost library you
+need to define EXT_BOOST.
+
+So to build against LLVM 3.0+ with boost support you would use the
+build command:
+
+ ./all.bash -DEXT_LLVM_3 -DEXT_BOOST
+
+
+
Ubuntu GNU/Linux Installation
=============================
@@ -70,6 +90,9 @@ You'll need some dependencies:
$ sudo apt-get install libpthread-stubs0 libpcre3 libpcre3-dev libglfw2
libglfw-dev glutg3 libglut3 libglut3-dev portaudio19-dev
+If you want to build against the boost libraries you'll also need:
+ $ sudo apt-get install libboost-dev
+
For now you need to build LLVM from source (it will take some time):
$ wget http://llvm.org/releases/2.8/llvm-2.8.tgz
@@ -86,25 +109,41 @@ Now you can build Extempore:
$ export EXT_LLVM_DIR=~/Documents/ext_llvm
$ ./all.bash
+OR with LLVM 3.0 and Boost and JACK
+
+ $ ./all.bash -DEXT_LLVM_3 -DEXT_BOOST -DJACK_AUDIO
+
NOTE1: If you want to compile against Jack instead of portaudio
provide all.bash with a -DJACK_AUDIO argument (and make sure
that the jack libs and headers are installed correctly!)
-NOTE2: If you are running Ubuntu in VirtualBox (on OSX but also
- possibly on other hosts as well) then you will need to make a
- small source modification and then compile and install glfw
- manually. I haven't spent the time to investigate this properly
- but the following hack will fix it in the short term:
-
- The required source change is a one liner:
- uninstall any glfw packages that you have installed
- download the glfw 2.7 source
- open the file glfw-2.7/lib/x11/x11_window.c
- then search in the file for GLX_DRAWABLE_TYPE
- comment out the body of the if statement
- now compile and install as normal
+
+
+
+WINDOWS
+===========
+Windows support is new but functional. Boost is mandatory for Extempore
+on WindowYou will need to build BOOST,
+PORTAUDIO and LLVM 3.0+ for yourself. These can all be built as static
+libs. Unfortunately there is currently no build process supported so
+you're on your own. I have an MSVS 2010 project for extempore that
+can get you started if you send me an email.
+
+Below are a few notes that may help to get you on the right track.
+
+Some Early Windows Build Notes (for me so I don't forget)
+=========================================================
+(a) Make sure you install CMake
+(b) Use CMake to Build LLVM (choose 64bit option)
+(c) Make sure portaudio msvc general project settings are set to static lib
+(d) boost command line for bjam is:
+:> bjam --build-dir=<dir> toodset=msvc link=static address-model=64 --build-type=complete stage
+(e) extempore msvs project settings needs "PCRE_STATIC" to be defined if you want to build against pcre static libs
+(f) extmepore msvs project needs EXT_BOOST and EXT_LLVM_3 to both be defined
+(g) pcreposix.lib needs to come before pcre.lib in link list
+
Running
=======
@@ -115,8 +154,9 @@ For example:
$ ./extempore runtime
-Once you've started extempore you can connect using either Telnet or
-Emacs (using the included extras/extempore.el file)
+Once you've started extempore you can connect using either Telnet,
+Emacs (using the included extras/extempore.el file), or vim (using
+the included extras/extempore.vim).
If using Telnet the default extempore port to connect to is
7099. Additionally extempore currently takes a second argument (1 for
View
51 README
@@ -1,3 +1,5 @@
+Extempore:
+
Extempore is a new live-coding environment which borrows a core
foundation from the Impromptu environment
(http://impromptu.moso.com.au). Extempore is named as a nod to the
@@ -9,6 +11,10 @@ end-users. Binaries will be made available when the project reaches a
more user friendly state.
+Building:
+
+See the INSTALL notes for build instructions.
+
Current Status:
@@ -22,9 +28,9 @@ Extempore's support for 3rd party libraries is fully dynamic. This
means that Extempore binds to dynamic libraries at runtime. There are
a number of example libraries which can be found in the libs
directory. Many (although not all) of these libraries require you to
-install a 3rd party library (.so for linux .dylib for OSX). In
-particular there is an 'example' DSP library and a library binding
-Extempore to the Horde3D game engine.
+install a 3rd party library (.so for linux .dylib for OSX, dll for
+Windows). In particular there is an 'example' DSP library and a
+library binding Extempore to the Horde3D game engine.
Although Extempore is immature it is worth mentioning that it is
already being used to develop some substantial audiovisual software.
@@ -33,10 +39,7 @@ already being used to develop some substantial audiovisual software.
Open Source - Open Platform:
-Extempore currently builds on both OSX and Linux platforms and should
-easily port to any UNIX environment. The project intends to also
-extend to the Windows platform at some point in the not to distant
-future.
+Extempore currently builds on OSX, Linux and Windows 7 platforms.
The project is released under a BSD style licence.
@@ -49,37 +52,3 @@ developer!
I have started a google group called "Extempore"
http://groups.google.com/group/extemporelang. Joining this group is
probably your best first step in getting involved.
-
-Here is a list of just a few of the things off the top of my head that
-would be very useful contributions for people to make.
-
-1) Developer documentation. Doco describing the overall layout of the
-system, the task scheduling system, the various FFI interfaces, any
-build requirements etc.. Of course I'm happy to help with this but it
-would be really great if someone could make a start on this *as they
-learn the system*. That way the doco would be a practical guide from
-someone who is also going through the motions of learning their way
-around. (also a good opportunity to clean up the code!)
-
-2) End user documentation repo. From experience with the Impromptu
-project it would be great if someone could start working on end-user
-documentation (particularly function documentation) right from the
-outset. This means doco can be added as the system grows rather than
-tagging it on as an after thought. It would be great to integrate the
-doco repository directly into the language infrastructure this time
-around.
-
-3) At this stage Emacs is the only *supported* editor. However, this
-support is extremely rudimentary. It would be excellent if someone
-with some emacs hacking skills could ramp up the extempore.el. It
-would be nice to have some of the features of impromptu's editor
-(better support for keyword highlighting, context sensitive tie in to
-the help system, decent tab-completion and alike)
-
-4) Port to Windows. Should be reasonably straight forward at the moment.
-
-5) It would be great to get some kind of basic web site in place.
-
-6) Most importantly there are many decisions to make in terms of
-development ideas and priorities so join the google group and get your
-hands dirty.
View
1  all.bash
@@ -1,6 +1,7 @@
#!/bin/bash
case $(uname) in
+ *NT*) EXTEMPORE_OS=windows ;;
Linux) EXTEMPORE_OS=linux ;;
Darwin) EXTEMPORE_OS=darwin ;;
*) echo Unsupported OS: $(uname) >&2 ; exit 1 ;;
View
0  build/mergedep.pl 100644 → 100755
File mode changed
View
2  config/linux.make
@@ -1,4 +1,4 @@
-PLATFORM_LIBS := -lportaudio -lglut /usr/lib/mesa/libGL.so.1
+PLATFORM_LIBS := -pthread -lboost_thread -lboost_system -lboost_filesystem -lm -lpcre -lglfw -lportaudio -lglut /usr/lib/mesa/libGL.so.1
PLATFORM_CXXFLAGS :=
PLATFORM_LDFLAGS :=
View
5 examples/extempore_lang.scm
@@ -2,6 +2,11 @@
;;
;; A basic introduction to the Extempore Language and Compiler
;;
+;; These examples are for Extempore lang for LLVM
+;; versions 2.8 and 2.9.
+;;
+;; For recent changes to extempore lang check out
+;; the extempore_lang_3.scm file which supports LLVM 3.0+
;; multiple a * 5
;; note that type infercing works out the type
View
43 examples/horde3d_knight.scm
@@ -8,12 +8,18 @@
;;
;; NOTE!:
;; a) You will need to load the horde3d_lib.scm to bind to Horde3D
-;; b) YOu will need to change the resource path to match your system!
+;; b) You will need to change the resource path to match your system!
+;; (resource path set on line 102)
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(define libglu (sys:open-dylib "libGLU.so"))
-(bind-lib libglu gluLookAt [double,double,double,double,double,double,double,double,double]*)
+(define libglu (if (string=? "Linux" (sys:platform))
+ (sys:open-dylib "libGLU.so")
+ (if (string=? "Windows" (sys:platform))
+ (sys:open-dylib "Glu32.dll")
+ #f)))
+
+(bind-lib libglu gluLookAt [void,double,double,double,double,double,double,double,double,double]*)
(bind-lib libglu gluPerspective [void,double,double,double,double]*)
(bind-lib libglu gluErrorString [i8*,i32]*)
@@ -22,12 +28,12 @@
(* f (/ 3.141592 180.0))))
;; globals
-(bind-val _knight H3DNode 0)
-(bind-val light H3DNode 0)
-(bind-val _particleSys H3DNode 0)
-(bind-val _particleSys2 H3DNode 0)
-(bind-val _cam H3DNode 0)
-(bind-val _hdrPipeRes H3DNode 0)
+(bind-val _knight i32 0)
+(bind-val light i32 0)
+(bind-val _particleSys i32 0)
+(bind-val _particleSys2 i32 0)
+(bind-val _cam i32 0)
+(bind-val _hdrPipeRes i32 0)
(bind-val _x float 5.0)
(bind-val _y float 3.0)
(bind-val _z float 19.0)
@@ -38,12 +44,12 @@
(bind-val _curFPS float 30.0)
(bind-val _weight float 1.0)
(bind-val _animTime float 0.0)
-(bind-val _forwardPipeRes H3DNode 0)
-(bind-val _deferredPipeRes H3DNode 0)
-(bind-val _fontMatRes H3DNode 0)
-(bind-val _panelMatRes H3DNode 0)
-(bind-val _logoMatRes H3DNode 0)
-(bind-val env H3DNode 0)
+(bind-val _forwardPipeRes i32 0)
+(bind-val _deferredPipeRes i32 0)
+(bind-val _fontMatRes i32 0)
+(bind-val _panelMatRes i32 0)
+(bind-val _logoMatRes i32 0)
+(bind-val env i32 0)
(definec resize
@@ -180,11 +186,12 @@
(define opengl-test
(lambda (time degree)
(mainLoop)
- (glx:swap-buffers pr2)
+ (gl:swap-buffers pr2)
(callback (+ time 500) 'opengl-test (+ time 1000) (+ degree 0.01))))
-(define pr2 (glx:make-ctx ":0.0" #f 0.0 0.0 1024.0 768.0))
+(define pr2 (gl:make-ctx ":0.0" #f 0.0 0.0 1024.0 768.0))
(h3d_init)
(resize 1024.0 768.0)
-(opengl-test (now) 0.0)
+(opengl-test (now) 0.0)
+
View
47 examples/opengl_101.scm
@@ -2,40 +2,31 @@
;
; Simplest possible OpenGL example
;
-; Are you running VirtualBox!! (if yes read install notes)
-;
-
-;; code to open a window
-(definec open-window
- (lambda (width height)
- (if (> (glfwInit) 0)
- (if (> (glfwOpenWindow width height 0 0 0 0 0 0 65537) 0)
- (begin (glfwSwapInterval 0) 1)
- 0)
- 0)))
;; a trivial opengl draw loop
-;; need to call glfwSwapBuffers to flush
(definec my-gl-loop
- (lambda (degree)
- (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
- (glLoadIdentity)
- (glTranslated 0.0 -1.0 0.0)
- (dotimes (i:double 1000.0)
- (glTranslated (/ i 2000.0) 0.0 0.0)
- (glColor3d (/ i 1500.0) 0.0 1.0)
- (glRotated degree (/ i 200000.0) 0.5 0.0)
- (glutWireCube 0.02))
- (glfwSwapBuffers)))
+ (let ((size 0.01))
+ (lambda (degree)
+ (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
+ (glLoadIdentity)
+ (glTranslated 0.0 -1.0 0.0)
+ (dotimes (i:double 1000.0)
+ (glTranslated (/ i 2000.0) 0.0 0.0)
+ (glColor3d (/ i 1500.0) 0.0 1.0)
+ (glRotated degree (/ i 200000.0) 0.5 0.0)
+ (glBegin GL_QUADS)
+ (glVertex2d 0.0 0.0)
+ (glVertex2d size 0.0)
+ (glVertex2d size size)
+ (glVertex2d 0.0 size)
+ (glEnd)))))
;; standard impromptu callback
(define opengl-test
(lambda (degree)
(my-gl-loop degree)
- (callback (+ (now) 500) 'opengl-test (+ degree .01))))
+ (gl:swap-buffers glctx)
+ (callback (+ (now) 500) 'opengl-test (+ degree .005))))
-;; open window
-(if (> (open-window 640 480) 0)
- ;; start animating
- (opengl-test 110.0)
- (print-notification "Error opening window!"))
+(define glctx (gl:make-ctx ":0.0" #f 0.0 0.0 1024.0 768.0))
+(opengl-test 70.0)
View
6 include/AudioDevice.h
@@ -111,10 +111,10 @@ namespace extemp {
jack_port_t** output_ports;
#elif defined (___ALSA_AUDIO___) // ALSA NOT CURRENTLY SUPPORTED
snd_pcm_t *pcm_handle;
-#elif defined (TARGET_OS_LINUX) // default on linux is portaudio
- PaStream* stream;
-#else
+#elif defined (TARGET_OS_MAC)
AudioDeviceID device;
+#else
+ PaStream* stream;
#endif
float* buffer;
void* dsp_closure;
View
15 include/EXTCondition.h
@@ -36,9 +36,14 @@
#ifndef EXT_CONDITION
#define EXT_CONDITION
+#ifdef EXT_BOOST
+#include <boost/thread/condition_variable.hpp>
+#include <boost/thread/locks.hpp>
+#else
#include "pthread.h"
-#include "EXTMutex.h"
+#endif
+#include "EXTMutex.h"
namespace extemp
{
@@ -53,12 +58,16 @@ namespace extemp
void destroy();
int wait(EXTMutex *mutex);
- int signal();
+ int signal(EXTMutex *mutex);
protected:
bool initialised;
-
+#ifdef EXT_BOOST
+ boost::condition_variable_any boost_cond;
+#else
pthread_cond_t pthread_cond;
+#endif
+
};
} //End Namespace
View
1  include/EXTMonitor.h
@@ -36,7 +36,6 @@
#ifndef EXT_MONTIOR_H
#define EXT_MONITOR_H
-#include "pthread.h"
#include <string>
#include "EXTMutex.h"
View
9 include/EXTMutex.h
@@ -36,7 +36,12 @@
#ifndef EXT_MUTEX
#define EXT_MUTEX
+#ifdef EXT_BOOST
+#include <boost/thread/recursive_mutex.hpp>
+#else
#include "pthread.h"
+#endif
+
#include <string>
namespace extemp
@@ -58,8 +63,12 @@ namespace extemp
protected:
bool initialised;
std::string name;
+#ifdef EXT_BOOST
+ boost::recursive_mutex bmutex;
+#else
pthread_mutex_t pthread_mutex;
pthread_t owner;
+#endif
friend class EXTCondition;
};
} //End Namespace
View
13 include/EXTThread.h
@@ -36,7 +36,11 @@
#ifndef EXT_THREAD
#define EXT_THREAD
+#ifdef EXT_BOOST
+#include <boost/thread/thread.hpp>
+#else
#include "pthread.h"
+#endif
namespace extemp
@@ -53,15 +57,22 @@ namespace extemp
int cancel();
bool isRunning();
bool isCurrentThread();
+#ifdef EXT_BOOST
+ boost::thread& getBthread();
+#else
pthread_t getPthread();
+#endif
protected:
bool initialised;
bool detached;
bool joined;
bool cancelled;
-
+#ifdef EXT_BOOST
+ boost::thread bthread;
+#else
pthread_t pthread;
+#endif
};
} //End Namespace
View
45 include/OSC.h
@@ -36,16 +36,23 @@
#ifndef OSC_H
#define OSC_H
+#include "UNIV.h"
#include <stdio.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
#include <iostream>
#include <stdexcept>
#include <map>
#include "SchemeProcess.h"
#include "EXTThread.h"
+
+#ifdef EXT_BOOST
+#include <boost/asio.hpp>
+#else
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#endif
+
uint64_t swap64f(double d);
double unswap64f(uint64_t a);
@@ -99,18 +106,27 @@ namespace extemp {
static pointer set_real_type(scheme* _sc, pointer args);
static pointer set_integer_type(scheme* _sc, pointer args);
static pointer send_from_server_socket(scheme* _sc, pointer args);
- //static void osc_callback(std::string* address, std::string* typetags, char* args, int length, char* reply, int* reply_length, std::string* caller);
-
+#ifdef EXT_BOOST
+ boost::asio::ip::udp::endpoint* getAddress() { return osc_address; }
+ boost::asio::ip::udp::endpoint* getClientAddress() { return osc_client_address; }
+ int* getClientAddressSize() { return &osc_client_address_size; }
+ char* getMessageData() { return message_data; }
+ int getMessageLength() { return message_length; }
+ boost::asio::ip::udp::socket* getSendFD() { return send_socket; }
+ void setSendFD(boost::asio::ip::udp::socket* fd) { send_socket = fd; }
+ void setSocket(boost::asio::ip::udp::socket* soc) { socket = soc; }
+ boost::asio::ip::udp::socket* getSocketFD() { return socket; }
+ boost::asio::io_service* getIOService() { return io_service; }
+#else
struct sockaddr_in* getAddress() { return &osc_address; }
struct sockaddr_in* getClientAddress() { return &osc_client_address; }
-// int sizeOfClientAddress() { return sizeof(osc_client_address); }
- int* getClientAddressSize() { return &osc_client_address_size; }
+ int* getClientAddressSize() { return &osc_client_address_size; }
char* getMessageData() { return message_data; }
int getMessageLength() { return message_length; }
int getSendFD() { return send_socket_fd; }
void setSendFD(int fd) { send_socket_fd = fd; }
- //OSC_CALLBACK getCallback() { return callback; }
int* getSocketFD() { return &socket_fd; }
+#endif
EXTThread& getThread() { return threadOSC; }
bool getStarted() { return started; }
void setStarted(bool val) { started = val; }
@@ -129,18 +145,23 @@ namespace extemp {
private:
static OSC* singleton;
EXTThread threadOSC;
+#ifdef EXT_BOOST
+ boost::asio::ip::udp::socket* socket;
+ boost::asio::ip::udp::socket* send_socket;
+ boost::asio::ip::udp::endpoint* osc_address;
+ boost::asio::ip::udp::endpoint* osc_client_address;
+ boost::asio::io_service* io_service;
+#else
int socket_fd;
int send_socket_fd;
struct sockaddr_in osc_address;
struct sockaddr_in osc_client_address;
+#endif
int osc_client_address_size;
- char message_data[256];
+ char message_data[20000];
int message_length;
bool started;
int(*native)(char*,char*,char*); /* if not null then use this compiled function for callbacks */
- //char scheme_real_type;
- //char scheme_integer_type;
- //OSC_CALLBACK callback;
};
} //End Namespace
View
20 include/Scheme.h
@@ -182,26 +182,26 @@ typedef struct num {
} value;
} num;
-SCHEME_EXPORT scheme *scheme_init_new();
-SCHEME_EXPORT scheme *scheme_init_new_custom_alloc(func_alloc malloc, func_dealloc free);
-SCHEME_EXPORT int scheme_init(scheme *sc);
-SCHEME_EXPORT int scheme_init_custom_alloc(scheme *sc, func_alloc, func_dealloc);
-SCHEME_EXPORT void scheme_deinit(scheme *sc);
+scheme *scheme_init_new();
+scheme *scheme_init_new_custom_alloc(func_alloc malloc, func_dealloc free);
+int scheme_init(scheme *sc);
+int scheme_init_custom_alloc(scheme *sc, func_alloc, func_dealloc);
+void scheme_deinit(scheme *sc);
void scheme_set_input_port_file(scheme *sc, FILE *fin);
void scheme_set_input_port_string(scheme *sc, char *start, char *past_the_end);
-SCHEME_EXPORT void scheme_set_output_port_file(scheme *sc, FILE *fin);
+void scheme_set_output_port_file(scheme *sc, FILE *fin);
void scheme_set_output_port_string(scheme *sc, char *start, char *past_the_end);
-SCHEME_EXPORT void scheme_load_file(scheme *sc, FILE *fin);
-SCHEME_EXPORT void scheme_load_string(scheme *sc, const char *cmd, unsigned long long int start_time, unsigned long long int end_time);
+void scheme_load_file(scheme *sc, FILE *fin);
+void scheme_load_string(scheme *sc, const char *cmd, unsigned long long int start_time, unsigned long long int end_time);
void scheme_apply0(scheme *sc, const char *procname);
-SCHEME_EXPORT pointer scheme_apply1(scheme *sc, const char *procname, pointer);
+pointer scheme_apply1(scheme *sc, const char *procname, pointer);
const char *procname(pointer x);
pointer mk_continuation(scheme* sc);
pointer mk_closure(scheme* sc, pointer c, pointer e);
void scheme_call(scheme *sc, pointer func, pointer args, uint64_t start_time, uint64_t call_duration);
void scheme_call_without_stack_reset(scheme *sc, pointer func, pointer args);
void scheme_set_external_data(scheme *sc, void *p);
-SCHEME_EXPORT void scheme_define(scheme *sc, pointer env, pointer symbol, pointer value);
+void scheme_define(scheme *sc, pointer env, pointer symbol, pointer value);
pointer find_slot_in_env(scheme *sc, pointer env, pointer sym, int all);
void set_slot_in_env(scheme *sc, pointer slot, pointer value);
View
17 include/SchemeFFI.h
@@ -38,7 +38,7 @@
#include "Scheme.h"
#include "EXTLLVM.h"
-#include "Task.h";
+#include "Task.h"
#include <map>
@@ -147,6 +147,8 @@ namespace extemp {
static pointer printLLVMFunction(scheme* _sc, pointer args);
static pointer bind_symbol(scheme* _sc, pointer args);
static pointer get_named_type(scheme* _sc, pointer args);
+ static pointer add_llvm_alias(scheme* _sc, pointer args);
+ static pointer get_llvm_alias(scheme* _sc, pointer args);
static pointer impcirGetName(scheme* _sc, pointer args);
static pointer impcirGetType(scheme* _sc, pointer args);
static pointer impcirAdd(scheme* _sc, pointer args);
@@ -164,14 +166,21 @@ namespace extemp {
#if defined (TARGET_OS_LINUX)
// some XWindows guff
static pointer getX11Event(scheme* _sc, pointer args);
- static pointer makeGLXContext(scheme* _sc, pointer args);
- static pointer glxSwapBuffers(scheme* _sc, pointer args);
- static pointer glxMakeContextCurrent(scheme* _sc, pointer args);
#endif
+
+ static pointer makeGLContext(scheme* _sc, pointer args);
+ static pointer glSwapBuffers(scheme* _sc, pointer args);
+ static pointer glMakeContextCurrent(scheme* _sc, pointer args);
+
static double CLOCK_OFFSET;
private:
static SchemeFFI SINGLETON;
static std::map<std::string,std::pair<std::string,std::string> > IMPCIR_DICT;
+ // these tmp buffers used for regex splits
+ static char* tmp_str_a;
+ static char* tmp_str_b;
+ // this used for trivial preoprocesor aliasing (for LLVM IR)
+ static std::map<std::string,std::string> LLVM_ALIAS_TABLE;
};
} // end namespace
View
48 include/SchemeProcess.h
@@ -45,6 +45,10 @@
#include <sstream>
#include "EXTLLVM.h"
+#ifdef EXT_BOOST
+#include <boost/asio.hpp>
+#endif
+
#define pair_caar(p) pair_car(pair_car(p))
#define pair_cadr(p) pair_car(pair_cdr(p))
#define pair_cdar(p) pair_cdr(pair_car(p))
@@ -69,10 +73,11 @@ namespace extemp {
class SchemeTask {
public:
- SchemeTask(uint64_t _time, uint64_t _max_duration, void* _ptr, std::string _label, int _type) : time(_time), max_duration(_max_duration), ptr(_ptr), label(_label), type(_type) {}
+ SchemeTask(uint64_t _time, uint64_t _max_duration, void* _ptr, std::string _label, int _type, void* _ptr2 = 0) : time(_time), max_duration(_max_duration), ptr(_ptr), label(_label), type(_type), ptr2(_ptr2) /*, cnt_access_ptr(0) */ {}
uint64_t getTime() { return time; }
uint64_t getMaxDuration() { return max_duration; }
void* getPtr() { return ptr; }
+ void* getPtr2() { return ptr2; }
std::string getLabel() { return label; }
int getType() { return type; }
@@ -82,6 +87,7 @@ namespace extemp {
void* ptr;
std::string label;
int type; // 0 = repl task, 1 = callback task, 2 = destroy env task
+ void* ptr2;
};
class SchemeProcess {
@@ -91,8 +97,11 @@ namespace extemp {
static SchemeProcess* I(int index=0);
static SchemeProcess* I(std::string name);
static SchemeProcess* I(scheme* sc);
+#ifdef EXT_BOOST
+ // static SchemeProcess* I(int);
+#else
static SchemeProcess* I(pthread_t);
-
+#endif
//Thread functions
static void* impromptu_server_thread(void* obj_p);
static void* impromptu_task_executer(void* obj_p);
@@ -128,12 +137,19 @@ namespace extemp {
bool getRunning() { return running; }
//static void printSchemeCons(scheme* sc, std::stringstream& ss, pointer cons, bool full = false, bool stringquotes = true);
static void banner(std::ostream* ss);
- int getServerSocket() { return server_socket; }
+#ifdef EXT_BOOST
+ boost::asio::ip::tcp::acceptor* getServerSocket() { return server_socket; }
+ boost::asio::io_service* getIOService() { return io_service; }
+ std::vector<boost::asio::ip::tcp::socket*>& getClientSockets() { return client_sockets;}
+ std::map<boost::asio::ip::tcp::socket*,std::stringstream*>& getInStreams() { return in_streams; }
+#else
+ int getServerSocket() { return server_socket; }
+#endif
int getServerPort() { return server_port; }
std::queue<SchemeTask>& getQueue() { return taskq; }
llvm_zone_t* getDefaultZone() { return default_zone; }
- std::string getName() { return name; }
+ std::string& getName() { return name; }
void setLoadedLibs(bool v) { libs_loaded = v; }
bool loadedLibs() {return libs_loaded; }
//std::vector<int>* getClientSockets() { return &client_sockets; }
@@ -149,9 +165,6 @@ namespace extemp {
static std::map<scheme*, SchemeProcess*> SCHEME_MAP;
static std::map<std::string, SchemeProcess*> SCHEME_NAME_MAP;
-// llvm::Module* M;
-// llvm::ExistingModuleProvider* MP;
-// llvm::ExecutionEngine* EE;
private:
bool libs_loaded;
@@ -160,21 +173,24 @@ namespace extemp {
scheme* sc;
EXTThread threadScheme;
EXTThread threadServer;
+#ifdef EXT_BOOST
+ EXTThread threadBoost;
+#endif
EXTMonitor guard;
- //CAPThread threadScheme;
- //CAPThread threadServer;
- //CAGuard guard;
bool running;
int server_port;
bool with_banner;
uint64_t max_duration;
+#ifdef EXT_BOOST
+ boost::asio::ip::tcp::acceptor* server_socket;
+ boost::asio::io_service* io_service;
+ std::vector<boost::asio::ip::tcp::socket*> client_sockets;
+ std::map<boost::asio::ip::tcp::socket*,std::stringstream*> in_streams;
+#else
int server_socket;
+#endif
std::queue<SchemeTask> taskq;
- llvm_zone_t* default_zone;
-
- //std::map<int, std::string> result_string;
- //std::vector<int> client_sockets;
- //static vars
+ llvm_zone_t* default_zone;
};
class SchemeObj{
@@ -184,8 +200,6 @@ namespace extemp {
pointer getEnvironment();
pointer getValue();
scheme* getScheme();
- //pointer copyList(scheme* _sc, pointer newlist, pointer val, int* i);
- //int totalItems(pointer list, int res =0);
private:
scheme* sc;
View
9 include/SchemeREPL.h
@@ -33,10 +33,14 @@
*
*/
+#include "UNIV.h"
#include "EXTThread.h"
#include <string>
#include <map>
+#ifdef EXT_BOOST
+#include <boost/asio.hpp>
+#endif
namespace extemp {
class EXTMutex;
@@ -55,7 +59,12 @@ namespace extemp {
private:
static std::map<std::string,SchemeREPL*> REPL_MAP;
static int BUFLENGTH;
+#ifdef EXT_BOOST
+ boost::asio::ip::tcp::socket* server_socket;
+ boost::asio::io_service* server_io_service;
+#else
int server_socket;
+#endif
char* buf;
bool connected;
bool active;
View
5 include/UNIV.h
@@ -41,6 +41,11 @@
#include <string>
+#ifdef TARGET_OS_WINDOWS
+#include <SDKDDKVer.h>
+//void uSleep(int waitTime);
+#endif
+
#if _WIN32 || _WIN64
#if _WIN64
#define TARGET_64BIT
View
6 libs/dsp_library.scm
@@ -726,9 +726,11 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; load highgui dynamic library
-(define libsndfile (if (string=? "Linux" (sys:platform))
+(define libsndfile (if (string=? "Linux" (sys:platform))
(sys:open-dylib "libsndfile.so.1")
- (sys:open-dylib "libsndfile.1.dylib")))
+ (if (string=? "OSX" (sys:platform))
+ (sys:open-dylib "libsndfile.1.dylib")
+ (sys:open-dylib "libsndfile-1.dll"))))
;; bind 3 sndfile lib functions
View
69 libs/horde3d_lib.scm
@@ -6,51 +6,50 @@
(define hordelib (if (string=? "Linux" (sys:platform))
(sys:open-dylib "libHorde3D.so")
- (sys:open-dylib "libHorde3D.dylib")))
+ (if (string=? "Windows" (sys:platform))
+ (sys:open-dylib "Horde3D.dll")
+ (sys:open-dylib "libHorde3D.dylib"))))
(define hordeutlib (if (string=? "Linux" (sys:platform))
(sys:open-dylib "libHorde3DUtils.so")
- (sys:open-dylib "libHorde3DUtils.dylib")))
+ (if (string=? "Windows" (sys:platform))
+ (sys:open-dylib "Horde3DUtils.dll")
+ (sys:open-dylib "libHorde3DUtils.dylib"))))
-(bind-type H3DRes i32)
-(bind-type H3DNode i32)
-(bind-type H3DOption i32)
-(bind-type bool i1)
-
-(bind-lib hordelib h3dInit [bool]*)
+(bind-lib hordelib h3dInit [i1]*)
(bind-lib hordelib h3dRelease [void]*)
-(bind-lib hordelib h3dSetOption [i8,H3DOption,float]*)
-(bind-lib hordelib h3dAddResource [H3DRes,i32,i8*,i32]*)
-(bind-lib hordelib h3dAddCameraNode [H3DNode,H3DNode,i8*,H3DRes]*)
-(bind-lib hordelib h3dAddLightNode [H3DNode,H3DNode,i8*,H3DRes,i8*,i8*]*)
-(bind-lib hordelib h3dAddNodes [H3DNode,H3DNode,H3DRes]*)
-(bind-lib hordelib h3dRemoveNode [void,H3DNode]*)
-(bind-lib hordelib h3dSetNodeTransform [void,H3DNode,float,float,float,float,float,float,float,float,float]*)
-(bind-lib hordelib h3dSetupModelAnimStage [void,H3DNode,i32,H3DRes,i32,i8*,bool]*)
-(bind-lib hordelib h3dFindNodes [i32,H3DNode,i8*,i32]*)
-(bind-lib hordelib h3dFindResource [H3DRes,i32,i8*]*)
-(bind-lib hordelib h3dGetNodeFindResult [H3DNode,i32]*)
-(bind-lib hordelib h3dGetNodeAABB [void,H3DNode,float*,float*,float*,float*,float*,float*]*)
-(bind-lib hordelib h3dSetNodeParamF [void,H3DNode,i32,i32,float]*)
-(bind-lib hordelib h3dSetMaterialUniform [bool,H3DRes,i8*,float,float,float,float]*)
-(bind-lib hordelib h3dSetModelAnimParams [void,H3DNode,i32,float,float]*)
-(bind-lib hordelib h3dAddEmitterNode [H3DNode,H3DNode,i8*,H3DRes,H3DRes,i32,i32]*)
-(bind-lib hordelib h3dAdvanceEmitterTime [void,H3DNode,float]*)
-(bind-lib hordelib h3dGetNodeParamI [i32,H3DNode,i32]*)
-(bind-lib hordelib h3dSetNodeParamI [void,H3DNode,i32,i32]*)
-(bind-lib hordelib h3dRender [void,H3DNode]*)
+(bind-lib hordelib h3dSetOption [i8,i32,float]*)
+(bind-lib hordelib h3dAddResource [i32,i32,i8*,i32]*)
+(bind-lib hordelib h3dAddCameraNode [i32,i32,i8*,i32]*)
+(bind-lib hordelib h3dAddLightNode [i32,i32,i8*,i32,i8*,i8*]*)
+(bind-lib hordelib h3dAddNodes [i32,i32,i32]*)
+(bind-lib hordelib h3dRemoveNode [void,i32]*)
+(bind-lib hordelib h3dSetNodeTransform [void,i32,float,float,float,float,float,float,float,float,float]*)
+(bind-lib hordelib h3dSetupModelAnimStage [void,i32,i32,i32,i32,i8*,i1]*)
+(bind-lib hordelib h3dFindNodes [i32,i32,i8*,i32]*)
+(bind-lib hordelib h3dFindResource [i32,i32,i8*]*)
+(bind-lib hordelib h3dGetNodeFindResult [i32,i32]*)
+(bind-lib hordelib h3dGetNodeAABB [void,i32,float*,float*,float*,float*,float*,float*]*)
+(bind-lib hordelib h3dSetNodeParamF [void,i32,i32,i32,float]*)
+(bind-lib hordelib h3dSetMaterialUniform [i1,i32,i8*,float,float,float,float]*)
+(bind-lib hordelib h3dSetModelAnimParams [void,i32,i32,float,float]*)
+(bind-lib hordelib h3dAddEmitterNode [i32,i32,i8*,i32,i32,i32,i32]*)
+(bind-lib hordelib h3dAdvanceEmitterTime [void,i32,float]*)
+(bind-lib hordelib h3dGetNodeParamI [i32,i32,i32]*)
+(bind-lib hordelib h3dSetNodeParamI [void,i32,i32,i32]*)
+(bind-lib hordelib h3dRender [void,i32]*)
(bind-lib hordelib h3dFinalizeFrame [void]*)
(bind-lib hordelib h3dClearOverlays [void]*)
-(bind-lib hordelib h3dResizePipelineBuffers [void,H3DRes,i32,i32]*)
-(bind-lib hordelib h3dSetupCameraView [void,H3DNode,float,float,float,float]*)
+(bind-lib hordelib h3dResizePipelineBuffers [void,i32,i32,i32]*)
+(bind-lib hordelib h3dSetupCameraView [void,i32,float,float,float,float]*)
(bind-lib hordelib h3dGetMessage [i8*,i32*,float*]*)
-(bind-lib hordelib h3dLoadResource [bool,H3DRes,i8*,i32]*)
-(bind-lib hordelib h3dIsResLoaded [bool,H3DRes]*)
-(bind-lib hordelib h3dUnloadResource [void,H3DRes]*)
+(bind-lib hordelib h3dLoadResource [i1,i32,i8*,i32]*)
+(bind-lib hordelib h3dIsResLoaded [i1,i32]*)
+(bind-lib hordelib h3dUnloadResource [void,i32]*)
-(bind-lib hordeutlib h3dutDumpMessages [bool]*)
-(bind-lib hordeutlib h3dutLoadResourcesFromDisk [bool,i8*]*)
+(bind-lib hordeutlib h3dutDumpMessages [i1]*)
+(bind-lib hordeutlib h3dutLoadResourcesFromDisk [i1,i8*]*)
;; global contants
View
9 runtime/code.ir
@@ -51,12 +51,11 @@ declare i32 @unswap32i(i32);
declare %mzone* @llvm_zone_create(i64) nounwind
declare void @llvm_zone_destroy(%mzone*) nounwind
declare %mzone* @llvm_zone_reset(%mzone*) nounwind
-;declare void @llvm_zone_copy_ptr(i8*, i8*) nounwind
+declare void @llvm_zone_copy_ptr(i8*, i8*) nounwind
declare void @llvm_zone_mark(%mzone*) nounwind
declare i64 @llvm_zone_mark_size(%mzone*) nounwind
declare void @llvm_zone_ptr_set_size(i8*, i64) nounwind
declare i64 @llvm_zone_ptr_size(i8*) nounwind
-declare void @llvm_zone_copy_ptr(i8*, i8*) nounwind
declare i8* @llvm_zone_malloc(%mzone*, i64) nounwind
declare i8* @llvm_stack_alloc(i64) nounwind
declare %clsvar* @get_address_table(i8*, %clsvar*) nounwind
@@ -70,7 +69,7 @@ declare void @llvm_print_i64(i64)
declare void @llvm_print_f32(float)
declare void @llvm_print_f64(double)
declare i8* @llvm_memset(i8*, i32, i64);
-declare i8* @itoa(i64);
+declare i8* @extitoa(i64);
declare i64 @next_prime(i64)
@@ -107,7 +106,7 @@ declare double @exp(double)
declare double @fmod(double,double)
declare double @pow(double,double)
declare double @log(double)
-;declare double @log2(double)
+declare double @log2(double)
declare double @log10(double)
declare double @sqrt(double)
declare double @fabs(double)
@@ -128,7 +127,6 @@ declare float @expf(float)
declare float @fmodf(float,float)
declare float @powf(float,float)
declare float @logf(float)
-;declare float @log2f(float)
declare float @log10f(float)
declare float @sqrtf(float)
declare float @fabsf(float)
@@ -157,7 +155,6 @@ declare i32 @rint(double)
declare i64 @llround(double)
declare i32 @lround(double)
declare double @log1p(double)
-declare double @log2(double)
declare i32 @logb(double)
declare double @nan(i8*)
declare double @nearbyint(double)
View
277 src/AudioDevice.cpp
@@ -38,12 +38,11 @@
#include <string.h>
#include "AudioDevice.h"
-#include "math.h"
#include "TaskScheduler.h"
//#include "EXTMonitor.h"
#include "EXTLLVM.h"
-#ifndef TARGET_OS_LINUX
+#ifdef TARGET_OS_OSX
#include <CoreAudio/HostTime.h>
#include <mach/mach_init.h>
#include <mach/task_policy.h>
@@ -54,9 +53,7 @@
#endif
#include <stdlib.h>
-
-
-
+#include <math.h>
///////////////////////////////////////////////////////////////////////
//
@@ -74,7 +71,8 @@
//
///////////////////////////////////////////////////////////////////////
-
+#ifdef EXT_BOOST
+#else
#ifdef TARGET_OS_LINUX
double time_to_double(struct timespec t) {
return t.tv_sec + t.tv_nsec/D_BILLION;
@@ -98,16 +96,21 @@ double getRealTime()
clock_gettime(CLOCK_REALTIME,&t);
return time_to_double(t);
}
-#endif
+#endif //TARGET_OS_LINUX
+#endif //EXT_BOOST
+#ifdef TARGET_OS_WINDOWS
+#define isnan(x) ((x) != (x))
+#define isinf(x) (isnan(x-x))
+#endif
SAMPLE audio_sanity(SAMPLE x)
{
- if(isinf(x)) return 0.0f;
- else if(isnan(x)) return 0.0f;
- else if(x < -0.99f) return -0.99f;
- else if(x > 0.99f) return 0.99f;
- else return x;
+ if(isinf(x)) return 0.0f;
+ else if(isnan(x)) return 0.0f;
+ else if(x < -0.99f) return -0.99f;
+ else if(x > 0.99f) return 0.99f;
+ else return x;
}
namespace extemp {
@@ -155,7 +158,6 @@ namespace extemp {
void audioCallback(snd_async_handler_t *pcm_callback)
{
- printf("HI\n");
snd_pcm_t* handle = snd_async_handler_get_pcm(pcm_callback);
AudioDevice* private_data = (AudioDevice*) snd_async_handler_get_callback_private(pcm_callback);
SAMPLE* outputBuffer = private_data->getBuffer();
@@ -498,130 +500,7 @@ namespace extemp {
started = false;
}
-#elif defined(TARGET_OS_LINUX)
- //-----------------------------------
- // PORT AUDIO
- //-----------------------------------
- int audioCallback(const void* inputBuffer, void* outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
- {
- TaskScheduler* sched = static_cast<TaskScheduler*>(userData);
- //sched->getGuard()->signal();
- UNIV::DEVICE_TIME = UNIV::DEVICE_TIME + UNIV::FRAMES;
- UNIV::TIME = UNIV::DEVICE_TIME;
-
- if(AudioDevice::CLOCKBASE < 1.0) AudioDevice::CLOCKBASE = getRealTime();
- AudioDevice::REALTIME = getRealTime();
-
- //device_time = UNIV::DEVICE_TIME;
- //if(UNIV::DEVIDE_TIME != device_time) std::cout << "Timeing Sychronization problem!!! UNIV::TIME[" << UNIV::TIME << "] DEVICE_TIME[ " << device_time << "]" << std::endl;
- int channels = 2;
- uint64_t numOfSamples = (uint64_t) (framesPerBuffer * channels);
- sched->getGuard()->signal();
-
- void* dsp_closure = AudioDevice::I()->getDSPClosure();
- void* cache_closure = 0;
- if(dsp_closure == 0) { memset(outputBuffer,0,(UNIV::CHANNELS*UNIV::FRAMES*sizeof(SAMPLE))); return 0; }
- cache_closure = ((void*(*)()) dsp_closure)(); // get actual LLVM closure from _getter() !
-
- if(AudioDevice::I()->getDSPWrapper()) { // if true then we must be sample by sample
- dsp_f_ptr dsp_wrapper = AudioDevice::I()->getDSPWrapper();
- dsp_f_ptr cache_wrapper = dsp_wrapper;
- double (*closure) (double,double,double,double*) = * ((double(**)(double,double,double,double*)) cache_closure);
- double* data = 0;
- llvm_zone_t* zone = llvm_zone_create(1024*1024); // 1M
- for(uint32_t i=0;i<UNIV::FRAMES;i++)
- {
- uint32_t ii = i*UNIV::CHANNELS;
- SAMPLE* dat = (SAMPLE*) outputBuffer;
- SAMPLE* in = (SAMPLE*) inputBuffer;
- for(uint32_t k=0; k<UNIV::CHANNELS; k++)
- {
- dat[ii+k] = audio_sanity((SAMPLE)cache_wrapper(zone, (void*)closure, /*(double)in[ii+k]*/0.0,(double)(i+UNIV::DEVICE_TIME),(double)k,data));
- llvm_zone_reset(zone);
- }
- }
- llvm_zone_destroy(zone);
- }else if(AudioDevice::I()->getDSPWrapperArray()) { // if true then we must be buffer by buffer
- dsp_f_ptr_array dsp_wrapper = AudioDevice::I()->getDSPWrapperArray();
- dsp_f_ptr_array cache_wrapper = dsp_wrapper;
- llvm_zone_t* zone = llvm_zone_create(1024*50);
- cache_wrapper(zone, cache_closure, (SAMPLE*)inputBuffer,(SAMPLE*)outputBuffer,UNIV::FRAMES,UNIV::DEVICE_TIME,UNIV::CHANNELS);
- llvm_zone_destroy(zone);
- }else{
- //zero out audiobuffer
- memset(outputBuffer,0,(UNIV::CHANNELS*UNIV::FRAMES*sizeof(SAMPLE)));
- //nothin to do
- }
- return 0;
- }
-
- AudioDevice::AudioDevice() : started(false), buffer(0), dsp_closure(0), dsp_wrapper(0), dsp_wrapper_array(0)
- {
- Pa_Initialize();
- //std::cout << "Initializing AudioDevice: " << std::endl;
- PaError err;
- int inputDevice = Pa_GetDefaultInputDevice();
- int outputDevice = Pa_GetDefaultOutputDevice();
-
- std::cout << "Input Device: " << inputDevice << std::endl;
- std::cout << "Output Device: " << outputDevice << std::endl;
- err = Pa_OpenDefaultStream(&stream, 0, 2, paFloat32, 44100.0, UNIV::FRAMES, audioCallback, (void*)TaskScheduler::I());
- if(err != paNoError) {
- std::cerr << "PA Error: " << Pa_GetErrorText(err) << std::endl;
- }
- UNIV::CHANNELS = 2;
- UNIV::SAMPLERATE = 44100;
- ascii_text_color(1,7,10);
- std::cout << "---PortAudio---" << std::endl;
- std::cout << "Loaded Default Audio Device: " << std::endl;
- ascii_text_color(0,7,10);
- std::cout << "SampleRate\t: " << std::flush;
- ascii_text_color(1,6,10);
- std::cout << UNIV::SAMPLERATE << std::endl << std::flush;
- ascii_text_color(0,7,10);
- std::cout << "Channels\t: " << std::flush;
- ascii_text_color(1,6,10);
- std::cout << UNIV::CHANNELS << std::endl << std::flush;
- ascii_text_color(0,7,10);
- std::cout << "Frames\t\t: " << std::flush;
- ascii_text_color(1,6,10);
- std::cout << UNIV::FRAMES << std::endl << std::flush;
- ascii_text_color(0,7,10);
- }
-
- AudioDevice::~AudioDevice()
- {
- PaError err;
- err = Pa_StopStream(stream);
- if(err != paNoError) std::cout << Pa_GetErrorText(err) << std::endl;
- err = Pa_CloseStream(stream);
- if(err != paNoError) std::cout << Pa_GetErrorText(err) << std::endl;
- err = Pa_Terminate();
- if(err != paNoError) std::cout << Pa_GetErrorText(err) << std::endl;
- }
-
- void AudioDevice::start()
- {
- if(started) return;
- UNIV::initRand();
- PaError err;
- err = Pa_StartStream(stream);
- ascii_text_color(1,1,10);
- if(err != paNoError) { std::cout << "PortAudio ERROR: " << Pa_GetErrorText(err) << std::endl; }
- ascii_text_color(0,9,10);
- RUNNING = true;
- //queueThread->Start();
- started = true;
- }
-
- void AudioDevice::stop()
- {
- if(!started) return;
- PaError err = Pa_StopStream(stream);
- if(err != paNoError) std::cout << "PA Error: " << Pa_GetErrorText(err) << std::endl;
- started = false;
- }
-#else
+#elif defined (TARGET_OS_MAC)
//-----------------------------------
@@ -809,7 +688,131 @@ namespace extemp {
if (err != kAudioHardwareNoError) { std::cerr << "CoreAudio ERROR: removing IOProc" << std::endl; }
started = false;
}
+#else
+ //-----------------------------------
+ // PORT AUDIO
+ //-----------------------------------
+ int audioCallback(const void* inputBuffer, void* outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
+ {
+ TaskScheduler* sched = static_cast<TaskScheduler*>(userData);
+ //sched->getGuard()->signal();
+ UNIV::DEVICE_TIME = UNIV::DEVICE_TIME + UNIV::FRAMES;
+ UNIV::TIME = UNIV::DEVICE_TIME;
+/*
+ if(AudioDevice::CLOCKBASE < 1.0) AudioDevice::CLOCKBASE = getRealTime();
+ AudioDevice::REALTIME = getRealTime();
+*/
+ //device_time = UNIV::DEVICE_TIME;
+ //if(UNIV::DEVIDE_TIME != device_time) std::cout << "Timeing Sychronization problem!!! UNIV::TIME[" << UNIV::TIME << "] DEVICE_TIME[ " << device_time << "]" << std::endl;
+ int channels = 2;
+ uint64_t numOfSamples = (uint64_t) (framesPerBuffer * channels);
+ sched->getGuard()->signal();
+
+ void* dsp_closure = AudioDevice::I()->getDSPClosure();
+ void* cache_closure = 0;
+ if(dsp_closure == 0) { memset(outputBuffer,0,(UNIV::CHANNELS*UNIV::FRAMES*sizeof(SAMPLE))); return 0; }
+ cache_closure = ((void*(*)()) dsp_closure)(); // get actual LLVM closure from _getter() !
+
+ if(AudioDevice::I()->getDSPWrapper()) { // if true then we must be sample by sample
+ dsp_f_ptr dsp_wrapper = AudioDevice::I()->getDSPWrapper();
+ dsp_f_ptr cache_wrapper = dsp_wrapper;
+ double (*closure) (double,double,double,double*) = * ((double(**)(double,double,double,double*)) cache_closure);
+ double* data = 0;
+ llvm_zone_t* zone = llvm_zone_create(1024*1024); // 1M
+ for(uint32_t i=0;i<UNIV::FRAMES;i++)
+ {
+ uint32_t ii = i*UNIV::CHANNELS;
+ SAMPLE* dat = (SAMPLE*) outputBuffer;
+ SAMPLE* in = (SAMPLE*) inputBuffer;
+ for(uint32_t k=0; k<UNIV::CHANNELS; k++)
+ {
+ dat[ii+k] = audio_sanity((SAMPLE)cache_wrapper(zone, (void*)closure, /*(double)in[ii+k]*/0.0,(double)(i+UNIV::DEVICE_TIME),(double)k,data));
+ llvm_zone_reset(zone);
+ }
+ }
+ llvm_zone_destroy(zone);
+ }else if(AudioDevice::I()->getDSPWrapperArray()) { // if true then we must be buffer by buffer
+ dsp_f_ptr_array dsp_wrapper = AudioDevice::I()->getDSPWrapperArray();
+ dsp_f_ptr_array cache_wrapper = dsp_wrapper;
+ llvm_zone_t* zone = llvm_zone_create(1024*50);
+ cache_wrapper(zone, cache_closure, (SAMPLE*)inputBuffer,(SAMPLE*)outputBuffer,UNIV::FRAMES,UNIV::DEVICE_TIME,UNIV::CHANNELS);
+ llvm_zone_destroy(zone);
+ }else{
+ //zero out audiobuffer
+ memset(outputBuffer,0,(UNIV::CHANNELS*UNIV::FRAMES*sizeof(SAMPLE)));
+ //nothin to do
+ }
+ return 0;
+ }
+ AudioDevice::AudioDevice() : started(false), buffer(0), dsp_closure(0), dsp_wrapper(0), dsp_wrapper_array(0)
+ {
+ Pa_Initialize();
+ //std::cout << "Initializing AudioDevice: " << std::endl;
+ PaError err;
+ int inputDevice = Pa_GetDefaultInputDevice();
+ int outputDevice = Pa_GetDefaultOutputDevice();
+
+ std::cout << "Input Device: " << inputDevice << std::endl;
+ std::cout << "Output Device: " << outputDevice << std::endl;
+ err = Pa_OpenDefaultStream(&stream, 0, 2, paFloat32, 44100.0, UNIV::FRAMES, audioCallback, (void*)TaskScheduler::I());
+ if(err != paNoError) {
+ std::cerr << "PA Error: " << Pa_GetErrorText(err) << std::endl;
+ }
+ UNIV::CHANNELS = 2;
+ UNIV::SAMPLERATE = 44100;
+ ascii_text_color(1,7,10);
+ std::cout << "---PortAudio---" << std::endl;
+ std::cout << "Loaded Default Audio Device: " << std::endl;
+ ascii_text_color(0,7,10);
+ std::cout << "SampleRate\t: " << std::flush;
+ ascii_text_color(1,6,10);
+ std::cout << UNIV::SAMPLERATE << std::endl << std::flush;
+ ascii_text_color(0,7,10);
+ std::cout << "Channels\t: " << std::flush;
+ ascii_text_color(1,6,10);
+ std::cout << UNIV::CHANNELS << std::endl << std::flush;
+ ascii_text_color(0,7,10);
+ std::cout << "Frames\t\t: " << std::flush;
+ ascii_text_color(1,6,10);
+ std::cout << UNIV::FRAMES << std::endl << std::flush;
+ ascii_text_color(0,7,10);
+ std::cout << std::endl << std::flush;
+ //ascii_text_color(0,7,10);
+ }
+
+ AudioDevice::~AudioDevice()
+ {
+ PaError err;
+ err = Pa_StopStream(stream);
+ if(err != paNoError) std::cout << Pa_GetErrorText(err) << std::endl;
+ err = Pa_CloseStream(stream);
+ if(err != paNoError) std::cout << Pa_GetErrorText(err) << std::endl;
+ err = Pa_Terminate();
+ if(err != paNoError) std::cout << Pa_GetErrorText(err) << std::endl;
+ }
+
+ void AudioDevice::start()
+ {
+ if(started) return;
+ UNIV::initRand();
+ PaError err;
+ err = Pa_StartStream(stream);
+ ascii_text_color(1,1,10);
+ if(err != paNoError) { std::cout << "PortAudio ERROR: " << Pa_GetErrorText(err) << std::endl; }
+ ascii_text_color(0,9,10);
+ RUNNING = true;
+ //queueThread->Start();
+ started = true;
+ }
+
+ void AudioDevice::stop()
+ {
+ if(!started) return;
+ PaError err = Pa_StopStream(stream);
+ if(err != paNoError) std::cout << "PA Error: " << Pa_GetErrorText(err) << std::endl;
+ started = false;
+ }
#endif
View
30 src/EXTCondition.cpp
@@ -35,7 +35,10 @@
#include <iostream>
+#ifdef EXT_BOOST
+#else
#include "pthread.h"
+#endif
#include "EXTCondition.h"
#include "EXTMutex.h"
@@ -59,9 +62,15 @@ namespace extemp
int EXTCondition::init()
- {
+ {
+#ifdef EXT_BOOST
+ //boost_cond = boost::condition_variable;
+ int result = 0;
+#else
int result = pthread_cond_init(&pthread_cond, NULL);
+#endif
initialised = ! result;
+
#ifdef _EXTCONDITION_DEBUG_
if (result)
@@ -81,7 +90,11 @@ namespace extemp
if (initialised)
{
initialised = false;
+#ifdef EXT_BOOST
+ result = 0;
+#else
result = pthread_cond_destroy(&pthread_cond);
+#endif
}
#ifdef _EXTCONDITION_DEBUG_
@@ -95,7 +108,15 @@ namespace extemp
int EXTCondition::wait(EXTMutex *aimeMutex)
{
+
+#ifdef EXT_BOOST
+ boost::recursive_mutex::scoped_lock lock(aimeMutex->bmutex);
+ boost_cond.wait(lock); //aimeMutex->block); // bmutex.scoped_lock); //lock);
+ int result = 0;
+#else
int result = pthread_cond_wait(&pthread_cond, &aimeMutex->pthread_mutex);
+#endif
+
#ifdef _EXTCONDITION_DEBUG_
if (result)
@@ -108,9 +129,14 @@ namespace extemp
}
- int EXTCondition::signal()
+ int EXTCondition::signal(EXTMutex* aimeMutex)
{
+#ifdef EXT_BOOST
+ boost_cond.notify_one();
+ int result = 0;
+#else
int result = pthread_cond_signal(&pthread_cond);
+#endif
#ifdef _EXTCONDITION_DEBUG_
if (result)
View
52 src/EXTLLVM.cpp
@@ -42,6 +42,11 @@
#include "pcre.h"
#include "OSC.h"
+#ifdef TARGET_OS_WINDOWS
+#include <malloc.h>
+#endif
+
+
#include "llvm/Assembly/Parser.h"
#include "llvm/LLVMContext.h"
#include "llvm/CallingConv.h"
@@ -49,8 +54,11 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
-
+#ifdef EXT_LLVM_3
+#include "llvm/Support/TargetSelect.h"
+#else
#include "llvm/Target/TargetSelect.h"
+#endif
//#include "llvm/ModuleProvider.h"
@@ -76,8 +84,16 @@
// make it thread safe but I'm not going to bother
// while still testing.
std::map<void*,uint64_t> LLVM_ZONE_ALLOC_MAP;
+// same as above.
+std::map<std::string,std::string> LLVM_STR_CONST_MAP;
extemp::EXTMutex alloc_mutex("alloc mutex");
+#ifdef TARGET_OS_WINDOWS
+double log2(double num) {
+ return log(num)/log(2.0);
+}
+#endif
+
llvm_zone_t* llvm_zone_create(uint64_t size)
{
llvm_zone_t* zone = (llvm_zone_t*) malloc(sizeof(llvm_zone_t));
@@ -105,7 +121,11 @@ void llvm_zone_destroy(llvm_zone_t* zone)
void* llvm_stack_alloc(int64_t size)
{
- alloca(size);
+#ifdef TARGET_OS_WINDOWS
+ return _alloca(size);
+#else
+ return alloca(size);
+#endif
}
void* llvm_zone_malloc(llvm_zone_t* zone, uint64_t size)
@@ -189,20 +209,28 @@ void llvm_destroy_zone_after_delay(llvm_zone_t* zone, double delay)
extemp::TaskScheduler::I()->add(task);
}
-char* itoa(int64_t val) {
+char* extitoa(int64_t val) {
+ /*
int base = 10;
static char buf[32] = {0};
int i = 30;
for(; val && i ; --i, val /= base)
- buf[i] = "0123456789abcdef"[val % base];
- return &buf[i+1];
+ buf[i] = "0123456789abcdef"[val % base];
+ */
+ static char buf[32] = {0};
+ sprintf(buf,"%lld",val);
+ return buf;//&buf[i+1];
}
int llvm_printf(char* format, ...)
{
va_list ap;
va_start(ap,format);
+#ifdef TARGET_OS_WINDOWS
+ char* ret = (char*) _alloca(2048);
+#else
char* ret = (char*) alloca(2048);
+#endif
int returnval = vsprintf(ret, format, ap);
printf("%s",ret);
fflush(stdout);
@@ -636,7 +664,11 @@ namespace extemp {
fseek(fp,0,SEEK_END);
int size = ftell(fp);
fseek(fp,0,SEEK_SET);
+#ifdef TARGET_OS_WINDOWS
+ char* assm = (char*) _alloca(size+1);
+#else
char* assm = (char*) alloca(size+1);
+#endif
int res = fread(assm, 1, size, fp);
assm[size]=0;
fclose(fp);
@@ -707,8 +739,8 @@ namespace extemp {
EE->updateGlobalMapping(gv,(void*)&llvm_zone_ptr_size);
gv = M->getNamedValue(std::string("llvm_memset"));
EE->updateGlobalMapping(gv,(void*)&llvm_memset);
- gv = M->getNamedValue(std::string("itoa"));
- EE->updateGlobalMapping(gv,(void*)&itoa);
+ gv = M->getNamedValue(std::string("extitoa"));
+ EE->updateGlobalMapping(gv,(void*)&extitoa);
gv = M->getNamedValue(std::string("swap64i"));
EE->updateGlobalMapping(gv,(void*)&swap64i);
@@ -725,7 +757,11 @@ namespace extemp {
gv = M->getNamedValue(std::string("unswap32i"));
EE->updateGlobalMapping(gv,(void*)&unswap32i);
gv = M->getNamedValue(std::string("unswap32f"));
- EE->updateGlobalMapping(gv,(void*)&unswap32f);
+ EE->updateGlobalMapping(gv,(void*)&unswap32f);
+#ifdef TARGET_OS_WINDOWS
+ gv = M->getNamedValue(std::string("log2"));
+ EE->updateGlobalMapping(gv,(void*)&log2);
+#endif
}
return;
}
View
4 src/EXTMonitor.cpp
@@ -35,8 +35,6 @@
#include <iostream>
-#include "pthread.h"
-
#include "EXTMonitor.h"
@@ -105,7 +103,7 @@ namespace extemp
int EXTMonitor::signal()
{
- int result = condition.signal();
+ int result = condition.signal(&mutex);
return result;
}
View
48 src/EXTMutex.cpp
@@ -36,6 +36,7 @@
#include <iostream>
#include <stdlib.h>
#include "EXTMutex.h"
+#include <cstring>
#define _EXTMUTEX_DEBUG_
@@ -45,8 +46,7 @@ namespace extemp
{
EXTMutex::EXTMutex(std::string _name) :
initialised(false),
- name(_name),
- owner(0)
+ name(_name)
{
}
@@ -58,6 +58,10 @@ namespace extemp
int EXTMutex::init()
{
+
+#ifdef EXT_BOOST // START BOOST
+ int result = 0;
+#else // START POSIX
pthread_mutexattr_t pthread_mutex_attr;
pthread_mutexattr_init(&pthread_mutex_attr);
@@ -71,6 +75,8 @@ namespace extemp
pthread_mutexattr_settype(&pthread_mutex_attr, PTHREAD_MUTEX_RECURSIVE);
#endif
int result = pthread_mutex_init(&pthread_mutex, &pthread_mutex_attr);
+#endif // END POSIX
+
initialised = ! result;
#ifdef _EXTMUTEX_DEBUG_
@@ -78,8 +84,7 @@ namespace extemp
{
std::cerr << "Error initialising mutex: " << name << " err: " << result << std::endl;
}
-#endif
-
+#endif
return result;
}
@@ -91,7 +96,11 @@ namespace extemp
if (initialised)
{
initialised = false;
+#ifdef EXT_BOOST
+ result = 0;
+#else
result = pthread_mutex_destroy(&pthread_mutex);
+#endif
}
#ifdef _EXTMUTEX_DEBUG_
@@ -105,11 +114,38 @@ namespace extemp
bool EXTMutex::isOwnedByCurrentThread()
{
+#ifdef EXT_BOOST
+ return false;
+#else
return pthread_equal(pthread_self(), owner);
- }
+#endif
+ }
-#if EXT_MUTEX_RECURSIVE
+#ifdef EXT_BOOST
+ int EXTMutex::lock()
+ {
+ try{
+ bmutex.lock();
+ return true;
+ }catch(std::exception& e){
+ std::cout << "Problem locking mutex: " << name << " " << e.what() << std::endl;
+ return false;
+ }
+ }
+
+ int EXTMutex::unlock()
+ {
+
+ try{
+ bmutex.unlock();
+ return 0;
+ }catch(std::exception& e){
+ std::cout << "Problem unlocking mutex: " << name << " " << e.what() << std::endl;
+ return 0;
+ }
+ }
+#elif EXT_MUTEX_RECURSIVE
int EXTMutex::unlock()
{
int result = pthread_mutex_unlock(&pthread_mutex);
View
43 src/EXTThread.cpp
@@ -35,21 +35,15 @@
#include <iostream>
-#include "pthread.h"
-
#include "EXTThread.h"
-
#define _EXTTHREAD_DEBUG_
namespace extemp
{
EXTThread::EXTThread() : initialised(false), detached(false), joined(false)
- {
-// initialised = false;
-// detached = false;
-// joined = false;
+ {
}
EXTThread::~EXTThread()
@@ -68,7 +62,12 @@ namespace extemp
if (! initialised)
{
+#ifdef EXT_BOOST
+ bthread = boost::thread(start_routine, arg);
+ result = 0;
+#else
result = pthread_create(&pthread, NULL, start_routine, arg);
+#endif
initialised = ! result;
}
@@ -89,7 +88,12 @@ namespace extemp
if (initialised)
{
+#ifdef EXT_BOOST
+ bthread.detach();
+ result = 0;
+#else
result = pthread_detach(pthread);
+#endif
detached = ! result;
}
@@ -109,7 +113,12 @@ namespace extemp
if (initialised)
{
+#ifdef EXT_BOOST
+ bthread.join();
+ result = 0;
+#else
result = pthread_join(pthread, NULL);
+#endif
joined = ! result;
}
@@ -131,7 +140,12 @@ namespace extemp
if(initialised)
{
+#ifdef EXT_BOOST
+ bthread.interrupt();
+ result = 0;
+#else
result = pthread_cancel(pthread);
+#endif
cancelled = ! result;
}
@@ -147,16 +161,31 @@ namespace extemp
bool EXTThread::isRunning()
{
+#ifdef EXT_BOOST
+ return initialised;
+#else
return 0 != pthread;
+#endif
}
bool EXTThread::isCurrentThread()
{
+#ifdef EXT_BOOST
+ return (bthread.get_id() == boost::this_thread::get_id());
+#else
return pthread_equal(pthread_self(), pthread);
+#endif
}
+#ifdef EXT_BOOST
+ boost::thread& EXTThread::getBthread()
+ {
+ return bthread;
+ }
+#else
pthread_t EXTThread::getPthread()
{
return pthread;
}
+#endif
}
View
8 src/Extempore.cpp
@@ -92,9 +92,11 @@ int main(int argv, char** args)
// sleep indefiniately let server process do the work
while(1) {
- // put printf here as a reminder that something is happending
- //printf("PING: %lld\n",extemp::UNIV::TIME);
- sleep(5000);
+#ifdef TARGET_OS_WINDOWS
+ Sleep(5000);
+#else
+ sleep(5000);
+#endif
}
return 0;
}
View
1,507 src/OSC.cpp
@@ -1,52 +1,60 @@
/*
- * Copyright (c) 2011, Andrew Sorensen
- *
- * All rights reserved.
- *
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the authors nor other contributors may be used to endorse
- * or promote products derived from this software without specific prior written
- * permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLEXTD. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- */
+* Copyright (c) 2011, Andrew Sorensen
+*
+* All rights reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* Neither the name of the authors nor other contributors may be used to endorse
+* or promote products derived from this software without specific prior written
+* permission.
+*
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLEXTD. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*
+*/
#include "OSC.h"
-#include <sys/fcntl.h>
-#include <arpa/inet.h>
#include <string>
#include <iomanip>
#include <sstream>
#include <math.h>
#include <stdlib.h>
+
+#ifdef EXT_BOOST
+// header boost/asio.h from OSC.h
+#else
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h> /* host to IP resolution */
+#include <sys/fcntl.h>
+#include <arpa/inet.h>
+#endif
+
+
+
///////////////////////////////////////////////
//
@@ -56,141 +64,141 @@
//
uint64_t swap64f(double d)
{
- uint64_t a;
- unsigned char *dst = (unsigned char *)&a;
- unsigned char *src = (unsigned char *)&d;
-
- dst[0] = src[7];
- dst[1] = src[6];
- dst[2] = src[5];
- dst[3] = src[4];
- dst[4] = src[3];
- dst[5] = src[2];
- dst[6] = src[1];
- dst[7] = src[0];
-
- return a;
+ uint64_t a;
+ unsigned char *dst = (unsigned char *)&a;
+ unsigned char *src = (unsigned char *)&d;
+
+ dst[0] = src[7];
+ dst[1] = src[6];
+ dst[2] = src[5];
+ dst[3] = src[4];
+ dst[4] = src[3];
+ dst[5] = src[2];
+ dst[6] = src[1];
+ dst[7] = src[0];
+
+ return a;
}
// unswap using char pointers
double unswap64f(uint64_t a)
{
- double d;
- unsigned char *src = (unsigned char *)&a;
- unsigned char *dst = (unsigned char *)&d;
+ double d;
+ unsigned char *src = (unsigned char *)&a;
+ unsigned char *dst = (unsigned char *)&d;
- dst[0] = src[7];
- dst[1] = src[6];
- dst[2] = src[5];
- dst[3] = src[4];
- dst[4] = src[3];
- dst[5] = src[2];
- dst[6] = src[1];
- dst[7] = src[0];
+ dst[0] = src[7];
+ dst[1] = src[6];
+ dst[2] = src[5];
+ dst[3] = src[4];
+ dst[4] = src[3];
+ dst[5] = src[2];
+ dst[6] = src[1];
+ dst[7] = src[0];
- return d;
+ return d;
}
// swap using char pointers
uint32_t swap32f(float f)
{
- uint32_t a;
- unsigned char *dst = (unsigned char *)&a;
- unsigned char *src = (unsigned char *)&f;
+ uint32_t a;
+ unsigned char *dst = (unsigned char *)&a;
+ unsigned char *src = (unsigned char *)&f;
- dst[0] = src[3];
- dst[1] = src[2];
- dst[2] = src[1];
- dst[3] = src[0];
+ dst[0] = src[3];
+ dst[1] = src[2];
+ dst[2] = src[1];
+ dst[3] = src[0];
- return a;
+ return a;
}
// unswap using char pointers
float unswap32f(uint32_t a)
{
- float f;
- unsigned char *src = (unsigned char *)&a;
- unsigned char *dst = (unsigned char *)&f;
+ float f;
+ unsigned char *src = (unsigned char *)&a;
+ unsigned char *dst = (unsigned char *)&f;
- dst[0] = src[3];
- dst[1] = src[2];
- dst[2] = src[1];
- dst[3] = src[0];
+ dst[0] = src[3];
+ dst[1] = src[2];
+ dst[2] = src[1];
+ dst[3] = src[0];
- return f;
+ return f;
}
// swap using char pointers
uint64_t swap64i(uint64_t d)
{
- uint64_t a;
- unsigned char *dst = (unsigned char *)&a;
- unsigned char *src = (unsigned char *)&d;
-
- dst[0] = src[7];
- dst[1] = src[6];
- dst[2] = src[5];
- dst[3] = src[4];
- dst[4] = src[3];
- dst[5] = src[2];
- dst[6] = src[1];
- dst[7] = src[0];
-
- return a;
+ uint64_t a;
+ unsigned char *dst = (unsigned char *)&a;
+ unsigned char *src = (unsigned char *)&d;
+
+ dst[0] = src[7];
+ dst[1] = src[6];
+ dst[2] = src[5];
+ dst[3] = src[4];
+ dst[4] = src[3];
+ dst[5] = src[2];
+ dst[6] = src[1];
+ dst[7] = src[0];
+
+ return a;
}
// unswap using char pointers
uint64_t unswap64i(uint64_t a)
{
- uint64_t d;
- unsigned char *src = (unsigned char *)&a;
- unsigned char *dst = (unsigned char *)&d;
+ uint64_t d;
+ unsigned char *src = (unsigned char *)&a;
+ unsigned char *dst = (unsigned char *)&d;
- dst[0] = src[7];
- dst[1] = src[6];
- dst[2] = src[5];
- dst[3] = src[4];
- dst[4] = src[3];
- dst[5] = src[2];
- dst[6] = src[1];
- dst[7] = src[0];
+ dst[0] = src[7];
+ dst[1] = src[6];
+ dst[2] = src[5];
+ dst[3] = src[4];
+ dst[4] = src[3];
+ dst[5] = src[2];
+ dst[6] = src[1];
+ dst[7] = src[0];
- return d;
+ return d;
}
// swap using char pointers
uint32_t swap32i(uint32_t f)
{
- uint32_t a;
- unsigned char *dst = (unsigned char *)&a;
- unsigned char *src = (unsigned char *)&f;
+ uint32_t a;
+ unsigned char *dst = (unsigned char *)&a;
+ unsigned char *src = (unsigned char *)&f;
- dst[0] = src[3];
- dst[1] = src[2];
- dst[2] = src[1];
- dst[3] = src[0];
+ dst[0] = src[3];
+ dst[1] = src[2];
+ dst[2] = src[1];
+ dst[3] = src[0];
- return a;