Help with adding something to the source code...

General chat related to ScummVM, adventure gaming, and so on.

Moderator: ScummVM Team

Post Reply
cisco17
Posts: 32
Joined: Wed Mar 12, 2008 1:55 am

Help with adding something to the source code...

Post by cisco17 »

I'm looking for a way to introduce a piece of code in the middle of scummvm execution so I can load and play an mp3 file.

I don't think it should be very difficult for someone who understands how this source works, but I don't know the way to do it.

What I want to do is just open an mp3 file and play it. Then, probably, close or destroy it. It could be streamed instead of loaded to memory, also.

Is there any programmer who can bring help to me with that?

Thanks in advance! :D
User avatar
dreammaster
ScummVM Developer
Posts: 559
Joined: Fri Nov 04, 2005 2:16 am
Location: San Jose, California, USA

Re: Help with adding something to the source code...

Post by dreammaster »

cisco17 wrote:I'm looking for a way to introduce a piece of code in the middle of scummvm execution so I can load and play an mp3 file.
That's an incredibly vague request. ScummVM consists of almost 50 game engines, many of which support multiple different games. So are you talking about a specific game? And when do you want the mp3 to be launched? Is this a case of trying to add speech support to a specific game? If so, then it would have to be hooked into the game's existing text display code for characters "speech", so couldn't be done generically for all ScummVM games. Not to mention that there'd be other secondary things you'd have to worry about too, in the case of speech, such as hacking the text display not to finish displaying what the character said until the MP3 of the speech had finished.

You'd likely do better narrowing your focus, and discuss it on the IRC channel. If it's a case of adding speech to an existing game, and you can demonstrate some effort already done to create a speech pack, you might be able to entice someone to assist you with the programming.
cisco17
Posts: 32
Joined: Wed Mar 12, 2008 1:55 am

Post by cisco17 »

Well, I'm sorry you found this request incredibly vague. Probably it is, but in the other thread I'm asking for the same with more explanation, I have been waiting and trying again for like 5 years with no luck or much interest.

So, as you supposed, that's what I wanted to do: a speech pack, concretely for Maniac Mansion and specifically in Spanish.

I have compiled a debug version of ScummVm where everytime an actor talks, a name for a wave file is generated depending on the actor number and the text.

In the same place of the code, a part that loads and plays this wave (or mp3) could be added, an also, a hack for the delay time for the text so it waits for the mp3 to finish.

I can do the speech pack. The actors and actresses part is not a problem. The problem is the tecnical part.

There is no hurry to do this project, I have been going to it for several years. But it could be great to try.

So, maybe I could go to IRC channel to seek for help?
User avatar
dreammaster
ScummVM Developer
Posts: 559
Joined: Fri Nov 04, 2005 2:16 am
Location: San Jose, California, USA

Post by dreammaster »

cisco17 wrote:Well, I'm sorry you found this request incredibly vague. Probably it is, but in the other thread I'm asking for the same with more explanation, I have been waiting and trying again for like 5 years with no luck or much interest.
Ah, that explains it. I wasn't really aware of the other thread; I've probably seen it in passing and only skimmed over it. Sounds like an interesting project, although the Scumm engine is (from what I gather) one of the more complicated engines, which is probably partly why you've had trouble finding any interested parties. I honesty can't say if you'll find anyone on IRC either, but it certainly couldn't hurt.
cisco17
Posts: 32
Joined: Wed Mar 12, 2008 1:55 am

Post by cisco17 »

By the way, with what I said, do you think as a developer that maybe you can help me with a little piece of code that just loads and play (or streams) and mp3 file?

I mean, with that, maybe I have everything else solved :)

Thanks for the answer!
User avatar
dreammaster
ScummVM Developer
Posts: 559
Joined: Fri Nov 04, 2005 2:16 am
Location: San Jose, California, USA

Post by dreammaster »

Sorry, no. I have no experience with the Scumm engine, and I have my hands full with other work.
User avatar
eriktorbjorn
ScummVM Developer
Posts: 3561
Joined: Mon Oct 31, 2005 7:39 am

Post by eriktorbjorn »

