Page 2 of 2

Re: Catch, Load and Play the Core Audio Format

Posted: Fri Sep 21, 2012 12:11 pm
by ts-soft
Image

from 2011 :wink:

Re: Catch, Load and Play the Core Audio Format

Posted: Fri Sep 21, 2012 12:18 pm
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.

Re: Catch, Load and Play the Core Audio Format

Posted: Fri Sep 21, 2012 8:37 pm
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.

Re: Catch, Load and Play the Core Audio Format

Posted: Fri Sep 21, 2012 8:51 pm
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

Re: Catch, Load and Play the Core Audio Format

Posted: Fri Sep 28, 2012 5:08 am
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.

Re: Catch, Load and Play the Core Audio Format

Posted: Fri Sep 28, 2012 6:11 am
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

Re: Catch, Load and Play the Core Audio Format

Posted: Fri Sep 28, 2012 10:04 am
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

Re: Catch, Load and Play the Core Audio Format

Posted: Fri Sep 28, 2012 1:40 pm
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)