home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************************/
- /* */
- /* Module Name: HandsetPlayback */
- /* */
- /* File Name: HandsetPlayback.c */
- /* */
- /* © Apple Computer, Inc. 1994-1995 */
- /* All Rights Reserved */
- /* */
- /* Revision History: */
- /* */
- /* Date Who Modification */
- /* */
- /* 1994-05-20 Jaakko Railo Original version */
- /* 1994-08-06 Gary Anwyl Modified GetDNSndInOut to make this module */
- /* 1995-02-01 Jaakko Railo Modified LinePlayback to make this module */
- /* */
- /************************************************************************************************/
-
- /****************************************** DESCRIPTION ******************************************
-
- This module uses the StandardFile interface to get the name of a file
- containing an 'snd ' 128 resource. It then plays the sound asynchronously
- to the handset until the user presses the mouse button or the
- sound is finished playing. If the compile time option SND_RESOURCE is undefined
- then the sound is taken from an AIFF file instead of a sound resource.
-
- *************************************************************************************************/
-
- /******************************************** HEADERS *******************************************/
-
- #include "Sound.h"
- #include "SoundInput.h"
- #include "Events.h"
- #include "Resources.h"
- #include "TextUtils.h"
- #include "Types.h"
-
- #ifndef __TELEPHONES__
- #include "Telephones.h"
- #endif
-
- #include "TestModule.h"
-
- /****************************************** DEFINITIONS *****************************************/
-
- #define SND_RESOURCE // define to use 'snd ' resource, undef to use AIFF file
- #define kTotalSize 24*1024
-
- /****************************************** PROTOTYPES ******************************************/
-
- short GetFileDialog(void);
- void PlaySnd (CHRSPtr paramPtr, Component mySndOut);
- void DoTest (CHRSPtr paramPtr);
-
- /************************************************************************************************/
- /************************************************************************************************/
-
-
- pascal short TestModule (CHRSPtr paramPtr)
- {
- short returnValue = noErr;
-
- if (paramPtr->version <= kTestModuleVersion) {
-
- DoTest (paramPtr);
-
- }
- else
- returnValue = kWrongVersion;
-
- return (returnValue);
- }
-
-
- short GetFileDialog(void)
- {
- StandardFileReply getReply;
- short fRefNum;
- SFTypeList fileTypes = {'AIFF', 0, 0, 0};
-
- #ifdef SND_RESOURCE
- StandardGetFile(0, -1, 0, &getReply);
- if (!getReply.sfGood)
- return 0;
- fRefNum = FSpOpenResFile(&getReply.sfFile, fsRdPerm);
- if (fRefNum == -1)
- return 0;
- #else
- StandardGetFile(0, 1, fileTypes, &getReply);
- if (!getReply.sfGood)
- return 0;
- err = FSpOpenDF(&getReply.sfFile, fsRdPerm, &fRefNum);
- if (err != noErr)
- return 0;
- #endif
-
- return fRefNum;
- }
-
-
- void PlaySnd (CHRSPtr paramPtr, Component mySndOut)
- {
- OSErr myErr;
- SndChannelPtr myChan = nil;
- short myRefNum, curResFile;
- AudioSelection sel;
- SCStatus scStatus;
-
- curResFile = CurResFile();
-
- if ((myErr = SndNewChannel (&myChan, kUseOptionalOutputDevice, (long) mySndOut, nil)) != noErr) {
- Print (paramPtr, "### SndNewChannel failed : %d", myErr);
- return;
- }
-
- myRefNum = GetFileDialog();
- if (myRefNum == 0) {
- Print (paramPtr, "### GetFile failed");
- goto errExit1;
- }
-
- Print (paramPtr, "Start of playback");
- sel.unitType = unitTypeSeconds;
- sel.selStart = (0L<<16);
- sel.selEnd = (9999L<<16);
- #ifdef SND_RESOURCE
- UseResFile(myRefNum);
- if (Count1Resources('snd ') == 0) {
- Print (paramPtr, "### No 'snd ' resource");
- goto errExit1;
- }
- myErr = SndStartFilePlay(myChan, 0, 128, kTotalSize, nil, &sel, nil, true);
- #else
- myErr = SndStartFilePlay(myChan, myRefNum, 0, kTotalSize, nil, &sel, nil, true);
- #endif
- if (myErr != noErr) {
- Print (paramPtr, "### SndPlay failed : %d", myErr);
- goto errExit1;
- }
-
- while (1) {
- if (Button())
- break;
-
- myErr = SndChannelStatus(myChan, sizeof(SCStatus), &scStatus);
- if (myErr != noErr) {
- Print (paramPtr, "### SndChannelStatus failed : %d", myErr);
- goto errExit1;
- }
-
- if (!scStatus.scChannelBusy)
- break;
- }
-
- Print (paramPtr, "End of playback");
- #ifdef SND_RESOURCE
- CloseResFile(myRefNum);
- #endif
-
- errExit1:
- UseResFile(curResFile);
- myErr = SndDisposeChannel (myChan, true);
- }
-
-
- void DoTest (CHRSPtr paramPtr)
- {
- TELHandle termHand = GetCurrentTELHandle (paramPtr);
- OSErr errCode;
- Component SndOut;
-
- if ((errCode = TELGetHSSoundOutput (termHand, &SndOut)) == noErr) {
- Print (paramPtr, "TELGetHSSoundOutput --> SndOut = %ld", (long) SndOut);
- PlaySnd (paramPtr, SndOut);
- if ((errCode = TELDisposeHSSoundOutput (termHand, SndOut)) == noErr)
- Print (paramPtr, "TELDisposeHSSoundOutput --> SndOut %ld disposed", (long) SndOut);
- else
- Print (paramPtr, "### TELDisposeHSSoundOutput failed : %d", errCode);
- }
- else
- Print (paramPtr, "### TELGetHSSoundOutput failed : %d", errCode);
- }
-
-
-