[futurebasic] Re: FB SOUND command Problem - More thoughts

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2006 : Group Archive : Group : All Groups

From: Walter Lenk <Walter_Lenk@...>
Date: Fri, 18 Aug 2006 14:55:22 -0400
Greetings again -

On Aug 14, 2006 I Wrote:
>  Recently I have started having problems with the SOUND Command on my
>  primary computer (machine #1 in the list below).

John McKernon wrote:
>  Alain Wrobel brilliantly came up with what the problem is, here's his
>  answer:
>  Check your audio setting in Applications / Utilities / Audio MIDI Setup. In
>  the Audio Devices section, check that your Audio Output format is set to
>  44100.0 Hz.
>  (some audio apps turn this format to 99000 Hz -audacity for example-)
>  The FB Sound command requires 44100, anything else causes an OS hang.

I then wrote:
>  This indeed fixed the problem - my thanks to Alain, John, and Brian.
>  Audacity WAS responsible for setting the default sample rate to 96 kHz.
>  Seems like this is a tidbit that could well be added to the FB SOUND
>  docs - any idea how?

Upon ruminating on this overnight, it seems like it also might be 
desirable to change the runtime a bit to alert the user of this 
problem instead of hanging the program (particularly since the newer 
machines can be set this way).  Here is the routine that I added to 
my program, and the two runtime routines that I modified (with the 
addition of a single line each) to alert of this condition.  Any 
comments?

Best,

Walter

============== Start FB Code ===============
'~ 'SOUND' command error check
local:dim A$, B$, C$, D$, err%
local FN NotifySOUNDerror
long if (gFBQuit%==_False)
beep
let gFBQuit% = _True
LET A$ = "The Audio Output is not set correctly."
LET B$ = "You must run 'Audio MIDI Setup', located"
let C$ = "in 'Applications:Utilities', and change"
LET D$ = "the Audio Output format to 44100 Hz"
CALL PARAMTEXT(A$,B$,C$,D$)
LET err% = FN STOPALERT(1,0)
end if
end fn

' Slightly Modified routines from 'Subs Sound.Incl'
local
DIM Err
OVERRIDE local fn FBPlaySoundHandle
LONG IF gFBSndHndl&
gFBSndHndlState% = FN HGetState(gFBSndHndl&)// Save Handle State
call MOVEHHI(gFBSndHndl&)// Avoid Heap Fragmentation
call HLOCK(gFBSndHndl&)// Keep in Memory Locked
long if gFBSndProc& == 0
gFBSndProc& = PROC "FBSndProc"
#if carbonlib
gFBSndProc& = fn NewSndCallBackUPP([gFBSndProc& + _FBprocToProcPtrOffset])
#endif
end if
gFBSndChanPtr& = 0
Err = FN SNDNEWCHANNEL(gFBSndChanPtr&,_SampledSynth,0,gFBSndProc&)
if Err then FN NotifySOUNDerror: Exit FN' **** Added line [08/18/06 WCL} ****
Err = FN SNDPLAY(gFBSndChanPtr&,gFBSndHndl&,_zTrue)
gFBSndCmd%  = 13// enter a call back command in snd mgr queue
gFBSndBusy% = -1// Sound Busy
Err = FN SNDDOCOMMAND(gFBSndChanPtr&,gFBSndCmd%,0)
END IF
end fn

local
dim err,@mySndCmd%
OVERRIDE runtime SoundFreqDur(Freq&,Dur&,Vol&,Async&)

long if gFBSndHndl& '*** new ***
gFBSndHndlState% = FN HGetState(gFBSndHndl&)// Save Handle State
long if (gFBSndHndlState% and 0x80) = _false
call MOVEHHI(gFBSndHndl&)// Avoid Heap Fragmentation
call HLOCK(gFBSndHndl&)// Keep in Memory Locked
end if
end if

long if gFBSndChanPtr&'Date { 9/19/01 }
mySndCmd% = _quietCmd
err = FN SndDoImmediate(gFBSndChanPtr&,mySndCmd%)
err = FN SNDDISPOSECHANNEL(gFBSndChanPtr&,_zTrue)
end if'Date { 9/19/01 }

long if gFBSndProc& == 0
gFBSndProc& = PROC "FBSndProc"
#if carbonlib
gFBSndProc& = fn NewSndCallBackUPP([gFBSndProc& + _FBprocToProcPtrOffset])
#endif
end if

gFBSndChanPtr& = 0
Err = FN SNDNEWCHANNEL(gFBSndChanPtr&,_squarewavesynth,0,gFBSndProc&)
if Err then FN NotifySOUNDerror: Exit FN' **** Added line [08/18/06 WCL} ****

gFBSndCmd% = _ampcmd
gFBSndP1%  = (Vol& << 1)//convert 0-127 to 0-255
gFBSndP2&  = 0//not used
err = fn SNDDOCOMMAND(gFBSndChanPtr&,gFBSndCmd%,Async&)
let err = 1

long if Freq& < 0//midi note value
Freq& =-Freq&
xelse
Freq& = 60.0 + int((log(Freq&) - 5.56691)/ 0.057762265)'Date { 6/23/02 }
///Freq& = 60.0 + (log(Freq&) - 5.56691)/ 0.057762265'3/2/00 at 7:29 AM
end if

gFBSndCmd% = _freqDurationCmd
gFBSndP1%  = Dur& * 33//convert tks to half milliseconds
gFBSndP2&  = Freq&
Err = FN SNDDOCOMMAND(gFBSndChanPtr&,gFBSndCmd%,Async&)

gFBSndCmd%  = _callbackcmd// enter a call back command in snd mgr queue
gFBSndBusy% = _zTrue// Sound Busy
Err = FN SNDDOCOMMAND(gFBSndChanPtr&,gFBSndCmd%,_false)

long if Async& = _false
do
until gFBSndBusy% = _false
end if

end fn
============== End FB Code ===============


-- 

===========================================
Walter Lenk    Cambridge Ma    617-547-7781
===========================================