project-navigation
Personal tools

Author Topic: Multiple Sound Files for Messages  (Read 8222 times)

Offline Neonin

  • Rookie
  • ***
  • Posts: 63
    • View Profile
Multiple Sound Files for Messages
« on: July 14, 2012, 10:15:08 pm »
Based on Crystan's idea to have voiceovers for the Geoscape messages and an observation I made that it might be better to have multiple options for each message so you don't get bombarded with the same phrase over and over again, I was wondering if something as simple as this would do the trick in cp_messages.cpp:

Code: [Select]
if (playSound) {
const char *sound = NULL;
int msgClipNum;

msgClipNum = rand()%4+1;

switch (type) {
case MSG_DEBUG:
break;
case MSG_STANDARD:
switch (msgClipNum) {
case 1:
sound = "geoscape/standard1";
break;
case 2:
sound = "geoscape/standard2";
break;
case 3:
sound = "geoscape/standard3";
break;
case 4:
sound = "geoscape/standard4";
break;
}
break;
case MSG_INFO:
case MSG_TRANSFERFINISHED:
case MSG_DEATH:
case MSG_CONSTRUCTION:
case MSG_PRODUCTION:
switch (msgClipNum) {
case 1:
sound = "geoscape/info1";
break;
case 2:
sound = "geoscape/info2";
break;
case 3:
sound = "geoscape/info3";
break;
case 4:
sound = "geoscape/info4";
break;
}
break;
case MSG_RESEARCH_PROPOSAL:
case MSG_RESEARCH_FINISHED:
assert(pedia);
case MSG_RESEARCH_HALTED:
case MSG_EVENT:
case MSG_NEWS:
/* reread the new mails in UP_GetUnreadMails */
ccs.numUnreadMails = -1;
switch (msgClipNum) {
case 1:
sound = "geoscape/mail1";
break;
case 2:
sound = "geoscape/mail2";
break;
case 3:
sound = "geoscape/mail3";
break;
case 4:
sound = "geoscape/mail4";
break;
}
break;
case MSG_UFOLOST:
switch (msgClipNum) {
case 1:
sound = "geoscape/ufolost1";
break;
case 2:
sound = "geoscape/ufolost2";
break;
case 3:
sound = "geoscape/ufolost3";
break;
case 4:
sound = "geoscape/ufolost4";
break;
}
break;
case MSG_UFOSPOTTED:
switch (msgClipNum) {
case 1:
sound = "geoscape/ufospotted1";
break;
case 2:
sound = "geoscape/ufospotted2";
break;
case 3:
sound = "geoscape/ufospotted3";
break;
case 4:
sound = "geoscape/ufospotted4";
break;
}
break;
case MSG_BASEATTACK:
switch (msgClipNum) {
case 1:
sound = "geoscape/basealert1";
break;
case 2:
sound = "geoscape/basealert2";
break;
case 3:
sound = "geoscape/basealert3";
break;
case 4:
sound = "geoscape/basealert4";
break;
}
break;
case MSG_TERRORSITE:
switch (msgClipNum) {
case 1:
sound = "geoscape/alien-activity1";
break;
case 2:
sound = "geoscape/alien-activity2";
break;
case 3:
sound = "geoscape/alien-activity3";
break;
case 4:
sound = "geoscape/alien-activity4";
break;
}
break;
case MSG_CRASHSITE:
switch (msgClipNum) {
case 1:
sound = "geoscape/newmission1";
break;
case 2:
sound = "geoscape/newmission2";
break;
case 3:
sound = "geoscape/newmission3";
break;
case 4:
sound = "geoscape/newmission4";
break;
}
break;
case MSG_PROMOTION:
switch (msgClipNum) {
case 1:
sound = "geoscape/promotion1";
break;
case 2:
sound = "geoscape/promotion2";
break;
case 3:
sound = "geoscape/promotion3";
break;
case 4:
sound = "geoscape/promotion4";
break;
}
break;
case MSG_MAX:
break;
}

cgi->S_StartLocalSample(sound, 1.0f);
}


The rand() function requires stdlib.h is defined in the includes but I'm assuming that's already in the code somewhere. My C++ coding is very rusty but I think that's all it would take to generate a number between 1-4 and then use that to select a sound file. To start with a quick copy/paste and rename of the original files would allow the code to work until the actual sound files were created.

Then again, this game is far more complex than anything I've ever fiddled with before code-wise so I don't know if this would do something horrible, and getting this stuff to compile on Windows looks like a pain in the arse just to test something as simple as this. Perhaps one of you experienced coders could look at it and see if it seems viable?

Offline Neonin

  • Rookie
  • ***
  • Posts: 63
    • View Profile
Re: Multiple Sound Files for Messages
« Reply #1 on: July 15, 2012, 01:38:11 pm »
I answered my own question, got the source to compile and tested it with copy/pasted sound effects with clicks in them to signify which one was being played :P

It does work :D

Offline geever

  • Project Coder
  • PHALANX Commander
  • ***
  • Posts: 2561
    • View Profile
Re: Multiple Sound Files for Messages
« Reply #2 on: July 15, 2012, 03:12:40 pm »
May I note that your approach with hardcoded number of sounds is not too flexible?
If we ever add that support for multiple geoscape sounds we need a way to either automatically detect number of available sounds per category or make them scripted.

-geever

Offline Neonin

  • Rookie
  • ***
  • Posts: 63
    • View Profile
Re: Multiple Sound Files for Messages
« Reply #3 on: July 15, 2012, 04:00:01 pm »
It's as flexible as the current system :P

But yes, a way of counting how many of a specific type of sound is in the folder (best to separate each type into its own folder if going down that route) would be much preferable. I've also encountered a problem while playing where, for example, when you research something that throws up more than one possible avenue of research it will try and play a file, often different ones, for each topic all at once. It's... noisy... to say the least. Obviously a way of detecting that a message of that type is already going to play or getting the message code to only play one sound per type of message queued would be needed.

No idea if my coding knowledge is up to either task but I shall give it a shot, it gives me a little project to do when I'm not playing :P

Offline Neonin

  • Rookie
  • ***
  • Posts: 63
    • View Profile
Re: Multiple Sound Files for Messages
« Reply #4 on: July 16, 2012, 04:21:18 pm »
Quick update:

Reading then number of files in a directory uses different commands in C++ dependant on the OS (unless you've installed certain libraries that bring it all under one set of commands) so I am looking to make this scriptable.

I've also modified the code some more so that you can have different sounds based on the type of tech in use in the message, so you could have one file for "Weapon research completed" and another for "Armour research finished", same for production, etc. This would enable a more varied and accurate Geoscape voiceover hopefully!

Anyway, big thing is making it scriptable so I shall be looking at current examples and trying to learn from those :P

Bibi94752

  • Guest
Re: Multiple Sound Files for Messages
« Reply #5 on: November 04, 2013, 08:52:07 am »
I will try this.
« Last Edit: March 14, 2014, 11:16:21 am by Bibi94752 »

Offline Grug

  • Rookie
  • ***
  • Posts: 56
    • View Profile
Re: Multiple Sound Files for Messages
« Reply #6 on: November 11, 2013, 04:34:38 pm »
This sounds like a great idea to me. One thought about detecting the number of available sounds - I assume (without having looked at the code) something similar is done for the various human/alien sounds that have multiples, so it might be worth looking around those parts of the code for ideas.