home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Demos / Tools / SoundMusicSys / Source Examples / EffectsToy.c next >
Encoding:
C/C++ Source or Header  |  1995-03-29  |  18.3 KB  |  718 lines  |  [TEXT/KAHL]

  1. /*****************************************************/
  2. /*
  3. **    EffectsToy.c
  4. **
  5. **        This tests out the music and sound effects drivers
  6. **
  7. **          © 1989-1995 Steve Hales. All Rights Reserved.
  8. **
  9. **    History    -
  10. **    8/6/91        Created
  11. **    10/5/91        Modified for Think C 5.0
  12. **    7/13/92        Modified for Rev 3 of the SoundMusicSys driver
  13. **    12/28/92    Modified for Resume returning an error
  14. **    3/6/92        Modified for SoundDone callback
  15. **    6/23/94        Updated for CodeWarrior
  16. **
  17. */
  18. /*****************************************************/
  19. #include <Types.h>
  20. #include <Memory.h>
  21. #include <Quickdraw.h>
  22. #include <OSEvents.h>
  23. #include <Desk.h>
  24. #include <Events.h>
  25. #include <StandardFile.h>
  26. #include <Resources.h>
  27. #include <Windows.h>
  28. #include <Fonts.h>
  29. #include <TextEdit.h>
  30. #include <Menus.h>
  31. #include <Dialogs.h>
  32. #include <ToolUtils.h>
  33. #include <Sound.h>
  34.  
  35. #if THINK_C
  36. #include <Think.h>
  37. #else
  38.  
  39. #if 0
  40. #include <Traps.h>
  41. #include <StdLib.h>
  42. #include <ctype.h>
  43. #include <files.h>
  44. #include <fcntl.h>
  45. #include <Strings.h>
  46. #endif
  47.  
  48.  
  49. #define TRUE    true
  50. #define FALSE    false
  51. #define NIL    0L
  52.  
  53. #endif
  54.  
  55.  
  56. #include "TestLibrary.h"
  57.  
  58. #include "SoundMusicSystem.h"
  59.  
  60.  
  61. short int            drawDebug;
  62. static WindowPtr    theWindow;
  63. static Boolean        doneFlag;
  64. static Boolean        continueResume;
  65. static Boolean        pauseMusicOnly = FALSE;
  66.  
  67. static char theDate[] = __DATE__;
  68. static char theTime[] = __TIME__;
  69.  
  70. static Boolean GetReadFileName(char *pName, short *pVRef, long *pType, short typeCount)
  71. {
  72.     static Point anchor = {100, 7};    /* top-left */
  73.     SFReply reply;
  74.  
  75.     SFGetFile(anchor, NIL, NIL, typeCount, (void *)pType, NIL, &reply);
  76.  
  77.     if (pType)
  78.     {
  79.         pType[0] = reply.fType;
  80.     }
  81.     BlockMove((void *)reply.fName, pName, 32L);
  82.     *pVRef = reply.vRefNum;
  83.     return(reply.good);
  84. }
  85.  
  86. static void StartTheFileForPlayback(void)
  87. {
  88.     char name[256];
  89.     short theVRef;
  90.     FSSpec theFile;
  91.     OSErr theErr;
  92.  
  93.     if (GetReadFileName(name, &theVRef, 0L, -1))
  94.     {
  95.         theErr = FSMakeFSSpec(theVRef, 0L, (void *)name, &theFile);
  96.         if (theErr == noErr)
  97.         {
  98.             theErr = StartFilePlayback(&theFile, SOUND_RATE_11k, 30000L);
  99.             DPrint(drawDebug, "StartFilePlayback() returns %ld\r", (long)theErr);
  100.         }
  101.         else
  102.         {
  103.             DPrint(drawDebug, "Error in FSMakeFSSpec (%d)\r", theErr);
  104.         }
  105.     }
  106. }
  107.  
  108.  
  109. static pascal Boolean AreWeDone(short int sampleID)
  110. {
  111.     return Button();
  112. }
  113.  
  114. static void PrintKeyboardMenu()
  115. {
  116.     DPrint(drawDebug, "\
  117. Press\r\
  118. '1' to play a song\r\
  119. '2' to end the song\r\
  120. '3' to play a song looped\r\
  121. '4' to pause, then play sound manager beep, then resume\r\
  122. '5' to play sound list\r\
  123. '6' to play random custom data\r\
  124. '7' to play buffer\r\
  125. '8' to play a file based sample\r\
  126. '9' to stop playing a file based sample\r\
  127. 'a' to auto fade master output out\r\
  128. 's' to auto fade master output in\r\
  129. 't' to determine CPU load\r\
  130. 'r' to toggle reverse\r\
  131. 'd' to toggle check sound done flag\r\
  132. 'i' to toggle intrepolation on or off.\r\
  133. 'o' to toggle between 11khz and 22khz output\r");
  134.     DPrint(drawDebug, "\
  135. space to end all sound effects\r\
  136. return to end last sound effect\r\
  137. 'zxcvbnm' for different sound effects\r\
  138. 'e' for enveloped sound effect while holding mouse button\r\
  139. 'f' for enveloped sound effect to play loop 5 times\r\
  140. 'g' for enveloped sound effect forever\r\
  141. '-' decrease pitch of current sound\r\
  142. '=' increase pitch of current sound\r\
  143. '[' decrease current master volume\r\
  144. ']' increase current master volume\r\
  145. 'j' return FadeLevel\r\
  146. 'k' return Midi Clock\r\
  147. '?' to display this command list\r\
  148. 'q' to quit\r\
  149. ");
  150. }
  151.  
  152. //'(' decrease sample volume\r\
  153. //')' increase sample volume\r\
  154.  
  155. /* When the callback is called by SoundMusicSys, theID will be the ID of the sample that is done.
  156. ** For buffer playback ie. PlayTheSample, theID will be CUSTOM_PLAY_ID
  157. */
  158. static Boolean soundDone;
  159. static short restartSoundID = -1;
  160. static short soundDoneID = -1;
  161.  
  162. static pascal void SoundCallBack(short theID)
  163. {
  164.     if (theID == CUSTOM_PLAY_ID)
  165.     {
  166.         soundDone = TRUE;
  167.     }
  168.     if (theID == 10000)
  169.     {
  170.         restartSoundID = 10000;
  171.     }
  172.     soundDoneID = theID;
  173. }
  174.  
  175. static pascal void SongCallBack(short theID)
  176. {
  177. //    Debugger();
  178. }
  179.  
  180.  
  181. static void PlayDoubleBuffer(void)
  182. {
  183.     Handle    waveHandle;
  184.     Ptr        wavePtr;
  185.     long        size;
  186.  
  187.     waveHandle = GetResource('wave', 128);
  188.     if (waveHandle)
  189.     {
  190.         HLock(waveHandle);
  191.         wavePtr = *waveHandle;
  192.  
  193.         soundDone = FALSE;
  194.         restartSoundID = -1;
  195.         SetSoundDoneCallBack(SoundCallBack);
  196. #if 1
  197.         BeginSoundLoop(10000, SOUND_RATE_DEFAULT, -1L, -1L);
  198. //        BeginSound(10000, SOUND_RATE_DEFAULT);
  199. #if 0
  200.         while (!IsThisSoundFXFinished(10000));
  201.         size = TickCount() + 45;
  202.         while (TickCount() < size);
  203. #endif
  204.         EndSound(10000);
  205. #endif
  206.         size = GetHandleSize(waveHandle) / 2;
  207. #if 1
  208.         while (!Button())
  209.         {
  210.             soundDone = FALSE;
  211.             PlayTheSample(wavePtr, size, SOUND_RATE_11k);
  212.             while ((soundDone == FALSE) and (!Button())) {};
  213.             soundDone = FALSE;
  214.             PlayTheSample(wavePtr+size, size, SOUND_RATE_11k);
  215.             while ((soundDone == FALSE) and (!Button())) {};
  216.         }
  217. #endif
  218.         EndSound(10000);
  219.         restartSoundID = -1;
  220.         HUnlock(waveHandle);
  221.         ReleaseResource(waveHandle);
  222.     }
  223. }
  224.  
  225. // Performance testing code
  226.  
  227. static void MeasureCPUPerformance(short int drawDebug)
  228. {
  229.     long    n_ticks;
  230.     long a, sys_clock;
  231.  
  232.     n_ticks = TickCount() + 300L;
  233.     sys_clock = 0;
  234.     a = 4322;
  235.     while (n_ticks > TickCount())
  236.     {
  237.         a = a * 2;
  238.         a = a / 2;
  239.         sys_clock++;
  240.     }
  241.  
  242.     DPrint(drawDebug, "Executed %ld iterations of benchmark.\r", sys_clock);
  243. }
  244.  
  245.  
  246.  
  247.  
  248. void main()
  249. {
  250.     short int        theCount, currentSampleVolume;
  251.     long            theRate, theRateMult;
  252.     long            tempLong, beatCount;
  253.     Boolean        reverseSample, checkDone, intrep;
  254.     Boolean        fileStream;
  255.     SoundQuality    quality;
  256.     short int        lastSound, newSound;
  257.     char            *intrepString;
  258.     OSErr        theErr;
  259.     EventRecord    theEvents;
  260.     short int        theSounds[] = {10000, 10001, 10002, 10003, 10003,10004, 10005, 10006, 10007, 10011, SOUND_END};
  261.     Ptr            waveData;
  262.     short        saveVolume, currentVolume;
  263.     Handle        theSong, theMidi;
  264.     short int        maxSongVoices, maxEffectsVoices, maxNormalVoices;
  265.     static SampleList 
  266.                 theSoundList[] =
  267.             {
  268.                 10000, SOUND_RATE_11k, PLAY_ALL_SAMPLE,
  269.                 10002, SOUND_RATE_22k, 40,
  270.                 10004, SOUND_RATE_11k, PLAY_ALL_SAMPLE,
  271.                 10001, SOUND_RATE_11k, PLAY_ALL_SAMPLE
  272.             };
  273. /* NOTE:  The order of initilizing the system seems very important when running under
  274. **        MultFinder!!!
  275. */
  276. #if THINK_C
  277.     InitGraf(&thePort);    /* set up screen port */
  278. #else
  279.     InitGraf(&qd.thePort);    /* set up screen port */
  280. #endif
  281.     InitFonts();        /* set up font manager */
  282.     InitWindows();        /* set up window stuff */
  283.     InitMenus();        /* set up menu mgr */
  284.     TEInit();            /* set up text editor for system use */
  285.     InitDialogs(NIL);    /* set up Dialog stuff */
  286.     InitCursor();        /* put pointer shape in mouse */
  287.  
  288.     ResrvMem(maxSize);
  289.     MaxApplZone();        /* force expansion */
  290.     FlushEvents(everyEvent, 0);    /* clear all events */    
  291.     for (theCount = 0; theCount < 10; theCount++)
  292.     {
  293.         MoreMasters();
  294.     }
  295.  
  296.     waveData = NewPtr(1000L);
  297.  
  298.     drawDebug = DNew((void *)"\pEffects Toy");
  299.  
  300.     DPrint(drawDebug, "Effect Toy - \r\
  301. %s %s\r\
  302. Demonstration of SoundMusicSys driver\r\
  303. © Copyright 1989-1995 Steve Hales, All rights reserved\r", theDate, theTime);
  304.     PrintKeyboardMenu();
  305.  
  306.     theWindow = DWindow(drawDebug);
  307.     SetPort(theWindow);
  308.  
  309.     theRateMult = 0;
  310.     doneFlag = FALSE;
  311.     fileStream = FALSE;
  312.     continueResume = FALSE;
  313.  
  314.     quality = jxHighQuality; // jxHighQuality;                    // jxIntrepBestHighQuality;    // jxAnalyzeQuality
  315.     maxSongVoices = 4;
  316.     maxNormalVoices = 4;
  317.     maxEffectsVoices = 2;
  318.     theErr = InitSoundMusicSystem(    maxSongVoices,        // max song voices
  319.                                 maxNormalVoices,        // max normalized voices
  320.                                 maxEffectsVoices,        // max sound effects track
  321.                                 quality);
  322.     if (theErr)
  323.     {
  324.         DPrint(drawDebug, "Error %ld initilizing the Music Driver.\r", (long)theErr);
  325.         DPrint(drawDebug, "\rClick to exit.\r");
  326.         while (Button()) {};
  327.         while(!Button()) {};
  328.         doneFlag = TRUE;
  329.     }
  330.     else
  331.     {
  332.         RegisterSounds(theSounds, TRUE);        /* TRUE - dont load, FALSE - load */
  333.         intrep = checkDone = reverseSample = FALSE;
  334.     }
  335.     saveVolume = GetMasterVolume();
  336.     currentVolume = saveVolume;
  337.     currentSampleVolume = FULL_VOLUME;
  338.     DPrint(drawDebug, "Current Volume %ld\r", (long)currentVolume);
  339.     EndSoundList();
  340.     while (doneFlag == FALSE)
  341.     {
  342.         PurgeAllSounds(maxSize);
  343.         if (ServiceFilePlayback())                // This must be called to process file streaming
  344.         {
  345.             DPrint(drawDebug, "Read block\r");
  346.         }
  347.         if (soundDoneID != -1)
  348.         {
  349.             DPrint(drawDebug, "%ld\r", (long)soundDoneID);
  350.             soundDoneID = -1;
  351.         }
  352.         if (restartSoundID != -1)
  353.         {
  354.             BeginSound(restartSoundID, SOUND_RATE_DEFAULT);
  355.             restartSoundID = -1;
  356.         }
  357.         if (WaitNextEvent(everyEvent,  &theEvents, 0L, NIL))
  358.         {
  359.             DEvent(&theEvents);
  360.  
  361.             if (continueResume)
  362.             {
  363.                 DPrint(drawDebug, "Resuming SoundGod…\r");
  364.                 theErr = ResumeSoundMusicSystem();
  365.                 if (theErr == noErr)
  366.                 {
  367.                     continueResume = FALSE;
  368.                 }
  369.                 else
  370.                 {
  371.                     DPrint(drawDebug, "Error Resuming %ld\r", (long)theErr);
  372.                 }
  373.             }
  374.             switch(theEvents.what)
  375.             {
  376.                 case app4Evt:        /* Suspend/Resume Events */
  377.                     if ( ((theEvents.message >> 24L) & 0x00FF) == 0x01)
  378.                     {
  379.                         if (theEvents.message & 1)    /* message field contains flags */
  380.                         {
  381.                             continueResume = TRUE;
  382.                         }
  383.                         else
  384.                         {
  385.                             /* suspend */
  386.                             PauseSoundMusicSystem();
  387.                         }
  388.                     }
  389.                     break;
  390.                 case autoKey:
  391.                 case keyDown:
  392.                     switch(theEvents.message & 0xFF)
  393.                     {
  394.                         case '?':
  395.                         case '/':
  396.                             PrintKeyboardMenu();
  397.                             break;
  398.                         case 'q':
  399.                             doneFlag = TRUE;
  400.                             break;
  401.                         case 'i':
  402.                             intrep = (intrep) ? FALSE : TRUE;
  403.                             DPrint(drawDebug, "Intrepolation now %s\r", (intrep) ? "ON" : "OFF");
  404. //                            break;
  405.                         case 'o':
  406.                             switch (quality)
  407.                             {
  408.                                 case jxLowQuality:
  409.                                 case jxIntrepLowQuality:
  410.                                 case jxIntrepBestLowQuality:
  411.                                     quality = (intrep) ? jxIntrepHighQuality : jxHighQuality;
  412.                                     intrepString = (intrep) ? "22khz (High, Intrep)" : "22khz (High)";
  413.                                     break;
  414.                                 case jxHighQuality:
  415.                                 case jxIntrepHighQuality:
  416.                                 case jxIntrepBestHighQuality:
  417.                                     quality = (intrep) ? jxIntrepLowQuality : jxLowQuality;
  418.                                     intrepString = (intrep) ? "11khz (Low, Intrep)" : "11khz (Low)";
  419.                                     break;
  420.                             }
  421.                             DPrint(drawDebug, "Quality is now: %s\r", intrepString);
  422.                             ChangeOuputQuality(quality);
  423.                             break;
  424.                         case '1':
  425.                             SetSongDoneCallBack(NIL);    // Callback will happen even with LoadSong
  426.                             theErr = LoadSong(128);
  427.                             theErr = BeginSong(128);
  428.                             tempLong = GetSongLength();
  429.                             SetSongDoneCallBack(SongCallBack);
  430.                             DPrint(drawDebug, "Begining song. 1-3 second delay.\r");
  431.                             DPrint(drawDebug, "BeginSong Returns %ld - Length %lX\r", (long)theErr, tempLong);
  432.                             break;
  433.                         case '!':
  434.                             /* NOTE: Don't release the resources until the song is finished playing. Once you
  435.                             **        start a song playing, the song and midi resources will become locked.
  436.                             */
  437.                             theSong = GetResource('SONG', 128);
  438.                             if (theSong)
  439.                             {
  440.                                 theMidi = GetResource('Midi', 128);
  441.                                 if (theMidi)
  442.                                 {
  443.                                     SetSongDoneCallBack(SongCallBack);
  444.                                     BeginSongFromMemory(128, theSong, theMidi, FALSE);
  445.                                 }
  446.                             }
  447.                             DPrint(drawDebug, "Begining song. 1-3 second delay.\r");
  448.                             break;                            
  449.                         case '2':
  450.                             DPrint(drawDebug, "End Song.\r");
  451.                             EndSong();
  452.                             break;
  453.                         case '@':
  454.                             DPrint(drawDebug, "Begining change test\r");
  455.                             while (Button() == FALSE)
  456.                             {
  457.                                 theErr = ChangeSystemVoices(    maxSongVoices,        // max song voices
  458.                                                         maxNormalVoices,        // max normalized voices
  459.                                                         maxEffectsVoices);        // max sound effects track
  460.                                 BeginSong(128);
  461.                                 DPrint(drawDebug, "Song Started\r");
  462.                                 tempLong = TickCount() + (2 * 60);
  463.                                 while ( (TickCount() < tempLong) && (Button() == FALSE) )
  464.                                 {
  465.                                 }
  466.                                 theErr = ChangeSystemVoices(0, 1, 1);
  467.                                 DPrint(drawDebug, "Voices changed (%ld)\r", (long)theErr);
  468.                                 BeginSound(10005, SOUND_RATE_DEFAULT);
  469.                                 while (IsThisSoundFXFinished(10005) == FALSE)
  470.                                 {
  471.                                 }
  472.                             }
  473.                             break;
  474.                         case '3':
  475.                             SetSongDoneCallBack(NIL);
  476.                             DPrint(drawDebug, "Looped song\r");
  477.                             BeginSongLooped(128);
  478.                             break;
  479.                         case '4':
  480.                             DPrint(drawDebug, "Pausing SoundGod…\r");
  481.                             PauseSoundMusicSystem();
  482.                             DPrint(drawDebug, "Beeping Sound Manager…\r");
  483.                             SysBeep(1);
  484.                             DPrint(drawDebug, "Click to continue…\r");
  485.                             while(Button()) {};
  486.                             while(!Button()) {};
  487.                             FlushEvents(mDownMask, 0);    /* clear button events */    
  488.                             continueResume = TRUE;
  489.                             break;
  490.                         case '5':
  491.                             BeginSoundList(theSoundList, 4);
  492.                             break;
  493.                         case '6':
  494.                             if (waveData)
  495.                             {
  496.                                 for (theCount = 0; theCount < 1000; theCount++)
  497.                                 {
  498.                                     waveData[theCount] = Random();
  499.                                 }
  500.                                 PlayTheSampleWithID(waveData, 1000L, SOUND_RATE_11k, 2300);
  501. //                                PlayTheSample(waveData, 1000L, SOUND_RATE_11k);
  502.                             }
  503.                             break;
  504.                         case '7':
  505.                             PlayDoubleBuffer();
  506.                             break;
  507.                         case '8':
  508.                             StartTheFileForPlayback();
  509.                             fileStream = TRUE;
  510.                             break;
  511.                         case '9':
  512.                             EndFilePlayback();
  513.                             fileStream = FALSE;
  514.                             DPrint(drawDebug, "EndFilePlayback()\r");
  515.                             break;
  516.                         case '0':
  517.                             if (pauseMusicOnly)
  518.                             {
  519.                                 ResumeMusicOnly();
  520.                                 pauseMusicOnly = FALSE;
  521.                             }
  522.                             else
  523.                             {
  524.                                 PauseMusicOnly();
  525.                                 pauseMusicOnly = TRUE;
  526.                             }
  527.                             break;
  528.                         case 's':
  529.                             BeginSong(128);
  530.                             BeginMasterFadeIn(40);
  531.                             DPrint(drawDebug, "BeginMasterFadeIn\r");
  532.                             break;
  533.     
  534.                         case 'a':
  535.                             BeginMasterFadeOut(40);    
  536.                             DPrint(drawDebug, "BeginMasterFadeOut\r");
  537. //                            while (FadeLevel() > 0);
  538. //                            while (IsSongDone() == FALSE);
  539. //                            DPrint(drawDebug, "done.\r");
  540.                             break;
  541.     
  542.                         case 'r':
  543.                             reverseSample = (reverseSample) ? FALSE : TRUE;
  544.                             DPrint(drawDebug, "Reverse now %s\r", (reverseSample) ? "TRUE" : "FALSE");
  545.                             break;
  546.                         case 'd':
  547.                             checkDone = (checkDone) ? FALSE : TRUE;
  548.                             DPrint(drawDebug, "CheckDone now %s\r", (checkDone) ? "TRUE" : "FALSE");
  549.                             break;
  550.                         case 0x0D:
  551. //                            DPrint(drawDebug, "Stop %ld\r", (long)lastSound);
  552.                             EndSound(lastSound);
  553.                             break;
  554.                         case 0x20:
  555.                             EndAllSound();
  556.                             restartSoundID = -1;
  557.                             break;
  558.                         case '(':
  559.                             currentSampleVolume -= 5;
  560.                             if (currentSampleVolume < 0)
  561.                             {
  562.                                 currentSampleVolume = 0;
  563.                             }
  564.                             DPrint(drawDebug, "New Sample Volume %ld\r", (long)currentSampleVolume);
  565.                             ChangeSoundVolume(lastSound, currentSampleVolume);
  566. //                            SetSongVolume(currentSampleVolume);
  567.                             break;
  568.                         case ')':
  569.                             currentSampleVolume += 5;
  570.                             if (currentSampleVolume > FULL_VOLUME)
  571.                             {
  572.                                 currentSampleVolume = FULL_VOLUME;
  573.                             }
  574.                             DPrint(drawDebug, "New Sample Volume %ld\r", (long)currentSampleVolume);
  575.                             ChangeSoundVolume(lastSound, currentSampleVolume);
  576. //                            SetSongVolume(currentSampleVolume);
  577.                             break;
  578.                         case ']':
  579.                             currentVolume += 5;
  580.                             if (currentVolume > FULL_VOLUME)
  581.                             {
  582.                                 currentVolume = FULL_VOLUME;
  583.                             }
  584.                             SetMasterVolume(currentVolume);
  585.                             DPrint(drawDebug, "New Volume %ld\r", (long)currentVolume);
  586.                             break;
  587.                         case '[':
  588.                             currentVolume -= 5;
  589.                             if (currentVolume < 0)
  590.                             {
  591.                                 currentVolume = 0;
  592.                             }
  593.                             SetMasterVolume(currentVolume);
  594.                             DPrint(drawDebug, "New Volume %ld\r", (long)currentVolume);
  595.                             break;
  596.                         case '=':
  597.                             theRateMult += 500L << 16L;
  598.                             goto changeRate;
  599.                         case '-':
  600.                             theRateMult -= 500L << 16L;
  601. changeRate:
  602.                             DPrint(drawDebug, "New rate modifier: %ld of Sound %ld\r", (long)theRateMult, (long)lastSound);
  603.                             if (fileStream)
  604.                             {
  605.                                 ChangeFilePlaybackRate(SOUND_RATE_7k + theRateMult);
  606.                             }
  607.                             else
  608.                             {
  609.                                 theRate = GetSoundDefaultRate(lastSound) + theRateMult;
  610.                                 ChangeSoundPitch(lastSound, theRate);
  611.                             }
  612.                             break;
  613.                         case 'k':
  614.                             beatCount = 0;
  615.                             while ((IsSongDone() == FALSE) && (Button() == FALSE) )
  616.                             {
  617.                                 tempLong = GetCurrentMidiClock();
  618.                                 theRate = GetNextBeatMidiClock();
  619.                                 theRateMult = GetCurrentMidiBeat();
  620.                                 if (beatCount != theRateMult)
  621.                                 {
  622.                                     beatCount = theRateMult;
  623.                                     DPrint(drawDebug, "MIdi Clock %lX %lX %lX %lX\r", tempLong, theRateMult, 
  624.                                                     theRate, GetCurrentTempo());
  625.                                 }
  626.                             }
  627.                             break;
  628.                         case 'j':
  629.                             DPrint(drawDebug, "FadeLevel %ld\r", (long)FadeLevel());
  630.                             break;
  631.                         case 'f':
  632.                             BeginSoundEnvelope(10006, SOUND_RATE_DEFAULT, 5);
  633.                             lastSound = 10006;
  634.                             break;
  635.                         case 'e':
  636.                             lastSound = 10006;
  637.                             BeginSoundEnvelopeProc(10006, SOUND_RATE_DEFAULT, AreWeDone);
  638.                             break;
  639.                         case 'g':
  640.                             BeginSoundEnvelope(10003, SOUND_RATE_DEFAULT, -1);
  641.                             lastSound = 10003;
  642.                             break;
  643.                         case 'z':
  644.                             newSound = 10000;
  645.                             goto playSoundEffect;
  646.                         case 'u':
  647.                             newSound = 10011;
  648.                             goto playSoundEffect;
  649.                         case 'x':
  650.                             newSound = 10001;
  651.                             goto playSoundEffect;
  652.                         case 'c':
  653.                             newSound = 10002;
  654.                             goto playSoundEffect;
  655.                         case 'v':
  656.                             newSound = 10003;
  657.                             goto playSoundEffect;
  658.                         case 'b':
  659.                             newSound = 10004;
  660.                             goto playSoundEffect;
  661.                         case 'n':
  662.                             newSound = 10005;
  663.                             goto playSoundEffect;
  664.                         case 'm':
  665.                             newSound = 10007;
  666. playSoundEffect:
  667. //                            EndSound(lastSound);
  668.                             lastSound = newSound;
  669.                             restartSoundID = -1;
  670.                             ChangeSoundVolume(newSound, currentSampleVolume);
  671.                             SetSoundDoneCallBack(SoundCallBack);
  672. //                            DPrint(drawDebug, "Sound effect!\r");
  673.                             if (reverseSample == FALSE)
  674.                             {
  675.                                 BeginSound(newSound, SOUND_RATE_DEFAULT);
  676.                             }
  677.                             else
  678.                             {
  679.                                 BeginSoundReverse(newSound, SOUND_RATE_DEFAULT);
  680.                             }
  681.                             if (checkDone)
  682.                             {
  683.                                 DPrint(drawDebug, "Waiting…");
  684.                                 while ( (IsSoundFXFinished() == FALSE) && (Button() == FALSE) ) {};
  685.                                 DPrint(drawDebug, "  done.\r");
  686.                             }
  687.                             break;
  688.                         case 't':
  689.                             DPrint(drawDebug, "Testing CPU...\r\r");
  690.                             MeasureCPUPerformance(drawDebug);
  691.                             DPrint(drawDebug, "\r");
  692.                             break;
  693.                         case 'h':
  694.                             maxSongVoices ^= 4;
  695.                             DPrint(drawDebug, "%d %d %d = ", maxSongVoices, maxNormalVoices, maxEffectsVoices);
  696.                             theErr = ChangeSystemVoices(    maxSongVoices,        // max song voices
  697.                                                     maxNormalVoices,        // max normalized voices
  698.                                                     maxEffectsVoices);        // max sound effects track
  699.                             DPrint(drawDebug, "%ld\r", (long)theErr);
  700.                             break;
  701.                 }
  702.                 break;
  703.             }
  704.         }
  705.     }
  706.      if (waveData)
  707.      {
  708.          DisposPtr(waveData);
  709.      }
  710.     SetMasterVolume(saveVolume);
  711.     FinisSoundMusicSystem();
  712.     FlushEvents(everyEvent, 0);    /* clear all events */    
  713. }
  714.  
  715. /* EOF of EffectsToy.c
  716. */
  717.  
  718.