Last visit was: It is currently Thu Dec 05, 2024 10:29 am


All times are UTC-05:00




Post new topic Reply to topic  [17 posts ] 
Author Message
 Post subject:Re: Uplink - Sound Modification
PostPosted:Mon Oct 21, 2013 1:33 pm 
 

Joined:Tue Oct 15, 2013 11:09 pm
Posts:18
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 5938 times ]
Top
Offline  
 Post subject:Re: Uplink - Sound Modification
PostPosted:Mon Oct 21, 2013 2:56 pm 
Literally Nine
User avatar
 

Joined:Tue Mar 01, 2005 9:00 am
Posts:1263
Ah, nevermind then. We had fmod before and I have generally no interest in it, being that it's a windows-only item.


Top
Offline  
Display posts from previous: Sort by 
Post new topic Reply to topic

All times are UTC-05:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created by Miah with assistance from hyprnova