[futurebasic] Re: [FB] Speaker -- Default Output Volume

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2002 : Group Archive : Group : All Groups

From: Chris Stasny <staz@...>
Date: Thu, 21 Feb 2002 20:25:02 -0600
>tedd wrote:
>>
>>  Hi:
>>
>>  I read in an obviously dated book (Foundations of Mac Programming by
>>  Sydow), that one could find the current volume level for the sound
>>  control panel by using:
>>
>>  in C
>>
>>       long theOrginalVol;
>>       GetDefaultOutPutVolume( &theOriginalVol );
>>
>>  And, then to set the volume, one would use:
>>
>>  Again, in C
>>
>>       long  theNewVolume = 0x04000400
>>       SetDefaultOutputVolume( theNewVolume );
>>
>>  However, I find no:
>>
>>     GetDefaultOutPutVolume( &theOriginalVol );
>>     SetDefaultOutputVolume( theNewVolume );
>>
>>  similar FB functions.
>>
>>  Now, I know that I can use the Sound Manager and change the volume
>>  and channel (right and left) of what's being played via _ampCmd and
>>  _volumeCmd commands using param1 and param2, but that's not my
>>  question.
>>
>>  I want to know how to change the volume settings in the system sound
>>  control panel. This means that after doing such, the values that the
>>  user has set in the sound control panel will change.
>>
>Tedd,


squz me for sending old fbII code, but it's the only thing i found on
my hd that fits the bill.


'----------------------------------
' FN setSndVolume.BAS
' by Ross W. Lambert
' Copyright © 1995
' Ariel Publishing, Inc.
'----------------------------------
COMPILE 0,_dimmedVarsOnly_noRedimVars

DEFSTR LONG
DIM a$, level%, level&
END GLOBALS
GOTO "demo"
'comments from Bill...
'The following two sets of translations of the "correct" way to do this
'are untested, but provided here in case you have trouble with the "original"
'method written by Ross, particularly on newer Macs or newer Systems.
'The author(s) of these are unknown to me, but they were posted to the
'FB list, so I assume they are "fair game"!

'--------- Option #1 --------

'      Function:GetDefaultOutputVolume
'
'=========================================
LOCAL MODE
LOCAL FN GetDefaultOutputVolume(@level&)
   '---------------------------------------
   `     CLR.W     -(SP)
   `     MOVE.L    ^level&,-(SP)                   ;Var: LONGINT
   `     DC.W      $203C,$022C,$0018,$A800
   `     MOVE.W    (SP)+,D0
   `     EXT.L     D0
END FN = REGISTER(D0)                             'OSErr
'
'      Function:SetDefaultOutputVolume
'
'=========================================
LOCAL MODE
LOCAL FN SetDefaultOutputVolume(level&)
   '---------------------------------------
   `     CLR.W     -(SP)
   `     MOVE.L    ^level&,-(SP)                   ;LONGINT
   `     DC.W      $203C,$0230,$0018,$A800
   `     MOVE.W    (SP)+,D0
   `     EXT.L     D0
END FN = REGISTER(D0)                             'OSErr
'

'--------Option #2----------

' FN GetDefaultOutputVolume returns the long integer version of the system
' volume. This is a toolbox interface.
' OK for Miniruntime: Yes
' INPUTS:  sndVolumePtr& -    VAR: pointer to a long integer for the volume
' OUTPUTS: osErr%   -         INTEGER: osErr% (0 = _noErr)
' GLOBALS: none

LOCAL MODE
LOCAL FN GetDefaultOutputVolume (@sndVolumePtr&)
   `  SUBQ.L    #2,sp                    ;clear space for osErr
   `  MOVE.L    ^sndVolumePtr&,-(sp)     ;push volume ptr on stack
   `  DC.W      $203C,$022C,$0018,$A800  ;_GetDefaultOutputVolume
   `  MOVE.W    (sp)+,D0                 ;D0 = result
   `  EXT.L     D0                       ;END FN = D0 = osErr%
END FN

'----------------------------------

' SetDefaultOutputVolume  sets the system volume. This is an interface to a
' new toolbox call.
' OK for Miniruntime: Yes
' INPUTS:      NewSndVolume& - LONGINT: the new sound volume -> this longint
'                              is in a special format. The low word is
'                              the left channel volume, the hi word is the
'                              right channel volume, each in the range of
'                              0 - 256 ($0000 to $0100). Note that you CAN
'                              overdrive the channels.
' OUTPUT:      osErr%    -     INTEGER: osErr% (0 = _noErr)
' GLOBALS:     none

LOCAL MODE
LOCAL FN SetDefaultOutputVolume (NewSndVolume&)
   `  SUBQ.L    #2,sp                    ;clear space for result
   `  MOVE.L    ^NewSndVolume&,-(sp)     ;push volume on stack
   `  DC.W      $203C,$0230,$0018,$A800 ;_SetSysBeepVolume
   `  MOVE.W    (sp)+,D0                 ;D0 = result
   `  EXT.L     D0                       ;END FN = D0
END FN


'---------------------------------- The Original Function Definitions

' FN setSndVolume sets the volume for the Mac speaker. Note that use of the
' FN may violate Apple Guidelines. The system volume should be under the user's
' control at all times; don't set it behind the user's back.
Generally speaking,
' programs should use whatever volume is set in the Sound control panel. It
' may nice in some situations, however (such as a game), to let the user set
' the speaker volume directly from the application without having to detour to
' a control panel. If you do this, it is polite to reset the old volume when
' your application terminates.

' OK for Miniruntime: Yes

' INPUT:   level%    -    INTEGER: the sound level (0-7)
' OUTPUT:  osErr%    -    INTEGER: System error, if any (0 = no error)
' GLOBALS: none

LOCAL MODE
LOCAL FN setSndVolume(level%)
   DIM pBlk.100
   DIM osErr%
   pBlk.ioCompletion& =  0                         'completion rtn
   pBlk.DCtlRefNum%   = -4                         'drvr ref num
   pBlk.CsCode%       =  2                         'control code
   pBlk.CSParam%      =  level%                    'snd vol (0-7)
   osErr% = FN CONTROL(@pBlk)
END FN = osErr%
'

'---------------------------------- Demonstration
"demo"

WINDOW 1,"FN  Demo"
TEXT _Monaco,9

PRINT
PRINT "------------------------------------------------"
PRINT

PRINT "Set sound level (0=Off, 1=low, 7=loudest),"
PRINT "<Q> quits"
DO
   a$=INKEY$
   level% = ASC(a$)-48
   LONG IF level%>=0 AND level%<=7
     PRINT "Old Volume: = ";PEEK(&260)
     PRINT "     OSErr: = ";FN setSndVolume(level%)
     PRINT "New Volume: = ";PEEK(&260)
     PRINT
     BEEP: BEEP
   END IF
UNTIL a$="Q" OR a$="q"
END



--


-STAZ  ~)~