Spinning Topp Logo BlackTopp Studios
inc
recorder.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 // Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
41 // This file is part of the "cAudio Engine"
42 // For conditions of distribution and use, see copyright notice in cAudio-ZLIBLicense.txt
43 #ifndef _audiorecorder_h
44 #define _audiorecorder_h
45 
46 #include "datatypes.h"
47 #include "Audio/audioenumerations.h"
48 
49 namespace Mezzanine
50 {
51  namespace Audio
52  {
53  ///////////////////////////////////////////////////////////////////////////////
54  /// @brief This is an interface class for the recording of audio.
55  /// @details
56  ///////////////////////////////////////
57  class iRecorder
58  {
59  public:
60  /// @brief Class constructor.
61  iRecorder() { }
62  /// @brief Class destructor.
63  virtual ~iRecorder() { }
64 
65  ///////////////////////////////////////////////////////////////////////////////
66  // Initialization and Shutdown
67 
68  /// @brief Initializes the recording device with the current configuration.
69  /// @param DeviceName The name of the recording device to use when recording audio. If left empty this will use the default device.
70  /// @param Freq The frequency at which to record and store the audio data in Hz.
71  /// @param Config The bit configuration to record and store the audio data. See enum @ref BitConfig for more information.
72  /// @param IntBufSize The size of the internal buffer to allocate for the recorded audio.
73  /// @return Returns true if the device was successfully initialized, false if there was a problem.
74  virtual Boole Initialize(const String& DeviceName = "", const UInt32 Freq = 22050, const BitConfig Config = BC_16Bit_Mono, const UInt32 IntBufSize = 8192) = 0;
75  /// @brief Shuts down and releases the recording device.
76  /// @note If you wish to reuse this recorder after it has been shut down, you will need to reinitialize it.
77  virtual void Shutdown() = 0;
78 
79  ///////////////////////////////////////////////////////////////////////////////
80  // Utility
81 
82  /// @brief Gets whether or not the current Recorder configuration is ready to start recording audio.
83  /// @return Returns true if this Recorder is ready to start recording, false otherise.
84  virtual Boole IsReady() const = 0;
85 
86  /// @brief Starts recording audio from the initialized device.
87  /// @note If there is any old data from previous recordings in the buffer, they will be wiped. You should call @ref iRecorder::GetRecordedAudio before calling this.
88  /// @return Returns true if recording was successfully started.
89  virtual Boole BeginRecording() = 0;
90  /// @brief Stops the recording of audio if this is currently recording.
91  virtual void StopRecording() = 0;
92  /// @brief Writes the current contents of the recorder buffer to another buffer.
93  /// @note This will clear the recorder buffer after being called.
94  /// @param OutputBuffer A pointer to the buffer to write to.
95  /// @param OutputBufferSize The available size of the OutputBuffer.
96  /// @return Returns a UInt32 representing the number of bytes written to the OutputBuffer.
97  virtual UInt32 GetRecordedAudio(void* OutputBuffer, UInt32 OutputBufferSize) = 0;
98  /// @brief Gets the size of the buffer storing the recorded audio.
99  /// @return Returns a UInt32 representing the current size of the recorder buffer.
100  virtual UInt32 GetBufferSize() const = 0;
101 
102  ///////////////////////////////////////////////////////////////////////////////
103  // Recording Configuration
104 
105  /// @brief Sets the device to be used for recording by name.
106  /// @note If this recorder is already initialized, calling this method may re-initialize it and clear the recorded audio buffer in the process.
107  /// @param DeviceName The name of the device to use to record audio.
108  /// @return Returns true if there were no errors in setting the device name, false if there was a problem.
109  virtual Boole SetDeviceName(const String& DeviceName) = 0;
110  /// @brief Gets the name of the currently set recording device.
111  /// @return Returns a String containing the name of the device this recorder was initialized with, or an empty string if one hasn't been initialized.
112  virtual String GetDeviceName() const = 0;
113  /// @brief Sets the frequency then the recorded audio will have.
114  /// @note If this recorder is already initialized, calling this method may re-initialize it and clear the recorded audio buffer in the process.
115  /// @param Freq The frequency at which to record and store the audio data in Hz.
116  /// @return Returns true if there were no errors in setting the frequency, false if there was a problem.
117  virtual Boole SetFrequency(const UInt32 Freq) = 0;
118  /// @brief Gets the frequency of the captured audio.
119  /// @return Returns a UInt32 containing the frequency of the captured audio in Hz.
120  virtual UInt32 GetFrequency() const = 0;
121  /// @brief Sets the bit configuration to use when recording data to the internal buffer.
122  /// @note If this recorder is already initialized, calling this method may re-initialize it and clear the recorded audio buffer in the process.
123  /// @param Config The bit configuration to record and store the audio data. See enum @ref BitConfig for more information.
124  /// @return Returns true if there were no errors in setting the bit configuration, false if there was a problem.
125  virtual Boole SetBitConfiguration(const BitConfig Config) = 0;
126  /// @brief Gets the bit configuration for the audio captured by this recorder.
127  /// @return Returns an BitConfig representing the bit format for the audio recorded.
128  virtual BitConfig GetBitConfiguration() const = 0;
129  /// @brief Sets the size of the internal buffer where the recorded audio may be placed.
130  /// @param Size The size of the internal buffer in bytes.
131  /// @return Returns true if the internal buffer size was successfully updated, false otherwise.
132  virtual Boole SetInternalBufferSize(const UInt32 Size) = 0;
133  /// @brief Gets the currently set size of the internal buffer in bytes.
134  /// @return Returns a UInt32 representing the internal size of the buffer in bytes.
135  virtual UInt32 GetInternalBufferSize() const = 0;
136  /// @brief Gets the size of a single sample of recorded audio data.
137  /// @return Returns a UInt32 representing the size of a sample from the recorder buffer.
138  virtual UInt32 GetSampleSize() const = 0;
139  };//Recorder
140  }//Audio
141 }//Mezzanine
142 
143 #endif
virtual UInt32 GetInternalBufferSize() const =0
Gets the currently set size of the internal buffer in bytes.
virtual Boole BeginRecording()=0
Starts recording audio from the initialized device.
virtual Boole SetInternalBufferSize(const UInt32 Size)=0
Sets the size of the internal buffer where the recorded audio may be placed.
virtual ~iRecorder()
Class destructor.
Definition: recorder.h:63
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual Boole SetFrequency(const UInt32 Freq)=0
Sets the frequency then the recorded audio will have.
virtual UInt32 GetBufferSize() const =0
Gets the size of the buffer storing the recorded audio.
All the definitions for datatypes as well as some basic conversion functions are defined here...
virtual Boole SetDeviceName(const String &DeviceName)=0
Sets the device to be used for recording by name.
virtual UInt32 GetRecordedAudio(void *OutputBuffer, UInt32 OutputBufferSize)=0
Writes the current contents of the recorder buffer to another buffer.
This is an interface class for the recording of audio.
Definition: recorder.h:57
virtual Boole SetBitConfiguration(const BitConfig Config)=0
Sets the bit configuration to use when recording data to the internal buffer.
virtual String GetDeviceName() const =0
Gets the name of the currently set recording device.
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
virtual UInt32 GetFrequency() const =0
Gets the frequency of the captured audio.
virtual BitConfig GetBitConfiguration() const =0
Gets the bit configuration for the audio captured by this recorder.
virtual UInt32 GetSampleSize() const =0
Gets the size of a single sample of recorded audio data.
virtual void StopRecording()=0
Stops the recording of audio if this is currently recording.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual Boole Initialize(const String &DeviceName="", const UInt32 Freq=22050, const BitConfig Config=BC_16Bit_Mono, const UInt32 IntBufSize=8192)=0
Initializes the recording device with the current configuration.
iRecorder()
Class constructor.
Definition: recorder.h:61
virtual void Shutdown()=0
Shuts down and releases the recording device.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
virtual Boole IsReady() const =0
Gets whether or not the current Recorder configuration is ready to start recording audio...
BitConfig
Used to describe the different bit configurations supported by this audio system. ...