PDA

View Full Version : The Music/Sound Engine


Kjurtyl
2002.07.14, 03:31 PM
Currently, the music engine plays any music in the home directory's music folder or in the music folder next to Hooptie. The one problem with this situation is that the music plays throughout the game without discrimination to what is happening on screen.

Although the engine currently has all the functionality it needs to play music, in order to improve it we will have to rework the process.

Consequently, I will be removing the ability to play anything in the home directory's music folder and will restrict Hooptie's access to music in the music folder next to the application. Afterwards, I will be collecting music files and establish the calls that will enable Hooptie to play the right music at appropriate times.

Input or comments welcome,
-Kjurtyl

Kjurtyl
2002.07.15, 02:18 PM
I get this warning whenever I build the jukebox, I'd like to know what is means and how I can fix it:

warning: could not use precompiled header '/System/Library/Frameworks/Carbon.framework/Headers/Carbon.p', because:
'OpenScripting/OpenScripting' has different date than in precomp

then it goes on to list all the items that has a different date than in precomp.

-Kjurtyl

Pazolli
2002.07.16, 02:41 AM
Originally posted by Kjurtyl
I get this warning whenever I build the jukebox, I'd like to know what is means and how I can fix it:

warning: could not use precompiled header '/System/Library/Frameworks/Carbon.framework/Headers/Carbon.p', because:
'OpenScripting/OpenScripting' has different date than in precomp

then it goes on to list all the items that has a different date than in precomp.


Go into the Terminal and type "sudo fixPrecomps". QuickTime 6 was also just released so you might want to get that too. Try to use QuickTime if possible as it also allows MP3 playback (and now MP4). One thing I haven't tried to boost QuickTime performance is multithreading. See here (http://www.cocoadevcentral.com/tutorials/showpage.php?show=00000033.php) for more information. Of course playing music should be a low priority to game play.

Mark.

Kjurtyl
2002.07.16, 03:54 PM
There is definitely a speed hit with Quicktime right now, although maybe the new QT 6 APIs might help with that. Currently, as soon as QT is started up, the game play skips a few frames at odd intervals even if no music is playing. Just installing QT 6 seemed to speed things up somewhat.

I agree that music should be a lower-priority right now, but that doesn't stop us from using sounds right away.

I have done some work in implementing both sound and music. Sound is much easier to implement, improves game play and doesn't hit Hooptie in performance as much as the music. I'm thinking I'll commit the sound changes soon and leave the music as-is (even though we can now call music at any time and stop it appropriately) until such a time as it is better performing.

-Kjurtyl

P.S. I used Carlos' sounds as placeholder sound, but I think they sound great and might not require replacement for a while.

Pazolli
2002.07.17, 05:07 AM
This is really great new Kjurtyl, thanks for all your work.

Originally posted by Kjurtyl
I agree that music should be a lower-priority right now, but that doesn't stop us from using sounds right away.


Sorry. I should've put that another way. What I meant was that music shouldn't heavily interrupt game play, i.e. that game play performance should be given priority to music playing. Multithreading and loading a single track after the bonus screen and then looping this might be a way to achieve this.

Mark.

Kjurtyl
2002.07.17, 12:09 PM
That is indeed much clearer. I'm still new to multi-threading, so it is still in the learning stages right now.

- Kjurtyl.

edit: The quicktime for Cocoa pages mention this warning:

Important: Call EnterMovies once before calling any other procedural C QuickTime functions. This needs to be done only once within your application (but redundant calls to EnterMovies are harmless). You do not need to call ExitMovies.

Any reason why it wasn't done with the jukebox, or have I missed the spot where it is done?

Pazolli
2002.07.17, 12:34 PM
I'm not sure. Sounds like it would be a good idea to call it. BTW I will make a few adjustments to the nib file which might cause a few headaches for you when committing back changes if you have also changed the nib file. If you can't resolve them send me the nib file: quirinus at mac dot com.

Mark.

Kjurtyl
2002.07.18, 12:27 AM
There is now a distinctively new thread whenever Hooptie runs. I can even guarantee that there is an instance of the jukebox residing happily within it.

Hooptie is now officially multi-threaded. Everyone hop in joy.

