Overte C++ Documentation
AudioConstants.h
1 //
2 // AudioConstants.h
3 // libraries/audio/src
4 //
5 // Created by Stephen Birarda on 2014-12-16.
6 // Copyright 2014 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_AudioConstants_h
13 #define hifi_AudioConstants_h
14 
15 #include <limits>
16 #include <math.h>
17 #include <stdint.h>
18 
19 namespace AudioConstants {
20  const int SAMPLE_RATE = 24000;
21  const int MONO = 1;
22  const int STEREO = 2;
23  const int AMBISONIC = 4;
24 
25  using AudioSample = int16_t;
26  const int SAMPLE_SIZE = sizeof(AudioSample);
27 
28  inline const char* getAudioFrameName() { return "com.highfidelity.recording.Audio"; }
29 
30  const int MAX_CODEC_NAME_LENGTH = 30;
31  const int MAX_CODEC_NAME_LENGTH_ON_WIRE = MAX_CODEC_NAME_LENGTH + sizeof(uint32_t);
32  const int NETWORK_FRAME_BYTES_STEREO = 960;
33  const int NETWORK_FRAME_SAMPLES_STEREO = NETWORK_FRAME_BYTES_STEREO / SAMPLE_SIZE;
34  const int NETWORK_FRAME_BYTES_PER_CHANNEL = NETWORK_FRAME_BYTES_STEREO / 2;
35  const int NETWORK_FRAME_SAMPLES_PER_CHANNEL = NETWORK_FRAME_BYTES_PER_CHANNEL / SAMPLE_SIZE;
36  const int NETWORK_FRAME_SAMPLES_AMBISONIC = NETWORK_FRAME_SAMPLES_PER_CHANNEL * AMBISONIC;
37  const float NETWORK_FRAME_SECS = (AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL / float(AudioConstants::SAMPLE_RATE));
38  const float NETWORK_FRAME_MSECS = NETWORK_FRAME_SECS * 1000.0f;
39  const float NETWORK_FRAMES_PER_SEC = 1.0f / NETWORK_FRAME_SECS;
40 
41  // be careful with overflows when using this constant
42  const int NETWORK_FRAME_USECS = static_cast<int>(NETWORK_FRAME_MSECS * 1000.0f);
43 
44  const int MIN_SAMPLE_VALUE = std::numeric_limits<AudioSample>::min();
45  const int MAX_SAMPLE_VALUE = std::numeric_limits<AudioSample>::max();
46 }
47 
48 
49 #endif // hifi_AudioConstants_h