Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Specification.h « respec « include « audaspace « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: efcbb4cabce448244e2b41c68089916fe403973d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*******************************************************************************
 * Copyright 2009-2016 Jörg Müller
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

#pragma once

/**
 * @file Specification.h
 * @ingroup respec
 * Defines all important macros and basic data structures for stream format descriptions.
 */

#include "Audaspace.h"

/// The size of a format in bytes.
#define AUD_FORMAT_SIZE(format) (format & 0x0F)
/// The size of a sample in the specified device format in bytes.
#define AUD_DEVICE_SAMPLE_SIZE(specs) (specs.channels * (specs.format & 0x0F))
/// The size of a sample in the specified format in bytes.
#define AUD_SAMPLE_SIZE(specs) (specs.channels * sizeof(sample_t))

/// Compares two audio data specifications.
#define AUD_COMPARE_SPECS(s1, s2) ((s1.rate == s2.rate) && (s1.channels == s2.channels))

/// Returns the bit for a channel mask.
#define AUD_CHANNEL_BIT(channel) (0x01 << channel)

AUD_NAMESPACE_BEGIN

/**
 * The format of a sample.
 * The last 4 bit save the byte count of the format.
 */
enum SampleFormat
{
	FORMAT_INVALID = 0x00,		/// Invalid sample format.
	FORMAT_U8      = 0x01,		/// 1 byte unsigned byte.
	FORMAT_S16     = 0x12,		/// 2 byte signed integer.
	FORMAT_S24     = 0x13,		/// 3 byte signed integer.
	FORMAT_S32     = 0x14,		/// 4 byte signed integer.
	FORMAT_FLOAT32 = 0x24,		/// 4 byte float.
	FORMAT_FLOAT64 = 0x28		/// 8 byte float.
};

/// The channel count.
enum Channels
{
	CHANNELS_INVALID    = 0,	/// Invalid channel count.
	CHANNELS_MONO       = 1,	/// Mono.
	CHANNELS_STEREO     = 2,	/// Stereo.
	CHANNELS_STEREO_LFE = 3,	/// Stereo with LFE channel.
	CHANNELS_SURROUND4  = 4,	/// 4 channel surround sound.
	CHANNELS_SURROUND5  = 5,	/// 5 channel surround sound.
	CHANNELS_SURROUND51 = 6,	/// 5.1 surround sound.
	CHANNELS_SURROUND61 = 7,	/// 6.1 surround sound.
	CHANNELS_SURROUND71 = 8	/// 7.1 surround sound.
};

/// The channel names.
enum Channel
{
	CHANNEL_FRONT_LEFT = 0,
	CHANNEL_FRONT_RIGHT,
	CHANNEL_FRONT_CENTER,
	CHANNEL_LFE,
	CHANNEL_REAR_LEFT,
	CHANNEL_REAR_RIGHT,
	CHANNEL_REAR_CENTER,
	CHANNEL_SIDE_LEFT,
	CHANNEL_SIDE_RIGHT,
	CHANNEL_MAX
};

/**
 * The sample rate tells how many samples are played back within one second.
 * Some exotic formats may use other sample rates than provided here.
 */
enum DefaultSampleRate
{
	RATE_INVALID = 0,			/// Invalid sample rate.
	RATE_8000    = 8000,		/// 8000 Hz.
	RATE_16000   = 16000,		/// 16000 Hz.
	RATE_11025   = 11025,		/// 11025 Hz.
	RATE_22050   = 22050,		/// 22050 Hz.
	RATE_32000   = 32000,		/// 32000 Hz.
	RATE_44100   = 44100,		/// 44100 Hz.
	RATE_48000   = 48000,		/// 48000 Hz.
	RATE_88200   = 88200,		/// 88200 Hz.
	RATE_96000   = 96000,		/// 96000 Hz.
	RATE_192000  = 192000		/// 192000 Hz.
};

/// Sample rate type.
typedef double SampleRate;

/// Specification of a sound source.
struct Specs
{
	/// Sample rate in Hz.
	SampleRate rate;

	/// Channel count.
	Channels channels;
};

/// Specification of a sound device.
struct DeviceSpecs
{
	/// Sample format.
	SampleFormat format;

	union
	{
		struct
		{
			/// Sample rate in Hz.
			SampleRate rate;

			/// Channel count.
			Channels channels;
		};
		Specs specs;
	};
};

AUD_NAMESPACE_END