示例#1
0
    //
    // Poll
    //
    // Poll the cd audio (used for proceeding to next track automatically)
    //
    void Poll()
    {
      if (initialized && driver)
      {
        U32 status;

        // Time to search
        if (search && (pollTime <= AIL_ms_count()))
        {
          // Read the status (this can be slow on some drives)
          switch (status = AIL_redbook_status(driver))
          {
            // Still playing a track
            case REDBOOK_PLAYING:
            {
              U32 curTrack, curPos, end;

              // Get current info
              curTrack = AIL_redbook_track(driver);
              curPos = AIL_redbook_position(driver);

              // Some systems will briefly report playing the NEXT track!
              if ((curTrack == track) && track && curPos)
              {
                // Get track info
                AIL_redbook_track_info(driver, track, NULL, &end);

                // Recalc the scan time
                pollTime = AIL_ms_count() + (end - curPos) + POLL_ERROR;
              }

              break;
            }

            // Finished playing track
            case REDBOOK_STOPPED:
              Play(track + 1);
              break;

            default :
              Stop();
              break;
          }
        }
      }    
    }
示例#2
0
    //
    // Play
    //
    // Play a redbook track (request is wrapped, so returns track number started)
    //
    U32 Play(U32 newTrack)
    {
      if (initialized && driver)
      {
        // Get number of tracks on disc
        U32 count = AIL_redbook_tracks(driver);

        // Clip track into acceptable range
        if ((newTrack > count) || (newTrack < minTrack)) 
        {
          newTrack = minTrack;
        }

        // If we ended up with a valid track number, start it playing
        if (newTrack >= 1 && newTrack <= count)
        {
          U32 start, end;
    
          // Get track info
          AIL_redbook_track_info(driver, newTrack, &start, &end);

          // Start it playing
          AIL_redbook_play(driver, start, end);

          // Update our track count
          track = newTrack;

          // Set next scan to be just past when this track ends
          pollTime = AIL_ms_count() + (end - start) + POLL_ERROR;

          // We're rockin, so turn on track searching
          search = TRUE;
        }
        else
        {
          // Probably a data cd
          search = FALSE;

          // Stop cd playing
          Stop();
        }
      }

      return (track);
    }
      //
      // Play3D
      //
      // Play a record as a 3D sample (TRUE if actually started)
      //
      Bool Play3D
      (
        Effect *e, Record *r, S32 vol, U32 owner, F32 priority, S32 loop, 
        F32 x, F32 y, F32 z, F32 min, F32 max
      )
      {
        ASSERT(e);
        ASSERT(r);

        // Request a 3D voice
        Voice *voice = Request(priority, TRUE, e->GetVoiceIndex());

        if (!voice)
        {
          return (FALSE);
        }

        ASSERT(voice->flag3D);

        // Request the cache data
        Cache::Item *item = Cache::Request(r);

        if (!item)
        {
          // Unable to load data
          return (FALSE);
        }

        // Stop any sounds from this owner
        if (owner != NO_OWNER) 
        {
          Output::StopByOwner(owner);
        }

        // The current time
        U32 time = AIL_ms_count();

        // Are we under the minimum repeat time
        if ((time - r->lastUse) < MIN_REPEATTIME)
        {
          return (FALSE);
        }

        // Save info about this use
        r->lastUse = time;

        // Initialise the sound effect data
        if (!AIL_set_3D_sample_file(voice->handle3D, item->data))
        {
          LOG_WARN(("Invalid 3D data '%s' (Require MS Mono Uncompressed PCM WAV)", r->Name()));
          r->valid = FALSE;
          return (FALSE);
        }

        // Setup the voice
        voice->effect = e;
        voice->record = r;
        voice->owner = owner;
        voice->priority = priority;

        // Set the volume
        AIL_set_3D_sample_volume(voice->handle3D, vol);

        // Set the loop count for this voice
        AIL_set_3D_sample_loop_count(voice->handle3D, loop);

        // Set the 3D world position
        AIL_set_3D_position(voice->handle3D, x, y, z);

        // Set the distances for this sample
        AIL_set_3D_sample_distances(voice->handle3D, max, min);

        // Always face the listener 
        AIL_set_3D_orientation(voice->handle3D, -x, -y, -z, 0.0F, 1.0F, 0.0F);

        // Start the sample playing
        AIL_start_3D_sample(voice->handle3D);

        return (TRUE);
      }
      //
      // Play2D
      //
      // Play a record as a 2D sample (TRUE if actually started)
      //
      Bool Play2D
      (
        Effect *e, Record *r, S32 vol, U32 owner, F32 priority, S32 loop, S32 pan
      )
      {
        ASSERT(e);
        ASSERT(r);

        // Request a 2D voice
        Voice *voice = Request(priority, FALSE, e->GetVoiceIndex());

        if (!voice)
        {
          return (FALSE);
        }

        // Request the cache data
        Cache::Item *item = Cache::Request(r);

        if (!item)
        {
          // Unable to load data
          return (FALSE);
        }

        // Stop any sounds from this owner
        if (owner != NO_OWNER) 
        {
          Output::StopByOwner(owner);
        }

        // The current time
        U32 time = AIL_ms_count();

        // Are we under the minimum repeat time
        if ((time - r->lastUse) < MIN_REPEATTIME)
        {
          return (FALSE);
        }

        // Save info about this use
        r->lastUse = time;

        // Initialise the voice
        AIL_init_sample(voice->handle2D);

        // Initialise the sound effect data
        if (!AIL_set_sample_file(voice->handle2D, item->data, 0))
        {
          LOG_WARN(("Ignoring possibly corrupted file '%s'", r->Name()));
          r->valid = FALSE;
          return (FALSE);
        }

        // Setup the voice
        voice->effect = e;
        voice->record = r;
        voice->owner = owner;
        voice->priority = priority;

        // Set the volume
        AIL_set_sample_volume(voice->handle2D, vol);

        // Set the stereo panning
        AIL_set_sample_pan(voice->handle2D, pan);

        // Set the loop count for this voice
        AIL_set_sample_loop_count(voice->handle2D, loop);

        // Start the sample playing
        AIL_start_sample(voice->handle2D);

        return (TRUE);
      }