├── .gitmodules
├── Doxyfile
├── Makefile
├── build
├── proAudio.vcproj
└── proteaAudio.sln
├── changelog.txt
├── doc
├── annotated.html
├── changelog.html
├── class_audio_sample-members.html
├── class_audio_sample.html
├── class_device_audio-members.html
├── class_device_audio.html
├── class_device_audio.png
├── class_device_audio_rt-members.html
├── class_device_audio_rt.html
├── class_device_audio_rt.png
├── class_device_audio_sdl-members.html
├── class_device_audio_sdl.html
├── class_device_audio_sdl.png
├── files.html
├── functions.html
├── functions_func.html
├── functions_vars.html
├── hierarchy.html
├── index.html
├── pages.html
├── pro_audio_8h-source.html
├── pro_audio_8h.html
├── pro_audio_rt_8h-source.html
├── pro_audio_rt_8h.html
├── pro_audio_sdl_8h-source.html
├── pro_audio_sdl_8h.html
├── protea.css
├── proteaAudio.png
└── proteaaudiolua.html
├── example.cpp
├── example.lua
├── footer.html
├── header.html
├── lua.txt
├── playAudioRt.cpp
├── playAudioSdl.cpp
├── proAudio.cpp
├── proAudio.h
├── proAudioRt.cpp
├── proAudioRt.h
├── proAudioRt_lua.cpp
├── proAudioSdl.cpp
├── proAudioSdl.h
├── protea.css
├── proteaAudio.png
├── readme.txt
├── sample.ogg
├── scale.lua
└── stb_vorbis.c
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "rtaudio"]
2 | path = rtaudio
3 | url = https://github.com/tmatth/RtAudio.git
4 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | #--- generic settings ----------------------------------------------
2 | # settings for C++ compiler:
3 | C = gcc
4 | CC = g++
5 | CFLAGS = -O2 -Wall -fPIC # -D_DEBUG -g
6 | INCDIR = -Irtaudio -Irtaudio/include -I../lua/src
7 |
8 | # linker settings:
9 | LCC = ar
10 | LFLAGS = -rcs
11 | LNAME = libproAudio.a
12 | LIB = $(LNAME)
13 | LIBDIR =
14 |
15 | # settings for optional libSDL backend:
16 | INCDIR += $(shell sdl-config --cflags)
17 | SDLLIB = $(shell sdl-config --libs)
18 |
19 | USE_PULSE=1
20 |
21 | #--- platform specific settings ------------------------------------
22 | ARCH = $(shell uname -s)
23 | ifeq ($(ARCH),Linux)
24 | LIBS = $(LIBDIR) $(LIB) -lpthread -lasound
25 |
26 | ifeq ($(USE_PULSE),1)
27 | INCDIR += $(shell pkg-config --cflags libpulse-simple)
28 | LIBS += $(shell pkg-config --libs libpulse-simple)
29 | endif
30 |
31 | LUALIB = -llua -ldl
32 | CFLAGS += -DHAVE_GETTIMEOFDAY $(if $(filter 1,$(USE_PULSE)),-D__LINUX_PULSE__,-D__LINUX_ALSA__) #-D__LINUX_OSS__
33 | DLLFLAGS = -fPIC -shared
34 | DLLSUFFIX = .so
35 | EXESUFFIX =
36 |
37 | else
38 | ifeq ($(ARCH),Darwin) # MacOSX
39 | LIBS = $(LIBDIR) $(LIB)
40 | LUALIB = -L/usr/local/lib -llua
41 | CFLAGS += -DHAVE_GETTIMEOFDAY -D__MACOSX_CORE__
42 | DLLFLAGS = -bundle
43 | DLLSUFFIX = .so
44 | EXESUFFIX = .app
45 |
46 | else # windows, MinGW
47 | LIBS = $(LIBDIR) $(LIB) -lole32 -ldsound -lwinmm -mconsole -s
48 | LUALIB = -L../lua/src -llua51
49 | SDLLIB = -lmingw32 -lSDLmain -lSDL -mconsole -s
50 | CFLAGS += -D__WINDOWS_DS__
51 | DLLFLAGS = -shared
52 | DLLSUFFIX = .dll
53 | EXESUFFIX = .exe
54 | endif
55 | endif
56 |
57 | #--- make targets and rules ----------------------------------------
58 |
59 | # by default, proteaAudio makes use of the included rtAudio backend
60 | rtaudio: $(LNAME) example$(EXESUFFIX) playAudioRt$(EXESUFFIX)
61 |
62 | # the make all target additionally builds the Lua frontend and SDL backend, and therefore has additional dependencies
63 | ALL = $(LNAME) example$(EXESUFFIX) playAudioRt$(EXESUFFIX) proAudioRt$(DLLSUFFIX) playAudioSdl$(EXESUFFIX)
64 | all: $(ALL)
65 |
66 | # static library
67 | OBJ = proAudio.o proAudioRt.o stb_vorbis.o rtaudio/RtAudio.o
68 | $(LNAME) : $(OBJ)
69 | $(LCC) $(LFLAGS) $@ $^
70 |
71 | # minimal example
72 | example$(EXESUFFIX) : example.o
73 | $(CC) $^ $(LIBS) -o $@
74 |
75 | # flexible example
76 | playAudioRt$(EXESUFFIX) : playAudioRt.o
77 | $(CC) $^ $(LIBS) -o $@
78 |
79 | # optional Lua frontend
80 | lua: proAudioRt$(DLLSUFFIX)
81 |
82 | proAudioRt$(DLLSUFFIX): proAudioRt_lua.o
83 | $(CC) -o $@ $(DLLFLAGS) $^ $(LIBS) $(LUALIB)
84 |
85 | # example for optional libSDL backend
86 | sdl: playAudioSdl$(EXESUFFIX)
87 |
88 | playAudioSdl$(EXESUFFIX): playAudioSdl.o proAudio.o proAudioSdl.o stb_vorbis.o
89 | $(CC) $(CFLAGS) $^ $(SDLLIB) -o $@
90 |
91 | # generic rules
92 | .c.o:
93 | $(C) $(CFLAGS) $(INCDIR) -c $< -o $@
94 | .cpp.o:
95 | $(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
96 | clean:
97 | rm -f *.o *~ $(OBJ) $(ALL)
98 |
99 | #--- project specific dependencies ---------------------------------
100 | HDR = proAudio.h proAudioRt.h
101 | playAudioRt.o: playAudioRt.cpp $(HDR)
102 | serverAudioRt.o: serverAudioRt.cpp $(HDR)
103 | proAudioRt_lua.o: proAudioRt_lua.cpp $(HDR)
104 | proAudio.o: proAudio.cpp proAudio.h
105 | proAudioRt.o: proAudioRt.cpp $(HDR)
106 | stb_vorbis.o: stb_vorbis.c
107 | rtaudio/RtAudio.o: rtaudio/RtAudio.cpp rtaudio/RtAudio.h rtaudio/RtError.h
108 | example.o: example.cpp $(HDR)
109 | playAudioSdl.o: playAudioSdl.cpp proAudioSdl.h proAudio.h
110 | proAudioSdl.o: proAudioSdl.cpp proAudioSdl.h proAudio.h
111 |
--------------------------------------------------------------------------------
/build/proAudio.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
AudioSample | Class representing an audio sample |
DeviceAudio | Abstract base class for stereo audio mixer/playback devices |
DeviceAudioRt | RtAudio based stereo audio mixer/playback device |
DeviceAudioSdl | SDL based stereo audio mixer/playback device |
18 | © 2009-02-04 by Gerald Franz, www.viremo.de 19 | | 20 |21 | impressum 22 | | 23 | 24 |
16 | © 2009-02-04 by Gerald Franz, www.viremo.de 17 | | 18 |19 | impressum 20 | | 21 | 22 |
AudioSample(unsigned char *data, unsigned int size, unsigned short channels, unsigned int sampleRate, unsigned short bitsPerSample) | AudioSample | [inline] |
AudioSample(const AudioSample &source) | AudioSample | |
bitsPerSample() const | AudioSample | [inline] |
bitsPerSample(unsigned short bits) | AudioSample | |
bytesPerSample() const | AudioSample | [inline] |
channels() const | AudioSample | [inline] |
data() | AudioSample | [inline] |
data() const | AudioSample | [inline] |
frames() const | AudioSample | [inline] |
loadWav(const std::string &fname) | AudioSample | [static] |
m_bitsPerSample | AudioSample | [protected] |
m_channels | AudioSample | [protected] |
m_data | AudioSample | [protected] |
m_sampleRate | AudioSample | [protected] |
m_size | AudioSample | [protected] |
readWav(FILE *stream, size_t(*readFunc)(void *, size_t, size_t, FILE *)) | AudioSample | [static] |
sampleRate() const | AudioSample | [inline] |
size() const | AudioSample | [inline] |
sizeFrame() const | AudioSample | [inline] |
volume(float f) | AudioSample | |
~AudioSample() | AudioSample | [inline] |
34 | © 2009-02-04 by Gerald Franz, www.viremo.de 35 | | 36 |37 | impressum 38 | | 39 | 40 |
destroy() | DeviceAudio | [inline, static] |
DeviceAudio() | DeviceAudio | [protected] |
loaderAvailable(const std::string &suffix) const | DeviceAudio | |
loaderRegister(AudioSample *(*loadFunc)(const std::string &), const std::string &suffix) | DeviceAudio | |
m_freqOut | DeviceAudio | [protected] |
m_volL | DeviceAudio | [protected] |
m_volR | DeviceAudio | [protected] |
mm_loader | DeviceAudio | [protected] |
s_instance | DeviceAudio | [protected, static] |
sample(unsigned int handle) const | DeviceAudio | [inline, virtual] |
sampleDestroy(unsigned int sample)=0 | DeviceAudio | [pure virtual] |
sampleFromFile(const std::string &filename, float volume=1.0f) | DeviceAudio | [virtual] |
sampleFromMemory(const AudioSample &sample, float volume=1.0f)=0 | DeviceAudio | [pure virtual] |
singleton() | DeviceAudio | [inline, static] |
soundActive() const =0 | DeviceAudio | [pure virtual] |
soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f)=0 | DeviceAudio | [pure virtual] |
soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f)=0 | DeviceAudio | [pure virtual] |
soundStop(unsigned int sound)=0 | DeviceAudio | [pure virtual] |
soundStop()=0 | DeviceAudio | [pure virtual] |
soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f)=0 | DeviceAudio | [pure virtual] |
volume(float left, float right) | DeviceAudio | [inline] |
volume(float leftAndRight) | DeviceAudio | [inline] |
~DeviceAudio() | DeviceAudio | [inline, protected, virtual] |
36 | © 2009-02-04 by Gerald Franz, www.viremo.de 37 | | 38 |39 | impressum 40 | | 41 | 42 |
cbMix(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *data) | DeviceAudioRt | [inline, protected, static] |
create(unsigned int nTracks=8, unsigned int frequency=22050, unsigned int chunkSize=1024) | DeviceAudioRt | [static] |
destroy() | DeviceAudio | [inline, static] |
DeviceAudio() | DeviceAudio | [protected] |
DeviceAudioRt(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize) | DeviceAudioRt | [protected] |
loaderAvailable(const std::string &suffix) const | DeviceAudio | |
loaderRegister(AudioSample *(*loadFunc)(const std::string &), const std::string &suffix) | DeviceAudio | |
m_dac | DeviceAudioRt | [protected] |
m_freqOut | DeviceAudio | [protected] |
m_nSound | DeviceAudioRt | [protected] |
m_sampleCounter | DeviceAudioRt | [protected] |
m_volL | DeviceAudio | [protected] |
m_volR | DeviceAudio | [protected] |
ma_sound | DeviceAudioRt | [protected] |
mixOutputFloat(signed short *outputBuffer, unsigned int nFrames) | DeviceAudioRt | [protected] |
mm_loader | DeviceAudio | [protected] |
mm_sample | DeviceAudioRt | [protected] |
s_instance | DeviceAudio | [protected, static] |
sample(unsigned int handle) const | DeviceAudioRt | [virtual] |
sampleDestroy(unsigned int sample) | DeviceAudioRt | [virtual] |
sampleFromFile(const std::string &filename, float volume=1.0f) | DeviceAudio | [virtual] |
sampleFromMemory(const AudioSample &sample, float volume=1.0f) | DeviceAudioRt | [virtual] |
singleton() | DeviceAudio | [inline, static] |
soundActive() const | DeviceAudioRt | [virtual] |
soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f) | DeviceAudioRt | [virtual] |
soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f) | DeviceAudioRt | [virtual] |
soundStop(unsigned int sound) | DeviceAudioRt | [virtual] |
soundStop() | DeviceAudioRt | [virtual] |
soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f) | DeviceAudioRt | [virtual] |
volume(float left, float right) | DeviceAudio | [inline] |
volume(float leftAndRight) | DeviceAudio | [inline] |
~DeviceAudio() | DeviceAudio | [inline, protected, virtual] |
~DeviceAudioRt() | DeviceAudioRt | [protected, virtual] |
46 | © 2009-02-04 by Gerald Franz, www.viremo.de 47 | | 48 |49 | impressum 50 | | 51 | 52 |
cbOutput(void *userData, Uint8 *stream, int len) | DeviceAudioSdl | [protected, static] |
create(unsigned int nTracks=8, unsigned int frequency=22050, unsigned int chunkSize=1024) | DeviceAudioSdl | [static] |
destroy() | DeviceAudio | [inline, static] |
DeviceAudio() | DeviceAudio | [protected] |
DeviceAudioSdl(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize) | DeviceAudioSdl | [protected] |
loaderAvailable(const std::string &suffix) const | DeviceAudio | |
loaderRegister(AudioSample *(*loadFunc)(const std::string &), const std::string &suffix) | DeviceAudio | |
m_freqOut | DeviceAudio | [protected] |
m_isDesiredFormat | DeviceAudioSdl | [protected] |
m_nSound | DeviceAudioSdl | [protected] |
m_sampleCounter | DeviceAudioSdl | [protected] |
m_spec | DeviceAudioSdl | [protected] |
m_volL | DeviceAudio | [protected] |
m_volR | DeviceAudio | [protected] |
ma_sound | DeviceAudioSdl | [protected] |
mixOutputFloat(signed short *outputBuffer, unsigned int nFrames) | DeviceAudioSdl | [protected] |
mixOutputSInt(Uint8 *stream, int len) | DeviceAudioSdl | [protected] |
mm_loader | DeviceAudio | [protected] |
mm_sample | DeviceAudioSdl | [protected] |
s_instance | DeviceAudio | [protected, static] |
sample(unsigned int handle) const | DeviceAudio | [inline, virtual] |
sampleDestroy(unsigned int sample) | DeviceAudioSdl | [virtual] |
sampleFromFile(const std::string &filename, float volume=1.0f) | DeviceAudio | [virtual] |
sampleFromMemory(const AudioSample &sample, float volume=1.0f) | DeviceAudioSdl | [virtual] |
singleton() | DeviceAudio | [inline, static] |
soundActive() const | DeviceAudioSdl | [virtual] |
soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f) | DeviceAudioSdl | [virtual] |
soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f) | DeviceAudioSdl | [virtual] |
soundStop(unsigned int sound) | DeviceAudioSdl | [virtual] |
soundStop() | DeviceAudioSdl | [virtual] |
soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f) | DeviceAudioSdl | [virtual] |
volume(float left, float right) | DeviceAudio | [inline] |
volume(float leftAndRight) | DeviceAudio | [inline] |
~DeviceAudio() | DeviceAudio | [inline, protected, virtual] |
~DeviceAudioSdl() | DeviceAudioSdl | [protected, virtual] |
48 | © 2009-02-04 by Gerald Franz, www.viremo.de 49 | | 50 |51 | impressum 52 | | 53 | 54 |
proAudio.h [code] | Public interface of proteaAudio |
proAudioRt.h [code] | RtAudio backend of proteaAudio |
proAudioSdl.h [code] | SDL backend of proteaAudio |
17 | © 2009-02-04 by Gerald Franz, www.viremo.de 18 | | 19 |20 | impressum 21 | | 22 | 23 |
13 | Here is a list of all documented class members with links to the class documentation for each member: 14 |
15 |
94 | © 2009-02-04 by Gerald Franz, www.viremo.de 95 | | 96 |97 | impressum 98 | | 99 | 100 |
13 | 14 |
15 |
77 | © 2009-02-04 by Gerald Franz, www.viremo.de 78 | | 79 |80 | impressum 81 | | 82 | 83 |
12 |
34 | © 2009-02-04 by Gerald Franz, www.viremo.de 35 | | 36 |37 | impressum 38 | | 39 | 40 |
20 | © 2009-02-04 by Gerald Franz, www.viremo.de 21 | | 22 |23 | impressum 24 | | 25 | 26 |
11 |
14 | Due to its straightforward interface and minimal open-source code base, proteaAudio is both easy to maintain and use.
15 | By default proteaAudio internally makes use of the excellent RtAudio low-level realtime audio input/output API, and therefore has no external dependencies apart from standard system libraries. Together with its liberal open-source licensing conditions (zlib style), this makes the integration of proteaAudio into both free and closed-source commercial software very easy. Alternatively, proteaAudio contains optional bindings for the highly portable SDL multimedia library and is therefore also usable on a plentitude of further platforms (e.g., iPhone, BEOS, FreeBSD).
16 | Despite its minimalistic design, proteaAudio offers advanced features such as dynamic pitch, per-channel volume control, and user-definable time shifts between channels. proteaAudio is capable of handling normal .wav files as well as ogg/vorbis audio samples (via stb_vorbis). Additionally it offers a simple interface for integrating further custom audio format loaders (e.g., .mp3).
31 |
36 | This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software.
37 | Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
38 |
43 | © 2009-02-04 by Gerald Franz, www.viremo.de 44 | | 45 |46 | impressum 47 | | 48 | 49 |
18 | © 2009-02-04 by Gerald Franz, www.viremo.de 19 | | 20 |21 | impressum 22 | | 23 | 24 |
00001 #ifndef _PRO_AUDIO 10 | 00002 #define _PRO_AUDIO 11 | 00003 12 | 00004 #include <string> 13 | 00005 #include <map> 14 | 00006 15 | 00036 //--- class AudioSample -------------------------------------------- 16 | 00038 class AudioSample { 17 | 00039 public: 18 | 00041 AudioSample(unsigned char * data, unsigned int size, unsigned short channels, unsigned int sampleRate, unsigned short bitsPerSample) : 19 | 00042 m_data(data), m_size(size), m_channels(channels), m_sampleRate(sampleRate), m_bitsPerSample(bitsPerSample) { } 20 | 00044 AudioSample(const AudioSample & source); 21 | 00046 ~AudioSample() { delete[] m_data; } 22 | 00047 23 | 00049 unsigned char * data() { return m_data; }; 24 | 00051 const unsigned char * data() const { return m_data; }; 25 | 00053 unsigned int size() const { return m_size; } 26 | 00055 unsigned int frames() const { return m_size/m_channels/(m_bitsPerSample>>3); } 27 | 00057 unsigned int sizeFrame() const { return m_channels*(m_bitsPerSample>>3); } 28 | 00059 unsigned short channels() const { return m_channels; } 29 | 00061 unsigned int sampleRate() const { return m_sampleRate; } 30 | 00063 unsigned short bitsPerSample() const { return m_bitsPerSample; } 31 | 00065 bool bitsPerSample(unsigned short bits); 32 | 00067 unsigned short bytesPerSample() const { return m_bitsPerSample>>3; } 33 | 00068 34 | 00070 void volume(float f); 35 | 00071 36 | 00073 static AudioSample* loadWav(const std::string & fname); 37 | 00075 static AudioSample* readWav(FILE* stream, size_t (*readFunc)( void *, size_t, size_t, FILE *)); 38 | 00076 protected: 39 | 00078 unsigned char * m_data; 40 | 00080 unsigned int m_size; 41 | 00082 unsigned short m_channels; 42 | 00084 unsigned int m_sampleRate; 43 | 00086 unsigned short m_bitsPerSample; 44 | 00087 }; 45 | 00088 46 | 00089 //--- class DeviceAudio -------------------------------------------- 47 | 00090 48 | 00092 class DeviceAudio { 49 | 00093 public: 50 | 00095 51 | 00096 static DeviceAudio& singleton() { return *s_instance; } 52 | 00098 static void destroy() { if(s_instance) delete s_instance; s_instance=0; }; 53 | 00099 54 | 00101 void volume(float left, float right) { m_volL=left; m_volR=right; } 55 | 00103 void volume(float leftAndRight) { m_volL=m_volR=leftAndRight; } 56 | 00105 57 | 00106 bool loaderRegister(AudioSample *(*loadFunc)(const std::string &), const std::string & suffix); 58 | 00108 bool loaderAvailable(const std::string & suffix) const; 59 | 00109 60 | 00111 virtual unsigned int sampleFromFile(const std::string & filename, float volume=1.0f); 61 | 00113 virtual unsigned int sampleFromMemory(const AudioSample & sample, float volume=1.0f)=0; 62 | 00115 virtual bool sampleDestroy(unsigned int sample)=0; 63 | 00117 virtual const AudioSample* sample(unsigned int handle) const { return 0; } 64 | 00118 65 | 00120 66 | 00126 virtual unsigned int soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f )=0; 67 | 00128 68 | 00134 virtual unsigned int soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f )=0; 69 | 00136 70 | 00142 virtual bool soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f )=0; 71 | 00144 virtual bool soundStop(unsigned int sound)=0; 72 | 00146 virtual void soundStop()=0; 73 | 00148 virtual unsigned int soundActive() const=0; 74 | 00149 75 | 00150 protected: 76 | 00152 DeviceAudio(); 77 | 00154 virtual ~DeviceAudio() { s_instance = 0; } 78 | 00155 79 | 00157 unsigned int m_freqOut; 80 | 00159 float m_volL; 81 | 00161 float m_volR; 82 | 00163 std::map<std::string, AudioSample * (*)(const std::string &)> mm_loader; 83 | 00164 84 | 00166 static DeviceAudio * s_instance; 85 | 00167 }; 86 | 00168 87 | 00169 #endif // _PRO_AUDIO 88 |
91 | © 2009-02-04 by Gerald Franz, www.viremo.de 92 | | 93 |94 | impressum 95 | | 96 | 97 |
11 | #include <string>
12 | #include <map>
13 |
14 |
15 | Go to the source code of this file.
Classes | |
class | AudioSample |
class representing an audio sample More... | |
class | DeviceAudio |
abstract base class for stereo audio mixer/playback devices More... |
28 | Contains the declaration of the audio sample class and the abstract base class for audio mixer/playback devices
29 |
32 | (c) 2009 by Gerald Franz, www.viremo.de
33 | This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software.
34 | Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
35 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.
38 | © 2009-02-04 by Gerald Franz, www.viremo.de 39 | | 40 |41 | impressum 42 | | 43 | 44 |
00001 #include "proAudio.h" 10 | 00002 #include <RtAudio.h> 11 | 00003 #include <map> 12 | 00004 13 | 00011 struct _AudioTrack; 14 | 00012 15 | 00014 16 | 00016 class DeviceAudioRt : public DeviceAudio { 17 | 00017 public: 18 | 00019 19 | 00026 static DeviceAudio* create(unsigned int nTracks=8, unsigned int frequency=22050, unsigned int chunkSize=1024); 20 | 00027 21 | 00029 virtual unsigned int sampleFromMemory(const AudioSample & sample, float volume=1.0f); 22 | 00031 virtual bool sampleDestroy(unsigned int sample); 23 | 00033 virtual const AudioSample* sample(unsigned int handle) const; 24 | 00034 25 | 00036 26 | 00042 virtual unsigned int soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f ); 27 | 00050 virtual unsigned int soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f ); 28 | 00052 29 | 00058 virtual bool soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f ); 30 | 00060 virtual bool soundStop(unsigned int sound); 31 | 00062 virtual void soundStop(); 32 | 00064 virtual unsigned soundActive() const; 33 | 00065 protected: 34 | 00067 DeviceAudioRt(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize); 35 | 00069 virtual ~DeviceAudioRt(); 36 | 00071 int mixOutputFloat(signed short *outputBuffer, unsigned int nFrames); 37 | 00072 38 | 00074 std::map<unsigned int, AudioSample*> mm_sample; 39 | 00076 unsigned int m_sampleCounter; 40 | 00077 41 | 00079 _AudioTrack * ma_sound; 42 | 00081 unsigned int m_nSound; 43 | 00083 RtAudio m_dac; 44 | 00084 45 | 00086 static int cbMix(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *data) { 46 | 00087 return static_cast<DeviceAudioRt*>(data)->mixOutputFloat((signed short*)outputBuffer, nFrames); } 47 | 00088 }; 48 |
51 | © 2009-02-04 by Gerald Franz, www.viremo.de 52 | | 53 |54 | impressum 55 | | 56 | 57 |
11 | #include "proAudio.h"
12 | #include <RtAudio.h>
13 | #include <map>
14 |
15 |
16 | Go to the source code of this file.
Classes | |
class | DeviceAudioRt |
an rtAudio based stereo audio mixer/playback device More... |
26 |
31 | © 2009-02-04 by Gerald Franz, www.viremo.de 32 | | 33 |34 | impressum 35 | | 36 | 37 |
00001 #ifndef _AUDIO_SDL_H 10 | 00002 #define _AUDIO_SDL_H 11 | 00003 12 | 00004 extern "C" { 13 | 00005 #include <SDL_audio.h> 14 | 00006 }; 15 | 00007 #include "proAudio.h" 16 | 00008 #include <map> 17 | 00009 18 | 00016 //--- class DeviceAudioSdl ----------------------------------------- 19 | 00017 20 | 00019 class _AudioTrack; 21 | 00020 22 | 00022 class DeviceAudioSdl : public DeviceAudio { 23 | 00023 public: 24 | 00025 25 | 00032 static DeviceAudio* create(unsigned int nTracks=8, unsigned int frequency=22050, unsigned int chunkSize=1024); 26 | 00033 27 | 00035 virtual unsigned int sampleFromMemory(const AudioSample & sample, float volume=1.0f); 28 | 00037 virtual bool sampleDestroy(unsigned int sample); 29 | 00038 30 | 00040 31 | 00046 virtual unsigned int soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f ); 32 | 00054 virtual unsigned int soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f ); 33 | 00056 34 | 00062 virtual bool soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f ); 35 | 00064 virtual bool soundStop(unsigned int sound); 36 | 00066 virtual void soundStop(); 37 | 00068 virtual unsigned int soundActive() const; 38 | 00069 protected: 39 | 00071 DeviceAudioSdl(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize); 40 | 00073 virtual ~DeviceAudioSdl(); 41 | 00075 SDL_AudioSpec m_spec; 42 | 00077 std::map<unsigned int, _AudioTrack> mm_sample; 43 | 00079 unsigned int m_sampleCounter; 44 | 00081 bool m_isDesiredFormat; 45 | 00082 46 | 00084 _AudioTrack * ma_sound; 47 | 00086 unsigned int m_nSound; 48 | 00087 49 | 00089 static void cbOutput(void *userData, Uint8 *stream, int len); 50 | 00091 void mixOutputFloat(signed short *outputBuffer, unsigned int nFrames); 51 | 00093 void mixOutputSInt(Uint8 *stream, int len); 52 | 00094 }; 53 | 00095 54 | 00096 #endif // _AUDIO_SDL_H 55 |
58 | © 2009-02-04 by Gerald Franz, www.viremo.de 59 | | 60 |61 | impressum 62 | | 63 | 64 |
11 | #include <SDL_audio.h>
12 | #include "proAudio.h"
13 | #include <map>
14 |
15 |
16 | Go to the source code of this file.
Classes | |
class | DeviceAudioSdl |
SDL based stereo audio mixer/playback device. More... |
26 |
31 | © 2009-02-04 by Gerald Franz, www.viremo.de 32 | | 33 |34 | impressum 35 | | 36 | 37 |
12 |
require("proAudioRt")
13 | All API calls are collected in the global table proAudio. Therefore, proteaAudio is initialized (using the default parameters) by the following call:
14 |
proAudio.create()
15 | After that the individual methods and functions may be called analogous to the C++ interface of class DeviceAudio.
proAudio.create( tracks = 8, frequency = 22050, chunkSize = 1024 )initializes audio playback device
18 | Parameters:
21 | Returns: true in case the device initialization was successful
22 |
proAudio.destroy( )closes audio device and terminates playback
23 | Returns: true in case the device was successfully closed
24 |
proAudio.loaderAvailable ( suffix )returns true in case a loader for this file type is available
25 |
proAudio.volume ( left, [ right ] )sets master volume, either for both channels uniformly, or individually
26 |
proAudio.sleep( seconds )Suspends the execution of the current thread for a definable number of seconds. Note that audio mixing and playback runs in its own background thread and is therefore not affected by this auxiliary call.
27 |
proAudio.sampleFromFile ( filename, volume = 1.0 )loads a sound sample from file, optionally adjusts volume, returns handle
28 |
proAudio.sampleFromMemory ( data, sampleRate )converts an array of numeric data into a sound sample having the defined sample rate, returns handle
29 |
proAudio.sampleDestroy ( sample )deletes a previously created sound sample resource identified by its handle
30 |
duration, channels, sampleRate, bitsPerSample = proAudio.sampleProperties ( sample )returns properties of a sample identified by its handle
31 |
proAudio.soundActive ( )returns number of currently active sounds
32 |
proAudio.soundLoop ( sample, volumeL = 1.0, volumeR = 1.0, disparity = 0.0, pitch = 1.0 )plays a specified sound sample continuously and sets its parameters
33 | Parameters:
36 | Returns: a handle to the currently played sound or -1 in case of error
37 |
proAudio.soundPlay ( sample, volumeL = 1.0, volumeR = 1.0, disparity = 0.0, pitch = 1.0 )plays a specified sound sample once and sets its parameters
38 | Parameters:
41 | Returns: a handle to the currently played sound or -1 in case of error
42 |
proAudio.soundStop ( [ sound ] )stops a specified sound immediately, if a sound handle is passed, or stops all sounds
43 |
proAudio.soundUpdate ( sound, volumeL, volumeR, disparity = 0.0, pitch = 1.0 )updates parameters of a specified sound
44 | Parameters:
47 | Returns: true in case the parameters have been updated successfully
50 | -- create an audio device using default parameters or exit in case of errors 51 | require("proAudioRt") 52 | if not proAudio.create() then os.exit(1) end
53 |
-- load and play a sample: 54 | sample = proAudio.sampleFromFile("sample.ogg") 55 | if sample then proAudio.soundPlay(sample) end
56 |
-- wait until the sound has finished: 57 | while proAudio.soundActive()>0 do 58 | proAudio.sleep(0.05) 59 | end
60 |
-- close audio device 61 | proAudio.destroy() 62 |
65 |
proAudio.sampleFromMemory(data, sampleRate)
66 | The data parameter has to be a table reference containing an array of numeric PCM data ranging from -1.0 to +1.0. The sampleRate parameter defines the number of samples per second. Typical sample rates are 22050 or 44100. Note that for obtaining good qualities when doing dynamic pitch shifts high sample rates (up to 88200) are recommended.
69 | -- function creating a sine wave sample: 70 | function sampleSine(freq, duration, sampleRate) 71 | local data = { } 72 | for i = 1,duration*sampleRate do 73 | data[i] = math.sin( (i*freq/sampleRate)*math.pi*2) 74 | end 75 | return proAudio.sampleFromMemory(data, sampleRate) 76 | end
77 |
-- plays a sample shifted by a number of halftones for a definable period of time 78 | function playNote(sample, pitch, duration, volumeL, volumeR, disparity) 79 | local scale = 2^(pitch/12) 80 | local sound = proAudio.soundLoop(sample, volumeL, volumeR, disparity, scale) 81 | proAudio.sleep(duration) 82 | proAudio.soundStop(sound) 83 | end
84 |
-- create an audio device using default parameters and exit in case of errors 85 | require("proAudioRt") 86 | if not proAudio.create() then os.exit(1) end
87 |
-- generate a sample: 88 | local sample = sampleSine(440, 0.5, 88200)
89 |
-- play scale (a major): 90 | local duration = 0.5 91 | for i,note in ipairs({ 0, 2, 4, 5, 7, 9, 11, 12 }) do 92 | playNote(sample, note, duration) 93 | end
94 |
-- cleanup 95 | proAudio.destroy() 96 |
103 | © 2009-02-04 by Gerald Franz, www.viremo.de 104 | | 105 |106 | impressum 107 | | 108 | 109 |
4 | © 2009-02-04 by Gerald Franz, www.viremo.de 5 | | 6 |7 | impressum 8 | | 9 | 10 |