Catch, Load and Play the Core Audio Format

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Catch, Load and Play the Core Audio Format

Post by ts-soft »

Image

from 2011 :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Catch, Load and Play the Core Audio Format

Post by wilbert »

Regardless of the market share, there can always be reasons to choose cross platform development or not.
In this case, support was asked for Core Audio Format which is Mac only so it makes little sense to develop a Windows tool for a Mac-only file format.
And when it comes to profit, the App store is a very easy way for distribution and my impression is that Apple users are more likely willing to pay for an application.
When you look at the mobile market for example, Google Android has a bigger market share compared to Apple iOS. Still a lot of developers choose to develop for iOS since in general the profits are higher.
Orreven
User
User
Posts: 10
Joined: Fri Sep 21, 2012 12:47 am

Re: Catch, Load and Play the Core Audio Format

Post by Orreven »

wilbert wrote:Still a lot of developers choose to develop for iOS since in general the profits are higher.
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.
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Catch, Load and Play the Core Audio Format

Post by J. Baker »

I chose Core Audio for the reasons wilbert has stated. That and the code wilbert wrote for my request uses less resources. So even if I were to develop the same app or game for Windows, I would still use Core Audio for Mac because it uses less resources and do something else for Windows, that also used minimal resources. <-- I believe that's what you call a "run on sentence". :D
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Catch, Load and Play the Core Audio Format

Post by chris319 »

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 ?
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
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Catch, Load and Play the Core Audio Format

Post by wilbert »

chris319 wrote:The thread topic only asks about Core Audio, not about specific file types.
Core Audio Format is a specific file type
http://en.wikipedia.org/wiki/Core_Audio_Format
infratec
Always Here
Always Here
Posts: 7591
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Catch, Load and Play the Core Audio Format

Post by infratec »

Hi,

I just looked at the specs for CAF files.

Hm...
It should be easy to open them, look if mp3 or pcm is inside and play this data with PB.

But since I have no Mac...

Bernd
infratec
Always Here
Always Here
Posts: 7591
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Catch, Load and Play the Core Audio Format

Post by infratec »

Since I had a bit time:

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)
Post Reply