1 /*******************************************************************************
2  * Copyright 2009-2016 Jörg Müller
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 #pragma once
18 
19 #include "Audaspace.h"
20 
21 #ifdef __cplusplus
22 using namespace aud;
23 #endif
24 
25 #ifdef AUD_CAPI_IMPLEMENTATION
26 #include "ISound.h"
27 #include "devices/IHandle.h"
28 #include "devices/IDevice.h"
29 #include "sequence/SequenceEntry.h"
30 #include "fx/PlaybackManager.h"
31 #include "fx/DynamicMusic.h"
32 #include "fx/Source.h"
33 #include "util/ThreadPool.h"
34 #ifdef WITH_CONVOLUTION
35 #include "fx/ImpulseResponse.h"
36 #include "fx/HRTF.h"
37 #endif
38 
39 typedef std::shared_ptr<aud::ISound> AUD_Sound;
40 typedef std::shared_ptr<aud::IHandle> AUD_Handle;
41 typedef std::shared_ptr<aud::IDevice> AUD_Device;
42 typedef std::shared_ptr<aud::SequenceEntry> AUD_SequenceEntry;
43 typedef std::shared_ptr<aud::PlaybackManager> AUD_PlaybackManager;
44 typedef std::shared_ptr<aud::DynamicMusic> AUD_DynamicMusic;
45 typedef std::shared_ptr<aud::ThreadPool> AUD_ThreadPool;
46 typedef std::shared_ptr<aud::Source> AUD_Source;
47 #ifdef WITH_CONVOLUTION
48 typedef std::shared_ptr<aud::ImpulseResponse> AUD_ImpulseResponse;
49 typedef std::shared_ptr<aud::HRTF> AUD_HRTF;
50 #endif
51 #else
52 typedef void AUD_Sound;
53 typedef void AUD_Handle;
54 typedef void AUD_Device;
55 typedef void AUD_SequenceEntry;
56 typedef void AUD_PlaybackManager;
57 typedef void AUD_DynamicMusic;
58 typedef void AUD_ThreadPool;
59 typedef void AUD_Source;
60 #ifdef WITH_CONVOLUTION
61 typedef void AUD_ImpulseResponse;
62 typedef void AUD_HRTF;
63 #endif
64 #endif
65 
66 /// Container formats for writers.
67 typedef enum
68 {
69 	AUD_CONTAINER_INVALID = 0,
70 	AUD_CONTAINER_AC3,
71 	AUD_CONTAINER_FLAC,
72 	AUD_CONTAINER_MATROSKA,
73 	AUD_CONTAINER_MP2,
74 	AUD_CONTAINER_MP3,
75 	AUD_CONTAINER_OGG,
76 	AUD_CONTAINER_WAV
77 } AUD_Container;
78 
79 /// Audio codecs for writers.
80 typedef enum
81 {
82 	AUD_CODEC_INVALID = 0,
83 	AUD_CODEC_AAC,
84 	AUD_CODEC_AC3,
85 	AUD_CODEC_FLAC,
86 	AUD_CODEC_MP2,
87 	AUD_CODEC_MP3,
88 	AUD_CODEC_PCM,
89 	AUD_CODEC_VORBIS,
90 	AUD_CODEC_OPUS
91 } AUD_Codec;
92 
93 /**
94  * The format of a sample.
95  * The last 4 bit save the byte count of the format.
96  */
97 typedef enum
98 {
99 	AUD_FORMAT_INVALID = 0x00,		/// Invalid sample format.
100 	AUD_FORMAT_U8      = 0x01,		/// 1 byte unsigned byte.
101 	AUD_FORMAT_S16     = 0x12,		/// 2 byte signed integer.
102 	AUD_FORMAT_S24     = 0x13,		/// 3 byte signed integer.
103 	AUD_FORMAT_S32     = 0x14,		/// 4 byte signed integer.
104 	AUD_FORMAT_FLOAT32 = 0x24,		/// 4 byte float.
105 	AUD_FORMAT_FLOAT64 = 0x28		/// 8 byte float.
106 } AUD_SampleFormat;
107 
108 /// The channel count.
109 typedef enum
110 {
111 	AUD_CHANNELS_INVALID    = 0,	/// Invalid channel count.
112 	AUD_CHANNELS_MONO       = 1,	/// Mono.
113 	AUD_CHANNELS_STEREO     = 2,	/// Stereo.
114 	AUD_CHANNELS_STEREO_LFE = 3,	/// Stereo with LFE channel.
115 	AUD_CHANNELS_SURROUND4  = 4,	/// 4 channel surround sound.
116 	AUD_CHANNELS_SURROUND5  = 5,	/// 5 channel surround sound.
117 	AUD_CHANNELS_SURROUND51 = 6,	/// 5.1 surround sound.
118 	AUD_CHANNELS_SURROUND61 = 7,	/// 6.1 surround sound.
119 	AUD_CHANNELS_SURROUND71 = 8	/// 7.1 surround sound.
120 } AUD_Channels;
121 
122 /**
123  * The sample rate tells how many samples are played back within one second.
124  * Some exotic formats may use other sample rates than provided here.
125  */
126 typedef enum
127 {
128 	AUD_RATE_INVALID = 0,			/// Invalid sample rate.
129 	AUD_RATE_8000    = 8000,		/// 8000 Hz.
130 	AUD_RATE_16000   = 16000,		/// 16000 Hz.
131 	AUD_RATE_11025   = 11025,		/// 11025 Hz.
132 	AUD_RATE_22050   = 22050,		/// 22050 Hz.
133 	AUD_RATE_32000   = 32000,		/// 32000 Hz.
134 	AUD_RATE_44100   = 44100,		/// 44100 Hz.
135 	AUD_RATE_48000   = 48000,		/// 48000 Hz.
136 	AUD_RATE_88200   = 88200,		/// 88200 Hz.
137 	AUD_RATE_96000   = 96000,		/// 96000 Hz.
138 	AUD_RATE_192000  = 192000		/// 192000 Hz.
139 } AUD_DefaultSampleRate;
140 
141 /// Sample rate type.
142 typedef double AUD_SampleRate;
143 
144 /// Specification of a sound source.
145 typedef struct
146 {
147 	/// Sample rate in Hz.
148 	AUD_SampleRate rate;
149 
150 	/// Channel count.
151 	AUD_Channels channels;
152 } AUD_Specs;
153 
154 /// Specification of a sound device.
155 typedef struct
156 {
157 	/// Sample format.
158 	AUD_SampleFormat format;
159 
160 	union
161 	{
162 		struct
163 		{
164 			/// Sample rate in Hz.
165 			AUD_SampleRate rate;
166 
167 			/// Channel count.
168 			AUD_Channels channels;
169 		};
170 		AUD_Specs specs;
171 	};
172 } AUD_DeviceSpecs;
173 
174 /// Sound information structure.
175 typedef struct
176 {
177 	AUD_Specs specs;
178 	float length;
179 } AUD_SoundInfo;
180