Ferrous Moon
http://www.ferrousmoon.com:80/forums/

Uplink - Sound Modification
http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=2881
Page 2 of 2

Author:  someguy [Mon Oct 21, 2013 1:33 pm ]
Post subject:  Re: Uplink - Sound Modification

Ok here is the code that replaces the init music, using this can replace the music for pretty much anyone modifying uplink using FMOD. This requires a bit of work on your end, blind copy and paste would likely fail, but this will for sure get you on your way.
Code:
resultUniqueFmod = FMOD::System_Create( & systemF); if(resultUniqueFmod != FMOD_OK) { exit(-1); } resultUniqueFmod = systemF - > init(100, FMOD_INIT_NORMAL, 0); if(resultUniqueFmod != FMOD_OK) { exit(-1); } resultUniqueFmod = systemF - > createStream(RsArchiveFileOpen(Playlist), FMOD_DEFAULT, 0, & playlistUniqueFmod); resultUniqueFmod = playlistUniqueFmod - > getFormat( & soundtypeUniqueFmod, 0, 0, 0); isplaylistUniqueFmod = (soundtypeUniqueFmod == FMOD_SOUND_TYPE_PLAYLIST); if(isplaylistUniqueFmod) { resultUniqueFmod = playlistUniqueFmod - > getTag("FILE", countUniqueFmod, & tagUniqueFmod); ERRCHECK(resultUniqueFmod); sprintf(fileUniqueFmod, "music/%s", (char * ) tagUniqueFmod.data); resultUniqueFmod = systemF - > createSound(RsArchiveFileOpen(fileUniqueFmod), FMOD_DEFAULT, 0, & soundUniqueFmod); ERRCHECK(resultUniqueFmod); resultUniqueFmod = systemF - > playSound(FMOD_CHANNEL_FREE, soundUniqueFmod, false, & channelUniqueFmod); ERRCHECK(resultUniqueFmod); playlistUniqueFmod - > getTag("TITLE", countUniqueFmod, & tagUniqueFmod); titleUniqueFmod = (char * ) tagUniqueFmod.data; countUniqueFmod++; }

In my hud update call i check to see if the track is playing, if it is not playing, than play music by using the count variable already incremented when the initmusic was called, if its the last song, go to the first song. This bit of code being used in the hud update is more ingenious than it seems, this is explained afterwards when using next track and previous track functions.

Code:
bool isplaying = false; if(channelUniqueFmod && isplaylistUniqueFmod) { channelUniqueFmod - > isPlaying( & isplaying); if(!isplaying) { if(soundUniqueFmod) { soundUniqueFmod - > release(); soundUniqueFmod = NULL; } if(countUniqueFmod < 0) { countUniqueFmod = trackCount - 1; } resultUniqueFmod = playlistUniqueFmod - > getTag("FILE", countUniqueFmod, & tagUniqueFmod); if(resultUniqueFmod != FMOD_OK) { countUniqueFmod = 0; } else { sprintf(fileUniqueFmod, "music/%s", (char * ) tagUniqueFmod.data); resultUniqueFmod = systemF - > createStream(RsArchiveFileOpen(fileUniqueFmod), FMOD_DEFAULT, 0, & soundUniqueFmod); ERRCHECK(resultUniqueFmod); resultUniqueFmod = systemF - > playSound(FMOD_CHANNEL_FREE, soundUniqueFmod, false, & channelUniqueFmod); ERRCHECK(resultUniqueFmod); playlistUniqueFmod - > getTag("TITLE", countUniqueFmod, & tagUniqueFmod); titleUniqueFmod = (char * ) tagUniqueFmod.data; std::ostrstream trackNum; trackNum << "Track " << countUniqueFmod + 1; trackNum << '\x0'; EclRegisterCaptionChange("hud_trackname", trackNum.str()); countUniqueFmod++; } } }
The variable "trackCount" is gathered from this function
Code:
FILE * infile = fopen(RsArchiveFileOpen( Playlist ), "r"); int ch; while(EOF != (ch = getc( infile ))) { if('\n' == ch) { ++trackCount; } }
The variable "Playlist" is just a simple
Code:
char *Playlist="music/playlist.m3u";

Ingeniously using the hud update to check if the song has stopped playing, makes it super easy to make a next track function, the code for the next track function is one line.
Code:
channelUniqueFmod->stop();
Stopping the track causes the hud update to say, "music is stopped so lets play music". Since when a track is played our count variable is increased by one, it will always play the next track.

The code for the previous track button is 2 lines which also is pretty nifty. It subtracts 2 from our count variable (since when the last track started it added 1 already) then calls stop so the hud update can once again say "music is stopped so lets play music", effectively playing the previous track.
Code:
countUniqueFmod=countUniqueFmod-2; channelUniqueFmod->stop();
This function lets you mute
Code:
float volume; channelUniqueFmod->getVolume(&volume); if ( volume <= .01f) { channelUniqueFmod->setVolume(1.0f); }else{ channelUniqueFmod->setVolume(0); }

There it is, I suppose I would be kind of a dick if I didn't expose the format of the global variables eh?
Code:
FMOD::System *systemF; FMOD_RESULT resultUniqueFmod; FMOD::Sound *soundUniqueFmod; FMOD::Channel *channelUniqueFmod; FMOD::Sound *playlistUniqueFmod = 0; FMOD_TAG tagUniqueFmod; bool isplaylistUniqueFmod = false; FMOD_SOUND_TYPE soundtypeUniqueFmod; int countUniqueFmod = 0; char *titleUniqueFmod = NULL; char fileUniqueFmod[128];


Attachments:
music.png
music.png [6.96KiB |Viewed 4728 times ]

Author:  Miah [Mon Oct 21, 2013 2:56 pm ]
Post subject:  Re: Uplink - Sound Modification

Ah, nevermind then. We had fmod before and I have generally no interest in it, being that it's a windows-only item.

Page 2 of 2 All times are UTC-05:00
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/