HephAudio v3.0.6
A cross-platform C++ library for recording, playing, and processing audio on Windows, Android, Linux, iOS, and macOS.
Loading...
Searching...
No Matches
HephAudioShared.h
Go to the documentation of this file.
1#pragma once
2#include "HephShared.h"
3#include <cmath>
4
7#if !defined(HEPH_ENV_64_BIT)
8#error 32-bit is not supported!
9#endif
10
15#define HEPHAUDIO_VERSION_MAJOR 3
16
21#define HEPHAUDIO_VERSION_MINOR 0
22
27#define HEPHAUDIO_VERSION_PATCH 6
28
33#define HEPHAUDIO_VERSION "v" \
34 HEPH_TOSTRING(HEPHAUDIO_VERSION_MAJOR) "." \
35 HEPH_TOSTRING(HEPHAUDIO_VERSION_MINOR) "." \
36 HEPH_TOSTRING(HEPHAUDIO_VERSION_PATCH)
37
38#define HEPHAUDIO_FORMAT_TAG_PCM (0x0001)
39#define HEPHAUDIO_FORMAT_TAG_IEEE_FLOAT (0x0003)
40#define HEPHAUDIO_FORMAT_TAG_ALAW (0x0006)
41#define HEPHAUDIO_FORMAT_TAG_MULAW (0x0007)
42#define HEPHAUDIO_FORMAT_TAG_WMA (0x0161)
43#define HEPHAUDIO_FORMAT_TAG_WMAUDIO_LOSSLESS (0x0163)
44#define HEPHAUDIO_FORMAT_TAG_WMAVOICE (0x000A)
45#define HEPHAUDIO_FORMAT_TAG_MPEG (0x0050)
46#define HEPHAUDIO_FORMAT_TAG_MP3 (0x0055)
47#define HEPHAUDIO_FORMAT_TAG_AAC (0xA106)
48#define HEPHAUDIO_FORMAT_TAG_ALAC (0x6C61)
49#define HEPHAUDIO_FORMAT_TAG_FLAC (0xF1AC)
50#define HEPHAUDIO_FORMAT_TAG_OPUS (0x704F)
51#define HEPHAUDIO_FORMAT_TAG_VORBIS (0x674F)
52#define HEPHAUDIO_FORMAT_TAG_EXTENSIBLE (0xFFFE)
53
59#if defined(HEPHAUDIO_INFO_LOGGING)
60#define HEPHAUDIO_LOG(logMessage, logType) Heph::ConsoleLogger::Log(logMessage, logType, "HephAudio")
61#else
62#define HEPHAUDIO_LOG(logMessage, logType)
63#endif
64
69#define HEPHAUDIO_SPEED_OF_SOUND 343.0
70
71#define UINT24_MAX 16777215
72#define INT24_MIN (-8388608)
73#define INT24_MAX 8388607
74
107#if defined(HEPH_AUDIO_SAMPLE_TYPE_DBL)
108typedef double heph_audio_sample_t;
109#define HEPH_AUDIO_SAMPLE_MIN (-1.0)
110#define HEPH_AUDIO_SAMPLE_MAX (1.0)
111#define HEPHAUDIO_FORMAT_TAG_HEPHAUDIO_INTERNAL HEPHAUDIO_FORMAT_TAG_IEEE_FLOAT
112#elif defined(HEPH_AUDIO_SAMPLE_TYPE_FLT)
113typedef float heph_audio_sample_t;
114#define HEPH_AUDIO_SAMPLE_MIN (-1.0f)
115#define HEPH_AUDIO_SAMPLE_MAX (1.0f)
116#define HEPHAUDIO_FORMAT_TAG_HEPHAUDIO_INTERNAL HEPHAUDIO_FORMAT_TAG_IEEE_FLOAT
117#elif defined(HEPH_AUDIO_SAMPLE_TYPE_S64)
118typedef int64_t heph_audio_sample_t;
119#define HEPH_AUDIO_SAMPLE_MIN (INT64_MIN)
120#define HEPH_AUDIO_SAMPLE_MAX (INT64_MAX)
121#define HEPHAUDIO_FORMAT_TAG_HEPHAUDIO_INTERNAL HEPHAUDIO_FORMAT_TAG_PCM
122#elif defined(HEPH_AUDIO_SAMPLE_TYPE_S32)
123typedef int32_t heph_audio_sample_t;
124#define HEPH_AUDIO_SAMPLE_MIN (INT32_MIN)
125#define HEPH_AUDIO_SAMPLE_MAX (INT32_MAX)
126#define HEPHAUDIO_FORMAT_TAG_HEPHAUDIO_INTERNAL HEPHAUDIO_FORMAT_TAG_PCM
127#elif defined(HEPH_AUDIO_SAMPLE_TYPE_S16)
128typedef int16_t heph_audio_sample_t;
129#define HEPH_AUDIO_SAMPLE_MIN (INT16_MIN)
130#define HEPH_AUDIO_SAMPLE_MAX (INT16_MAX)
131#define HEPHAUDIO_FORMAT_TAG_HEPHAUDIO_INTERNAL HEPHAUDIO_FORMAT_TAG_PCM
132#else
134#define HEPH_AUDIO_SAMPLE_MIN (-1.0f)
135#define HEPH_AUDIO_SAMPLE_MAX (1.0f)
136#define HEPHAUDIO_FORMAT_TAG_HEPHAUDIO_INTERNAL HEPHAUDIO_FORMAT_TAG_IEEE_FLOAT
137#endif
138
139#if HEPHAUDIO_FORMAT_TAG_HEPHAUDIO_INTERNAL == HEPHAUDIO_FORMAT_TAG_PCM
140
141#define HEPH_AUDIO_SAMPLE_TO_IEEE_FLT(sample) (((double)sample) / (-((double)HEPH_AUDIO_SAMPLE_MIN)))
142#define HEPH_AUDIO_SAMPLE_FROM_IEEE_FLT(fltSample) ((heph_audio_sample_t)((fltSample) * (-((double)HEPH_AUDIO_SAMPLE_MIN))))
143
144#elif HEPHAUDIO_FORMAT_TAG_HEPHAUDIO_INTERNAL == HEPHAUDIO_FORMAT_TAG_IEEE_FLOAT
145
146#define HEPH_AUDIO_SAMPLE_TO_IEEE_FLT(sample) (sample)
147#define HEPH_AUDIO_SAMPLE_FROM_IEEE_FLT(fltSample) (fltSample)
148
149#else
150#error heph_audio_sample_t/ieee_float conversions are not implemented for this internal format yet.
151#endif
152
157#define HEPHAUDIO_ANDROID_OPENSL_MIN_API_LEVEL (21)
158
163#define HEPHAUDIO_ANDROID_AAUDIO_MIN_API_LEVEL (26)
164
165namespace HephAudio
166{
167 HEPH_API const char* GetVersion();
168 HEPH_API unsigned int GetVersionMajor();
169 HEPH_API unsigned int GetVersionMinor();
170 HEPH_API unsigned int GetVersionPatch();
171
176 inline double DecibelToGain(double decibel)
177 {
178 return pow(10.0, decibel * 0.05);
179 }
180
185 inline double GainToDecibel(double gain)
186 {
187 return gain == 0 ? -120.0 : 20.0 * log10(abs(gain));
188 }
189
194 inline constexpr double SemitoneToCent(double semitone)
195 {
196 return semitone * 100.0;
197 }
198
203 inline constexpr double SemitoneToOctave(double semitone)
204 {
205 return semitone / 12.0;
206 }
207
212 inline constexpr double CentToSemitone(double cent)
213 {
214 return cent / 100.0;
215 }
216
221 inline constexpr double CentToOctave(double cent)
222 {
223 return cent / 1200.0;
224 }
225
230 inline constexpr double OctaveToSemitone(double octave)
231 {
232 return octave * 12.0;
233 }
234
239 inline constexpr double OctaveToCent(double octave)
240 {
241 return octave * 1200.0;
242 }
243}
constexpr double SemitoneToOctave(double semitone)
Definition HephAudioShared.h:203
double GainToDecibel(double gain)
Definition HephAudioShared.h:185
constexpr double CentToSemitone(double cent)
Definition HephAudioShared.h:212
float heph_audio_sample_t
Definition HephAudioShared.h:133
constexpr double OctaveToCent(double octave)
Definition HephAudioShared.h:239
double DecibelToGain(double decibel)
Definition HephAudioShared.h:176
constexpr double CentToOctave(double cent)
Definition HephAudioShared.h:221
constexpr double SemitoneToCent(double semitone)
Definition HephAudioShared.h:194
constexpr double OctaveToSemitone(double octave)
Definition HephAudioShared.h:230
#define HEPH_API
Definition HephShared.h:132