home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Telephone Manager / Stiletto Sources / ModuleSources / LinePlayback.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-03  |  5.2 KB  |  190 lines  |  [TEXT/MPS ]

  1. /************************************************************************************************/
  2. /*                                                                                                */
  3. /*    Module Name:    LinePlayback                                                                */
  4. /*                                                                                                */
  5. /*    File Name:        LinePlayback.c                                                                */
  6. /*                                                                                                */
  7. /*    © Apple Computer, Inc. 1994-1995                                                            */
  8. /*    All Rights Reserved                                                                            */
  9. /*                                                                                                */
  10. /*    Revision History:                                                                            */
  11. /*                                                                                                */
  12. /*        Date        Who                    Modification                                            */
  13. /*                                                                                                */
  14. /*        1994-05-20    Jaakko Railo        Original version                                        */
  15. /*        1994-08-06    Gary Anwyl            Modified GetDNSndInOut to make this module                */
  16. /*                                                                                                */
  17. /************************************************************************************************/
  18.  
  19. /****************************************** DESCRIPTION ******************************************
  20.  
  21.     This module uses the StandardFile interface to get the name of a file
  22.     containing an 'snd ' 128 resource. It then plays the sound asynchronously
  23.     over the telephone line until the user presses the mouse button or the
  24.     sound is finished playing. If the compile time option SND_RESOURCE is undefined
  25.     then the sound is taken from an AIFF file instead of a sound resource.
  26.  
  27. *************************************************************************************************/
  28.  
  29. /******************************************** HEADERS *******************************************/
  30.  
  31. #include "Sound.h"
  32. #include "SoundInput.h"
  33. #include "Events.h"
  34. #include "Resources.h"
  35. #include "TextUtils.h"
  36. #include "Types.h"
  37.  
  38. #ifndef __TELEPHONES__
  39. #include "Telephones.h"
  40. #endif
  41.  
  42. #include "TestModule.h"
  43.  
  44. /****************************************** DEFINITIONS *****************************************/
  45.  
  46. #define    SND_RESOURCE                // define to use 'snd ' resource, undef to use AIFF file
  47. #define kTotalSize        24*1024
  48.  
  49. /****************************************** PROTOTYPES ******************************************/
  50.  
  51. short    GetFileDialog(void);
  52. void     PlaySnd (CHRSPtr paramPtr, Component mySndOut);
  53. void     DoTest (CHRSPtr paramPtr);
  54.  
  55. /************************************************************************************************/
  56. /************************************************************************************************/
  57.  
  58.  
  59. pascal short TestModule (CHRSPtr paramPtr)
  60. {
  61.     short    returnValue = noErr;
  62.     
  63.     if (paramPtr->version <= kTestModuleVersion) {
  64.         
  65.         DoTest (paramPtr);
  66.         
  67.     }
  68.     else
  69.         returnValue = kWrongVersion;
  70.         
  71.     return (returnValue);
  72. }
  73.  
  74.  
  75. short GetFileDialog(void)
  76. {
  77.     StandardFileReply    getReply;
  78.     short                fRefNum;
  79.     SFTypeList            fileTypes = {'AIFF', 0, 0, 0};
  80.     
  81. #ifdef SND_RESOURCE
  82.     StandardGetFile(0, -1, 0, &getReply);
  83.     if (!getReply.sfGood)
  84.         return 0;
  85.     fRefNum = FSpOpenResFile(&getReply.sfFile, fsRdPerm);
  86.     if (fRefNum == -1)
  87.         return 0;
  88. #else
  89.     StandardGetFile(0, 1, fileTypes, &getReply);
  90.     if (!getReply.sfGood)
  91.         return 0;
  92.     err = FSpOpenDF(&getReply.sfFile, fsRdPerm, &fRefNum);
  93.     if (err != noErr)
  94.         return 0;
  95. #endif
  96.         
  97.     return fRefNum;
  98. }
  99.  
  100.  
  101. void PlaySnd (CHRSPtr paramPtr, Component mySndOut)
  102. {
  103.     OSErr            myErr;
  104.     SndChannelPtr    myChan = nil;
  105.     short            myRefNum, curResFile;
  106.     AudioSelection    sel;
  107.     SCStatus        scStatus;
  108.     
  109.     curResFile = CurResFile();
  110.     
  111.     if ((myErr = SndNewChannel (&myChan, kUseOptionalOutputDevice, (long) mySndOut, nil)) != noErr) {
  112.         Print (paramPtr, "### SndNewChannel failed : %d", myErr);
  113.         return;
  114.     }
  115.  
  116.     myRefNum = GetFileDialog();
  117.     if (myRefNum == 0) {
  118.         Print (paramPtr, "### GetFile failed");
  119.         goto errExit1;
  120.     }
  121.         
  122.     Print (paramPtr, "Start of playback");
  123.     sel.unitType = unitTypeSeconds;
  124.     sel.selStart = (0L<<16);
  125.     sel.selEnd = (9999L<<16);
  126. #ifdef SND_RESOURCE
  127.     UseResFile(myRefNum);
  128.     if (Count1Resources('snd ') == 0) {
  129.         Print (paramPtr, "### No 'snd ' resource");
  130.         goto errExit1;
  131.     }
  132.     myErr = SndStartFilePlay(myChan, 0, 128, kTotalSize, nil, &sel, nil, true);
  133. #else
  134.     myErr = SndStartFilePlay(myChan, myRefNum, 0, kTotalSize, nil, &sel, nil, true);
  135. #endif
  136.     if (myErr != noErr) {
  137.         Print (paramPtr, "### SndPlay failed : %d", myErr);
  138.         goto errExit1;
  139.     }
  140.  
  141.     while (1) {
  142.         if (Button())
  143.             break;
  144.             
  145.         myErr = SndChannelStatus(myChan, sizeof(SCStatus), &scStatus);
  146.         if (myErr != noErr) {
  147.             Print (paramPtr, "### SndChannelStatus failed : %d", myErr);
  148.             goto errExit1;
  149.         }
  150.             
  151.         if (!scStatus.scChannelBusy)
  152.             break;
  153.     }
  154.  
  155.     Print (paramPtr, "End of playback");
  156. #ifdef SND_RESOURCE
  157.     CloseResFile(myRefNum);
  158. #endif
  159.  
  160. errExit1:
  161.     UseResFile(curResFile);
  162.     myErr = SndDisposeChannel (myChan, true);
  163. }
  164.  
  165.  
  166. void DoTest (CHRSPtr paramPtr)
  167. {
  168.     TELHandle    termHand = GetCurrentTELHandle (paramPtr);
  169.     TELDNHandle    dnHand;
  170.     OSErr        errCode;
  171.     Component    SndOut;
  172.     
  173.     if ((dnHand = GetDNHandle (paramPtr)) != nil) {
  174.         if ((errCode = TELGetDNSoundOutput (dnHand, &SndOut)) == noErr) {
  175.             Print (paramPtr, "TELGetDNSoundOutput --> SndOut = %ld", (long) SndOut);
  176.             PlaySnd (paramPtr, SndOut);
  177.             if ((errCode = TELDisposeDNSoundOutput (dnHand, SndOut)) == noErr)
  178.                 Print (paramPtr, "TELDisposeDNSoundOutput --> SndOut %ld disposed", (long) SndOut);
  179.             else
  180.                 Print (paramPtr, "### TELDisposeDNSoundOutput failed : %d", errCode);
  181.         }
  182.         else
  183.             Print (paramPtr, "### TELGetDNSoundOutput failed : %d", errCode);
  184.     }
  185.     else
  186.         Print (paramPtr, "### Unable to retrieve the DN handle");
  187. }
  188.  
  189.  
  190.