├── .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 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 24 | 27 | 30 | 33 | 36 | 39 | 52 | 55 | 58 | 61 | 69 | 72 | 75 | 78 | 81 | 84 | 87 | 90 | 93 | 94 | 100 | 103 | 106 | 109 | 112 | 115 | 124 | 127 | 130 | 133 | 142 | 145 | 148 | 151 | 154 | 157 | 160 | 163 | 166 | 167 | 168 | 169 | 170 | 171 | 176 | 179 | 180 | 183 | 184 | 187 | 188 | 191 | 192 | 193 | 198 | 199 | 204 | 207 | 208 | 211 | 212 | 215 | 216 | 219 | 220 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /build/proteaAudio.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual C++ Express 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "proAudio", "proAudio.vcproj", "{8DC73909-327A-45CD-93CA-7BA09993357E}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {8DC73909-327A-45CD-93CA-7BA09993357E}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {8DC73909-327A-45CD-93CA-7BA09993357E}.Debug|Win32.Build.0 = Debug|Win32 14 | {8DC73909-327A-45CD-93CA-7BA09993357E}.Release|Win32.ActiveCfg = Release|Win32 15 | {8DC73909-327A-45CD-93CA-7BA09993357E}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | /** \page Changelog Changelog 2 | 3 | \section v062 Version 0.6.2 (2009-02-04) 4 | - switch to new rtAudio version 4.0.5 5 | - additional includes to support also newer versions of gcc/g++ 6 | - proteaAudio zip archives expand to single folders 7 | */ -------------------------------------------------------------------------------- /doc/annotated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proteaAudio Class List

Here are the classes, structs, unions and interfaces with brief descriptions: 10 | 11 | 12 | 13 | 14 |
AudioSampleClass representing an audio sample
DeviceAudioAbstract base class for stereo audio mixer/playback devices
DeviceAudioRtRtAudio based stereo audio mixer/playback device
DeviceAudioSdlSDL based stereo audio mixer/playback device
15 |
16 | 17 | 20 | 23 | 24 |
18 | © 2009-02-04 by Gerald Franz, www.viremo.de 19 | 21 | impressum 22 |
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/changelog.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

Changelog

10 | Version 0.6.2 (2009-02-04)

11 | 13 |
14 | 15 | 18 | 21 | 22 |
16 | © 2009-02-04 by Gerald Franz, www.viremo.de 17 | 19 | impressum 20 |
23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /doc/class_audio_sample-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

AudioSample Member List

This is the complete list of members for AudioSample, including all inherited members.

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
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_bitsPerSampleAudioSample [protected]
m_channelsAudioSample [protected]
m_dataAudioSample [protected]
m_sampleRateAudioSample [protected]
m_sizeAudioSample [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]

32 | 33 | 36 | 39 | 40 |
34 | © 2009-02-04 by Gerald Franz, www.viremo.de 35 | 37 | impressum 38 |
41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /doc/class_device_audio-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

DeviceAudio Member List

This is the complete list of members for DeviceAudio, including all inherited members.

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
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_freqOutDeviceAudio [protected]
m_volLDeviceAudio [protected]
m_volRDeviceAudio [protected]
mm_loaderDeviceAudio [protected]
s_instanceDeviceAudio [protected, static]
sample(unsigned int handle) const DeviceAudio [inline, virtual]
sampleDestroy(unsigned int sample)=0DeviceAudio [pure virtual]
sampleFromFile(const std::string &filename, float volume=1.0f)DeviceAudio [virtual]
sampleFromMemory(const AudioSample &sample, float volume=1.0f)=0DeviceAudio [pure virtual]
singleton()DeviceAudio [inline, static]
soundActive() const =0DeviceAudio [pure virtual]
soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f)=0DeviceAudio [pure virtual]
soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f)=0DeviceAudio [pure virtual]
soundStop(unsigned int sound)=0DeviceAudio [pure virtual]
soundStop()=0DeviceAudio [pure virtual]
soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f)=0DeviceAudio [pure virtual]
volume(float left, float right)DeviceAudio [inline]
volume(float leftAndRight)DeviceAudio [inline]
~DeviceAudio()DeviceAudio [inline, protected, virtual]

34 | 35 | 38 | 41 | 42 |
36 | © 2009-02-04 by Gerald Franz, www.viremo.de 37 | 39 | impressum 40 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /doc/class_device_audio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkl1337/proteaAudio/08178b5d9859defd42ff6a156a476d0f60337b6f/doc/class_device_audio.png -------------------------------------------------------------------------------- /doc/class_device_audio_rt-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

DeviceAudioRt Member List

This is the complete list of members for DeviceAudioRt, including all inherited members.

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
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_dacDeviceAudioRt [protected]
m_freqOutDeviceAudio [protected]
m_nSoundDeviceAudioRt [protected]
m_sampleCounterDeviceAudioRt [protected]
m_volLDeviceAudio [protected]
m_volRDeviceAudio [protected]
ma_soundDeviceAudioRt [protected]
mixOutputFloat(signed short *outputBuffer, unsigned int nFrames)DeviceAudioRt [protected]
mm_loaderDeviceAudio [protected]
mm_sampleDeviceAudioRt [protected]
s_instanceDeviceAudio [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]

44 | 45 | 48 | 51 | 52 |
46 | © 2009-02-04 by Gerald Franz, www.viremo.de 47 | 49 | impressum 50 |
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /doc/class_device_audio_rt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkl1337/proteaAudio/08178b5d9859defd42ff6a156a476d0f60337b6f/doc/class_device_audio_rt.png -------------------------------------------------------------------------------- /doc/class_device_audio_sdl-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

DeviceAudioSdl Member List

This is the complete list of members for DeviceAudioSdl, including all inherited members.

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
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_freqOutDeviceAudio [protected]
m_isDesiredFormatDeviceAudioSdl [protected]
m_nSoundDeviceAudioSdl [protected]
m_sampleCounterDeviceAudioSdl [protected]
m_specDeviceAudioSdl [protected]
m_volLDeviceAudio [protected]
m_volRDeviceAudio [protected]
ma_soundDeviceAudioSdl [protected]
mixOutputFloat(signed short *outputBuffer, unsigned int nFrames)DeviceAudioSdl [protected]
mixOutputSInt(Uint8 *stream, int len)DeviceAudioSdl [protected]
mm_loaderDeviceAudio [protected]
mm_sampleDeviceAudioSdl [protected]
s_instanceDeviceAudio [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]

46 | 47 | 50 | 53 | 54 |
48 | © 2009-02-04 by Gerald Franz, www.viremo.de 49 | 51 | impressum 52 |
55 |
56 | 57 | 58 | -------------------------------------------------------------------------------- /doc/class_device_audio_sdl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkl1337/proteaAudio/08178b5d9859defd42ff6a156a476d0f60337b6f/doc/class_device_audio_sdl.png -------------------------------------------------------------------------------- /doc/files.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proteaAudio File List

Here is a list of all documented files with brief descriptions: 10 | 11 | 12 | 13 |
proAudio.h [code]Public interface of proteaAudio
proAudioRt.h [code]RtAudio backend of proteaAudio
proAudioSdl.h [code]SDL backend of proteaAudio
14 |
15 | 16 | 19 | 22 | 23 |
17 | © 2009-02-04 by Gerald Franz, www.viremo.de 18 | 20 | impressum 21 |
24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /doc/functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |
All | Functions | Variables
10 |
a | b | c | d | f | l | m | r | s | v | ~
11 | 12 |

13 | Here is a list of all documented class members with links to the class documentation for each member: 14 |

15 |

- a -

18 |

- b -

22 |

- c -

28 |

- d -

35 |

- f -

38 |

- l -

43 |

- m -

63 |

- r -

66 |

- s -

82 |

- v -

85 |

- ~ -

91 |
92 | 93 | 96 | 99 | 100 |
94 | © 2009-02-04 by Gerald Franz, www.viremo.de 95 | 97 | impressum 98 |
101 |
102 | 103 | 104 | -------------------------------------------------------------------------------- /doc/functions_func.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |
All | Functions | Variables
10 |
a | b | c | d | f | l | m | r | s | v | ~
11 | 12 |

13 | 14 |

15 |

- a -

18 |

- b -

22 |

- c -

28 |

- d -

35 |

- f -

38 |

- l -

43 |

- m -

47 |

- r -

50 |

- s -

65 |

- v -

68 |

- ~ -

74 |
75 | 76 | 79 | 82 | 83 |
77 | © 2009-02-04 by Gerald Franz, www.viremo.de 78 | 80 | impressum 81 |
84 |
85 | 86 | 87 | -------------------------------------------------------------------------------- /doc/functions_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |
All | Functions | Variables
10 | 11 |

12 |

31 |
32 | 33 | 36 | 39 | 40 |
34 | © 2009-02-04 by Gerald Franz, www.viremo.de 35 | 37 | impressum 38 |
41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /doc/hierarchy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proteaAudio Class Hierarchy

This inheritance list is sorted roughly, but not completely, alphabetically: 17 |
18 | 19 | 22 | 25 | 26 |
20 | © 2009-02-04 by Gerald Franz, www.viremo.de 21 | 23 | impressum 24 |
27 |
28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proteaAudio Documentation

10 |

11 |

v0.6.2

12 | Overview

13 | proteaAudio is a free cross-platform 2D audio library for C++ and Lua.

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).

17 | Main features at a glance

18 | 20 |

21 | Download

22 | 24 |

25 | Documentation

26 | 28 |

29 | Links

30 | proteaAudio internally makes use of the following excellent open-source components:

31 |

33 |

34 | License notice (zlib license):

35 | (c) 2009 by Gerald Franz, www.viremo.de

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 |

    39 |
  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.
40 |
41 | 42 | 45 | 48 | 49 |
43 | © 2009-02-04 by Gerald Franz, www.viremo.de 44 | 46 | impressum 47 |
50 |
51 | 52 | 53 | -------------------------------------------------------------------------------- /doc/pages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proteaAudio Related Pages

Here is a list of all related documentation pages: 15 |
16 | 17 | 20 | 23 | 24 |
18 | © 2009-02-04 by Gerald Franz, www.viremo.de 19 | 21 | impressum 22 |
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/pro_audio_8h-source.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proAudio.h

Go to the documentation of this file.
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 | 
89 | 90 | 93 | 96 | 97 |
91 | © 2009-02-04 by Gerald Franz, www.viremo.de 92 | 94 | impressum 95 |
98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /doc/pro_audio_8h.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proAudio.h File Reference

Public interface of proteaAudio. More... 10 |

11 | #include <string>
12 | #include <map>
13 | 14 |

15 | Go to the source code of this file. 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |

Classes

class  AudioSample
 class representing an audio sample More...
class  DeviceAudio
 abstract base class for stereo audio mixer/playback devices More...
25 |


Detailed Description

26 | Public interface of proteaAudio. 27 |

28 | Contains the declaration of the audio sample class and the abstract base class for audio mixer/playback devices

29 |

Author:
Gerald Franz, www.viremo.de
30 |
Version:
0.6
31 | License notice (zlib license):

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.

36 | 37 | 40 | 43 | 44 |
38 | © 2009-02-04 by Gerald Franz, www.viremo.de 39 | 41 | impressum 42 |
45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /doc/pro_audio_rt_8h-source.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proAudioRt.h

