libvisual  0.5.0
lv_audio.h
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Chong Kai Xiong <kaixiong@codeleft.sg>
7  * Dennis Smit <ds@nerds-incorporated.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef _LV_AUDIO_H
25 #define _LV_AUDIO_H
26 
27 #include <libvisual/lv_buffer.h>
28 
34 #define VISUAL_AUDIO_CHANNEL_LEFT "left"
35 #define VISUAL_AUDIO_CHANNEL_RIGHT "right"
36 
37 typedef enum {
38  VISUAL_AUDIO_SAMPLE_RATE_NONE = 0,
39  VISUAL_AUDIO_SAMPLE_RATE_8000,
40  VISUAL_AUDIO_SAMPLE_RATE_11250,
41  VISUAL_AUDIO_SAMPLE_RATE_22500,
42  VISUAL_AUDIO_SAMPLE_RATE_32000,
43  VISUAL_AUDIO_SAMPLE_RATE_44100,
44  VISUAL_AUDIO_SAMPLE_RATE_48000,
45  VISUAL_AUDIO_SAMPLE_RATE_96000,
46  VISUAL_AUDIO_SAMPLE_RATE_LAST
47 } VisAudioSampleRateType;
48 
49 typedef enum {
50  VISUAL_AUDIO_SAMPLE_FORMAT_NONE = 0,
51  VISUAL_AUDIO_SAMPLE_FORMAT_U8,
52  VISUAL_AUDIO_SAMPLE_FORMAT_S8,
53  VISUAL_AUDIO_SAMPLE_FORMAT_U16,
54  VISUAL_AUDIO_SAMPLE_FORMAT_S16,
55  VISUAL_AUDIO_SAMPLE_FORMAT_U32,
56  VISUAL_AUDIO_SAMPLE_FORMAT_S32,
57  VISUAL_AUDIO_SAMPLE_FORMAT_FLOAT,
58  VISUAL_AUDIO_SAMPLE_FORMAT_LAST
59 } VisAudioSampleFormatType;
60 
61 typedef enum {
62  VISUAL_AUDIO_SAMPLE_CHANNEL_NONE = 0,
63  VISUAL_AUDIO_SAMPLE_CHANNEL_STEREO
64 } VisAudioSampleChannelType;
65 
66 #ifdef __cplusplus
67 
68 #include <memory>
69 #include <string>
70 #include <cstdarg>
71 
72 namespace LV {
73 
79  class LV_API Audio
80  {
81  public:
82 
86  Audio ();
87 
88  Audio (Audio const&) = delete;
89 
93  Audio (Audio&& rhs);
94 
98  ~Audio ();
99 
100  Audio& operator= (Audio const&) = delete;
101 
105  Audio& operator= (Audio&& rhs);
106 
117  bool get_sample (BufferPtr const& buffer, std::string const& channel_name);
118 
128  void get_sample_mixed_simple (BufferPtr const& buffer, unsigned int channels, ...);
129 
130  void get_sample_mixed_simple (BufferPtr const& buffer, unsigned int channels, va_list args);
131 
142  void get_sample_mixed (BufferPtr const& buffer, bool divide, unsigned int channels, ...);
143 
144  void get_sample_mixed (BufferPtr const& buffer, bool divide, unsigned int channels, va_list args);
145 
156  void get_spectrum (BufferPtr const& buffer, std::size_t sample_count, std::string const& channel_name, bool normalised);
157 
158  void get_spectrum (BufferPtr const& buffer, std::size_t sample_count, std::string const& channel_name, bool normalised, float multiplier);
159 
169  static void get_spectrum_for_sample (BufferPtr const& buffer, BufferConstPtr const& samples, bool normalised);
170 
171  static void get_spectrum_for_sample (BufferPtr const& buffer, BufferConstPtr const& samples, bool normalised, float multiplier);
172 
173  static void normalise_spectrum (BufferPtr const& buffer);
174 
183  void input (BufferPtr const& buffer,
184  VisAudioSampleRateType rate,
185  VisAudioSampleFormatType format,
186  VisAudioSampleChannelType channel_type);
187 
196  void input (BufferPtr const& buffer,
197  VisAudioSampleRateType rate,
198  VisAudioSampleFormatType format,
199  std::string const& channel_name);
200 
201  private:
202 
203  class Impl;
204 
205  std::unique_ptr<Impl> m_impl;
206  };
207 
208 } // LV namespace
209 
210 #endif /* __cplusplus */
211 
212 #ifdef __cplusplus
213 typedef LV::Audio VisAudio;
214 #else
215 typedef struct _VisAudio VisAudio;
216 struct _VisAudio;
217 #endif
218 
219 LV_BEGIN_DECLS
220 
221 LV_API VisAudio *visual_audio_new (void);
222 LV_API void visual_audio_free (VisAudio *audio);
223 
224 LV_API int visual_audio_get_sample (VisAudio *audio, VisBuffer *buffer, const char *channelid);
225 LV_API void visual_audio_get_sample_mixed_simple (VisAudio *audio, VisBuffer *buffer, unsigned int channels, ...);
226 LV_API void visual_audio_get_sample_mixed (VisAudio *audio, VisBuffer *buffer, int divide, unsigned int channels, ...);
227 
228 LV_API void visual_audio_get_spectrum (VisAudio *audio, VisBuffer *buffer, int samplelen, const char *channelid, int normalised);
229 LV_API void visual_audio_get_spectrum_multiplied (VisAudio *audio, VisBuffer *buffer, int samplelen, const char *channelid, int normalised, float multiplier);
230 LV_API void visual_audio_get_spectrum_for_sample (VisBuffer *buffer, VisBuffer *sample, int normalised);
231 LV_API void visual_audio_get_spectrum_for_sample_multiplied (VisBuffer *buffer, VisBuffer *sample, int normalised, float multiplier);
232 
233 LV_API void visual_audio_input (VisAudio *audio,
234  VisBuffer *buffer,
235  VisAudioSampleRateType rate,
236  VisAudioSampleFormatType format,
237  VisAudioSampleChannelType channeltype);
238 
239 LV_API void visual_audio_input_channel (VisAudio *audio,
240  VisBuffer *buffer,
241  VisAudioSampleRateType rate,
242  VisAudioSampleFormatType format,
243  const char *channelid);
244 
245 LV_API void visual_audio_normalise_spectrum (VisBuffer *buffer);
246 
247 LV_API visual_size_t visual_audio_sample_rate_get_length (VisAudioSampleRateType rate);
248 LV_API visual_size_t visual_audio_sample_format_get_size (VisAudioSampleFormatType format);
249 LV_API int visual_audio_sample_format_is_signed (VisAudioSampleFormatType format);
250 
251 LV_END_DECLS
252 
257 #endif /* _LV_AUDIO_H */