[futurebasic] Re: [FB] Anyone done any Core Audio work in FB?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2005 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Thu, 17 Nov 2005 16:57:56 +1300
Bill Sanford wrote:

> First, how would I add the Core Audio APIs to FB?

You'll need to be more specific. Which Core Audio APIs?

> Can I assume that they are in a library like the QuickTime APIs?

No.

> To add various QuickTime APIs, I did the following:
>
> LIBRARY "QuickTimeLib"
> toolbox FN SGStop(ptr) = long
> toolbox FN SGStartRecord(ptr) = long
> toolbox FN SGIdle(ptr) = long
> toolbox FN SGPause(ptr, int) = long
> 'And other QT APIs...
> LIBRARY
>
> I found a QuickTime API file that showed the C APIs and made the FB  
> toolbox
> functions from looking the C API over.

That library statement won't work in Carbon.
Those toolbox definitions are written in an style that removes a lot  
of helpful information.

The demo below (written by Alain, Ken and me) is intended to record 2  
s of sound and save it as a QT movie file. It could serve as a base  
for your explorations in QuickTime sound.

Robert P.

'----------------------------------
'~'A
'                             Runtime : Rntm Appearance.Incl
'                                 CPU : Carbon
'~'B
#define SeqGrabComponent      as ComponentInstance
#define SGChannel             as ComponentInstance
#define ConstComponentListPtr as pointer
#define SGModalFilterUPP      as pointer

library "Apple;Carbon;Multimedia"

toolbox fn SGNewChannel( ¬
     SeqGrabComponent  s,¬
     OSType            channelType,¬
     SGChannel         *ref ) = ComponentResult

toolbox fn SGSettingsDialog( ¬
     SeqGrabComponent  s,¬
     SGChannel         c,¬
     short             numPanels,¬
     ConstComponentListPtr panelList,¬
     long              flags,¬
     SGModalFilterUPP  proc,¬
     long              procRefNum ) = ComponentResult

toolbox fn SGSetDataOutput( ¬
     SeqGrabComponent  s, ¬
     const FSSpec      *movieFile, ¬
     long              whereFlags ) = ComponentResult
toolbox fn SGStartRecord( SeqGrabComponent s ) = ComponentResult
toolbox fn SGSetChannelUsage( SGChannel c, long usage) = ComponentResult
toolbox fn SGIdle( SeqGrabComponent s ) = ComponentResult
toolbox fn SGStop( SeqGrabComponent s ) = ComponentResult

library

local mode
local fn SoundRecordQT( fileSpec as ^FSSpec, numTicks as long )
'~'1
dim as ComponentResult      err, ignore
dim as SGChannel          @ sgSoundChanRef
dim as SeqGrabComponent     sgComponent

sgComponent = fn OpenDefaultComponent ( _SeqGrabComponentType, 0 )
err = fn SGInitialize ( sgComponent )
if ( err == _noErr ) then err = ¬
   fn SGNewChannel( sgComponent, _SoundMediaType, sgSoundChanRef )
if ( err == _noErr ) then err = ¬
   fn SGSetChannelUsage( sgSoundChanRef, _seqGrabRecord )
if ( err == _noErr ) then err = ¬
   fn SGSettingsDialog( sgComponent, sgSoundChanRef, 0, 0, 0, 0, 0 )
if ( err == _noErr ) then err = ¬
   fn SGSetDataOutput( sgComponent, #fileSpec, _seqGrabToDisk )
if ( err == _noErr ) then err = ¬
   fn SGStartRecord( sgComponent )
long if ( err == _noErr )
print "Recording..."
numTicks = fn TickCount() + numTicks
do
err = fn SGIdle( sgComponent )
delay 70 // 70 ms approx 1 tick
until ( err != _noErr or fn TickCount() > numTicks )
print "Done"
ignore = fn SGStop( sgComponent )
end if
if ( sgComponent ) then ignore = fn CloseComponent( sgComponent )

end fn = err


dim as FSSpec            fSpec
dim as ComponentResult   err
window 1
long if files$( _fSSpecSave,,, fSpec )
err = fn SoundRecordQT( fSpec, 120 ) // 120 ticks = 2 s
long if ( err != _noErr and err != _userCanceledErr )
stop "SoundRecordQT error " + str$( err )
end if
end if
do
HandleEvents
until 0
'----------------------------------