Microsoft KB Archive/43253

= Example of Playing a Sound Resource in Macintosh QuickBasic =

Article ID: 43253

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q43253



SUMMARY
The SOUND and WAVE statements in QuickBasic for the Macintosh let you generate four-voice sound. In addition, using Macintosh Sound Manager routines, you can also play sounds that have been stored on disk as resources, as described below.

The following is an explanation and example of playing a sound or &quot;snd &quot; resource using Macintosh QuickBasic. The routines for playing sounds are managed by the Sound Manager. The Sound Manager is documented in Volume V of &quot;Inside Macintosh&quot; by Apple Computer (published by Addison-Wesley).

There are seven routines that call the Sound Manager. SndPlay is the one that plays &quot;snd &quot; resources. The seven Sound Manager routines are not available as QuickBasic Toolbox Library routines (MBLCs), and they must be called with a modified version of QuickBasic's ToolBox statement. The ToolBox statement itself is an MBLC.

This information applies to Microsoft QuickBasic versions 1.0, 1.0a, and 1.0b for Apple Macintosh.



MORE INFORMATION
The &quot;snd &quot; resource name must be lowercase and followed by a space as shown.

To play large sounds (greater than 100K or so), you need to increase the memory available for QuickBasic for Macintosh so that it can load the resource (which is done when you call GetIndRes). Under Apple MultiFinder, you have to do this by changing the memory requirements from the 'Get Info' or with ResEdit so MultiFinder allocates enough memory when the program starts up. If you don't increase the memory limit, you will hang or get a system error when the program tries to invoke 'GetIndRes'.

The steps for calling Sound Manager routines are as follows:

 Steps to take before writing QuickBasic code are as follows:

 You must have an application that can create &quot;snd &quot; resources or have obtained them from a third party. QuickBasic does not create &quot;snd &quot; resources. To play &quot;snd &quot; resources, you must use ResEdit to insert them into some file that you can open with OpenResFile. If you cannot obtain any &quot;snd &quot; resources, there should be at least one in the resource fork of the SYSTEM itself so that this program example can be executed. You should verify this with ResEdit. QuickBasic's ToolBox routine itself needs modification. You must create two new MBLCs with ResEdit: ToolBoxOS and ToolBoxNewTool. For instructions to create these routines, query on the words ToolBoxNewTool or ToolBoxNewOS in this knowledge base. The instructions are also found in an application note, which can be obtained by calling Microsoft Technical Support at (425) 454-2030.  Steps inside of the QuickBasic source code are as follows:

 Use OpenResFile to open the resource fork of the file where the &quot;snd &quot; resources are stored. Get a handle to the first &quot;snd &quot; resource available using GetIndRes. This MBLC routine uses the index, which is passed to it, to get the nth resource of that type available. It searches all of the resource forks currently open, including the SYSTEM itself. That is why it's important that the SYSTEM include at least one &quot;snd &quot; resource for this program to work.</li> Use ToolBoxNewTool to call SndPlay with trap number &HA805. You must consult &quot;Inside Macintosh,&quot; Volume V, and &quot;Microsoft QuickBasic for Apple Macintosh: Language Reference,&quot; pages 497 to 503, to determine what parameters to pass, their data types, and whether to pass them by reference or by value.</li></ol> </li></ol>

Code Example
The following should be compiled with the &quot;Include MBPCs & MBLCs&quot; option: ' parameters for SndPlay DIM chan&, sndHdl&, OSErr%, async%, ref% ' Trap Numbers for SndPlay SndPlay% = &HA805 ' Initialize program variables chan& = 0 : sndHdl&= 0 : OSErr% = 0 async% = 0 : ref% = 0  : Index% = 1

ON ERROR GOTO errtrap ON DIALOG GOSUB PlaySound DIALOG ON BUTTON 1, 1, &quot;Sound&quot;, (100, 100)-(200, 200), 1

' Include the following line if you have an &quot;snd &quot; resource file. '   OpenResFile &quot;Your Resource File&quot;, ref% ToolBoxNewTool &quot;I&quot;

WHILE 1 ' Loop waiting for the button to be pressed. WEND END errtrap: Index% = 1 RESUME retry

PlaySound: temp = DIALOG(0) retry: GetIndRes &quot;snd &quot;,Index%, sndHdl& Index% = Index% + 1 ToolBoxNewTool &quot;WQ&quot;,SndPlay%,(chan&),(sndHdl&),(async%),OSErr% RETURN

Additional query words: MQuickB 1.00 1.00a 1.00b

Keywords: KB43253

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.