Current "features" include no more presence of the jukebox in the nib file, no appreciable improvements in speed and every msg sent towards the jukebox must be routed to the gameController who is the only object with access to the new thread. Aside from creating another thread I haven't done anything that should actually increase game speed. Sound still works as does music, however.

I'll look into speeding things up tomorrow. On a side note, I've now developed a twitch that is triggered whenever I see the word thread on screen.

- Kjurtyl.

Kjurtyl
2002.07.19, 11:52 PM
The re-worked sound/music engine is now part of cvs tree. There are some new issues raised everyone contributing (and playing Hooptie) should consider.

Quicktime is not "Thread-safe" calling Quicktime in any other thread than GameJukebox runs the risk of causing an immediate crash upon execution.

Speed while playing music has not made much progress thus far, and I recommend keeping music turned off for the time being. Sounds are NOT affected by this.

If you want music to be played, be sure to have a music folder in the same folder as Hooptie. This folder should include .mp3 or .mid files only, NOT .midi; apparently QT in OS X doesn't appropriately recognize those. Rename any .midi to .mid to make it work.

The music files in the music folder are loaded in sequential manner; the order in which they are loaded affects where they play.

Here is the order:

Rank Function
0 Splash Screen Music
1 Playing Music
2 Opening Screen Music
3 Game Over Music
4 Out Of Time Music
5 Time Bonus Music
6 You Win Music

To insure this order is respected, you can rename the music files to include their rank as prefix.

I.e.: 0Hooptie_titles.mid

Not all of these are implemented yet, for example, there is no splash screen music call made. However you still need an appropriate file to fill that slot.

I'd like to know everyone's experience with sound and music to see how it can be improved upon.

Kjurtyl
2002.07.22, 10:31 PM
I strongly believe I have found the source of the speed hit caused by having some music play in Hooptie.

It seems that because QuickTime is currently Carbon-based, it has it's own way of handling multi-threading. Specifically, whenever we invoke QuickTime, whether it is through Cocoa (NSMovieView, NSMovie) or through the QT API directly by means of C functions, QT directs it's calls into new self-created threads. That means there are four to six more threads added to the Hooptie scheme as soon as we push play(or turn music on).

That would in essence void all our efforts at multithreading that side of Hooptie because QT callbacks effectively ignore our entire structure to create it's own method of handling audio. I believe
we cannot handle this problem through Cocoa. Although
we might be able to affect changes to the way we draw things on screen to synchronize both audio and graphics - not something I recommend.

One possible path would be to handle QT on its own turf; Carbon. However that would detract us from our Cocoa-oriented approach. Another option would be to go with something else, like CoreAudio. That might yield more problems than benefits since we'd have to reinvent the many features of QT to make it worthwhile.

We could also wait for Jaguar and see if it includes any improvements on that front (and I have reason to believe it will - no rumors).

I'm perfectly happy with letting this issue rest for now, even though some clean-up of the jukebox is certainly in order.

- Kjurtyl.

Pazolli
2002.07.25, 06:19 AM
Hmm...well congratulations on getting the sound and multithreading working well. If QuickTime fails (which it looks like it will) we might be best finding something else to play the MIDI files. (BTW the music that used to skip now doesn't on my machine so congrats on getting that working). If anyone wants to collect sound (not music) for the game that would be great. I'll also see if I can have a go at the music engine myself this weekend. I'm not too keen on the Golden Letters of Hooptie idea any more (seems like it would be too-much in a game if you get what I'm saying) and I think we'll leave different AI's for different creatures (the AI code is a mess at that moment). That leaves little to do for most of us until Alan finishes some new sprites for us.

That said, I welcome your suggestion for additions not requiring graphics suited to this stage of development (the more ambitious ones like Internet Game Scoring I think we'll leave for later). I also welcome any general improvements to the code.

Thanks all for your work,
Mark Pazolli

P.S. Congratulations DaFalcon on the new release of SnakeQuest :-)

Pazolli
2002.07.26, 12:46 AM
Mathieu has said he is unable to complete the discrete scores (http://sourceforge.net/pm/task.php?func=detailtask&project_task_id=55267&group_id=31218&group_project_id=13463) task. Would anyone else like to have a go at it?

Mark.