cisco17 wrote:By the way, with what I said, do you think as a developer that maybe you can help me with a little piece of code that just loads and play (or streams) and mp3 file?
I guess it would be just a matter of opening the file, using the Common::File class. That class inherits from Common::SeekableReadStream, which can be used to create an MP3 stream, using the Audio::makeMP3Stream() method. That can then be played using the mixer's playStream() method.

Of course, there's a bit more to it than that, since some of those functions take a few more parameters. Also, note that makeMP3Stream() will only be available if USE_MAD is defined.

Instead of using the File class and makeMP3Stream() method, I guess you could also use the Audio::SeekableAudioStream::openStreamFile() method, which should look for any supported compressed format. But the original question was about MP3 specifically...

I can't test any of this at the moment, but you should be able to find examples by searching through the ScummVM source code.
cisco17
Posts: 32
Joined: Wed Mar 12, 2008 1:55 am

Post by cisco17 »

This is very helpful!

But I'm stuck because I'm not really sure of what I'm doing with the code. Everytime I look for something related with sound and paste it trying it to work on the file I'm modyfing (string.cpp inside engines/scumm) I got messages when compiling like things not declared on this scope, logically.

At this point I'm on the code place where I can "freeeze" the time counter for the talkdelay, and here is where I want to load and send to the mixer the mp3 (or ogg, maybe better).

Maybe I have to declare at the start of string.cpp the audio before beeing able to load and play it, or something :(

This is what I tried the last:

Code: Select all

Audio::SeekableAudioStream *stream = Audio::SeekableAudioStream::openStreamFile("test.mp3");
	if (stream) {
		_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, Audio::makeLoopingAudioStream(stream, loops ? 0 : 1));
		return;
	}
I'm trying to just make a test.mp3 play, before trying to locate for specific filenames, but I have no luck because I'm kinda blind here. But I think the way must be not very different from this....

What I get here when trying to compile is:

'_musicHandle' was not declared in this scope
'loops' was not declared in this scope

But I can't replace them with another thing because I don't know what I have or can put there
:(
User avatar
md5
ScummVM Developer
Posts: 2250
Joined: Thu Nov 03, 2005 9:31 pm
Location: Athens, Greece

Post by md5 »

You need a sound handle to play a sound. 'loops' refers to sound looping. The file name refers to the base file (without the extension).

Try:

Code: Select all

    Audio::SeekableAudioStream *stream = Audio::SeekableAudioStream::openStreamFile("test");
    Audio::SoundHandle speechHandle;
    if (stream) {
        _mixer->playStream(Audio::Mixer::kSFXSoundType, &speechHandle, Audio::makeLoopingAudioStream(stream, 1));
        return;
    }
cisco17
Posts: 32
Joined: Wed Mar 12, 2008 1:55 am

Post by cisco17 »

I will try it as soon as i'm back at home, thank you!
cisco17
Posts: 32
Joined: Wed Mar 12, 2008 1:55 am

Post by cisco17 »

It's done! It was JUST what I need!

Now it plays perfectly a test.ogg (missing a test.flac and test.fla before) everytime a text phrase is said, so I can rework that with what I have done and make it play the specific ogg file for each phrase!

Some things that could help me now, if you want to help me a little more, are:

- Make the program directly look for OGG files instead of first trying flac and fla.
- There is a way to check if the sound is still playing and another one to stop it?


THANK YOU VERY MUCH!!! :)
User avatar
eriktorbjorn
ScummVM Developer
Posts: 3561
Joined: Mon Oct 31, 2005 7:39 am

Post by eriktorbjorn »

cisco17 wrote: - Make the program directly look for OGG files instead of first trying flac and fla.
Well, then you're back to creating the specific kind of audio stream I mentioned earlier, I guess.
cisco17 wrote: - There is a way to check if the sound is still playing and another one to stop it?
When you started playing the audio stream, you presumably passed a SoundHandle to the mixer as one of the parameters to playStream(). If you still have that sound handle available, you should be able to use the isSoundHandleActive() and stopHandle() methods in the mixer.
fischkopf
Posts: 113
Joined: Sun Mar 22, 2009 1:08 pm
Location: germany

Post by fischkopf »

Why do you want to use an outdated format such as mp3? These days there is ogg, there is opus and more. You should use one of these more efficient formats.
Post Reply