Turns out TR2 is using a totally different API - makes sense, as it's now a Windows app. Instead of MSCDEX, it's using Windows MCI. This deals with the blocking for them - they just don't set the MCI_WAIT flag on the MCI_PLAY call, and it does its stuff in the background.
I think I'm going to have to assume that the CD stalls aren't easily resolvable with MSCDEX - if they were, I imagine Core would have done so. So let's concentrate on getting Glidos to play the tracks from HDD.
Let's talk about interfacing to Glidos. Can we generalise the interface in case other games want similar patches? What can Glidos currently do? My thoughts are that a fully featured RedBook replacement API would offer:
int InitialiseGlidosAudio(const char *game_name);
// this tells Glidos which game this is, so it can look in an appropriate directory. Tells us whether or not audio support is enabled in the Glidos config (so the user has the option to fall back to normal behaviour).
int GetTrackLength(int track_num);
// in CD frame units (1/75 of a second). 0 if not available
int GetCurrentPlayPosition(int track_num);
// return current play position in frames, -1 for not playing.
int PlayTrack(int track_num, int flags);
// reports success; flags are
// bit 0: clear = stop any existing audio; set = play on top of any current audio (and ignore call if currently playing)
// bit 1: clear = play once, set = play continuously
void StopTrack(int track_num);
// track_num = 0 to stop all tracks.
If Glidos could offer all those calls, then it would be pretty easy to patch any RedBook CD-based program to use them, if available. If it detects that it's not running with Glidos, or that the tracks aren't available, it could default to normal CD behaviour.
Can Glidos actually play multiple sounds simultaneously? Also, can Glidos play WAV versions of the audio, if we want better than MP3?
And on another note, a correspondent on tombraiderforums confirms that the PlayStation has no general ambience - just the one ambient track (equal to the PC Peru one - slube's table has a slight error, but the MP3 tracks are right), which is triggered occasionally like any other cue.
Presumably we want to get the game to do both general ambience and cues, like TR2 on the PC (and PlayStation?). It might need a little bit of jiggery-pokery to ignore the ambient cues if the ambient loops are available. My thoughts are that the patched version should work like this:
If Glidos is not in use, or audio pack support is disabled:
- Map cues (2,22..25,57..60) to CD tracks (2..10) like the original PC version
- Map cues (13,26..56) to internal audio like the original PC version
- Map cues (3,4,6..12,14..21) to CD tracks 11..27, and attempt to play them if available on the CD
- Ignore cue 5.
This gives people the option of making a CD if they don't want to use Glidos. But they will suffer pauses when it plays; Glidos will work better. And I will have to muck around a bit to make it resume ambience afterwards. But I should be able to do it.
If Glidos is in use and has Audio Pack support enabled:
- Never attempt Red Book audio.
- Tell Glidos to play cues (2..4,6..60) (but not 5 by default). Remap numbers to match and extend slube's ordering.
- If Glidos reports track unavailable for 57..60, treat this as an indication that the user doesn't want looping ambience, and enable playing of track 5.
- If Glidos reports track unavailable for (13,26..56), fall back to internal audio. (Possibly useful if someone is still using the current audio pack without those sounds).
- If Glidos reports track unavailable for any other track, don't worry.
We need to extend the audio track pack up to include PlayStation tracks 13,26..56. The remapping is ugly, but it makes sense to try and keep a single coherent ordering. I'd rather start counting from 2, but I guess we should stick with what we've already got.
It will go:
Audio pack index = Internal cue number (PS track number)
01 = cue 2 (title)
02..05 = cues 57..60 (PC ambient tracks)
06..09 = cues 22..25 (cut scenes)
10..26 = cues 3,4,6..12,14..21 (missing music cues)
27 = cue 5 (PlayStation ambience)
28 = cue 13 (secret chimes)
29..59 = cues 26..56 (tutorials, baddy dialogue)
Thus tracks 01..26 are the current audio pack ordering, and the ordering that the game will support if running off CD (where they will be tracks 02..27). That'll make people's life easier if they're using the Audio Pack to burn a CD.
I've separated the PlayStation ambience off for greater flexibility. Cues 5 and 59 are distinct in the code, so they probably should remain so in the track list.
How's all that sound?