Nsound  0.9.4
AudioPlayback.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: AudioPlayback.h 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2011-Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 #ifndef _NSOUND_AUDIO_PLAYBACK_H_
34 #define _NSOUND_AUDIO_PLAYBACK_H_
35 
36 #include <Nsound/Nsound.h>
37 #include <Nsound/AudioBackend.h>
39 
40 #include <string>
41 #include <vector>
42 
43 namespace Nsound
44 {
45 
46 // forward declare
47 class AudioStream;
48 class Buffer;
49 
51 {
52  public:
53 
55  const float64 & sample_rate = 44100.0,
56  const uint32 channels = 1,
57  const uint32 bits_per_sample = 16);
58 
60 
62  static
63  void
65 
67  static
70 
71  uint32
73 
74  void
75  setBitsPerSample(uint32 bits_per_sample)
76  {bits_per_sample_ = bits_per_sample;};
77 
78  uint32
79  getChannels();
80 
81  void
82  setChannels(uint32 channels)
83  {channels_ = channels;};
84 
86  std::string
87  getError();
88 
90  std::string
91  getInfo();
92 
93  uint32
94  getSampleRate();
95 
96  void
97  setSampleRate(uint32 sample_rate)
98  {sample_rate_ = sample_rate;};
99 
102  getState();
103 
105  std::string
106  getStateString();
107 
109  std::string
110  getStateString(const AudioBackend::State & state);
111 
113  void
114  initialize();
115 
117  void
118  play(const AudioStream & a);
119 
121  void
122  play(const Buffer & b);
123 
125  void
126  scanDevices();
127 
129  void
130  setOption(const std::string & key, const std::string & value);
131 
133  void
134  shutdown();
135 
136  #ifndef SWIG
137  friend void operator>>(const AudioStream & lhs, AudioPlayback & rhs);
138  friend void operator>>(const Buffer & lhs, AudioPlayback & rhs);
139  #endif
140 
141  private:
142 
144  :
146  channels_(copy.channels_),
148  backend_(NULL){};
149 
150  AudioPlayback & operator=(const AudioPlayback & rhs){return *this;};
151 
152  // Members
153 
157 
159 
161 }; // AudioPlayback
162 
163 // Must delcare friend functions here to give them proper namespace scope.
164 void operator>>(const AudioStream & lhs, AudioPlayback & rhs);
165 void operator>>(const Buffer & lhs, AudioPlayback & rhs);
166 
167 //-----------------------------------------------------------------------------
169 //
182 void use(const std::string & backend);
183 void use(const AudioBackendType & type);
184 
185 //-----------------------------------------------------------------------------
187 //
196 std::vector< std::string > getBackends();
197 
198 //-----------------------------------------------------------------------------
200 //
209 std::vector< AudioBackendType > getBackendTypes();
210 
211 } // namespace Nsound
212 
213 // :mode=c++: jEdit modeline
214 #endif
void setBitsPerSample(uint32 bits_per_sample)
Definition: AudioPlayback.h:75
std::string getError()
Returns an error string describing any backend error.
unsigned int uint32
Definition: Nsound.h:153
static AudioBackendType getBackendType()
Gets the AudioBackendType that is currently set.
void initialize()
Initializes the backend and transitions to the BACKEND_READY state on success.
void scanDevices()
Scans for devices and tries to play a test sound.
void setOption(const std::string &key, const std::string &value)
Sets an options, must be called before initialize().
AudioBackend::State getState()
Returns the backend state.
void use(const std::string &backend)
Selects the AudioBackend to use by name.
AudioPlayback(const float64 &sample_rate=44100.0, const uint32 channels=1, const uint32 bits_per_sample=16)
double float64
Definition: Nsound.h:146
AudioBackend * backend_
void shutdown()
Shuts down the backend.
static AudioBackendType backend_type_
void operator>>(const AudioStream &lhs, AudioPlayback &rhs)
static void setBackendType(const AudioBackendType ab)
Sets the AudioBackendType.
friend void operator>>(const AudioStream &lhs, AudioPlayback &rhs)
std::string getStateString()
Returns the backend state string.
AudioPlayback(const AudioPlayback &copy)
std::vector< AudioBackendType > getBackendTypes()
Returns a list of the available audio backends types.
AudioPlayback & operator=(const AudioPlayback &rhs)
std::string getInfo()
Returns information about the backend driver.
void setChannels(uint32 channels)
Definition: AudioPlayback.h:82
A Buffer for storing audio samples.
Definition: Buffer.h:60
void play(const AudioStream &a)
Plays the AudioStream throuh the backend.
void setSampleRate(uint32 sample_rate)
Definition: AudioPlayback.h:97
std::vector< std::string > getBackends()
Returns a list of the available audio backends by name.