Go to the documentation of this file.
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 | 
49 | 50 | 53 | 56 | 57 |
51 | © 2009-02-04 by Gerald Franz, www.viremo.de 52 | 54 | impressum 55 |
58 |
59 | 60 | 61 | -------------------------------------------------------------------------------- /doc/pro_audio_rt_8h.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proAudioRt.h File Reference

RtAudio backend of proteaAudio. More... 10 |

11 | #include "proAudio.h"
12 | #include <RtAudio.h>
13 | #include <map>
14 | 15 |

16 | Go to the source code of this file. 17 | 18 | 19 | 20 | 21 | 22 |

Classes

class  DeviceAudioRt
 an rtAudio based stereo audio mixer/playback device More...
23 |


Detailed Description

24 | RtAudio backend of proteaAudio. 25 |

26 |

Author:
Gerald Franz, www.viremo.de
27 |
Version:
0.6
28 |
29 | 30 | 33 | 36 | 37 |
31 | © 2009-02-04 by Gerald Franz, www.viremo.de 32 | 34 | impressum 35 |
38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /doc/pro_audio_sdl_8h-source.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proAudioSdl.h

Go to the documentation of this file.
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 | 
56 | 57 | 60 | 63 | 64 |
58 | © 2009-02-04 by Gerald Franz, www.viremo.de 59 | 61 | impressum 62 |
65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /doc/pro_audio_sdl_8h.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proAudioSdl.h File Reference

SDL backend of proteaAudio. More... 10 |

11 | #include <SDL_audio.h>
12 | #include "proAudio.h"
13 | #include <map>
14 | 15 |

16 | Go to the source code of this file. 17 | 18 | 19 | 20 | 21 | 22 |

Classes

class  DeviceAudioSdl
 SDL based stereo audio mixer/playback device. More...
23 |


Detailed Description

24 | SDL backend of proteaAudio. 25 |

26 |

