• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This file was written by Bill Cox in 2010, and is licensed under the Apache
2# 2.0 license.
3#
4# Note that -pthread is only included so that older Linux builds will be thread
5# safe.  We call malloc, and older Linux versions only linked in the thread-safe
6# malloc if -pthread is specified.
7
8# Uncomment this if you want to link in spectrogram generation.  It is not
9# needed to adjust speech speed or pitch.  It is included primarily to provide
10# high-quality spectrograms with low CPU overhead, for applications such a
11# speech recognition.
12#USE_SPECTROGRAM=1
13
14PREFIX=/usr
15
16UNAME := $(shell uname)
17ifeq ($(UNAME), Darwin)
18  PREFIX=/usr/local
19endif
20
21BINDIR=$(PREFIX)/bin
22LIBDIR=$(PREFIX)/lib
23INCDIR=$(PREFIX)/include
24
25SONAME=-soname,
26SHARED_OPT=-shared
27LIB_NAME=libsonic.so
28LIB_INTERNAL_NAME=libsonic_internal.so
29LIB_TAG=.0.3.0
30
31ifeq ($(UNAME), Darwin)
32  SONAME=-install_name,$(LIBDIR)/
33  SHARED_OPT=-dynamiclib
34  LIB_NAME=libsonic.dylib
35  LIB_TAG=
36endif
37
38#CFLAGS=-Wall -Wno-unused-function -g -ansi -fPIC -pthread
39CFLAGS ?= -O3
40CFLAGS += -Wall -Wno-unused-function -ansi -fPIC -pthread
41
42CC=gcc
43
44# Set NO_MALLOC=1 as a parameter to make to compile Sonic with static buffers
45# instead of calling malloc.  This is usefule primarily on microcontrollers.
46ifeq ($(NO_MALLOC), 1)
47  CFLAGS+= -DSONIC_NO_MALLOC
48  # Set MAX_MEMORY=<memory size> if you need to incease the static memory buffer
49  ifdef MAX_MEMORY
50    CFLAGS+= -DSONIC_MAX_MEMORY=$(MAX_MEMORY)
51  else
52    CFLAGS+= -DSONIC_MAX_MEMORY=4096
53  endif
54endif
55
56ifdef MIN_PITCH
57  CFLAGS+= -DSONIC_MIN_PITCH=$(MIN_PITCH)
58endif
59
60EXTRA_SRC=
61# Set this to empty if not using spectrograms.
62FFTLIB=
63ifeq ($(USE_SPECTROGRAM), 1)
64  CFLAGS+= -DSONIC_SPECTROGRAM
65  EXTRA_SRC+= spectrogram.c
66  FFTLIB= -L$(LIBDIR) -lfftw3
67endif
68EXTRA_OBJ=$(EXTRA_SRC:.c=.o)
69
70all: sonic sonic_lite $(LIB_NAME)$(LIB_TAG) libsonic.a libsonic_internal.a $(LIB_INTERNAL_NAME)$(LIB_TAG)
71
72sonic: main.o libsonic.a
73	$(CC) $(CFLAGS) $(LDFLAGS) -o sonic main.o libsonic.a -lm $(FFTLIB)
74
75sonic_lite: wave.c main_lite.c sonic_lite.c sonic_lite.h
76	$(CC) $(CFLAGS) $(LDFLAGS) -o sonic_lite sonic_lite.c wave.c main_lite.c
77
78sonic.o: sonic.c sonic.h
79	$(CC) $(CPPFLAGS) $(CFLAGS) -c sonic.c
80
81# Define a version of sonic with the internal names defined so others (i.e. Speedy)
82# can build new APIs that superscede the default API.
83sonic_internal.o: sonic.c sonic.h
84	$(CC) $(CPPFLAGS) $(CFLAGS) -DSONIC_INTERNAL -c sonic.c -o sonic_internal.o
85
86wave.o: wave.c wave.h
87	$(CC) $(CPPFLAGS) $(CFLAGS) -c wave.c
88
89main.o: main.c sonic.h wave.h
90	$(CC) $(CPPFLAGS) $(CFLAGS) -c main.c
91
92spectrogram.o: spectrogram.c sonic.h
93	$(CC) $(CPPFLAGS) $(CFLAGS) -DSONIC_SPECTROGRAM -c spectrogram.c
94
95$(LIB_NAME)$(LIB_TAG): $(EXTRA_OBJ) sonic.o wave.o
96	$(CC) $(CFLAGS) $(LDFLAGS) $(SHARED_OPT) -Wl,$(SONAME)$(LIB_NAME) $(EXTRA_OBJ) sonic.o -o $(LIB_NAME)$(LIB_TAG) $(FFTLIB) wave.o
97ifneq ($(UNAME), Darwin)
98	ln -sf $(LIB_NAME)$(LIB_TAG) $(LIB_NAME)
99	ln -sf $(LIB_NAME)$(LIB_TAG) $(LIB_NAME).0
100endif
101
102$(LIB_INTERNAL_NAME)$(LIB_TAG): $(EXTRA_OBJ) sonic_internal.o wave.o  # No spectrogram needed here.
103	$(CC) $(CFLAGS) $(LDFLAGS) $(SHARED_OPT) -Wl,$(SONAME)$(LIB_INTERNAL_NAME) $(EXTRA_OBJ) sonic_internal.o -o $(LIB_INTERNAL_NAME)$(LIB_TAG) $(FFTLIB)  wave.o
104ifneq ($(UNAME), Darwin)
105	ln -sf $(LIB_INTERNAL_NAME)$(LIB_TAG) $(LIB_INTERNAL_NAME)
106	ln -sf $(LIB_INTERNAL_NAME)$(LIB_TAG) $(LIB_INTERNAL_NAME).0
107endif
108
109libsonic.a: $(EXTRA_OBJ) sonic.o wave.o
110	$(AR) cqs libsonic.a $(EXTRA_OBJ) sonic.o wave.o
111
112# Define a version of sonic with the internal names defined so others (i.e. Speedy)
113# can build new APIs that superscede the default API.
114libsonic_internal.a: $(EXTRA_OBJ) sonic_internal.o wave.o
115	$(AR) cqs libsonic_internal.a $(EXTRA_OBJ) sonic_internal.o wave.o
116
117install: sonic $(LIB_NAME)$(LIB_TAG) sonic.h
118	install -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(INCDIR) $(DESTDIR)$(LIBDIR)
119	install sonic $(DESTDIR)$(BINDIR)
120	install sonic.h $(DESTDIR)$(INCDIR)
121	install libsonic.a $(DESTDIR)$(LIBDIR)
122	install $(LIB_NAME)$(LIB_TAG) $(DESTDIR)$(LIBDIR)
123ifneq ($(UNAME), Darwin)
124	ln -sf $(LIB_NAME)$(LIB_TAG) $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
125	ln -sf $(LIB_NAME)$(LIB_TAG) $(DESTDIR)$(LIBDIR)/$(LIB_NAME).0
126endif
127
128uninstall:
129	rm -f $(DESTDIR)$(BINDIR)/sonic
130	rm -f $(DESTDIR)$(INCDIR)/sonic.h
131	rm -f $(DESTDIR)$(LIBDIR)/libsonic.a
132	rm -f $(DESTDIR)$(LIBDIR)/$(LIB_NAME)$(LIB_TAG)
133	rm -f $(DESTDIR)$(LIBDIR)/$(LIB_NAME).0
134	rm -f $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
135
136clean:
137	rm -f *.o sonic sonic_lite $(LIB_NAME)* libsonic.a libsonic_internal.a test.wav
138
139check:
140	./sonic -s 2.0 ./samples/talking.wav ./test.wav
141
142
143libspeedy.so:
144	cd speedy; make libspeedy.so  SONIC_DIR=.. FFTW_DIR=../../fftw
145
146speedy_wave: libsonic_internal.so
147	cd speedy; make speedy_wave SONIC_DIR=.. FFTW_DIR=../../fftw
148	# You will probably also need to set the LDPATH.  For example
149	#    export LD_LIBRARY_PATH=/usr/local/lib:../kissfft:speedy:.
150
151