home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 348.lha / chatterbox_v1.0 / sources / deferredload.c < prev    next >
C/C++ Source or Header  |  1990-02-14  |  2KB  |  79 lines

  1.  
  2. int sample_was_in_cache;
  3.  
  4. struct deferred_load_info deferred_stuff;
  5.  
  6. Sample *Load8SVX();
  7.  
  8. DeferredStuffCleanup()
  9. {
  10.     int i;
  11.  
  12.     for (i = 0; i < MAX_GAB_ITEMS; i++)
  13.     {
  14.         if (deferred_stuff.filename[i])
  15.         {
  16.             FreeMem(deferred_stuff.filename[i],strlen(deferred_stuff.filename[i]) + 1);
  17.             deferred_stuff.filename[i] = NULL;
  18.         }
  19.     }
  20.     deferred_stuff.n_deferred_items = 0;
  21. }
  22.  
  23. InitDeferredStuff()
  24. {
  25.     int i;
  26.  
  27.     for (i = 0; i < MAX_GAB_ITEMS; i++)
  28.     {
  29.         deferred_stuff.filename[i] = NULL;
  30.     }
  31.  
  32.     add_cleanup(DeferredStuffCleanup);
  33. }
  34.  
  35. AddDeferredSound(s)
  36. char *s;
  37. {
  38.     char *t;
  39.  
  40.     if (deferred_stuff.n_deferred_items >= MAX_GAB_ITEMS)
  41.     {
  42.         printf("too many deferred timer sounds, '%s' ignored\n",s);
  43.         return;
  44.     }
  45.  
  46.     /* note: normally you would need to allocmem strlen(s)+1 to leave
  47.      * room for the terminating NULL character, but in this case we
  48.      * have a blank in column one that we don't want, so that accounts
  49.      * for the extra char needed to be allocated */
  50.  
  51.     if ((t = AllocMem(strlen(s),0)) == NULL)
  52.         panic("couldn't alloc mem for deferred sound");
  53.  
  54.     strcpy(t,&s[1]);
  55.     deferred_stuff.filename[deferred_stuff.n_deferred_items++] = t;
  56.  
  57. }
  58.  
  59. PlayDeferredSound()
  60. {
  61.     Sample *sampleptr;
  62.     int one_i_want;
  63.  
  64.     one_i_want = rando(deferred_stuff.n_deferred_items);
  65.  
  66.     sampleptr = Load8SVX(deferred_stuff.filename[one_i_want]);
  67.  
  68.     if (sampleptr == NULL)
  69.         return;
  70.  
  71.     /* if the sample wasn't in the RAM cache, we wan't to purge it
  72.      * when finished (code that receives the play_complete message
  73.      * checks this bit) */
  74.     if (!sample_was_in_cache)
  75.         sampleptr->sample_flags |= PURGE_SAMPLE_AFTER_PLAYING;
  76.  
  77.     PlayChannelSample(sampleptr,64,rando(2));
  78. }
  79.