Example #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;
          }
        }
      }    
    }
Example #2
0
void SoundManager::StartMusic(const sint32 &InTrackNum)
{
	m_stopRedbookTemporarily = FALSE;

	if (!g_theProfileDB->IsUseRedbookAudio() || !c3files_HasCD()) return;

	if (m_noSound) return;

	if (m_usePlaySound) return;

	if (m_curTrack == -1) return;

#if defined(USE_SDL)
    if (!m_cdrom) {
        return;
    }

    CDstatus status = SDL_CDStatus(m_cdrom);

    if ((CD_ERROR == status) || (!CD_INDRIVE(status))) {
        return;
    }

	sint32 const numTracks = m_cdrom->numtracks;
#else
    if (!m_redbook) {
        return;
    }

	U32 status = AIL_redbook_status(m_redbook);

    if (status == REDBOOK_ERROR) {
        return;
    }
	
	if (AIL_redbook_track(m_redbook)) {
		AIL_redbook_stop(m_redbook);
	}

	sint32 const numTracks = AIL_redbook_tracks(m_redbook);
#endif

	if (numTracks <= s_startTrack) return;

	m_numTracks = numTracks;
	
	sint32 trackNum = InTrackNum;
	if (trackNum < 0) trackNum = 0;
	if (trackNum > m_numTracks) trackNum = m_numTracks;

	m_curTrack = trackNum;

#if defined(USE_SDL)
    SDL_CDPlayTracks(m_cdrom, trackNum, 0, 1, 0);
#else
	U32 start;
    U32 end;
	AIL_redbook_track_info(m_redbook, trackNum, &start, &end);

    // Why?
	TerminateAllSounds();

	AIL_redbook_play(m_redbook, start, end);
#endif
}
Example #3
0
void SoundManager::ProcessRedbook()
{
	if (!g_theProfileDB->IsUseRedbookAudio()) return;

	if (!m_musicEnabled) return;

	if (GetTickCount() > m_timeToCheckCD) {
#if defined(USE_SDL)
        CDstatus status;
        if (m_cdrom) {
            status = SDL_CDStatus(m_cdrom);
#else
        U32 status;
		if (m_redbook) {
			status = AIL_redbook_status(m_redbook);
#endif
			switch (status) {
#if !defined(USE_SDL)
			case REDBOOK_ERROR:
#else
            case CD_TRAYEMPTY:
                break;
            case CD_ERROR:
#endif
				break;
#if !defined(USE_SDL)
			case REDBOOK_PLAYING:
#else
            case CD_PLAYING:
#endif
				break;
#if !defined(USE_SDL)
			case REDBOOK_PAUSED:
#else
            case CD_PAUSED:
#endif
				break;
#if !defined(USE_SDL)
			case REDBOOK_STOPPED:
#else
            case CD_STOPPED:
#endif			
				if (m_curTrack != -1) 
					PickNextTrack();
				
				if (m_curTrack != -1 && !m_stopRedbookTemporarily) 
					StartMusic(m_curTrack);
				break;
			}
		}

		m_timeToCheckCD = GetTickCount() + k_CHECK_CD_PERIOD;
	}
}

void SoundManager::Process(const uint32 &target_milliseconds,
                           uint32 &used_milliseconds)
{
	CivSound						*sound;

    sint32 start_time_ms = GetTickCount(); 

    if ((m_noSound) ||(m_usePlaySound)) { 
        used_milliseconds = GetTickCount() - start_time_ms; 
        return;
    }

	
	if (m_sfxSounds->GetCount() > 0) {
		m_soundWalker->SetList(m_sfxSounds);
		while (m_soundWalker->IsValid()) {
			sound = m_soundWalker->GetObj();
			Assert(sound);
			if (!sound) continue;
			
			if (sound->IsPlaying()) {
#if !defined(USE_SDL)
				if (AIL_quick_status(sound->GetHAudio()) == QSTAT_DONE) {
#else
                if (!Mix_Playing(sound->GetChannel())) {
#endif
					m_soundWalker->Remove();

					delete sound;
				} else {
					m_soundWalker->Next();
				}
			}
		}
	}

	if (m_voiceSounds->GetCount() > 0) {
		
		m_soundWalker->SetList(m_voiceSounds);
		while (m_soundWalker->IsValid()) {
			sound = m_soundWalker->GetObj();
			Assert(sound);
			if (!sound) continue;
			
			if (sound->IsPlaying()) {
#if !defined(USE_SDL)
				if (AIL_quick_status(sound->GetHAudio()) == QSTAT_DONE) {
#else
                if ((-1 == sound->GetChannel()) ||
                    (!Mix_Playing(sound->GetChannel()))) {
#endif
					m_soundWalker->Remove();
					delete sound;
				} else {
					m_soundWalker->Next();
				}
			}
		}
	}

	ProcessRedbook();

    used_milliseconds = GetTickCount() - start_time_ms; 
}


bool FindSoundinList(PointerList<CivSound> * sndList, sint32 soundID)
{
    for 
    (
	    PointerList<CivSound>::Walker walk(sndList);
	    walk.IsValid();
        walk.Next()
    ) 
    {
		if (walk.GetObj()->GetSoundID() == soundID)
		{
			return true;
		}
	}

	return false;
}

void
SoundManager::AddGameSound(const GAMESOUNDS &sound)
{
	sint32 id = gamesounds_GetGameSoundID(sound);
	AddSound(SOUNDTYPE_SFX, 0, id, 0, 0);
}