Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.

Commit 60c5d15

Browse files
committed
Compile fix
0 parents  commit 60c5d15

File tree

323 files changed

+270771
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

323 files changed

+270771
-0
lines changed

.hgignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The default pattern syntax is Python/Perl-style regular expressions.
2+
3+
\.log$
4+
\.DS_Store$
5+
\.out$
6+
\.out\.dSYM$

LICENSE

+394
Large diffs are not rendered by default.

Makefile

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
INCLUDE_DIR := include
3+
SRC_DIR := source
4+
OBJ_DIR := objects
5+
TESTS_DIR := tests
6+
7+
STATIC_LIB_NAME := librho.a
8+
9+
C := $(TARGET)gcc
10+
CC := $(TARGET)g++
11+
AR := $(TARGET)ar
12+
C_FLAGS_LOCAL := $(CC_FLAGS) \
13+
-g -O2 -fvisibility=hidden -Wall -Wextra -Werror -pedantic \
14+
-Wno-unused-parameter -Wno-long-long -Wno-sign-conversion \
15+
-D_FILE_OFFSET_BITS=64 \
16+
-maes \
17+
-I $(INCLUDE_DIR)
18+
CC_FLAGS_LOCAL := $(CC_FLAGS) \
19+
-g -O2 -fvisibility=hidden -Wall -Wextra -Werror -pedantic \
20+
-Wswitch-default -Wcast-qual -Wcast-align -Wconversion \
21+
-Wno-unused-parameter -Wno-long-long -Wno-sign-conversion \
22+
-D_FILE_OFFSET_BITS=64 \
23+
-maes \
24+
-I $(INCLUDE_DIR) # consider: -Wold-style-cast -Wshadow
25+
26+
ifeq ($(shell uname),Linux)
27+
# Linux stuff:
28+
CC_FLAGS_LOCAL += -rdynamic -Wdouble-promotion
29+
else
30+
ifeq ($(shell uname),Darwin)
31+
# OSX stuff:
32+
CC_FLAGS_LOCAL += -mmacosx-version-min=10.6 -I /usr/local/include
33+
PRE_STEP := osx_pre_step
34+
POST_STEP := osx_post_step
35+
else
36+
# Mingw and Cygwin stuff:
37+
endif
38+
endif
39+
40+
C_SRC_FILES = $(shell find $(SRC_DIR) -name '*.c' -type f)
41+
C_OBJ_FILES = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(C_SRC_FILES))
42+
43+
CPP_SRC_FILES = $(shell find $(SRC_DIR) -name '*.cpp' -type f)
44+
CPP_OBJ_FILES = $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(CPP_SRC_FILES))
45+
46+
MM_SRC_FILES = $(shell find $(SRC_DIR) -name '*.mm' -type f)
47+
MM_OBJ_FILES = $(patsubst $(SRC_DIR)/%.mm,$(OBJ_DIR)/%.o,$(MM_SRC_FILES))
48+
49+
all : $(PRE_STEP) $(C_OBJ_FILES) $(CPP_OBJ_FILES) $(MM_OBJ_FILES) $(POST_STEP)
50+
51+
install : ensure_root uninstall all
52+
@echo
53+
@cp -r $(INCLUDE_DIR)/* /usr/local/include
54+
@cp $(OBJ_DIR)/$(STATIC_LIB_NAME) /usr/local/lib
55+
@echo "Install successful."
56+
57+
uninstall : ensure_root
58+
@(cd $(INCLUDE_DIR) && for i in *; do rm -rf /usr/local/include/$$i; done)
59+
60+
ensure_root :
61+
$(if $(shell whoami | grep root),,\
62+
@echo 'You must be root to run to perform that operation.' && exit 1; \
63+
)
64+
65+
test : all
66+
@$(TESTS_DIR)/RunTests.bash
67+
68+
clean :
69+
@rm -rf $(OBJ_DIR)
70+
@echo "Clean successful."
71+
72+
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c
73+
@echo "Compiling $< ..."
74+
@mkdir -p $(@D)
75+
$(C) $(C_FLAGS_LOCAL) -c -o $@ $<
76+
$(AR) crsv $(OBJ_DIR)/$(STATIC_LIB_NAME) $@
77+
@echo
78+
79+
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.cpp
80+
@echo "Compiling $< ..."
81+
@mkdir -p $(@D)
82+
$(CC) $(CC_FLAGS_LOCAL) -c -o $@ $<
83+
$(AR) crsv $(OBJ_DIR)/$(STATIC_LIB_NAME) $@
84+
@echo
85+
86+
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.mm
87+
@echo "Compiling $< ..."
88+
@mkdir -p $(@D)
89+
$(CC) $(CC_FLAGS_LOCAL) -c -o $@ $<
90+
$(AR) crsv $(OBJ_DIR)/$(STATIC_LIB_NAME) $@
91+
@echo
92+
93+
osx_pre_step :
94+
@mv source/rho/img/tImageCapFactory.cpp \
95+
source/rho/img/tImageCapFactory.mm
96+
97+
osx_post_step :
98+
@mv source/rho/img/tImageCapFactory.mm \
99+
source/rho/img/tImageCapFactory.cpp
100+
101+
.PHONY : all install uninstall ensure_root test clean osx_pre_step osx_post_step

README.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
LIBRHO
2+
======
3+
4+
This library compiles under:
5+
- Linux
6+
- Cygwin
7+
- OSX
8+
- iOS
9+
- Mingw (on Windows)
10+
11+
Following are instructions for compiling on each platform.
12+
13+
14+
Linux, Cygwin, OSX
15+
------------------
16+
17+
Compiling and testing under Linux, Cygwin, and OSX is easy. Do the following:
18+
19+
To make the library, run:
20+
21+
make
22+
23+
That will put a bunch of object files and a static library file in 'objects/'.
24+
25+
You can now run the tests with the command:
26+
27+
make test
28+
29+
If you'd like to install the header files and the static lib permanently, run:
30+
31+
sudo make install
32+
33+
That will put stuff in '/usr/local/include' and in '/usr/local/lib'. You can
34+
now compile your programs by passing '-lrho' to `g++`. Try it out with the
35+
examples in 'examples/'.
36+
37+
To clean-up, run:
38+
39+
make clean
40+
41+
42+
iOS
43+
---
44+
45+
Compiling for iOS takes a little love, but not too much. Do the following:
46+
47+
1. Copy the 'source/' and 'include/' directories into your iOS Xcode project.
48+
2. Rename tImageCapFactory.cpp to tImageCapFactory.mm
49+
3. Make sure tImageCapFactory.mm is set to compile without ARC. To do this,
50+
add a flag in the project settings to tImageCapFactory.mm that disables
51+
ARC for just that file. That flag is '-fno-objc-arc'.
52+
4. Add the following frameworks to the project (if they are not already
53+
present):
54+
- AVFoundation.framework
55+
- CoreVideo.framework
56+
- CoreMedia.framework
57+
58+
59+
Mingw
60+
-----
61+
62+
Compiling for Mingw is easy if you do so using the Cygwin environment. Simply
63+
install Cygwin (make sure the Mingw package is installed along with it), then
64+
within the Cygwin environment, set the $TARGET environment variable equal to
65+
the mingw-prefix (which was 'i686-pc-mingw32-' last time I checked). You can
66+
set the $TARGET environment variable and run make on one line as follows:
67+
68+
TARGET=i686-pc-mingw32- make
69+
70+
You can then proceed as the Linux instructions dictate, setting the $TARGET
71+
variable for each command as is done above.
72+
73+
74+
Other compilation notes
75+
-----------------------
76+
77+
1. To compile the library for x86 (as opposed to for x86_64), you must pass '-m32'
78+
to `g++`. You can easily do this by running `CC_FLAGS=-m32 make`. That sets
79+
$CC_FLAGS equal to '-m32' just for the duration of the `make` command.
80+
81+
2. If you want to run a version of `g++` that contains a prefix (for example,
82+
for doing some sort of cross-compilation), you can set the $TARGET variable
83+
to the desired g++-prefix before running `make`. Do this in the same way as
84+
described in the Mingw section.
85+
86+
87+
Usage notes
88+
-----------
89+
90+
1. This library contains static data which gets initialized in some arbitrary
91+
order by the compiler. Within the library there are no dependencies between
92+
any of the static data, so it doesn't matter what order initialization happens.
93+
Users of the library should be careful about what they allocate in static space,
94+
however, because if that application-specific static data gets initialized
95+
before some required part of librho, then bad things could happen. For example,
96+
librho does some socket initialization stuff (like setting signals to be
97+
ignored) as a part of its static initialization; thus, if a user's application
98+
creates a socket in the static area, it may happen before librho gets a chance
99+
to do its own socket initialization stuff. The best thing to do is avoid using
100+
static allocations, and also read the next note.
101+
102+
2. Users of librho must understand the refc templated class. It is awesome.
103+
Also, it is okay to create a NULL refc in static space (since a NULL refc does
104+
not depend on any static initialization within librho). Doing so is useful if
105+
you *really* need a global object. Simply set the NULL global refc equal to a
106+
real object as a part of main(), then use you global object happily.
107+
108+
3. Be careful if your application does a fork()+exec(). Librho sets most of
109+
the file descriptors that it opens to close-on-exec, but not all of them.
110+
It cannot set close-on-exec when a file is opened via the C++ fstream library.
111+
Currently only geo::tMesh and audio::tWaveMaker use the fstream library, so
112+
chances are that you are okay. Also, currently, reading an image from file
113+
using the img::tImage constructor opens a file without setting close-on-
114+
exec. If you do any of these in an application that does a fork()+exec(),
115+
you could end up leaking file descriptors. Using tFileReadable, tFileWritable,
116+
ip::tcp::tSocket, and ip::tcp::tServer are all safe, however.
117+
118+
119+
Other
120+
-----
121+
122+
Here are a few things I'd like the library to have soon:
123+
124+
- non-blocking tcp & udp sockets
125+
- graph library
126+
127+
Things left to do are marked with a comment that contains 'libtodo' or 'LIBTODO'.
128+
129+
130+
Contributing
131+
------------
132+
133+
This library is built with portability in mind. For that reason, it doesn't have any external dependencies and it only contains highly portable C++ code (i.e. code that is agnostic to platform and CPU architecture). We welcome pull requests, but we only accept changelists that contain portable code with no external dependencies. :)

examples/rho/algo/tFFTExample.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <rho/algo/tFFT.h>
2+
#include <rho/audio/tWaveMaker.h>
3+
#include <rho/tCrashReporter.h>
4+
5+
#include <iostream>
6+
7+
using namespace rho;
8+
using std::vector;
9+
using std::pair;
10+
using std::cout;
11+
using std::endl;
12+
13+
14+
int main()
15+
{
16+
tCrashReporter::init();
17+
18+
u32 sampleRate = 8000;
19+
u32 numSamples = 1 << 14;
20+
21+
audio::tWaveMaker m(numSamples, sampleRate);
22+
23+
{
24+
double freq = 1000.0;
25+
double amp = 4.2;
26+
m.addWave(freq, amp);
27+
}
28+
29+
{
30+
double freq = 325.0;
31+
double amp = 2.8;
32+
m.addWave(freq, amp);
33+
}
34+
35+
{
36+
double freq = 670.0;
37+
double amp = 1.5;
38+
m.addWave(freq, amp);
39+
}
40+
41+
vector<double> signal = m.getWave();
42+
43+
algo::tFFT fft(signal, sampleRate);
44+
45+
vector< pair<double, double> > ampFreqPairs =
46+
fft.getAmpFreqPairs();
47+
48+
cout << "Printing the five partials with the largest amplitudes ..." << endl << endl;
49+
cout << "Frequency (amplitude)" << endl;
50+
for (int i = 0; i < 5; i++)
51+
{
52+
int k = ampFreqPairs.size() - 1 - i;
53+
cout << ampFreqPairs[k].second << " ("
54+
<< ampFreqPairs[k].first << ")" << endl;
55+
}
56+
57+
return 0;
58+
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <rho/audio/tWaveMaker.h>
2+
#include <rho/tCrashReporter.h>
3+
4+
#include <iostream>
5+
6+
using namespace rho;
7+
using std::cout;
8+
using std::endl;
9+
10+
11+
int main()
12+
{
13+
tCrashReporter::init();
14+
15+
u32 sampleRate = 8000;
16+
u32 numSamples = sampleRate * 3.5;
17+
18+
audio::tWaveMaker m(numSamples, sampleRate);
19+
20+
{
21+
double frequency = 1000.0;
22+
double amplitute = 1.0;
23+
m.addWave(frequency, amplitute);
24+
}
25+
26+
{
27+
double frequency = 400.0;
28+
double amplitute = 0.5;
29+
m.addWave(frequency, amplitute);
30+
}
31+
32+
{
33+
double frequency = 123.0;
34+
double amplitute = 0.8;
35+
m.addWave(frequency, amplitute);
36+
}
37+
38+
m.writeToFile("example1.wav");
39+
40+
cout << "Wave file has been written!" << endl;
41+
42+
return 0;
43+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <rho/audio/tWaveMaker.h>
2+
#include <rho/tCrashReporter.h>
3+
4+
#include <iostream>
5+
6+
using namespace rho;
7+
using std::cout;
8+
using std::endl;
9+
using std::vector;
10+
11+
12+
int main()
13+
{
14+
tCrashReporter::init();
15+
16+
audio::tWaveMaker m = audio::tWaveMaker::readFromFile("example1.wav");
17+
18+
u32 sampleRate = m.getSampleRate();
19+
20+
cout << "Wave file has been read!" << endl << endl;
21+
cout << "Sample rate is " << sampleRate << " Hz." << endl << endl;
22+
23+
cout << "Will write a wave file which is double that sample rate... ";
24+
25+
vector<double> wave = m.getWave();
26+
27+
audio::tWaveMaker m2(wave, 2*sampleRate);
28+
29+
m2.writeToFile("example2.wav");
30+
31+
cout << "DONE!" << endl;
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)