reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofSoundBaseTypes.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofConstants.h"
4#include <functional>
5
6class ofSoundBuffer;
7
10 public:
12 virtual ~ofBaseSoundInput() {};
13
16 virtual void audioIn( ofSoundBuffer& buffer );
17
20 virtual void audioIn( float * input, int bufferSize, int nChannels, int deviceID, long unsigned long tickCount );
21
24 virtual void audioIn( float * input, int bufferSize, int nChannels );
25
28 virtual void audioReceived( float * input, int bufferSize, int nChannels ){}
29};
30
31
34 public:
36 virtual ~ofBaseSoundOutput() {};
37
40 virtual void audioOut( ofSoundBuffer& buffer );
41
44 virtual void audioOut( float * output, int bufferSize, int nChannels, int deviceID, long unsigned long tickCount );
45
48 virtual void audioOut( float * output, int bufferSize, int nChannels );
49
52 virtual void audioRequested( float * output, int bufferSize, int nChannels ){}
53};
54
58public:
72
73 friend std::ostream& operator << (std::ostream& os, const ofSoundDevice& dev);
74 friend std::ostream& operator << (std::ostream& os, const std::vector<ofSoundDevice>& devs);
75
78 std::string name{"Unknown"};
79
81 int deviceID = -1;
82
84 unsigned int inputChannels = 0;
85
87 unsigned int outputChannels = 0;
88
90 bool isDefaultInput = false;
91
93 bool isDefaultOutput = false;
94
96 std::vector<unsigned int> sampleRates;
97};
98
100public:
102 size_t sampleRate = 44100;
103 size_t bufferSize = 256;
104 size_t numBuffers = 4;
107 virtual bool setInDevice(const ofSoundDevice & device);
108 virtual bool setOutDevice(const ofSoundDevice & device);
109 virtual bool setApi(ofSoundDevice::Api api);
110 virtual const ofSoundDevice * getInDevice() const;
111 virtual const ofSoundDevice * getOutDevice() const;
112 virtual ofSoundDevice::Api getApi() const;
113
114 template<typename Listener>
115 void setInListener(Listener * inListener){
116 inCallback = std::bind(static_cast<void(Listener::*)(ofSoundBuffer &)>(&Listener::audioIn), inListener, std::placeholders::_1);
117 }
118
119 template<typename Listener>
120 void setOutListener(Listener * outListener){
121 outCallback = std::bind(static_cast<void(Listener::*)(ofSoundBuffer &)>(&Listener::audioOut), outListener, std::placeholders::_1);
122 }
123
124 std::function<void(ofSoundBuffer &)> inCallback;
125 std::function<void(ofSoundBuffer &)> outCallback;
126private:
127 ofSoundDevice inDevice;
128 ofSoundDevice outDevice;
130};
131
133public:
135 virtual bool setup(const ofSoundStreamSettings & settings) = 0;
136 virtual void setInput(ofBaseSoundInput * soundInput) = 0;
137 virtual void setOutput(ofBaseSoundOutput * soundOutput) = 0;
138
139 virtual std::vector<ofSoundDevice> getDeviceList(ofSoundDevice::Api api) const = 0;
140 virtual void printDeviceList() const;
141
142 virtual void start() = 0;
143 virtual void stop() = 0;
144 virtual void close() = 0;
145
146 virtual uint64_t getTickCount() const = 0;
147 virtual int getNumInputChannels() const = 0;
148 virtual int getNumOutputChannels() const = 0;
149 virtual int getSampleRate() const = 0;
150 virtual int getBufferSize() const = 0;
151 virtual ofSoundDevice getInDevice() const = 0;
152 virtual ofSoundDevice getOutDevice() const = 0;
153};
154
155std::string toString(ofSoundDevice::Api api);
156
157
158//----------------------------------------------------------
159// ofBaseSoundPlayer
160//----------------------------------------------------------
162
163public:
164
167
168 virtual bool load(const of::filesystem::path& fileName, bool stream = false)=0;
169 virtual void unload()=0;
170 virtual void play() = 0;
171 virtual void stop() = 0;
172
173 virtual void setVolume(float vol) = 0;
174 virtual void setPan(float vol) = 0; // -1 = left, 1 = right
175 virtual void setSpeed(float spd) = 0;
176 virtual void setPaused(bool bP) = 0;
177 virtual void setLoop(bool bLp) = 0;
178 virtual void setMultiPlay(bool bMp) = 0;
179 virtual void setPosition(float pct) = 0; // 0 = start, 1 = end;
180 virtual void setPositionMS(int ms) = 0;
181
182 virtual float getPosition() const = 0;
183 virtual int getPositionMS() const = 0;
184 virtual bool isPlaying() const = 0;
185 virtual float getSpeed() const = 0;
186 virtual float getPan() const = 0;
187 virtual bool isLoaded() const = 0;
188 virtual float getVolume() const = 0;
189
190};
A base class representing a sound input stream.
Definition ofSoundBaseTypes.h:9
virtual ~ofBaseSoundInput()
Destroy the ofBaseSoundInput.
Definition ofSoundBaseTypes.h:12
virtual void audioReceived(float *input, int bufferSize, int nChannels)
Definition ofSoundBaseTypes.h:28
virtual void audioIn(ofSoundBuffer &buffer)
Receive an audio buffer.
Definition ofBaseTypes.cpp:337
A base class representing a sound output stream.
Definition ofSoundBaseTypes.h:33
virtual void audioOut(ofSoundBuffer &buffer)
Output an audio buffer.
Definition ofBaseTypes.cpp:350
virtual ~ofBaseSoundOutput()
Destroy the ofBaseSoundOutput.
Definition ofSoundBaseTypes.h:36
virtual void audioRequested(float *output, int bufferSize, int nChannels)
Definition ofSoundBaseTypes.h:52
Definition ofSoundBaseTypes.h:161
virtual void setSpeed(float spd)=0
virtual bool load(const of::filesystem::path &fileName, bool stream=false)=0
virtual void setPositionMS(int ms)=0
virtual bool isLoaded() const =0
virtual bool isPlaying() const =0
virtual void setMultiPlay(bool bMp)=0
virtual float getPosition() const =0
virtual void play()=0
virtual void stop()=0
virtual void setPan(float vol)=0
virtual void setVolume(float vol)=0
virtual ~ofBaseSoundPlayer()
Definition ofSoundBaseTypes.h:166
virtual float getVolume() const =0
virtual void setPaused(bool bP)=0
virtual float getPan() const =0
virtual int getPositionMS() const =0
ofBaseSoundPlayer()
Definition ofSoundBaseTypes.h:165
virtual float getSpeed() const =0
virtual void setPosition(float pct)=0
virtual void unload()=0
virtual void setLoop(bool bLp)=0
Definition ofSoundBaseTypes.h:132
virtual bool setup(const ofSoundStreamSettings &settings)=0
virtual int getNumOutputChannels() const =0
virtual void printDeviceList() const
Definition ofSoundBaseTypes.cpp:30
virtual int getNumInputChannels() const =0
virtual void setInput(ofBaseSoundInput *soundInput)=0
virtual ~ofBaseSoundStream()
Definition ofSoundBaseTypes.h:134
virtual std::vector< ofSoundDevice > getDeviceList(ofSoundDevice::Api api) const =0
virtual void stop()=0
virtual ofSoundDevice getInDevice() const =0
virtual uint64_t getTickCount() const =0
virtual void start()=0
virtual int getSampleRate() const =0
virtual void setOutput(ofBaseSoundOutput *soundOutput)=0
virtual int getBufferSize() const =0
virtual void close()=0
virtual ofSoundDevice getOutDevice() const =0
Buffer for audio samples and associated metadata.
Definition ofSoundBuffer.h:84
Represents information about a sound device on the system.
Definition ofSoundBaseTypes.h:57
bool isDefaultInput
If true, this device will be used by ofSoundStream unless changed with setDeviceID()
Definition ofSoundBaseTypes.h:90
unsigned int inputChannels
Number of input channels the device supports.
Definition ofSoundBaseTypes.h:84
std::string name
Descriptive name for the device This is the same string that ofSoundStream::getMatchingDevices() will...
Definition ofSoundBaseTypes.h:78
enum ofSoundDevice::Api api
std::vector< unsigned int > sampleRates
List of sample rates the device claims to support.
Definition ofSoundBaseTypes.h:96
bool isDefaultOutput
If true, this device will be used by ofSoundStream unless changed with setDeviceID()
Definition ofSoundBaseTypes.h:93
int deviceID
The device's unique ID (to be used in ofSoundStream::setDeviceID() )
Definition ofSoundBaseTypes.h:81
friend std::ostream & operator<<(std::ostream &os, const ofSoundDevice &dev)
Definition ofSoundBaseTypes.cpp:48
Api
Definition ofSoundBaseTypes.h:59
@ DEFAULT
Definition ofSoundBaseTypes.h:61
@ MS_DS
Definition ofSoundBaseTypes.h:69
@ ALSA
Definition ofSoundBaseTypes.h:62
@ MS_ASIO
Definition ofSoundBaseTypes.h:68
@ NUM_APIS
Definition ofSoundBaseTypes.h:70
@ JACK
Definition ofSoundBaseTypes.h:65
@ OSS
Definition ofSoundBaseTypes.h:64
@ PULSE
Definition ofSoundBaseTypes.h:63
@ OSX_CORE
Definition ofSoundBaseTypes.h:66
@ UNSPECIFIED
Definition ofSoundBaseTypes.h:60
@ MS_WASAPI
Definition ofSoundBaseTypes.h:67
unsigned int outputChannels
Number of output channels the device supports.
Definition ofSoundBaseTypes.h:87
Definition ofSoundBaseTypes.h:99
std::function< void(ofSoundBuffer &)> outCallback
Definition ofSoundBaseTypes.h:125
virtual const ofSoundDevice * getInDevice() const
Definition ofSoundStream.cpp:82
size_t sampleRate
Definition ofSoundBaseTypes.h:102
virtual ofSoundDevice::Api getApi() const
Definition ofSoundStream.cpp:92
size_t numInputChannels
Definition ofSoundBaseTypes.h:105
virtual ~ofSoundStreamSettings()
Definition ofSoundBaseTypes.h:101
size_t bufferSize
Definition ofSoundBaseTypes.h:103
virtual bool setApi(ofSoundDevice::Api api)
Definition ofSoundStream.cpp:68
virtual bool setOutDevice(const ofSoundDevice &device)
Definition ofSoundStream.cpp:58
size_t numOutputChannels
Definition ofSoundBaseTypes.h:106
std::function< void(ofSoundBuffer &)> inCallback
Definition ofSoundBaseTypes.h:124
virtual bool setInDevice(const ofSoundDevice &device)
Definition ofSoundStream.cpp:48
void setInListener(Listener *inListener)
Definition ofSoundBaseTypes.h:115
void setOutListener(Listener *outListener)
Definition ofSoundBaseTypes.h:120
virtual const ofSoundDevice * getOutDevice() const
Definition ofSoundStream.cpp:87
size_t numBuffers
Definition ofSoundBaseTypes.h:104
map< string, int > device
Definition ofAppEGLWindow.cpp:36
std::string toString(ofSoundDevice::Api api)
Definition ofSoundBaseTypes.cpp:6