aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2009-11-17 00:42:31 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2009-11-17 00:42:31 +0000
commit1d3d6852a34779dd726b81b867fe9c928f4731e1 (patch)
tree13448530a9c67b38fc8197a0b3a90b688f981d5a
first successful test, but its outputting secondssvn2git-root
svn path=/trunk/externals/soundfile/; revision=12784
-rw-r--r--Makefile171
-rw-r--r--sfsamples-help.pd6
-rw-r--r--sfsamples.c81
3 files changed, 258 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..f0d7dd7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,171 @@
+# To use this Makefile for your project, first put the name of your library in
+# LIBRARY_NAME variable. The folder for your project should have the same name
+# as your library.
+LIBRARY_NAME = soundfile
+
+# Next, add your source files to the SOURCES variable.
+SOURCES = sfsamples.c
+
+# For objects that only build on certain platforms, add those to the SOURCES
+# line for the right platforms.
+SOURCES_Darwin =
+SOURCES_Linux =
+SOURCES_Windows =
+
+#------------------------------------------------------------------------------#
+#
+# you shouldn't need to edit anything below here, if we did it right :)
+#
+#------------------------------------------------------------------------------#
+
+# where Pd lives
+PD_PATH = ../../pd
+# where to install the library
+objectsdir = $(PD_PATH)/extra
+
+CFLAGS = -DPD -I$(PD_PATH)/src -Wall -W -g
+LDFLAGS =
+LIBS =
+
+UNAME := $(shell uname -s)
+ifeq ($(UNAME),Darwin)
+ CPU := $(shell uname -p)
+ ifeq ($(CPU),arm) # iPhone/iPod Touch
+ SOURCES += $(SOURCES_Darwin)
+ EXTENSION = pd_darwin
+ OS = iphoneos
+ IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
+ CC=$(IPHONE_BASE)/gcc
+ CPP=$(IPHONE_BASE)/cpp
+ CXX=$(IPHONE_BASE)/g++
+ ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk
+ IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6
+ OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer
+ CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS)
+ LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT)
+ LIBS += -lc
+ STRIP = strip -x
+ else # Mac OS X
+ SOURCES += $(SOURCES_Darwin)
+ EXTENSION = pd_darwin
+ OS = macosx
+ OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast
+ FAT_FLAGS = -arch i386 -arch ppc -mmacosx-version-min=10.4
+ CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include
+ LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib
+ LIBS += -lc
+ STRIP = strip -x
+ endif
+endif
+ifeq ($(UNAME),Linux)
+ SOURCES += $(SOURCES_Linux)
+ EXTENSION = pd_linux
+ OS = linux
+ OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+ CFLAGS += -fPIC
+ LDFLAGS += -Wl,--export-dynamic -shared -fPIC
+ LIBS += -lc
+ STRIP = strip --strip-unneeded -R .note -R .comment
+endif
+ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME)))
+ SOURCES +=
+ EXTENSION = dll
+ OS = cygwin
+ OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+ CFLAGS +=
+ LDFLAGS += -Wl,--export-dynamic -shared -L$(PD_PATH)/src
+ LIBS += -lc -lpd
+ STRIP = strip --strip-unneeded -R .note -R .comment
+endif
+ifeq (MINGW,$(findstring MINGW,$(UNAME)))
+ SOURCES += $(SOURCES_Windows)
+ EXTENSION = dll
+ OS = windows
+ OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer -march=i686 -mtune=pentium4
+ WINDOWS_HACKS = -D'O_NONBLOCK=1'
+ CFLAGS += -mms-bitfields $(WINDOWS_HACKS)
+ LDFLAGS += -s -shared -Wl,--enable-auto-import
+ LIBS += -L$(PD_PATH)/src -L$(PD_PATH)/bin -L$(PD_PATH)/obj -lpd -lwsock32 -lkernel32 -luser32 -lgdi32
+ STRIP = strip --strip-unneeded -R .note -R .comment
+endif
+
+CFLAGS += $(OPT_CFLAGS)
+
+
+.PHONY = install libdir_install single_install install-doc install-exec clean dist etags
+
+all: $(SOURCES:.c=.$(EXTENSION))
+
+%.o: %.c
+ $(CC) $(CFLAGS) -o "$*.o" -c "$*.c"
+
+%.$(EXTENSION): %.o
+ $(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(LIBS)
+ chmod a-x "$*.$(EXTENSION)"
+
+# this links everything into a single binary file
+$(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o
+ $(CC) $(LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(LIBS)
+ chmod a-x $(LIBRARY_NAME).$(EXTENSION)
+
+
+install: libdir_install
+
+# The meta and help files are explicitly installed to make sure they are
+# actually there. Those files are not optional, then need to be there.
+libdir_install: $(SOURCES:.c=.$(EXTENSION)) install-doc install-exec
+ install -d $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ install -m644 -p $(LIBRARY_NAME)-meta.pd $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ install -m644 -p $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION)))
+
+# install library linked as single binary
+single_install: $(LIBRARY_NAME) install-doc install-exec
+ install -d $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ install -m644 -p $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION)
+
+install-doc:
+ install -d $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+# install -m644 -p $(SOURCES:.c=-help.pd) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ install -m644 -p $(wildcard *.pd) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ install -m644 -p README $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/README.txt
+ install -m644 -p VERSION $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/VERSION.txt
+ install -m644 -p CHANGES $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/CHANGES.txt
+
+install-exec:
+ install -d $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ install -m644 -p $(wildcard *.pd) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+
+
+clean:
+ -rm -f -- $(SOURCES:.c=.o)
+ -rm -f -- $(SOURCES:.c=.$(EXTENSION))
+ -rm -f -- $(LIBRARY_NAME).$(EXTENSION)
+
+distclean: clean
+ -rm -f -- ../$(LIBRARY_NAME)-$(OS)-$(shell uname -m).tar.bz2
+ -rm -f -- ../$(LIBRARY_NAME)-$(OS).tar.bz2
+
+dist: all dist_$(OS)
+
+dist_linux:
+ cd .. && tar --exclude=.svn -cjpf $(LIBRARY_NAME)-$(OS)-$(shell uname -m).tar.bz2 $(LIBRARY_NAME)
+
+dist_macosx:
+ cd .. && tar --exclude=.svn -cjpf $(LIBRARY_NAME)-$(OS).tar.bz2 $(LIBRARY_NAME)
+
+dist_windows:
+ cd .. && tar --exclude=.svn -cjpf $(LIBRARY_NAME)-$(OS).tar.bz2 $(LIBRARY_NAME)
+
+
+etags:
+ etags *.[ch] ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h
+
+showpaths:
+ @echo "PD_PATH: $(PD_PATH)"
+ @echo "objectsdir: $(objectsdir)"
+ @echo "LIBRARY_NAME: $(LIBRARY_NAME)"
+ @echo "SOURCES: $(SOURCES)"
+ @echo "UNAME: $(UNAME)"
+ @echo "CPU: $(CPU)"
diff --git a/sfsamples-help.pd b/sfsamples-help.pd
new file mode 100644
index 0000000..563d03e
--- /dev/null
+++ b/sfsamples-help.pd
@@ -0,0 +1,6 @@
+#N canvas 198 412 450 300 10;
+#X obj 111 157 sfsamples;
+#X floatatom 111 182 0 0 0 0 - - -;
+#X msg 111 112 symbol ../../sound/voice.wav;
+#X connect 0 0 1 0;
+#X connect 2 0 0 0;
diff --git a/sfsamples.c b/sfsamples.c
new file mode 100644
index 0000000..a5d2b78
--- /dev/null
+++ b/sfsamples.c
@@ -0,0 +1,81 @@
+
+#include <gmerlin/avdec.h>
+#include <gavl/gavl.h>
+
+#include <m_pd.h>
+
+#define DEBUG(x) x
+//#define DEBUG(x)
+
+static t_class *sfsamples_class;
+static t_canvas *canvas;
+
+typedef struct _sfsamples
+{
+ t_object x_obj;
+ t_symbol* filename;
+ bgav_t* decoder;
+} t_sfsamples;
+
+static void sfsamples_bang(t_sfsamples *x)
+{
+ DEBUG(post("sfsamples_bang"));
+ const gavl_audio_format_t* open_audio_format;
+ gavl_time_t gavl_time;
+
+ if(x->filename == &s_) {
+ pd_error(x,"no file set");
+ return;
+ }
+ if(!bgav_open(x->decoder, x->filename->s_name)) {
+ pd_error(x, "Could not open file %s", x->filename->s_name);
+ }
+ // only concerned with the first audio stream
+ open_audio_format = bgav_get_audio_format(x->decoder, 0);
+
+ // we can get audio formats that are unkown
+ if (open_audio_format->sample_format == GAVL_SAMPLE_NONE) {
+ pd_error(x, "sorry, this file has unsupported audio.");
+ }
+
+ gavl_time = bgav_get_duration(x->decoder, 0);
+ outlet_float(x->x_obj.ob_outlet, (float)(gavl_time_to_samples(open_audio_format->samplerate, gavl_time) / (float)open_audio_format->samplerate));
+
+}
+
+static void sfsamples_symbol(t_sfsamples *x, t_symbol* filename)
+{
+ DEBUG(post("sfsamples_symbol"));
+ x->filename = filename;
+ sfsamples_bang(x);
+}
+
+static void *sfsamples_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_sfsamples *x = (t_sfsamples *)pd_new(sfsamples_class);
+ // TODO convert args into a filename, so spaces are valid
+ x->filename == &s_;
+
+ outlet_new(&x->x_obj, &s_float);
+
+ x->decoder = bgav_create();
+
+ return(x);
+}
+
+static void sfsamples_free(t_sfsamples *x)
+{
+ bgav_close(x->decoder);
+}
+
+void sfsamples_setup(void)
+{
+ sfsamples_class = class_new(gensym("sfsamples"),
+ (t_newmethod)sfsamples_new,
+ (t_method)sfsamples_free,
+ sizeof(t_sfsamples),
+ 0, A_GIMME, 0);
+
+ class_addbang(sfsamples_class, (t_method)sfsamples_bang);
+ class_addsymbol(sfsamples_class, (t_method)sfsamples_symbol);
+}