Re: Catch, Load and Play the Core Audio Format
Posted: Fri Sep 21, 2012 12:11 pm

from 2011

http://www.purebasic.com
https://www.purebasic.fr/english/
I agree, but still, nearly all either have, or soon develop an Android version once they release their iOS version. Also, I did not state 39% as an official fact, I just said that's the results of one survey. Other survey's are probably more accurate than the one I used though.wilbert wrote:Still a lot of developers choose to develop for iOS since in general the profits are higher.
The same way DirectSound or WASAPI help you load a .caf or .aac file. The thread topic only asks about Core Audio, not about specific file types.wilbert wrote:chris319 wrote:PortAudio is cross platform and is well developed for PureBasic.
PortAudio is great for realtime rendering of audio samples but how does it help you with loading a .caf or .aac file ?
Core Audio Format is a specific file typechris319 wrote:The thread topic only asks about Core Audio, not about specific file types.
Code: Select all
;
; CAF loader
;
#kAudioFormatLinearPCM = "lpcm"
#kAudioFormatAppleIMA4 = "ima4"
#kAudioFormatMPEG4AAC = "aac"
#kAudioFormatMACE3 = "MAC3"
#kAudioFormatMACE6 = "MAC6"
#kAudioFormatULaw = "ulaw"
#kAudioFormatALaw = "alaw"
#kAudioFormatMPEGLayer1 = ".mp1"
#kAudioFormatMPEGLayer2 = ".mp2"
#kAudioFormatMPEGLayer3 = ".mp3"
#kAudioFormatAppleLossless = "alac"
#kCAFLinearPCMFormatFlagIsFloat = (1 << 0)
#kCAFLinearPCMFormatFlagIsLittleEndian = (1 << 1)
#kMP4Audio_AAC_LC_ObjectType = 2
#CAFFileType = "caff"
#AudioChunkType = "desc"
#DataChunkType = "data"
#PacketChunkType = "pakt"
#ChannelLayoutChunkType = "chan"
#CookieChunkType = "kuki"
#StringChunkType = "strg"
#MarkerChunkType = "mark"
#InstrumentChunkType = "inst"
#MIDIChunkType = "midi"
#OverviewChunkType = "ovvw"
#PeakChunkType = "peak"
#EditCommentsChunkType = "edct"
#InfoChunkType = "info"
#UMIDChunkType = "umid"
#UUIDChunkType = "uuid"
#FreeChunkType = "free"
Structure CAFFileHeaderStructure
mFileType.l
mFileVersion.u
mFileFlags.u
EndStructure
Structure CAFChunkHeaderStructure
mChunkType.l
mChunkSize.q
EndStructure
Structure CAFAudioFormatStructure
mSampleRate.d
mFormatID.l
mFormatFlags.l
mBytesPerPacket.l
mFramesPerPacket.l
mChannelsPerFrame.l
mBitsPerChannel.l
EndStructure
Structure CAFDataStructure
mEditCount.l
*mData.a
EndStructure
Structure CAFPacketTableHeaderStructure
mNumberPackets.q
mNumberValidFrames.q
mPrimingFrames.l
mRemainderFrames.l
EndStructure
Structure CAFChannelDescriptionsStructure
mChannelLabel.l
mChannelFlags.l
mCoordinates.f[3]
EndStructure
Structure CAFChannelLayoutStructure
mChannelLayoutTag.l
mChannelBitmap.l
mNumberChannelDescriptions.l
*mChannelDescriptions.CAFChannelDescriptionsStructure
EndStructure
Structure CAFStringIDStructure
mStringID.l
mStringStartByteOffset.q
EndStructure
Structure CAFStringsStructure
mNumEntries.l
*mStringsIDs.CAFStringIDStructure
*mStrings.s
EndStructure
Structure CAF_SMPTE_TimeStructure
mHours.a
mMinutes.a
mSeconds.a
mFrames.a
mSubFrameSampleOffset.l
EndStructure
Structure CAFMarkerStructure
mType.l
mFramePosition.d
mMarkerID.l
mSMPTETime.CAF_SMPTE_TimeStructure
mChannel.l
EndStructure
Structure CAFMarkerChunkStructure
mSMPTE_TimeType.l
mNumberMarkers.l
*mMarkers.CAFMarkerStructure
EndStructure
Structure CAFRegionStructure
mRegionID.l
mFlags.l
mNumberMarkers.l
*mMarkers.CAFMarkerStructure
EndStructure
Structure CAFRegionChunkStructure
mSMPTE_TimeType.l
mNumberRegions.l
*mRegions.CAFRegionStructure
EndStructure
Structure CAFInstrumentChunkStructure
mBaseNote.f
mMIDILowNote.a
mMIDIHighNote.a
mMIDILowVelocity.a
mMIDIHighVelocity.a
mdBGain.f
mStartRegionID.l
mSustainRegionID.l
mReleaseRegionID.l
mInstrumentID.l
EndStructure
Structure CAFOverviewSampleStructure
mMinValue.w
mMaxValue.w
EndStructure
Structure CAFOverviewStructure
mEditCount.l
mNumFramesPerOVWSample.l
*mData.CAFOverviewSampleStructure
EndStructure
Structure CAFPositionPeakStructure
mValue.f
mFrameNumber.q
EndStructure
Structure CAFPeakChunkStructure
mEditCount.l
*mPeaks.CAFPositionPeakStructure
EndStructure
Structure CAFCommentStringsChunkStructure
mNumEntries.l
*mStrings.CAFStringIDStructure
EndStructure
Structure editCommmentStructure
mKey.s
mValue.s
EndStructure
Structure CAFStringsChunkStructure
mNumEntries.l
*mStrings.CAFStringIDStructure
EndStructure
Structure CAFInformationStructure
mKey.s
mValue.s
EndStructure
Structure CAFUMIDChunkStructure
mBytes.a[64]
EndStructure
Structure CAF_UUID_ChunkHeaderStructure
mHeader.CAFChunkHeaderStructure
mUUID.a[16]
EndStructure
Procedure.q Swap64(Value.q)
Protected Result.q, *ptrSrc, *ptrDst
*ptrSrc = @Value
*ptrDst = @Result + 7
For i = 0 To 7
PokeA(*ptrDst, PeekA(*ptrSrc))
*ptrSrc + 1
*ptrDst - 1
Next i
ProcedureReturn Result
EndProcedure
Procedure.i CAFInfo(Filename$)
Protected Result.i, File.i, FileSize.q, FilePos.q, Chunk$, FormatID$
Protected CAFFileHeader.CAFFileHeaderStructure
Protected CAFChunkHeader.CAFChunkHeaderStructure
Protected CAFAudioFormat.CAFAudioFormatStructure
Result = #False
File = ReadFile(#PB_Any, Filename$)
If File
FileSize = Lof(File)
If ReadData(File, @CAFFileHeader, SizeOf(CAFFileHeaderStructure))
If PeekS(@CAFFileHeader\mFileType,4) = #CAFFileType
Debug "CAF file detected"
While FilePos < FileSize
If ReadData(File, @CAFChunkHeader, SizeOf(CAFChunkHeaderStructure))
FilePos = Loc(File)
Chunk$ = PeekS(@CAFChunkHeader\mChunkType, 4)
Debug Chunk$
If Chunk$ = #AudioChunkType
If ReadData(File, @CAFAudioFormat, SizeOf(CAFAudioFormatStructure))
FormatID$ = PeekS(@CAFAudioFormat\mFormatID, 4)
Debug FormatID$
EndIf
EndIf
CAFChunkHeader\mChunkSize = Swap64(CAFChunkHeader\mChunkSize)
FilePos + CAFChunkHeader\mChunkSize
FileSeek(File, FilePos)
EndIf
Wend
EndIf
EndIf
CloseFile(File)
EndIf
ProcedureReturn Result
EndProcedure
CAFInfo(YourFilename.caf)