SoundRecorder.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef CPP3DS_SOUNDRECORDER_HPP
26 #define CPP3DS_SOUNDRECORDER_HPP
27 
29 // Headers
31 #include <cpp3ds/Audio/AlResource.hpp>
32 #include <cpp3ds/System/Thread.hpp>
33 #include <cpp3ds/System/Time.hpp>
34 #include <vector>
35 #include <string>
36 #ifdef EMULATION
37 #include <SFML/Audio/SoundRecorder.hpp>
38 #else
39 #include <3ds.h>
40 #endif
41 
42 
43 namespace cpp3ds
44 {
50 {
51 public :
52 
57  virtual ~SoundRecorder();
58 
81  bool start(unsigned int sampleRate = 44100);
82 
89  void stop();
90 
101  unsigned int getSampleRate() const;
102 
112  static std::vector<std::string> getAvailableDevices();
113 
124  static std::string getDefaultDevice();
125 
141  bool setDevice(const std::string& name);
142 
149  const std::string& getDevice() const;
150 
162  static bool isAvailable();
163 
164 protected :
165 
172  SoundRecorder();
173 
190  void setProcessingInterval(cpp3ds::Time interval);
191 
203  virtual bool onStart();
204 
219  virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount) = 0;
220 
230  virtual void onStop();
231 
232 private :
233 
241  void record();
242 
251  void processCapturedSamples();
252 
259  void cleanup();
260 
262  // Member data
264  Thread m_thread;
265  std::vector<Int16> m_samples;
266  unsigned int m_sampleRate;
267  cpp3ds::Time m_processingInterval;
268  volatile bool m_isCapturing;
269  std::string m_deviceName;
270 
271  #ifdef EMULATION
272 // sf::SoundRecorder m_recorder;
273  #else
274  Uint8* audiobuf;
275  Int16* audiobuf2;
276  volatile u32 audiobuf_size, audiobuf_pos;
277  #endif
278 };
279 
280 } // namespace cpp3ds
281 
282 
283 #endif // CPP3DS_SOUNDRECORDER_HPP
284 
285 
virtual void onStop()
Stop capturing audio data.
Utility class to manipulate threads.
Definition: Thread.hpp:53
unsigned int getSampleRate() const
Get the sample rate.
bool setDevice(const std::string &name)
Set the audio capture device.
static std::vector< std::string > getAvailableDevices()
Get a list of the names of all availabe audio capture devices.
void stop()
Stop the capture.
void setProcessingInterval(cpp3ds::Time interval)
Set the processing interval.
const std::string & getDevice() const
Get the name of the current audio capture device.
Represents a time value.
Definition: Time.hpp:37
bool start(unsigned int sampleRate=44100)
Start the capture.
virtual ~SoundRecorder()
destructor
virtual bool onStart()
Start capturing audio data.
Abstract base class for capturing sound data.
SoundRecorder()
Default constructor.
static std::string getDefaultDevice()
Get the name of the default audio capture device.
Base class for classes that require an OpenAL context.
Definition: AlResource.hpp:39
virtual bool onProcessSamples(const Int16 *samples, std::size_t sampleCount)=0
Process a new chunk of recorded samples.
static bool isAvailable()
Check if the system supports audio capture.