1 /* 2 * Copyright (c) 2016 Guillaume Piolat 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the names 'Derelict', 'DerelictSDL', nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 /** 33 Dynamic bindings to the CoreAudio framework. 34 */ 35 module derelict.carbon.coreaudio; 36 37 38 import derelict.carbon.corefoundation; 39 40 // <CoreAudio/CoreAudioTypes.h> 41 42 struct SMPTETime 43 { 44 short mSubframes; 45 short mSubframeDivisor; 46 uint mCounter; 47 uint mType; 48 uint mFlags; 49 short mHours; 50 short mMinutes; 51 short mSeconds; 52 short mFrames; 53 } 54 55 56 alias AudioTimeStampFlags = UInt32; 57 enum : AudioTimeStampFlags 58 { 59 kAudioTimeStampNothingValid = 0, 60 kAudioTimeStampSampleTimeValid = (1U << 0), 61 kAudioTimeStampHostTimeValid = (1U << 1), 62 kAudioTimeStampRateScalarValid = (1U << 2), 63 kAudioTimeStampWordClockTimeValid = (1U << 3), 64 kAudioTimeStampSMPTETimeValid = (1U << 4), 65 kAudioTimeStampSampleHostTimeValid = (kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid) 66 } 67 68 69 struct AudioTimeStamp 70 { 71 double mSampleTime; 72 ulong mHostTime; 73 double mRateScalar; 74 ulong mWordClockTime; 75 SMPTETime mSMPTETime; 76 uint mFlags; 77 uint mReserved; 78 } 79 80 struct AudioBuffer 81 { 82 uint mNumberChannels; 83 uint mDataByteSize; 84 void* mData; 85 } 86 87 struct AudioBufferList 88 { 89 uint mNumberBuffers; 90 AudioBuffer[1] mBuffers; 91 } 92 93 alias AudioSampleType = float; 94 95 alias AudioFormatID = uint; 96 alias AudioFormatFlags = uint; 97 enum : AudioFormatFlags 98 { 99 kAudioFormatFlagIsFloat = (1U << 0), // 0x1 100 kAudioFormatFlagIsBigEndian = (1U << 1), // 0x2 101 kAudioFormatFlagIsSignedInteger = (1U << 2), // 0x4 102 kAudioFormatFlagIsPacked = (1U << 3), // 0x8 103 kAudioFormatFlagIsAlignedHigh = (1U << 4), // 0x10 104 kAudioFormatFlagIsNonInterleaved = (1U << 5), // 0x20 105 kAudioFormatFlagIsNonMixable = (1U << 6), // 0x40 106 kAudioFormatFlagsAreAllClear = 0x80000000, 107 108 kLinearPCMFormatFlagIsFloat = kAudioFormatFlagIsFloat, 109 kLinearPCMFormatFlagIsBigEndian = kAudioFormatFlagIsBigEndian, 110 kLinearPCMFormatFlagIsSignedInteger = kAudioFormatFlagIsSignedInteger, 111 kLinearPCMFormatFlagIsPacked = kAudioFormatFlagIsPacked, 112 kLinearPCMFormatFlagIsAlignedHigh = kAudioFormatFlagIsAlignedHigh, 113 kLinearPCMFormatFlagIsNonInterleaved = kAudioFormatFlagIsNonInterleaved, 114 kLinearPCMFormatFlagIsNonMixable = kAudioFormatFlagIsNonMixable, 115 kLinearPCMFormatFlagsSampleFractionShift = 7, 116 kLinearPCMFormatFlagsSampleFractionMask = (0x3F << kLinearPCMFormatFlagsSampleFractionShift), 117 kLinearPCMFormatFlagsAreAllClear = kAudioFormatFlagsAreAllClear, 118 119 kAppleLosslessFormatFlag_16BitSourceData = 1, 120 kAppleLosslessFormatFlag_20BitSourceData = 2, 121 kAppleLosslessFormatFlag_24BitSourceData = 3, 122 kAppleLosslessFormatFlag_32BitSourceData = 4 123 } 124 version(LittleEndian) 125 { 126 enum : AudioFormatFlags 127 { 128 kAudioFormatFlagsNativeEndian = 0 129 } 130 } 131 132 version(BigEndian) 133 { 134 enum : AudioFormatFlags 135 { 136 kAudioFormatFlagsNativeEndian = kAudioFormatFlagIsBigEndian 137 } 138 } 139 140 enum : AudioFormatFlags 141 { 142 kAudioFormatFlagsNativeFloatPacked = kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked 143 } 144 145 146 struct AudioStreamBasicDescription 147 { 148 double mSampleRate; 149 AudioFormatID mFormatID; 150 AudioFormatFlags mFormatFlags; 151 uint mBytesPerPacket; 152 uint mFramesPerPacket; 153 uint mBytesPerFrame; 154 uint mChannelsPerFrame; 155 uint mBitsPerChannel; 156 uint mReserved; 157 } 158 159 enum : AudioFormatID 160 { 161 kAudioFormatLinearPCM = CCONST('l', 'p', 'c', 'm') 162 } 163 164 alias AudioChannelLayoutTag = UInt32; 165 enum : AudioChannelLayoutTag 166 { 167 kAudioChannelLayoutTag_Mono = (100U<<16) | 1, // a standard mono stream 168 kAudioChannelLayoutTag_Stereo = (101U<<16) | 2, // a standard stereo stream (L R) - implied playback 169 kAudioChannelLayoutTag_StereoHeadphones = (102U<<16) | 2, // a standard stereo stream (L R) - implied headphone playback 170 kAudioChannelLayoutTag_MatrixStereo = (103U<<16) | 2, // a matrix encoded stereo stream (Lt, Rt) 171 kAudioChannelLayoutTag_MidSide = (104U<<16) | 2, // mid/side recording 172 kAudioChannelLayoutTag_XY = (105U<<16) | 2, // coincident mic pair (often 2 figure 8's) 173 kAudioChannelLayoutTag_Binaural = (106U<<16) | 2, // binaural stereo (left, right) 174 kAudioChannelLayoutTag_Unknown = 0xFFFF0000 // needs to be OR'd with number of channels 175 } 176