I've made a few changes in the code to make Celestia support script controlled sound, i.e., you can tell the program to play a sound file in a script file.
This is the "second release" of this stuff... the first one is in this topic:http://shatters.net/forum/viewtopic.php?t=7628
The previous version really sucked, in many ways... it supported only raw wav files, with very low bitrates; you could only play one file at a time; there was no control on the volume of the sound; etc...
For this new version I used a library called OpenAL (http://www.openal.org), that is cross-platform, so theorically these changes will work in Windows and Mac too, theorically... I don't have a Mac to try...
I wasn't able to compile a windows version, even with a fresh copy of the released source code 1.4.0 (cvs version also doesn't work)... I kept getting several errors messages in the octree.cpp file, something with the DynamicStarOctree... probably the micro$oft compiler is making something stupid with the templates... (I tried with the Visual Studio 2005)
This code was made and tested in Ubuntu 5.10.. tomorrow I'll test in a Fedora Core 4...
The features of this version:
* Supports up to 8 channels (you can play 8 sound files simultaneously) - you can use one as background music, one for narration, one for sound effects, ... (yes, I know sound doesn't travel in space...)
* Supports various formats, and bitrates, .wav files (all wav files that I tried worked just fine)
* Supports both legacy scripts files (.cel) as new scripting language (.celx)
* Supports looping
* Supports volume changing
* Supports play stop
I don't know if there's a way to attach a file in this forum... so I uploaded the patch file to the virtual drive of my ISP. The address is:http://discovirtual.uol.com.br/disco_virtual/rluizfilho/celestia
The password is: celestia
To apply the patch, download the patch file from the above url, and in the root directory of your copy of the celestia code type the command: patch -p1 < path_to_patch_file
This patch works both on the release version 1.4.0 and on the cvs-version (01/01/2006). I didn't tested on previous versions.
I don't know if there's a way to apply a patch file automatically on Windows... You can always open the patch file on the wordpad (it's a text file) and apply the changes yourself.
The patch will only change the source files... To compile you'll have add the OpenAL library. One easy way to do that is add the following to the ./configure command: LDFLAGS=-lopenal. For instance, my full ./configure command was:
Code: Select all
./configure --with-gtk --with-lua LDFLAGS=-lopenal
Of course, this assumes that you already have installed OpenAL on your system, and that it is on the path...
Now, finally, how you use this stuff...
On legacy scripts (.cel):
There's a new command: Play
This command accepts four arguments:
channel - specifies the channel that'll be affected by this call. If not given, will assume the default value of 0, You can put any number between 0 and 7. Any number out of this range will cause the script to fail.
volume - specifies the new volume of this channel. If not given, the volume of the channel will remain unchanged. It starts with the volume 1.0. You can specify any number between 0.0 (minimum, mute) and 1.0 (maximum). If the number given is negative, the value is ignored, and the volume remains unchanged. If the number is bigger than 1.0, the volume will be set to the maximum volume, 1.0.
loop - specifies if the sound file will be played in looping or not. If not given, the looping mode of the channel will remain unchanged. It starts with looping off. The value 1 turns the looping on. Any other value turns the looping off.
filename - name of the file that will be played. The name can be in full path or relative path. Full path names must begin with '/'. Relative path names are relative to the dir <CELESTIA_DATA_DIR>/sounds. The default <CELESTIA_DATA_DIR> is /usr/local/share/celestia. To stop the playback in one channel, you should pass "" as the filename argument.
Small example:
Code: Select all
# start playing background music
play { channel 0 volume 1.0 loop 1 filename "/home/victor/background.wav" }
# do some stuff
wait { duration 5.0 }
# lower the volume of channel 0, so you can hear the narration
play { channel 0 volume 0.4 }
# say something
play { channel 1 volume 1.0 filename "narration1.wav" }
# wait the narration to end
wait { duration 6.0 }
# increases the background volume
play { channel 0 volume 1.0 }
# some other stuff
wait { duration 3.0 }
# stop the background playback
play { channel 0 filename "" }
On the new script files (.celx)
It's pretty much the same as above...
The command name is celestia:play
It accepts 2 to 4 arguments, that are:
celestia:play(channel,volume,loop,filename)
Their meanings are the same from before. But in .celx you MUST pass always, at least, the first two arguments (channel and volume), or else the script will fail, and the celestia will crash...
The two last arguments are optional... If you need to pass the filename argument, but don't want to change the volume neither the loop you can use the -1 value,
Some examples:
Code: Select all
celestia:play(0,0.8,1,"sample1.wav")
celestia:play(1,1)
celestia:play(1,0.5,-1,"sample2.wav")
celestia:play(2,-1,-1,"sample3.wav")
Well, I guess it's all...
Hope this helps someone out there...
Any doubt, just scream...
Victor
P.S. - Forgive me for my bad english and the very long post...