1 /**
2 Dynamic bindings to the CoreAudio framework.
3 
4 Copyright: Guillaume Piolat 2015.
5 License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6 */
7 module derelict.carbon.coreaudio;
8 
9 
10 import derelict.carbon.corefoundation;
11 
12 // <CoreAudio/CoreAudioTypes.h>
13 
14 struct SMPTETime
15 {
16     short          mSubframes;
17     short          mSubframeDivisor;
18     uint           mCounter;
19     uint           mType;
20     uint           mFlags;
21     short          mHours;
22     short          mMinutes;
23     short          mSeconds;
24     short          mFrames;
25 }
26 
27 
28 alias AudioTimeStampFlags = UInt32;
29 enum : AudioTimeStampFlags
30 {
31     kAudioTimeStampNothingValid         = 0,
32     kAudioTimeStampSampleTimeValid      = (1U << 0),
33     kAudioTimeStampHostTimeValid        = (1U << 1),
34     kAudioTimeStampRateScalarValid      = (1U << 2),
35     kAudioTimeStampWordClockTimeValid   = (1U << 3),
36     kAudioTimeStampSMPTETimeValid       = (1U << 4),
37     kAudioTimeStampSampleHostTimeValid  = (kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid)
38 }
39 
40 
41 struct AudioTimeStamp
42 {
43     double              mSampleTime;
44     ulong               mHostTime;
45     double              mRateScalar;
46     ulong               mWordClockTime;
47     SMPTETime           mSMPTETime;
48     uint                mFlags;
49     uint                mReserved;
50 }
51 
52 struct AudioBuffer
53 {
54     uint              mNumberChannels;
55     uint              mDataByteSize;
56     void*             mData;
57 }
58 
59 struct AudioBufferList
60 {
61     uint      mNumberBuffers;
62     AudioBuffer[1] mBuffers;
63 }
64 
65 alias AudioSampleType = float;
66 
67 alias AudioFormatID = uint;
68 alias AudioFormatFlags = uint;
69 enum : AudioFormatFlags
70 {
71     kAudioFormatFlagIsFloat                     = (1U << 0),     // 0x1
72     kAudioFormatFlagIsBigEndian                 = (1U << 1),     // 0x2
73     kAudioFormatFlagIsSignedInteger             = (1U << 2),     // 0x4
74     kAudioFormatFlagIsPacked                    = (1U << 3),     // 0x8
75     kAudioFormatFlagIsAlignedHigh               = (1U << 4),     // 0x10
76     kAudioFormatFlagIsNonInterleaved            = (1U << 5),     // 0x20
77     kAudioFormatFlagIsNonMixable                = (1U << 6),     // 0x40
78     kAudioFormatFlagsAreAllClear                = 0x80000000,
79 
80     kLinearPCMFormatFlagIsFloat                 = kAudioFormatFlagIsFloat,
81     kLinearPCMFormatFlagIsBigEndian             = kAudioFormatFlagIsBigEndian,
82     kLinearPCMFormatFlagIsSignedInteger         = kAudioFormatFlagIsSignedInteger,
83     kLinearPCMFormatFlagIsPacked                = kAudioFormatFlagIsPacked,
84     kLinearPCMFormatFlagIsAlignedHigh           = kAudioFormatFlagIsAlignedHigh,
85     kLinearPCMFormatFlagIsNonInterleaved        = kAudioFormatFlagIsNonInterleaved,
86     kLinearPCMFormatFlagIsNonMixable            = kAudioFormatFlagIsNonMixable,
87     kLinearPCMFormatFlagsSampleFractionShift    = 7,
88     kLinearPCMFormatFlagsSampleFractionMask     = (0x3F << kLinearPCMFormatFlagsSampleFractionShift),
89     kLinearPCMFormatFlagsAreAllClear            = kAudioFormatFlagsAreAllClear,
90 
91     kAppleLosslessFormatFlag_16BitSourceData    = 1,
92     kAppleLosslessFormatFlag_20BitSourceData    = 2,
93     kAppleLosslessFormatFlag_24BitSourceData    = 3,
94     kAppleLosslessFormatFlag_32BitSourceData    = 4
95 }
96 version(LittleEndian)
97 {
98     enum : AudioFormatFlags
99     {
100         kAudioFormatFlagsNativeEndian = 0
101     }
102 }
103 
104 version(BigEndian)
105 {
106     enum : AudioFormatFlags
107     {
108         kAudioFormatFlagsNativeEndian = kAudioFormatFlagIsBigEndian
109     }
110 }
111 
112 enum : AudioFormatFlags
113 {
114     kAudioFormatFlagsNativeFloatPacked = kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked
115 }
116 
117 
118 struct AudioStreamBasicDescription
119 {
120     double              mSampleRate;
121     AudioFormatID       mFormatID;
122     AudioFormatFlags    mFormatFlags;
123     uint              mBytesPerPacket;
124     uint              mFramesPerPacket;
125     uint              mBytesPerFrame;
126     uint              mChannelsPerFrame;
127     uint              mBitsPerChannel;
128     uint              mReserved;
129 }
130 
131 enum : AudioFormatID
132 {
133     kAudioFormatLinearPCM = CCONST('l', 'p', 'c', 'm')
134 }
135 
136 alias AudioChannelLayoutTag = UInt32;
137 enum : AudioChannelLayoutTag
138 {
139     kAudioChannelLayoutTag_Mono                     = (100U<<16) | 1,   // a standard mono stream
140     kAudioChannelLayoutTag_Stereo                   = (101U<<16) | 2,   // a standard stereo stream (L R) - implied playback
141     kAudioChannelLayoutTag_StereoHeadphones         = (102U<<16) | 2,   // a standard stereo stream (L R) - implied headphone playback
142     kAudioChannelLayoutTag_MatrixStereo             = (103U<<16) | 2,   // a matrix encoded stereo stream (Lt, Rt)
143     kAudioChannelLayoutTag_MidSide                  = (104U<<16) | 2,   // mid/side recording
144     kAudioChannelLayoutTag_XY                       = (105U<<16) | 2,   // coincident mic pair (often 2 figure 8's)
145     kAudioChannelLayoutTag_Binaural                 = (106U<<16) | 2,   // binaural stereo (left, right)
146     kAudioChannelLayoutTag_Unknown                  = 0xFFFF0000        // needs to be OR'd with number of channels
147 }
148