Author:
Gerald Franz, www.viremo.de
27 |
Version:
2.0
28 |
29 | 30 | 33 | 36 | 37 |
31 | © 2009-02-04 by Gerald Franz, www.viremo.de 32 | 34 | impressum 35 |
38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /doc/protea.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Helvetica,sans-serif; 3 | color: black; 4 | background-color: white; 5 | margin: 30px 50px 50px 50px; 6 | text-align: left; 7 | width: 640px; 8 | font-size: 90%; 9 | } 10 | 11 | h1, h2, h3, h4, h5, h6 { 12 | color: maroon; 13 | } 14 | 15 | h1 { 16 | font-size: 150%; 17 | } 18 | 19 | h2 { 20 | margin: 25px 0px 10px 0px; 21 | font-size: 110%; 22 | } 23 | 24 | a:link, a:visited, a:link:active { 25 | text-decoration: none; 26 | color: maroon; 27 | } 28 | 29 | a:link:hover, a:visited:hover { 30 | text-decoration: underline; 31 | color: red; 32 | } 33 | 34 | p, ul { 35 | font-size: 90%; 36 | } 37 | 38 | pre { 39 | background-color: #DDD; 40 | width: 100%; 41 | font-weight: bold; 42 | } 43 | 44 | 45 | 46 | CAPTION { font-weight: bold } 47 | DIV.qindex { 48 | font-size: 90%; 49 | width: 100%; 50 | border-bottom: 1px solid #b0b0b0; 51 | margin: 2px; 52 | padding: 2px; 53 | line-height: 140%; 54 | } 55 | 56 | TD { 57 | font-size: 90%; 58 | } 59 | TABLE.mdtable { 60 | background-color: #DDD; 61 | width: 100%; 62 | } 63 | TD.md { 64 | font-weight: bold; 65 | } 66 | TD.mdPrefix { 67 | color: #606060; 68 | } 69 | TD.mdname { 70 | font-weight: bold; 71 | color: #602020; 72 | } 73 | 74 | DIV.groupHeader { 75 | margin-left: 16px; 76 | margin-top: 12px; 77 | margin-bottom: 6px; 78 | font-weight: bold; 79 | } 80 | DIV.groupText { margin-left: 16px; font-style: italic; font-size: 90% } 81 | TD.indexkey { 82 | font-weight: bold; 83 | padding-right : 10px; 84 | padding-top : 2px; 85 | padding-left : 10px; 86 | padding-bottom : 2px; 87 | margin-left : 0px; 88 | margin-right : 0px; 89 | margin-top : 2px; 90 | margin-bottom : 2px; 91 | border-top: 1px solid #CCCCCC; 92 | border-bottom: 1px solid #CCCCCC; 93 | } 94 | TD.indexvalue { 95 | font-style: italic; 96 | padding-right : 10px; 97 | padding-top : 2px; 98 | padding-left : 10px; 99 | padding-bottom : 2px; 100 | margin-left : 0px; 101 | margin-right : 0px; 102 | margin-top : 2px; 103 | margin-bottom : 2px; 104 | border-top: 1px solid #CCCCCC; 105 | border-bottom: 1px solid #CCCCCC; 106 | } 107 | TR.memlist { 108 | background-color: #DDD; 109 | } 110 | SPAN.keyword { color: #008000 } 111 | SPAN.keywordtype { color: #604020 } 112 | SPAN.keywordflow { color: #e08000 } 113 | SPAN.comment { color: #800000 } 114 | SPAN.preprocessor { color: #806020 } 115 | SPAN.stringliteral { color: #002080 } 116 | SPAN.charliteral { color: #008080 } 117 | -------------------------------------------------------------------------------- /doc/proteaAudio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkl1337/proteaAudio/08178b5d9859defd42ff6a156a476d0f60337b6f/doc/proteaAudio.png -------------------------------------------------------------------------------- /doc/proteaaudiolua.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | 8 |
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages
9 |

proteaAudio Lua API

10 | Overview

11 | Lua is a lightweight yet powerful dynamic language. proteaAudio contains almost complete Lua bindings that widely correspond to the C++ API. By default, the proteaAudio Lua bindings are compiled to a dynamic library based on the RtAudio backend which is imported via the following statement:

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.

16 | Functions

17 |
proAudio.create( tracks = 8, frequency = 22050, chunkSize = 1024 )
initializes audio playback device

18 | Parameters:

20 |

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:

35 |

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:

40 |

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:

46 |

47 | Returns: true in case the parameters have been updated successfully

48 | Example 1

49 |
 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 | 

63 | Dynamic creation of audio samples

64 | There is no equivalent to the C++ AudioSample class in the proteaAudio Lua API. However, mono audio samples may be dynamically created by the following call:

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.

67 | Example 2

68 |
 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 | 

97 | Limitations

98 | 100 |
101 | 102 | 105 | 108 | 109 |
103 | © 2009-02-04 by Gerald Franz, www.viremo.de 104 | 106 | impressum 107 |
110 |
111 | 112 | 113 | -------------------------------------------------------------------------------- /example.cpp: -------------------------------------------------------------------------------- 1 | #include "proAudioRt.h" 2 | 3 | int main( int argc, char **argv ) { 4 | // create an audio device using the RtAudio backend and default parameters: 5 | DeviceAudio* audio=DeviceAudioRt::create(); 6 | if(!audio) return 1; // exit in case of errors 7 | 8 | // load and play a sample: 9 | unsigned int sample = audio->sampleFromFile("sample.ogg"); 10 | if(sample) audio->soundPlay(sample); 11 | 12 | // wait until the sound has finished: 13 | while(audio->soundActive()); // for the sake of simplicity busy waiting instead of a preferable sleep() call 14 | 15 | // cleanup and exit: 16 | audio->destroy(); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /example.lua: -------------------------------------------------------------------------------- 1 | -- create an audio device using default parameters and exit in case of errors 2 | require("proAudioRt") 3 | if not proAudio.create() then os.exit(1) end 4 | 5 | -- load and play a sample: 6 | sample = proAudio.sampleFromFile("sample.ogg") 7 | if sample then proAudio.soundPlay(sample) end 8 | 9 | -- wait until the sound has finished: 10 | while proAudio.soundActive()>0 do 11 | proAudio.sleep(0.05) 12 | end 13 | 14 | -- close audio device 15 | proAudio.destroy() 16 | -------------------------------------------------------------------------------- /footer.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 6 | 9 | 10 |
4 | © 2009-02-04 by Gerald Franz, www.viremo.de 5 | 7 | impressum 8 |
11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | proteaAudio 4 | 5 | 6 |
7 | -------------------------------------------------------------------------------- /lua.txt: -------------------------------------------------------------------------------- 1 | /** \page proteaAudioLua proteaAudio Lua API 2 | 3 | 4 | 5 | \section intro Overview 6 | Lua is a lightweight yet powerful dynamic language. proteaAudio contains almost complete Lua bindings that widely correspond to the C++ API. By default, the proteaAudio Lua bindings are compiled to a dynamic library based on the RtAudio backend which is imported via the following statement: 7 | 8 |
require("proAudioRt")
9 | 10 | All API calls are collected in the global table proAudio. Therefore, proteaAudio is initialized (using the default parameters) by the following call: 11 | 12 |
proAudio.create()
13 | 14 | After that the individual methods and functions may be called analogous to the C++ interface of class DeviceAudio. 15 | 16 | 17 | 18 | \section functions Functions 19 | 20 |
proAudio.create( tracks = 8, frequency = 22050, chunkSize = 1024 )
21 | initializes audio playback device 22 | 23 | Parameters: 24 | - tracks (optional) number of sounds that can be played in parallel 25 | - frequency (optional) playback frequency 26 | - chunkSize (optional) size of the internal buffer in bytes. Note that a small chunkSize results in low playback latency, but may cause computational overhead and hick-ups under higher system load 27 | 28 | Returns: 29 | true in case the device initialization was successful 30 | 31 |
proAudio.destroy( )
32 | closes audio device and terminates playback 33 | 34 | Returns: 35 | true in case the device was successfully closed 36 | 37 |
proAudio.loaderAvailable ( suffix )
38 | returns true in case a loader for this file type is available 39 | 40 |
proAudio.volume 	(  left, [ right ] )
41 | sets master volume, either for both channels uniformly, or individually 42 | 43 |
proAudio.sleep( seconds )
44 | 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. 45 | 46 |
proAudio.sampleFromFile (  filename, volume = 1.0 )
47 | loads a sound sample from file, optionally adjusts volume, returns handle 48 | 49 |
proAudio.sampleFromMemory ( data, sampleRate )
50 | converts an array of numeric data into a sound sample having the defined sample rate, returns handle 51 | 52 |
proAudio.sampleDestroy ( sample )
53 | deletes a previously created sound sample resource identified by its handle 54 | 55 |
duration, channels, sampleRate, bitsPerSample = proAudio.sampleProperties ( sample )
56 | returns properties of a sample identified by its handle 57 | 58 |
proAudio.soundActive ( )
59 | returns number of currently active sounds 60 | 61 |
proAudio.soundLoop ( sample, volumeL = 1.0, volumeR = 1.0, disparity = 0.0, pitch = 1.0 )
62 | plays a specified sound sample continuously and sets its parameters 63 | 64 | Parameters: 65 | - sample handle of a previously loaded sample 66 | - volumeL (optional) left volume 67 | - volumeR (optional) right volume 68 | - disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 69 | - pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 70 | 71 | Returns: 72 | a handle to the currently played sound or -1 in case of error 73 | 74 |
proAudio.soundPlay ( sample, volumeL = 1.0, volumeR = 1.0, disparity = 0.0, pitch = 1.0 )
75 | plays a specified sound sample once and sets its parameters 76 | 77 | Parameters: 78 | - sample handle of a previously loaded sample 79 | - volumeL (optional) left volume 80 | - volumeR (optional) right volume 81 | - disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 82 | - pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 83 | 84 | Returns: 85 | a handle to the currently played sound or -1 in case of error 86 | 87 |
proAudio.soundStop 	(  [ sound ] ) 
88 | stops a specified sound immediately, if a sound handle is passed, or stops all sounds 89 | 90 |
proAudio.soundUpdate ( sound, volumeL, volumeR, disparity = 0.0, pitch = 1.0 )
91 | updates parameters of a specified sound 92 | 93 | Parameters: 94 | - sound handle of a currently active sound 95 | - volumeL left volume 96 | - volumeR right volume 97 | - disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 98 | - pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 99 | 100 | Returns: 101 | true in case the parameters have been updated successfully 102 | 103 | 104 | 105 | \section example1 Example 1 106 | 107 |
108 | -- create an audio device using default parameters or exit in case of errors
109 | require("proAudioRt")
110 | if not proAudio.create() then os.exit(1) end
111 | 
112 | -- load and play a sample:
113 | sample = proAudio.sampleFromFile("sample.ogg")
114 | if sample then proAudio.soundPlay(sample) end
115 | 
116 | -- wait until the sound has finished:
117 | while proAudio.soundActive()>0 do
118 |   proAudio.sleep(0.05)
119 | end
120 | 
121 | -- close audio device
122 | proAudio.destroy()
123 | 
124 | 125 | \section dynSamples Dynamic creation of audio samples 126 | 127 | There is no equivalent to the C++ AudioSample class in the proteaAudio Lua API. However, mono audio samples may be dynamically created by the following call: 128 | 129 |
proAudio.sampleFromMemory(data, sampleRate)
130 | 131 | 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. 132 | 133 | \section example2 Example 2 134 | 135 |
136 | -- function creating a sine wave sample:
137 | function sampleSine(freq, duration, sampleRate)
138 | 	local data = { }
139 | 	for i = 1,duration*sampleRate do
140 | 		data[i] = math.sin( (i*freq/sampleRate)*math.pi*2)
141 | 	end
142 | 	return proAudio.sampleFromMemory(data, sampleRate)
143 | end
144 | 
145 | -- plays a sample shifted by a number of halftones for a definable period of time
146 | function playNote(sample, pitch, duration, volumeL, volumeR, disparity)
147 | 	local scale = 2^(pitch/12)
148 | 	local sound = proAudio.soundLoop(sample, volumeL, volumeR, disparity, scale)
149 | 	proAudio.sleep(duration)
150 | 	proAudio.soundStop(sound)
151 | end
152 | 
153 | 
154 | -- create an audio device using default parameters and exit in case of errors
155 | require("proAudioRt")
156 | if not proAudio.create() then os.exit(1) end
157 | 
158 | -- generate a sample:
159 | local sample = sampleSine(440, 0.5, 88200)
160 | 
161 | -- play scale (a major):
162 | local duration = 0.5
163 | for i,note in ipairs({ 0, 2, 4, 5, 7, 9, 11, 12 }) do
164 | 	playNote(sample, note, duration)
165 | end
166 | 
167 | -- cleanup
168 | proAudio.destroy()
169 | 
170 | 171 | \section limitations Limitations 172 | 173 | - The proteaAudio Lua API currently has no equivalent to the C++ API's DeviceAudio::loaderRegister() method. 174 | - no bindings to the SDL backend yet 175 | 176 | */ -------------------------------------------------------------------------------- /playAudioRt.cpp: -------------------------------------------------------------------------------- 1 | #include "proAudioRt.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | // Platform-dependent sleep routines. 8 | #if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ ) 9 | #include 10 | #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) 11 | #else // Unix variants 12 | #include 13 | #define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) ) 14 | #endif 15 | 16 | 17 | int main( int argc, char **argv ) { 18 | if(argc<2) { 19 | fprintf(stderr, "usage: %s audiofile [volumeFactor] [pitchFactor]\n", argv[0]); 20 | return 1; 21 | } 22 | DeviceAudio* audio=DeviceAudioRt::create(); 23 | if(!audio) { 24 | fprintf(stderr, "ERROR opening audio device. Abort.\n"); 25 | return 1; 26 | } 27 | 28 | float volume = (argc>2) ? atof(argv[2]) : 1.0f; 29 | float pitch = (argc>3) ? atof(argv[3]) : 1.0f; 30 | unsigned int sample1=audio->sampleFromFile(argv[1], volume); 31 | if(sample1) audio->soundPlay(sample1, 1.0f,1.0f,0.0f, pitch); 32 | 33 | // main loop: 34 | while(audio->soundActive()) 35 | SLEEP(100); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /playAudioSdl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include "proAudioSdl.h" 7 | 8 | using namespace std; 9 | 10 | //--- main --------------------------------------------------------- 11 | 12 | int main(int argc, char **argv) { 13 | if(argc<2) { 14 | fprintf(stderr, "usage: %s audiofile [volumeFactor] [pitchFactor]\n", argv[0]); 15 | return 1; 16 | } 17 | DeviceAudio* audio=DeviceAudioSdl::create(); 18 | if(!audio) { 19 | fprintf(stderr, "ERROR opening audio device. Abort.\n"); 20 | return 1; 21 | } 22 | 23 | float volume = (argc>2) ? atof(argv[2]) : 1.0f; 24 | float pitch = (argc>3) ? atof(argv[3]) : 1.0f; 25 | unsigned int sample1=audio->sampleFromFile(argv[1], volume); 26 | if(sample1) audio->soundPlay(sample1, 1.0f,1.0f,0.0f, pitch); 27 | 28 | // main loop: 29 | while(audio->soundActive()) 30 | SDL_Delay(10); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /proAudio.cpp: -------------------------------------------------------------------------------- 1 | #include "proAudio.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | //--- class AudioSample -------------------------------------------- 10 | AudioSample::AudioSample(const AudioSample & source) : 11 | m_size(source.m_size), m_channels(source.m_channels), m_sampleRate(source.m_sampleRate), m_bitsPerSample(source.m_bitsPerSample) { 12 | m_data = new unsigned char [m_size]; memcpy(m_data,source.m_data, m_size); 13 | } 14 | 15 | bool AudioSample::bitsPerSample(unsigned short bits) { 16 | if(bits==16) { 17 | if(m_bitsPerSample==8) { 18 | unsigned char* data = new unsigned char[2*m_size]; 19 | for(unsigned int i=0; iCHAR_MAX) *ptr =CHAR_MAX; 52 | else if(valueSHRT_MAX) *ptr =SHRT_MAX; 58 | else if(value1.0f) *ptr=1.0f; 64 | else if(*ptr<-1.0f) *ptr=-1.0f; 65 | } 66 | else fprintf(stderr,"AudioSample::changeVolume ERROR: %i bits per sample not supported.\n",m_bitsPerSample); 67 | } 68 | 69 | AudioSample* AudioSample::readWav(FILE* stream, size_t (*readFunc)( void *, size_t, size_t, FILE *)) { 70 | char id[4]; //four unsigned chars to hold chunk IDs 71 | readFunc(id,sizeof(unsigned char),4,stream); 72 | if (strncmp(id,"RIFF",4)!=0) return 0; 73 | 74 | unsigned int size; 75 | readFunc(&size,sizeof(unsigned int),1,stream); 76 | 77 | readFunc(id,sizeof(unsigned char),4,stream); 78 | if (strncmp(id,"WAVE",4)!=0) return 0; 79 | 80 | unsigned short encoding, block_align, channels, bitsPerSample; 81 | unsigned int chunk_length, byte_rate, sampleRate; 82 | 83 | readFunc(id, sizeof(unsigned char), 4, stream); //read ID 'fmt '; 84 | readFunc(&chunk_length, sizeof(unsigned int),1,stream); // header length, 16 expected 85 | readFunc(&encoding, sizeof(short), 1, stream); // should be "1" for simple PCM data 86 | if(encoding!=1) return 0; 87 | 88 | readFunc(&channels, sizeof(short),1,stream); 89 | readFunc(&sampleRate, sizeof(unsigned int), 1, stream); 90 | readFunc(&byte_rate, sizeof(unsigned int), 1, stream); 91 | readFunc(&block_align, sizeof(short), 1, stream); 92 | readFunc(&bitsPerSample, sizeof(short), 1, stream); 93 | 94 | readFunc(id, sizeof(unsigned char), 4, stream); // read ID 'data' 95 | readFunc(&size, sizeof(unsigned int), 1, stream); 96 | unsigned char *data = new unsigned char[size]; 97 | readFunc(data, sizeof(unsigned char), size, stream); 98 | 99 | return new AudioSample(data,size, channels, sampleRate, bitsPerSample); 100 | } 101 | 102 | AudioSample* AudioSample::loadWav(const std::string & fname) { 103 | #ifdef _MSC_VER 104 | FILE *fp = 0; 105 | fopen_s(&fp, fname.c_str(), "rb"); 106 | #else 107 | FILE *fp = fopen(fname.c_str(), "rb"); 108 | #endif 109 | if (!fp) return 0; 110 | AudioSample * pSample = readWav(fp, fread); 111 | fclose(fp); 112 | return pSample; 113 | } 114 | 115 | //--- class DeviceAudio -------------------------------------------- 116 | 117 | DeviceAudio* DeviceAudio::s_instance=0; 118 | 119 | extern "C" { 120 | extern int stb_vorbis_decode_filename(char *filename, int *channels, int* sample_rate, short **output); 121 | }; 122 | 123 | static AudioSample* loadOgg(const std::string & fname) { 124 | int channels, sampleRate; 125 | short *decoded; 126 | int len = stb_vorbis_decode_filename(const_cast(fname.c_str()), &channels, &sampleRate, &decoded); 127 | if(len<0) return 0; 128 | // convert to AudioSample: 129 | unsigned int size = len*channels*sizeof(short); 130 | unsigned char * data = new unsigned char[size]; 131 | if(!data) return 0; 132 | memcpy(data,decoded, size); 133 | free(decoded); 134 | return new AudioSample(data, size, channels, sampleRate, 16); 135 | } 136 | 137 | static string toLower(const string & s) { 138 | string retStr(s); 139 | for(size_t i=0; i(tolower(retStr[i])); 141 | return retStr; 142 | } 143 | 144 | DeviceAudio::DeviceAudio() : m_freqOut(0), m_volL(1.0f), m_volR(1.0f) { 145 | loaderRegister(AudioSample::loadWav,"wav"); 146 | loaderRegister(loadOgg,"ogg"); 147 | } 148 | 149 | unsigned int DeviceAudio::sampleFromFile(const std::string & filename, float volume) { 150 | if(filename.rfind('.')>filename.size()) return 0; 151 | string suffix=toLower(filename.substr(filename.rfind('.')+1)); 152 | map::iterator it = mm_loader.find(suffix); 153 | if(it==mm_loader.end()) return 0; 154 | AudioSample* pSample = (*(it->second))(filename); 155 | if(!pSample) return 0; 156 | unsigned int ret = sampleFromMemory(*pSample, volume); 157 | delete pSample; 158 | return ret; 159 | } 160 | 161 | bool DeviceAudio::loaderRegister(AudioSample *(*loadFunc)(const std::string &), const std::string & suffix) { 162 | return mm_loader.insert(std::make_pair(toLower(suffix),loadFunc)).second; 163 | } 164 | 165 | bool DeviceAudio::loaderAvailable(const std::string & suffix) const { 166 | return mm_loader.find(toLower(suffix))!=mm_loader.end(); 167 | } 168 | -------------------------------------------------------------------------------- /proAudio.h: -------------------------------------------------------------------------------- 1 | #ifndef _PRO_AUDIO 2 | #define _PRO_AUDIO 3 | 4 | #include 5 | #include 6 | 7 | /** @file proAudio.h 8 | \brief Public interface of proteaAudio 9 | 10 | Contains the declaration of the audio sample class and the abstract base class for audio mixer/playback devices 11 | 12 | \author Gerald Franz, www.viremo.de 13 | \version 0.6 14 | 15 | License notice (zlib license): 16 | 17 | (c) 2009 by Gerald Franz, www.viremo.de 18 | 19 | This software is provided 'as-is', without any express or implied 20 | warranty. In no event will the author be held liable for any damages 21 | arising from the use of this software. 22 | 23 | Permission is granted to anyone to use this software for any purpose, 24 | including commercial applications, and to alter it and redistribute it 25 | freely, subject to the following restrictions: 26 | 27 | 1. The origin of this software must not be misrepresented; you must not 28 | claim that you wrote the original software. If you use this software 29 | in a product, an acknowledgment in the product documentation would be 30 | appreciated but is not required. 31 | 2. Altered source versions must be plainly marked as such, and must not be 32 | misrepresented as being the original software. 33 | 3. This notice may not be removed or altered from any source distribution. 34 | */ 35 | 36 | //--- class AudioSample -------------------------------------------- 37 | /// class representing an audio sample 38 | class AudioSample { 39 | public: 40 | /// constructor from memory data 41 | AudioSample(unsigned char * data, unsigned int size, unsigned short channels, unsigned int sampleRate, unsigned short bitsPerSample) : 42 | m_data(data), m_size(size), m_channels(channels), m_sampleRate(sampleRate), m_bitsPerSample(bitsPerSample) { } 43 | /// copy constructor 44 | AudioSample(const AudioSample & source); 45 | /// destructor 46 | ~AudioSample() { delete[] m_data; } 47 | 48 | /// allows accessing sample data 49 | unsigned char * data() { return m_data; }; 50 | /// allows reading sample data 51 | const unsigned char * data() const { return m_data; }; 52 | /// returns sample size in bytes 53 | unsigned int size() const { return m_size; } 54 | /// returns sample size in number of frames 55 | unsigned int frames() const { return m_size/m_channels/(m_bitsPerSample>>3); } 56 | /// returns size of a single frame in bytes 57 | unsigned int sizeFrame() const { return m_channels*(m_bitsPerSample>>3); } 58 | /// returns number of parallel channels, 1 mono, 2 stereo 59 | unsigned short channels() const { return m_channels; } 60 | /// returns number of frames per second, e.g., 44100, 22050 61 | unsigned int sampleRate() const { return m_sampleRate; } 62 | /// returns number of bits per mono sample, e.g., 8, 16 63 | unsigned short bitsPerSample() const { return m_bitsPerSample; } 64 | /// converts to a different bit rate, e.g., 8, 16 65 | bool bitsPerSample(unsigned short bits); 66 | /// returns number of bytes per sample, e.g., 1, 2 67 | unsigned short bytesPerSample() const { return m_bitsPerSample>>3; } 68 | 69 | /// changes volume by given factor 70 | void volume(float f); 71 | 72 | /// loads a WAV file 73 | static AudioSample* loadWav(const std::string & fname); 74 | /// reads WAV data from a stream via a function compatible to std::fread 75 | static AudioSample* readWav(FILE* stream, size_t (*readFunc)( void *, size_t, size_t, FILE *)); 76 | protected: 77 | /// stores sample data 78 | unsigned char * m_data; 79 | /// sample size in bytes 80 | unsigned int m_size; 81 | /// number of parallel channels, 1 mono, 2 stereo 82 | unsigned short m_channels; 83 | /// number of samples per second, e.g., 44100, 22050 84 | unsigned int m_sampleRate; 85 | /// number of bits per sample, e.g., 8, 16 86 | unsigned short m_bitsPerSample; 87 | }; 88 | 89 | //--- class DeviceAudio -------------------------------------------- 90 | 91 | /// abstract base class for stereo audio mixer/playback devices 92 | class DeviceAudio { 93 | public: 94 | /// returns singleton object 95 | /** This call is only allowed after a successful precedent creation of an audio device */ 96 | static DeviceAudio& singleton() { return *s_instance; } 97 | /// calls the destructor of the singleton object 98 | static void destroy() { if(s_instance) delete s_instance; s_instance=0; }; 99 | 100 | /// sets master volume 101 | void volume(float left, float right) { m_volL=left; m_volR=right; } 102 | /// sets master volume 103 | void volume(float leftAndRight) { m_volL=m_volR=leftAndRight; } 104 | /// registers an audio sample loader function handling a file type identified by suffix 105 | /** The function has to be of type AudioSample * loadXYZ(const std::string & filename).*/ 106 | bool loaderRegister(AudioSample *(*loadFunc)(const std::string &), const std::string & suffix); 107 | /// returns true in case a loader for this file type is available 108 | bool loaderAvailable(const std::string & suffix) const; 109 | 110 | /// loads a sound sample from file, optionally adjusts volume, returns handle 111 | virtual unsigned int sampleFromFile(const std::string & filename, float volume=1.0f); 112 | /// converts a sound sample to internal audio format, returns handle 113 | virtual unsigned int sampleFromMemory(const AudioSample & sample, float volume=1.0f)=0; 114 | /// deletes a previously created sound sample resource identified by its handle 115 | virtual bool sampleDestroy(unsigned int sample)=0; 116 | /// allows read access to a sample identified by its handle 117 | virtual const AudioSample* sample(unsigned int handle) const { return 0; } 118 | 119 | /// plays a specified sound sample once and sets its parameters 120 | /** \param sample handle of a previously loaded sample 121 | \param volumeL (optional) left volume 122 | \param volumeR (optional) right volume 123 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 124 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 125 | \return a handle to the currently played sound or -1 in case of error */ 126 | virtual unsigned int soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f )=0; 127 | /// plays a specified sound sample continuously and sets its parameters 128 | /** \param sample handle of a previously loaded sample 129 | \param volumeL (optional) left volume 130 | \param volumeR (optional) right volume 131 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 132 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 133 | \return a handle to the currently played sound or -1 in case of error */ 134 | virtual unsigned int soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f )=0; 135 | /// updates parameters of a specified sound 136 | /** \param sound handle of a currently active sound 137 | \param volumeL left volume 138 | \param volumeR right volume 139 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 140 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 141 | \return true in case the parameters have been updated successfully */ 142 | virtual bool soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f )=0; 143 | /// stops a specified sound immediately 144 | virtual bool soundStop(unsigned int sound)=0; 145 | /// stops all sounds immediately 146 | virtual void soundStop()=0; 147 | /// returns number of currently active sounds 148 | virtual unsigned int soundActive() const=0; 149 | 150 | protected: 151 | /// constructor 152 | DeviceAudio(); 153 | /// destructor 154 | virtual ~DeviceAudio() { s_instance = 0; } 155 | 156 | /// stores output stream frequency 157 | unsigned int m_freqOut; 158 | /// stores left master volume 159 | float m_volL; 160 | /// stores right master volume 161 | float m_volR; 162 | /// map associating suffixes to loader functions 163 | std::map mm_loader; 164 | 165 | /// pointer to singleton 166 | static DeviceAudio * s_instance; 167 | }; 168 | 169 | #endif // _PRO_AUDIO 170 | -------------------------------------------------------------------------------- /proAudioRt.cpp: -------------------------------------------------------------------------------- 1 | #include "proAudioRt.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | struct _AudioTrack { 11 | /// sample 12 | AudioSample * sample; 13 | 14 | /// position in sample in frames 15 | unsigned int dpos; 16 | /// length of sample in frames 17 | unsigned int dlen; 18 | /// disparity in seconds between left and right, normally 0.0f 19 | float disparity; 20 | /// left volume 21 | float volL; 22 | /// right volume 23 | float volR; 24 | /// pitch factor, normally 1.0f 25 | float pitch; 26 | /// stores whether sample has to be looped 27 | bool isLoop; 28 | /// stores whether sample is currently playing 29 | bool isPlaying; 30 | }; 31 | 32 | DeviceAudio* DeviceAudioRt::create(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize) { 33 | if(!s_instance) { 34 | DeviceAudioRt* pAudio = new DeviceAudioRt(nTracks,frequency,chunkSize); 35 | if(!pAudio->m_freqOut) delete pAudio; 36 | else s_instance = pAudio; 37 | } 38 | return s_instance; 39 | } 40 | 41 | DeviceAudioRt::DeviceAudioRt(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize) 42 | : DeviceAudio(), ma_sound(0) { 43 | if ( m_dac.getDeviceCount() < 1 ) { 44 | fprintf(stderr,"DeviceAudioRt ERROR: No audio devices found!\n"); 45 | return; 46 | } 47 | // Set our stream parameters for output only. 48 | RtAudio::StreamParameters oParams; 49 | oParams.deviceId = m_dac.getDefaultOutputDevice(); // default device 50 | oParams.nChannels = 2; // stereo 51 | oParams.firstChannel = 0; 52 | 53 | try { 54 | m_dac.openStream( &oParams, NULL, RTAUDIO_SINT16, frequency, &chunkSize, &cbMix, (void *)this ); 55 | m_dac.startStream(); 56 | } 57 | catch ( RtError& e ) { 58 | fprintf(stderr,"%s\n", e.getMessage().c_str()); 59 | if(m_dac.isStreamOpen()) m_dac.closeStream(); 60 | return; 61 | } 62 | 63 | // initialize tracks: 64 | m_nSound=nTracks; 65 | ma_sound=new _AudioTrack[m_nSound]; 66 | memset(ma_sound,0,m_nSound*sizeof(_AudioTrack)); 67 | m_freqOut = frequency; 68 | } 69 | 70 | DeviceAudioRt::~DeviceAudioRt() { 71 | if(m_dac.isStreamOpen()) m_dac.closeStream(); 72 | delete [] ma_sound; 73 | for( map::iterator it=mm_sample.begin(); it!=mm_sample.end(); ++it) 74 | delete it->second; 75 | mm_sample.clear(); 76 | } 77 | 78 | unsigned int DeviceAudioRt::sampleFromMemory(const AudioSample & sample, float volume) { 79 | AudioSample * pSample = new AudioSample(sample); 80 | if(volume!=1.0f) pSample->volume(volume); 81 | pSample->bitsPerSample(16); 82 | mm_sample.insert(make_pair(++m_sampleCounter,pSample)); 83 | return m_sampleCounter; 84 | } 85 | 86 | bool DeviceAudioRt::sampleDestroy(unsigned int sample) { 87 | // look for sample: 88 | map::iterator iter=mm_sample.find(sample); 89 | if( iter == mm_sample.end() ) return false; 90 | // stop currently playing sounds referring to this sample: 91 | for (unsigned int i=0; isecond) 92 | ma_sound[i].isPlaying=false; 93 | // cleanup: 94 | delete iter->second; 95 | if(iter->first==m_sampleCounter) --m_sampleCounter; 96 | mm_sample.erase(iter); 97 | return true; 98 | } 99 | 100 | const AudioSample* DeviceAudioRt::sample(unsigned int handle) const { 101 | map::const_iterator it=mm_sample.find(handle); 102 | if( it == mm_sample.end() ) return 0; 103 | return it->second; 104 | } 105 | 106 | 107 | unsigned int DeviceAudioRt::soundPlay(unsigned int sample, float volumeL, float volumeR, float disparity, float pitch ) { 108 | // look for sample: 109 | map::iterator iter=mm_sample.find(sample); 110 | if( iter == mm_sample.end() ) return 0; // no sample found 111 | // look for an empty (or finished) sound track 112 | unsigned int i; 113 | for ( i=0; isecond->sampleRate(); 118 | if(sampleRate!=m_freqOut) pitch*=(float)sampleRate/(float)m_freqOut; 119 | 120 | // put the sample data in the slot and play it 121 | ma_sound[i].sample = iter->second; 122 | ma_sound[i].dlen = iter->second->frames(); 123 | ma_sound[i].dpos = 0; 124 | ma_sound[i].volL=volumeL; 125 | ma_sound[i].volR=volumeR; 126 | ma_sound[i].disparity=disparity; 127 | ma_sound[i].pitch=fabs(pitch); 128 | ma_sound[i].isLoop=false; 129 | ma_sound[i].isPlaying=true; 130 | return i+1; 131 | } 132 | 133 | unsigned int DeviceAudioRt::soundLoop(unsigned int sample, float volumeL, float volumeR, float disparity, float pitch ) { 134 | unsigned int ret=soundPlay(sample,volumeL,volumeR,disparity, pitch); 135 | if(ret) ma_sound[ret-1].isLoop=true; 136 | return ret; 137 | } 138 | 139 | bool DeviceAudioRt::soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity, float pitch ) { 140 | if(!sound || (sound>m_nSound) || !ma_sound[sound-1].isPlaying) return false; 141 | ma_sound[--sound].volL=volumeL; 142 | ma_sound[sound].volR=volumeR; 143 | ma_sound[sound].disparity=disparity; 144 | unsigned int sampleRate = ma_sound[sound].sample->sampleRate(); 145 | if(sampleRate!=m_freqOut) pitch*=(float)sampleRate/(float)m_freqOut; 146 | ma_sound[sound].pitch=fabs(pitch); 147 | return true; 148 | } 149 | 150 | bool DeviceAudioRt::soundStop(unsigned int sound) { 151 | if(!sound||(sound>m_nSound)||!ma_sound[sound-1].isPlaying) return false; 152 | ma_sound[sound-1].isPlaying=false; 153 | return true; 154 | } 155 | 156 | void DeviceAudioRt::soundStop() { 157 | for (unsigned int i=0; i(&m_dac)->isStreamRunning() ) return 0; 163 | unsigned int ret = 0, i; 164 | for ( i=0; ichannels(); 175 | if((ma_sound[i].pitch==1.0f)&&!ma_sound[i].disparity) { // use optimized default mixing: 176 | unsigned int currPos=ma_sound[i].dpos+j; 177 | if(ma_sound[i].isLoop) currPos%=ma_sound[i].dlen; 178 | else if(currPos >= ma_sound[i].dlen) continue; 179 | currPos*=ma_sound[i].sample->sizeFrame(); 180 | float dataL = (float)(*((signed short *)(&ma_sound[i].sample->data()[currPos]))); 181 | left += dataL * m_volL*ma_sound[i].volL; 182 | float dataR = (nChannels>1) ? (float)(*((signed short *)(&ma_sound[i].sample->data()[currPos+2]))) : dataL; 183 | right+= dataR * m_volR*ma_sound[i].volR; 184 | } 185 | else { // use nearest sample and disparity: 186 | double fract=ma_sound[i].dpos+j*ma_sound[i].pitch; 187 | unsigned int currPos=(unsigned int)fract; 188 | fract = fmod(fract,1.0); 189 | int currPosL= (ma_sound[i].disparity<0.0f) ? currPos+int(m_freqOut*ma_sound[i].disparity) : currPos; 190 | int currPosR= (ma_sound[i].disparity>0.0f) ? currPos-int(m_freqOut*ma_sound[i].disparity) : currPos; 191 | if(nChannels>1) currPosR+=sizeof(signed short); // use second channel 192 | if(ma_sound[i].isLoop) { 193 | currPosL+=ma_sound[i].dlen; 194 | currPosL%=ma_sound[i].dlen; 195 | currPosR+=ma_sound[i].dlen; 196 | currPosR%=ma_sound[i].dlen; 197 | } 198 | if(currPosL<0) { 199 | // do nothing 200 | } 201 | else if((unsigned int)currPosL+1 < ma_sound[i].dlen) { 202 | currPosL*=ma_sound[i].sample->sizeFrame(); 203 | float dataL = (1.0f-(float)fract)*(float)(*((signed short *)(&ma_sound[i].sample->data()[currPosL]))) 204 | + (float)fract*(float)(*((signed short *)(&ma_sound[i].sample->data()[currPosL+ma_sound[i].sample->sizeFrame()]))); 205 | left += dataL * m_volL*ma_sound[i].volL; 206 | } 207 | else if((unsigned int)currPosL+1 == ma_sound[i].dlen) { 208 | currPosL*=ma_sound[i].sample->sizeFrame(); 209 | float dataL = (float)(*((signed short *)(&ma_sound[i].sample->data()[currPosL]))); 210 | left += dataL * m_volL*ma_sound[i].volL; 211 | } 212 | 213 | if(currPosR<0) { 214 | // do nothing 215 | } 216 | else if((unsigned int)currPosR+1 < ma_sound[i].dlen) { 217 | currPosR*=ma_sound[i].sample->sizeFrame(); 218 | float dataR = (1.0f-(float)fract)*(float)(*((signed short *)(&ma_sound[i].sample->data()[currPosR]))) 219 | + (float)fract*(float)(*((signed short *)(&ma_sound[i].sample->data()[currPosR+ma_sound[i].sample->sizeFrame()]))); 220 | right += dataR * m_volR*ma_sound[i].volR; 221 | } 222 | else if((unsigned int)currPosR+1 == ma_sound[i].dlen) { 223 | currPosR*=ma_sound[i].sample->sizeFrame(); 224 | float dataR = (float)(*((signed short *)(&ma_sound[i].sample->data()[currPosR]))); 225 | right += dataR * m_volR*ma_sound[i].volR; 226 | } 227 | } 228 | } 229 | // clamp and set output: 230 | outputBuffer[2*j] = left>SHRT_MAX ? SHRT_MAX : leftSHRT_MAX ? SHRT_MAX : rightma_sound[i].dlen+2*abs(int(m_freqOut*-ma_sound[i].disparity))) 240 | ma_sound[i].isPlaying=false; 241 | } 242 | return 0; 243 | } 244 | -------------------------------------------------------------------------------- /proAudioRt.h: -------------------------------------------------------------------------------- 1 | #include "proAudio.h" 2 | #include 3 | #include 4 | 5 | /** @file proAudioRt.h 6 | \brief RtAudio backend of proteaAudio 7 | \author Gerald Franz, www.viremo.de 8 | \version 0.6 9 | */ 10 | 11 | struct _AudioTrack; 12 | 13 | /// an rtAudio based stereo audio mixer/playback device 14 | /** DeviceAudioRt offers some advanced features such as dynamic pitch, 15 | independent volume control for both channels, and user-defined time shifts between the channels. */ 16 | class DeviceAudioRt : public DeviceAudio { 17 | public: 18 | ///creates audio device 19 | /** Use this method instead of a constructor. 20 | \param nTracks (optional) the maximum number of sounds that are played parallely. Computation time is linearly correlated to this factor. 21 | \param frequency (optional) sample frequency of the playback in Hz. 22050 corresponds to FM radio 44100 is CD quality. Computation time is linearly correlated to this factor. 22 | \param chunkSize (optional) the number of bytes that are sent to the sound card at once. Low numbers lead to smaller latencies but need more computation time (thread switches). If a too small number is chosen, the sounds might not be played continuously. The default value 512 guarantees a good latency below 40 ms at 22050 Hz sample frequency. 23 | \return a pointer to an audio device object in case of success 24 | Note that the parameters are only handled when calling for the first time. Afterwards always the same object is returned until an explicit destroy() is called. 25 | */ 26 | static DeviceAudio* create(unsigned int nTracks=8, unsigned int frequency=22050, unsigned int chunkSize=1024); 27 | 28 | /// converts a sound sample to internal audio format, returns handle 29 | virtual unsigned int sampleFromMemory(const AudioSample & sample, float volume=1.0f); 30 | /// deletes a previously created sound sample resource identified by its handle 31 | virtual bool sampleDestroy(unsigned int sample); 32 | /// allows read access to a sample identified by its handle 33 | virtual const AudioSample* sample(unsigned int handle) const; 34 | 35 | /// plays a specified sample once and sets its parameters 36 | /** \param sample a sample handle returned by a previous load() call 37 | \param volumeL (optional) left volume 38 | \param volumeR (optional) right volume 39 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 40 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 41 | \return a handle to the currently played sound or 0 in case of error */ 42 | virtual unsigned int soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f ); 43 | /** plays a specified sample continuously and sets its parameters 44 | \param sample a sample handle returned by a previous load() call 45 | \param volumeL (optional) left volume 46 | \param volumeR (optional) right volume 47 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 48 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 49 | \return a handle to the currently played sound or 0 in case of error */ 50 | virtual unsigned int soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f ); 51 | /// updates parameters of a specified sound 52 | /** \param sound handle of a currently active sound 53 | \param volumeL left volume 54 | \param volumeR right volume 55 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 56 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 57 | \return true in case the parameters have been updated successfully */ 58 | virtual bool soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f ); 59 | /// stops a specified sound immediately 60 | virtual bool soundStop(unsigned int sound); 61 | /// stops all sounds immediately 62 | virtual void soundStop(); 63 | /// returns number of currently active sounds 64 | virtual unsigned soundActive() const; 65 | protected: 66 | /// constructor. Use the create() method instead 67 | DeviceAudioRt(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize); 68 | /// destructor. Use the destroy() method instead 69 | virtual ~DeviceAudioRt(); 70 | /// mixes tracks to a single output stream 71 | int mixOutputFloat(signed short *outputBuffer, unsigned int nFrames); 72 | 73 | /// stores loaded sound samples 74 | std::map mm_sample; 75 | /// stores maximum sample id 76 | unsigned int m_sampleCounter; 77 | 78 | /// stores sounds to be mixed 79 | _AudioTrack * ma_sound; 80 | /// stores number of parallel sounds 81 | unsigned int m_nSound; 82 | /// audio manager 83 | RtAudio m_dac; 84 | 85 | /// mixer callback 86 | static int cbMix(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *data) { 87 | return static_cast(data)->mixOutputFloat((signed short*)outputBuffer, nFrames); } 88 | }; 89 | -------------------------------------------------------------------------------- /proAudioRt_lua.cpp: -------------------------------------------------------------------------------- 1 | #if defined __WIN32__ || defined WIN32 2 | # define WINDOWS_LEAN_AND_MEAN 3 | # include 4 | # define _EXPORT __declspec(dllexport) 5 | #else 6 | # include 7 | # define _EXPORT 8 | #endif 9 | 10 | extern "C" { 11 | #include 12 | #include 13 | #include 14 | }; 15 | 16 | #include "proAudioRt.h" 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | static int create(lua_State *L) { 23 | unsigned int nTracks = lua_isnumber(L,1) ? lua_tointeger(L,1) : 8; 24 | unsigned int frequency = lua_isnumber(L,2) ? lua_tointeger(L,2) : 22050; 25 | unsigned int chunkSize = lua_isnumber(L,3) ? lua_tointeger(L,3) : 1024; 26 | DeviceAudio* pAudio = DeviceAudioRt::create(nTracks, frequency, chunkSize); 27 | lua_pushboolean(L, pAudio ? 1 : 0); 28 | return 1; 29 | } 30 | 31 | static int destroy(lua_State *L) { 32 | DeviceAudio::destroy(); 33 | return 0; 34 | } 35 | 36 | static int loaderAvailable(lua_State *L) { 37 | const char * fname = luaL_checkstring(L,1); 38 | DeviceAudio & audio = DeviceAudio::singleton(); 39 | if(!&audio) return 0; 40 | lua_pushboolean(L, audio.loaderAvailable(fname)); 41 | return 1; 42 | } 43 | 44 | static int volume(lua_State *L) { 45 | int argc = lua_gettop(L); 46 | if(!argc) return 0; 47 | DeviceAudio & audio = DeviceAudio::singleton(); 48 | if(!&audio) return 0; 49 | if(argc==1) audio.volume(luaL_checknumber(L,1)); 50 | else audio.volume(luaL_checknumber(L,1),luaL_checknumber(L,2)); 51 | return 0; 52 | } 53 | 54 | static int sleep(lua_State*L) { 55 | double secs = luaL_checknumber(L,1); 56 | #if defined __WIN32__ || defined WIN32 57 | Sleep( (DWORD)(secs*1000.0) ) ; 58 | #else // Unix variants 59 | usleep( (unsigned long) (secs * 1000000.0) ); 60 | #endif 61 | return 0; 62 | } 63 | 64 | static int sampleFromFile(lua_State *L) { 65 | const char * fname = luaL_checkstring(L,1); 66 | DeviceAudio & audio = DeviceAudio::singleton(); 67 | if(!&audio) return 0; 68 | int argc = lua_gettop(L); 69 | float volume = argc>1 ? luaL_checknumber(L,2) : 1.0f; 70 | int ret = (int)audio.sampleFromFile(fname, volume); 71 | if(ret) { 72 | lua_pushinteger(L, ret); 73 | return 1; 74 | } 75 | return 0; 76 | } 77 | 78 | static int sampleFromMemory(lua_State *L) { 79 | int argc = lua_gettop(L); 80 | DeviceAudio & audio = DeviceAudio::singleton(); 81 | if(!&audio||argc<2||!lua_istable(L,1)) return 0; 82 | 83 | size_t len = lua_objlen(L,1); 84 | if(!len) return 0; 85 | int sampleRate = luaL_checkinteger(L,2); 86 | signed short *data = new signed short[len]; 87 | for(size_t i = 0; i=1.0f) data[i] = SHRT_MAX; 93 | else data[i] = (signed short)(value*SHRT_MAX); 94 | } 95 | lua_pop(L,1); 96 | } 97 | AudioSample sample((unsigned char*)data, len*sizeof(signed short), 1, sampleRate, 16); 98 | int ret = (int)audio.sampleFromMemory(sample); 99 | if(ret) { 100 | lua_pushinteger(L, ret); 101 | return 1; 102 | } 103 | return 0; 104 | } 105 | 106 | static int sampleDestroy(lua_State *L) { 107 | DeviceAudio & audio = DeviceAudio::singleton(); 108 | if(!&audio) return 0; 109 | lua_pushboolean(L, audio.sampleDestroy(luaL_checkinteger(L,1))); 110 | return 1; 111 | } 112 | 113 | static int sampleProperties(lua_State *L) { 114 | DeviceAudio & audio = DeviceAudio::singleton(); 115 | if(!&audio) return 0; 116 | const AudioSample *pSample = audio.sample(luaL_checkinteger(L,1)); 117 | if(!pSample) return 0; 118 | lua_pushnumber(L, (double)pSample->frames() / (double)pSample->sampleRate()); 119 | lua_pushinteger(L, pSample->channels()); 120 | lua_pushinteger(L, pSample->sampleRate()); 121 | lua_pushinteger(L, pSample->bitsPerSample()); 122 | return 4; 123 | } 124 | 125 | static int soundPlay(lua_State *L) { 126 | DeviceAudio & audio = DeviceAudio::singleton(); 127 | if(!&audio) return 0; 128 | unsigned int sample = luaL_checkinteger(L,1); 129 | float volL= lua_isnumber(L,2) ? lua_tonumber(L,2) : 1.0f; 130 | float volR= lua_isnumber(L,3) ? lua_tonumber(L,3) : 1.0f; 131 | float disparity= lua_isnumber(L,4) ? lua_tonumber(L,4) : 0.0f; 132 | float pitch = lua_isnumber(L,5) ? lua_tonumber(L,5) : 1.0f; 133 | int ret = (int)audio.soundPlay(sample, volL,volR,disparity,pitch); 134 | if(ret) { 135 | lua_pushinteger(L, ret); 136 | return 1; 137 | } 138 | return 0; 139 | } 140 | 141 | static int soundLoop(lua_State *L) { 142 | DeviceAudio & audio = DeviceAudio::singleton(); 143 | if(!&audio) return 0; 144 | unsigned int sample = luaL_checkinteger(L,1); 145 | float volL= lua_isnumber(L,2) ? lua_tonumber(L,2) : 1.0f; 146 | float volR= lua_isnumber(L,3) ? lua_tonumber(L,3) : 1.0f; 147 | float disparity= lua_isnumber(L,4) ? lua_tonumber(L,4) : 0.0f; 148 | float pitch = lua_isnumber(L,5) ? lua_tonumber(L,5) : 1.0f; 149 | int ret = (int)audio.soundLoop(sample, volL,volR,disparity,pitch); 150 | if(ret) { 151 | lua_pushinteger(L, ret); 152 | return 1; 153 | } 154 | return 0; 155 | } 156 | 157 | static int soundUpdate(lua_State *L) { 158 | DeviceAudio & audio = DeviceAudio::singleton(); 159 | if(!&audio) return 0; 160 | unsigned int sound = luaL_checkinteger(L,1); 161 | float volL= lua_isnumber(L,2) ? lua_tonumber(L,2) : 1.0f; 162 | float volR= lua_isnumber(L,3) ? lua_tonumber(L,3) : 1.0f; 163 | float disparity= lua_isnumber(L,4) ? lua_tonumber(L,4) : 0.0f; 164 | float pitch = lua_isnumber(L,5) ? lua_tonumber(L,5) : 1.0f; 165 | int ret = (int)audio.soundUpdate(sound, volL,volR,disparity,pitch); 166 | if(ret) { 167 | lua_pushinteger(L, ret); 168 | return 1; 169 | } 170 | return 0; 171 | } 172 | 173 | static int soundStop(lua_State *L) { 174 | int argc = lua_gettop(L); 175 | DeviceAudio & audio = DeviceAudio::singleton(); 176 | if(!&audio) return 0; 177 | if(!argc) { 178 | audio.soundStop(); 179 | return 0; 180 | } 181 | unsigned int sound = luaL_checkinteger(L,1); 182 | int ret = (int)audio.soundStop(sound); 183 | if(ret) { 184 | lua_pushinteger(L, ret); 185 | return 1; 186 | } 187 | return 0; 188 | } 189 | 190 | static int soundActive(lua_State *L) { 191 | DeviceAudio & audio = DeviceAudio::singleton(); 192 | if(!&audio) return 0; 193 | lua_pushinteger(L, (int)audio.soundActive()); 194 | return 1; 195 | } 196 | 197 | extern "C" int _EXPORT luaopen_proAudioRt (lua_State* L) { 198 | static const struct luaL_Reg funcs[] = { 199 | {"create", create }, 200 | {"destroy", destroy }, 201 | {"loaderAvailable", loaderAvailable }, 202 | {"volume", volume }, 203 | {"sleep", sleep }, 204 | 205 | {"sampleFromFile", sampleFromFile }, 206 | {"sampleFromMemory", sampleFromMemory }, 207 | {"sampleDestroy", sampleDestroy }, 208 | {"sampleProperties", sampleProperties }, 209 | 210 | {"soundPlay", soundPlay }, 211 | {"soundLoop", soundLoop }, 212 | {"soundUpdate", soundUpdate }, 213 | {"soundStop", soundStop }, 214 | {"soundActive", soundActive }, 215 | {NULL, NULL} 216 | }; 217 | luaL_register(L, "proAudio", funcs); 218 | return 1; 219 | } 220 | -------------------------------------------------------------------------------- /proAudioSdl.cpp: -------------------------------------------------------------------------------- 1 | #include "proAudioSdl.h" 2 | extern "C" { 3 | #include 4 | }; 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | //--- class DeviceAudioSdl ------------------------------------------ 13 | 14 | /// internal class to store sample data 15 | class _AudioTrack { 16 | public: 17 | /// default constructor 18 | _AudioTrack(Uint8 * pData=0, unsigned int length=0) : data(pData), dlen(length) { 19 | dpos=0; disparity=0.0f; volL=1.0f; volR=1.0f; pitch=1.0f; isLoop=false; isPlaying=false; }; 20 | /// pointer to raw sample data 21 | Uint8 *data; 22 | /// position in playback 23 | Uint32 dpos; 24 | /// length of sample in bytes 25 | Uint32 dlen; 26 | /// disparity in seconds between left and right, normally 0.0f 27 | float disparity; 28 | /// left volume 29 | float volL; 30 | /// right volume 31 | float volR; 32 | /// pitch factor, normally 1.0f 33 | float pitch; 34 | /// stores whether sample has to be looped 35 | bool isLoop; 36 | /// stores whether sample is currently playing 37 | bool isPlaying; 38 | }; 39 | 40 | DeviceAudio* DeviceAudioSdl::create(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize) { 41 | if(!s_instance) { 42 | DeviceAudioSdl* pAudio = new DeviceAudioSdl(nTracks,frequency,chunkSize); 43 | if(!pAudio->m_freqOut) delete pAudio; 44 | else s_instance = pAudio; 45 | } 46 | return s_instance; 47 | } 48 | 49 | DeviceAudioSdl::DeviceAudioSdl(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize) : DeviceAudio(), m_sampleCounter(0) { 50 | // initialize SDL sound system: 51 | if(!SDL_WasInit(SDL_INIT_AUDIO)&&(SDL_InitSubSystem(SDL_INIT_AUDIO)<0)) { 52 | fprintf(stderr, "DeviceAudioSdl ERROR: cannot initialize SDL audio subsystem.\n"); 53 | return; 54 | } 55 | 56 | // set the audio format: 57 | SDL_AudioSpec desired; 58 | desired.freq = frequency; 59 | desired.format = AUDIO_S16; 60 | desired.channels = 2; // 1 = mono, 2 = stereo 61 | desired.samples = chunkSize; // good low-latency value for callback 62 | desired.callback = cbOutput; 63 | desired.userdata = NULL; 64 | // open the audio device 65 | if ( SDL_OpenAudio(&desired, &m_spec) < 0 ) { 66 | fprintf(stderr, "DeviceAudioSdl ERROR: Couldn't open audio.\n"); 67 | return; 68 | } 69 | if((m_spec.format!=AUDIO_S16)||(m_spec.channels!=2)) { 70 | fprintf(stderr, "DeviceAudioSdl WARNING: Could not get desired signed 16 bit stereo. Expect low quality sound.\n"); 71 | m_isDesiredFormat=false; 72 | } 73 | else { 74 | m_isDesiredFormat=true; 75 | } 76 | 77 | // initialize tracks: 78 | m_nSound=nTracks; 79 | ma_sound=new _AudioTrack[m_nSound]; 80 | 81 | SDL_PauseAudio(0); // start sound 82 | m_freqOut = frequency; 83 | } 84 | 85 | DeviceAudioSdl::~DeviceAudioSdl() { 86 | SDL_PauseAudio(1); 87 | SDL_CloseAudio(); 88 | delete [] ma_sound; 89 | } 90 | 91 | void DeviceAudioSdl::cbOutput(void * userData, Uint8 *stream, int len) { 92 | if(dynamic_cast(s_instance)->m_isDesiredFormat) 93 | dynamic_cast(s_instance)->mixOutputFloat((signed short *)stream, len/2); 94 | else dynamic_cast(s_instance)->mixOutputSInt(stream, len); 95 | } 96 | 97 | void DeviceAudioSdl::mixOutputFloat(signed short *outputBuffer, unsigned int nFrames) { 98 | for(unsigned int j=0; j= ma_sound[i].dlen) continue; 106 | left +=float(*((Sint16 *)(&ma_sound[i].data[currPos]))) 107 | *m_volL*ma_sound[i].volL; 108 | right+=float(*((Sint16 *)(&ma_sound[i].data[currPos]))) 109 | *m_volR*ma_sound[i].volR; 110 | } 111 | else { // use linear interpolation and disparity: 112 | double fract=ma_sound[i].dpos+j*ma_sound[i].pitch; 113 | int currPos=int(fract*0.5f)*2; 114 | fract=(fract-currPos)*0.5f; 115 | 116 | int currPosL= (ma_sound[i].disparity<0.0f) 117 | ? currPos-2*int(m_spec.freq*-ma_sound[i].disparity) 118 | : currPos; 119 | int currPosR= (ma_sound[i].disparity>0.0f) 120 | ? currPos-2*int(m_spec.freq*ma_sound[i].disparity) 121 | : currPos; 122 | 123 | if(ma_sound[i].isLoop) { 124 | currPosL=(currPosL+10*ma_sound[i].dlen-2)%(ma_sound[i].dlen-2); 125 | currPosR=(currPosR+10*ma_sound[i].dlen-2)%(ma_sound[i].dlen-2); 126 | } 127 | if((currPosL < int(ma_sound[i].dlen)-2)&&(currPosL>=0)) { 128 | float currWavL=(1.0f-fract)*float(*((Sint16 *)(&ma_sound[i].data[currPosL]))) 129 | +fract*float(*((Sint16 *)(&ma_sound[i].data[currPosL+2]))); 130 | left +=currWavL*m_volL*ma_sound[i].volL; 131 | } 132 | if((currPosR < int(ma_sound[i].dlen)-2)&&(currPosR>=0)) { 133 | float currWavR=(1.0f-fract)*float(*((Sint16 *)(&ma_sound[i].data[currPosR]))) 134 | +fract*float(*((Sint16 *)(&ma_sound[i].data[currPosR+2]))); 135 | right+=currWavR*m_volR*ma_sound[i].volR; 136 | } 137 | } 138 | } 139 | // clamp: 140 | if(left>(float)SHRT_MAX) outputBuffer[j]=SHRT_MAX; 141 | else if(left<(float)SHRT_MIN) outputBuffer[j]=SHRT_MIN; 142 | else outputBuffer[j]=(Sint16)left; 143 | if(right>(float)SHRT_MAX) outputBuffer[j+1]=SHRT_MAX; 144 | else if(right<(float)SHRT_MIN) outputBuffer[j+1]=SHRT_MIN; 145 | else outputBuffer[j+1]=(Sint16)right; 146 | } 147 | for (unsigned int i=0; ima_sound[i].dlen+2*abs(int(m_spec.freq*-ma_sound[i].disparity))) 153 | ma_sound[i].isPlaying=false; 154 | } 155 | } 156 | 157 | void DeviceAudioSdl::mixOutputSInt(Uint8 *stream, int len) { 158 | for (unsigned int i=0; i (unsigned int)len) amount = (unsigned int)len; 161 | SDL_MixAudio(stream, &ma_sound[i].data[ma_sound[i].dpos], amount, SDL_MIX_MAXVOLUME); 162 | ma_sound[i].dpos += amount; 163 | } 164 | } 165 | 166 | static void adjustVolume(signed short* data, size_t len, float volume) { 167 | for(size_t i=0; i(float)SHRT_MAX) value=(float)SHRT_MAX; // clamp 171 | else if(value<(float)SHRT_MIN) value=(float)SHRT_MIN; 172 | shortValue=(signed short)value; 173 | } 174 | } 175 | 176 | unsigned int DeviceAudioSdl::sampleFromMemory(const AudioSample & sample, float volume) { 177 | Uint8 destChannels= m_isDesiredFormat ? 1 : m_spec.channels; // convert to mono 178 | Uint16 format = sample.bytesPerSample()==2 ? AUDIO_S16 : sample.bytesPerSample()==1 ? AUDIO_S8 : 0; 179 | if(!format) { 180 | fprintf(stderr, "DeviceAudioSdl WARNING: %i bit samples not supported.\n", sample.bitsPerSample()); 181 | return 0; 182 | } 183 | SDL_AudioCVT cvt; 184 | SDL_BuildAudioCVT(&cvt, format, sample.channels(), sample.sampleRate(), 185 | m_spec.format, destChannels, m_spec.freq); 186 | cvt.buf = new Uint8[sample.size()*cvt.len_mult]; 187 | memcpy(cvt.buf, sample.data(), sample.size()); 188 | cvt.len = sample.size(); 189 | SDL_ConvertAudio(&cvt); 190 | 191 | _AudioTrack track; 192 | track.data = cvt.buf; 193 | track.dlen = cvt.len_cvt; 194 | track.dpos = 0; 195 | if (!track.dlen) { 196 | fprintf(stderr, "DeviceAudioSdl WARNING: Sample has zero length.\n"); 197 | return 0; 198 | } 199 | // adjust volume: 200 | if((volume!=1.0f)&&m_isDesiredFormat) 201 | adjustVolume((signed short *)track.data, track.dlen/2, volume); 202 | 203 | mm_sample.insert(make_pair(++m_sampleCounter,track)); 204 | return m_sampleCounter; 205 | } 206 | 207 | bool DeviceAudioSdl::sampleDestroy(unsigned int sample) { 208 | // look for sample: 209 | map::iterator iter=mm_sample.find(sample); 210 | if( iter == mm_sample.end() ) return false; 211 | // stop currently playing sounds referring to this sample: 212 | SDL_LockAudio(); 213 | for (unsigned int i=0; isecond.data) 214 | ma_sound[i].isPlaying=false; 215 | SDL_UnlockAudio(); 216 | // cleanup: 217 | delete iter->second.data; 218 | if(iter->first==m_sampleCounter) --m_sampleCounter; 219 | mm_sample.erase(iter); 220 | return true; 221 | } 222 | 223 | unsigned int DeviceAudioSdl::soundPlay(unsigned int sample, float volumeL, float volumeR, float disparity, float pitch) { 224 | // look for sample: 225 | map::iterator iter=mm_sample.find(sample); 226 | if(iter==mm_sample.end()) return 0; // no sample found 227 | // look for an empty (or finished) sound track 228 | unsigned int i; 229 | for ( i=0; isecond.data; 236 | ma_sound[i].dlen = iter->second.dlen; 237 | ma_sound[i].dpos = 0; 238 | ma_sound[i].volL=volumeL; 239 | ma_sound[i].volR=volumeR; 240 | ma_sound[i].disparity=disparity; 241 | ma_sound[i].pitch=fabs(pitch); 242 | ma_sound[i].isLoop=false; 243 | ma_sound[i].isPlaying=true; 244 | SDL_UnlockAudio(); 245 | return i+1; 246 | } 247 | 248 | unsigned int DeviceAudioSdl::soundLoop(unsigned int sample, float volumeL, float volumeR, float disparity, float pitch) { 249 | unsigned int ret=soundPlay(sample,volumeL,volumeR,disparity, pitch); 250 | if(ret) { 251 | SDL_LockAudio(); 252 | ma_sound[ret-1].isLoop=true; 253 | SDL_UnlockAudio(); 254 | } 255 | return ret; 256 | } 257 | 258 | bool DeviceAudioSdl::soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity, float pitch ) { 259 | if(!sound || (sound>m_nSound) || !ma_sound[sound-1].isPlaying) return false; 260 | SDL_LockAudio(); 261 | ma_sound[--sound].volL=volumeL; 262 | ma_sound[sound].volR=volumeR; 263 | ma_sound[sound].disparity=disparity; 264 | ma_sound[sound].pitch=fabs(pitch); 265 | SDL_UnlockAudio(); 266 | return true; 267 | } 268 | 269 | bool DeviceAudioSdl::soundStop(unsigned int sound) { 270 | if(!sound||(sound>m_nSound)||!ma_sound[sound-1].isPlaying) return false; 271 | SDL_LockAudio(); 272 | ma_sound[sound-1].isPlaying=false; 273 | SDL_UnlockAudio(); 274 | return true; 275 | } 276 | 277 | void DeviceAudioSdl::soundStop() { 278 | SDL_LockAudio(); 279 | for (unsigned int i=0; i 6 | }; 7 | #include "proAudio.h" 8 | #include 9 | 10 | /** @file proAudioSdl.h 11 | \brief SDL backend of proteaAudio 12 | \author Gerald Franz, www.viremo.de 13 | \version 2.0 14 | */ 15 | 16 | //--- class DeviceAudioSdl ----------------------------------------- 17 | 18 | /// internal class to manage sample data 19 | class _AudioTrack; 20 | 21 | /// SDL based stereo audio mixer/playback device 22 | class DeviceAudioSdl : public DeviceAudio { 23 | public: 24 | ///creates audio device 25 | /** Use this method instead of a constructor. 26 | \param nTracks (optional) the maximum number of sounds that are played parallely. Computation time is linearly correlated to this factor. 27 | \param frequency (optional) sample frequency of the playback in Hz. 22050 corresponds to FM radio 44100 is CD quality. Computation time is linearly correlated to this factor. 28 | \param chunkSize (optional) the number of bytes that are sent to the sound card at once. Low numbers lead to smaller latencies but need more computation time (thread switches). If a too small number is chosen, the sounds might not be played continuously. The default value 512 guarantees a good latency below 40 ms at 22050 Hz sample frequency. 29 | \return a pointer to an audio device object in case of success 30 | Note that the parameters are only handled when calling for the first time. Afterwards always the same object is returned until an explicit destroy() is called. 31 | */ 32 | static DeviceAudio* create(unsigned int nTracks=8, unsigned int frequency=22050, unsigned int chunkSize=1024); 33 | 34 | /// converts a sound sample to internal audio format, returns handle 35 | virtual unsigned int sampleFromMemory(const AudioSample & sample, float volume=1.0f); 36 | /// deletes a previously created sound sample resource identified by its handle 37 | virtual bool sampleDestroy(unsigned int sample); 38 | 39 | /// plays a specified sample once and sets its parameters 40 | /** \param sample a sample handle returned by a previous load() call 41 | \param volumeL (optional) left volume 42 | \param volumeR (optional) right volume 43 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 44 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 45 | \return a handle to the currently played sound or 0 in case of error */ 46 | virtual unsigned int soundPlay(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f ); 47 | /** plays a specified sample continuously and sets its parameters 48 | \param sample a sample handle returned by a previous load() call 49 | \param volumeL (optional) left volume 50 | \param volumeR (optional) right volume 51 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 52 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 53 | \return a handle to the currently played sound or 0 in case of error */ 54 | virtual unsigned int soundLoop(unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f ); 55 | /// updates parameters of a specified sound 56 | /** \param sound handle of a currently active sound 57 | \param volumeL left volume 58 | \param volumeR right volume 59 | \param disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right. 60 | \param pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample. 61 | \return true in case the parameters have been updated successfully */ 62 | virtual bool soundUpdate(unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f ); 63 | /// stops a specified sound immediately 64 | virtual bool soundStop(unsigned int sound); 65 | /// stops all sounds immediately 66 | virtual void soundStop(); 67 | /// returns number of currently active sounds 68 | virtual unsigned int soundActive() const; 69 | protected: 70 | /// constructor. Use the create() method instead 71 | DeviceAudioSdl(unsigned int nTracks, unsigned int frequency, unsigned int chunkSize); 72 | /// destructor. Use the destroy() method instead 73 | virtual ~DeviceAudioSdl(); 74 | /// stores audio specification 75 | SDL_AudioSpec m_spec; 76 | /// stores loaded sound samples 77 | std::map mm_sample; 78 | /// stores maximum sample id 79 | unsigned int m_sampleCounter; 80 | /// stores whether obtained audio format corresponds to expectations 81 | bool m_isDesiredFormat; 82 | 83 | /// stores sounds to be mixed 84 | _AudioTrack * ma_sound; 85 | /// stores number of parallel tracks 86 | unsigned int m_nSound; 87 | 88 | /// output callback 89 | static void cbOutput(void *userData, Uint8 *stream, int len); 90 | /// advanced mixer method 91 | void mixOutputFloat(signed short *outputBuffer, unsigned int nFrames); 92 | /// fallback mixer method 93 | void mixOutputSInt(Uint8 *stream, int len); 94 | }; 95 | 96 | #endif // _AUDIO_SDL_H 97 | -------------------------------------------------------------------------------- /protea.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Helvetica,sans-serif; 3 | color: black; 4 | background-color: white; 5 | margin: 30px 50px 50px 50px; 6 | text-align: left; 7 | width: 640px; 8 | font-size: 90%; 9 | } 10 | 11 | h1, h2, h3, h4, h5, h6 { 12 | color: maroon; 13 | } 14 | 15 | h1 { 16 | font-size: 150%; 17 | } 18 | 19 | h2 { 20 | margin: 25px 0px 10px 0px; 21 | font-size: 110%; 22 | } 23 | 24 | a:link, a:visited, a:link:active { 25 | text-decoration: none; 26 | color: maroon; 27 | } 28 | 29 | a:link:hover, a:visited:hover { 30 | text-decoration: underline; 31 | color: red; 32 | } 33 | 34 | p, ul { 35 | font-size: 90%; 36 | } 37 | 38 | pre { 39 | background-color: #DDD; 40 | width: 100%; 41 | font-weight: bold; 42 | } 43 | 44 | 45 | 46 | CAPTION { font-weight: bold } 47 | DIV.qindex { 48 | font-size: 90%; 49 | width: 100%; 50 | border-bottom: 1px solid #b0b0b0; 51 | margin: 2px; 52 | padding: 2px; 53 | line-height: 140%; 54 | } 55 | 56 | TD { 57 | font-size: 90%; 58 | } 59 | TABLE.mdtable { 60 | background-color: #DDD; 61 | width: 100%; 62 | } 63 | TD.md { 64 | font-weight: bold; 65 | } 66 | TD.mdPrefix { 67 | color: #606060; 68 | } 69 | TD.mdname { 70 | font-weight: bold; 71 | color: #602020; 72 | } 73 | 74 | DIV.groupHeader { 75 | margin-left: 16px; 76 | margin-top: 12px; 77 | margin-bottom: 6px; 78 | font-weight: bold; 79 | } 80 | DIV.groupText { margin-left: 16px; font-style: italic; font-size: 90% } 81 | TD.indexkey { 82 | font-weight: bold; 83 | padding-right : 10px; 84 | padding-top : 2px; 85 | padding-left : 10px; 86 | padding-bottom : 2px; 87 | margin-left : 0px; 88 | margin-right : 0px; 89 | margin-top : 2px; 90 | margin-bottom : 2px; 91 | border-top: 1px solid #CCCCCC; 92 | border-bottom: 1px solid #CCCCCC; 93 | } 94 | TD.indexvalue { 95 | font-style: italic; 96 | padding-right : 10px; 97 | padding-top : 2px; 98 | padding-left : 10px; 99 | padding-bottom : 2px; 100 | margin-left : 0px; 101 | margin-right : 0px; 102 | margin-top : 2px; 103 | margin-bottom : 2px; 104 | border-top: 1px solid #CCCCCC; 105 | border-bottom: 1px solid #CCCCCC; 106 | } 107 | TR.memlist { 108 | background-color: #DDD; 109 | } 110 | SPAN.keyword { color: #008000 } 111 | SPAN.keywordtype { color: #604020 } 112 | SPAN.keywordflow { color: #e08000 } 113 | SPAN.comment { color: #800000 } 114 | SPAN.preprocessor { color: #806020 } 115 | SPAN.stringliteral { color: #002080 } 116 | SPAN.charliteral { color: #008080 } 117 | -------------------------------------------------------------------------------- /proteaAudio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkl1337/proteaAudio/08178b5d9859defd42ff6a156a476d0f60337b6f/proteaAudio.png -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | /**\mainpage 2 | 3 | \section intro Overview 4 | proteaAudio is a free cross-platform 2D audio library for C++ and Lua. 5 | 6 | Due to its straightforward interface and minimal open-source code base, proteaAudio is both easy to maintain and use. 7 | 8 | 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). 9 | 10 | 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). 11 | 12 | \section features Main features at a glance 13 | - clean minimal C++ code base, portable, extendable class design 14 | - supports playback of an arbitrary number of parallel mono/stereo sounds 15 | - dynamic pitch shifts, panning between the stereo channels, user-definable disparity 16 | - low CPU consumption, runs in its own dedicated thread 17 | - regularly tested on MS Windows (MinGW/VisualStudio) and Linux (gcc) 18 | - loaders for standard wav and ogg/vorbis audio samples included 19 | - easily extensible to support further audio sample formats, e.g., mp3 20 | - C++ and Lua API 21 | - by default makes use of the RtAudio low-level cross-platform audio backend, supporting Windows (DirectSound, ASIO), Linux (ALSA, OSS, JACK), and MacOSX (CoreAudio, JACK) 22 | - makes optionally use of libSDL as cross-platform audio backend, supporting various further platforms 23 | 24 | \section download Download 25 | - proteaAudio source code release 2009-02-04 26 | - proteaAudio Lua Windows/Linux binary release 2009-02-04 27 | 28 | \section documentation Documentation 29 | - C++ API 30 | - Lua API 31 | - Changelog 32 | 33 | \section links Links 34 | 35 | proteaAudio internally makes use of the following excellent open-source components: 36 | 37 | - RtAudio cross-platform low-level audio library (optional) 38 | - SDL cross-platform multimedia layer (optional) 39 | - stb_vorbis Ogg Vorbis audio decoder 40 | 41 | 42 | \section license License notice (zlib license): 43 | 44 | (c) 2009 by Gerald Franz, www.viremo.de 45 | 46 | This software is provided 'as-is', without any express or implied 47 | warranty. In no event will the author be held liable for any damages 48 | arising from the use of this software. 49 | 50 | Permission is granted to anyone to use this software for any purpose, 51 | including commercial applications, and to alter it and redistribute it 52 | freely, subject to the following restrictions: 53 | 54 | -# The origin of this software must not be misrepresented; you must not 55 | claim that you wrote the original software. If you use this software 56 | in a product, an acknowledgment in the product documentation would be 57 | appreciated but is not required. 58 | -# Altered source versions must be plainly marked as such, and must not be 59 | misrepresented as being the original software. 60 | -# This notice may not be removed or altered from any source distribution. 61 | 62 | */ 63 | -------------------------------------------------------------------------------- /sample.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkl1337/proteaAudio/08178b5d9859defd42ff6a156a476d0f60337b6f/sample.ogg -------------------------------------------------------------------------------- /scale.lua: -------------------------------------------------------------------------------- 1 | -- function creating a sine wave sample: 2 | function sampleSine(freq, duration, sampleRate) 3 | local data = { } 4 | for i = 1,duration*sampleRate do 5 | data[i] = math.sin( (i*freq/sampleRate)*math.pi*2) 6 | end 7 | return proAudio.sampleFromMemory(data, sampleRate) 8 | end 9 | 10 | -- plays a sample shifted by a number of halftones for a definable period of time 11 | function playNote(sample, pitch, duration, volumeL, volumeR, disparity) 12 | local scale = 2^(pitch/12) 13 | local sound = proAudio.soundLoop(sample, volumeL, volumeR, disparity, scale) 14 | proAudio.sleep(duration) 15 | proAudio.soundStop(sound) 16 | end 17 | 18 | 19 | -- create an audio device using default parameters and exit in case of errors 20 | require("proAudioRt") 21 | if not proAudio.create() then os.exit(1) end 22 | 23 | -- generate a sample: 24 | local sample = sampleSine(440, 0.5, 88200) 25 | 26 | -- play scale (a major): 27 | local duration = 0.5 28 | for i,note in ipairs({ 0, 2, 4, 5, 7, 9, 11, 12 }) do 29 | playNote(sample, note, duration) 30 | end 31 | 32 | -- cleanup 33 | proAudio.destroy() 34 | --------------------------------------------------------------------------------