Page 1 of 2

sound

Posted: 28.09.2009, 17:40
by eafbsd
I’m still running, or should I say forced to run, Celestia 1.4.1 because of the sound capabilities of the 1.4.1 patch 3. Is there any way to achieve sound in the later versions (1.5 or 1.6) ?

Re: sound

Posted: 28.09.2009, 21:37
by selden
The v1.5.1-ED variant of Celestia includes sound support.
See http://www.celestiamotherlode.net/catal ... tional.php

Re: sound

Posted: 02.10.2009, 19:16
by eafbsd
Selden – first, thanks for the quick reply. Celestia is great, but I have a hard time understanding why it’s necessary to download a 489Mb 1.5.1 ED version file when the 1.4.1 patch3 sound download was only 4.91Mb? The only reason I’m kind of complaining is that my Celestia folder is currently at 4.77Gb. Is it possible there’s a patch somewhere that can enable sound in 1.5 or 1.6? Once again, thanks for the reply…

Re: sound

Posted: 02.10.2009, 19:27
by selden
The base ED download includes many Addons. The modified executable is only about 2MB. I don't know what else is needed in order for sound to work, if that's really all you want.. Hopefully Frank will comment.

Re: sound

Posted: 04.10.2009, 17:37
by Vincent
eafbsd wrote:Selden – first, thanks for the quick reply. Celestia is great, but I have a hard time understanding why it’s necessary to download a 489Mb 1.5.1 ED version file when the 1.4.1 patch3 sound download was only 4.91Mb? The only reason I’m kind of complaining is that my Celestia folder is currently at 4.77Gb. Is it possible there’s a patch somewhere that can enable sound in 1.5 or 1.6? Once again, thanks for the reply…
eafbsd,

- Bad news: I won't release a patched version of Celestia 1.6
- Good news: I managed to add sound support to Celestia - at least, to the Windows version for now - without adding one single
line to the Celestia source code. :) This can be done using proteaAudio, which is a free cross-platform stand-alone Lua audio library.

You can download the 'sound of a pulsar' test package below.

The zip contains:
- a pulsar_sound.celx script file
- a pulsar.ogg audio file
- the lua51.dll and proAudioRt.dll files.

The lua51.dll and proAudioRt.dll files should be placed right into your celestia base folder.
Other files can be placed wherever on your disk, e.g., in your celestia/extras/ folder...
Just make sure the sound file is located in the same folder as the script file.

The volume of the sound depends on the distance from the pulsar,
and the left/right components vary according to the position
of the pulsar relative to the observer. So you can test the stereo
audio effect by moving the pulsar around the observer using the 4/6 keys.

Please let me know how it works on your system.

Re: sound

Posted: 04.10.2009, 18:59
by Ricardo
Vincent wrote:I managed to add sound support to Celestia - at least, to the Windows version for now -

I confirm this do not work on Mac... Too bad, this is great...
I tried to put the dll files everywhere, but no chance with the script... (no feedback in the console either)

Re: sound

Posted: 04.10.2009, 23:59
by fsgregs
Vincent:

Your knowledge of programming continues to put me in awe. I have looked at some of the commands in the celx script that you included with the pulsar sound test, and well ... they look completely Greek to me :?

I have tested out the pulsar sound and it works fine on a Windows XP machine with Celestia 1.6.0, including stereo effects as you swing the view left or right

Two questions: (1) The sound file is an extension ending in .ogg. How would one convert a wav file to an ogg file, or can we use a .wav in the script instead? If we can use a wav file, what would the line in the celx script look like??

2. Is it possible to play two or more sound files simultaneously, as is possible with 151-ED?


eafbsd: I will answer you in more detail about 151-ED, after Vincent has a chance to comment on my two questions above.

Frank

Re: sound

Posted: 05.10.2009, 10:17
by Fenerit
A - M - A - Z - I - N - G!!! 8O . This is a "must have" in LUATOOLS toolkit as "sounds" in general. BTW: for whom are interested should be easy to modify the .OGG file to add surround... :wink:

Re: sound

Posted: 05.10.2009, 11:34
by chris
I have the proteaAudio library working on the Mac as well. I will try and release a version of it as soon as I have the time (later today, I think...) This audio library should also work on Linux, but I haven't tested that.

--Chris

Re: sound

Posted: 05.10.2009, 16:46
by Vincent
Frank,

fsgregs wrote:I have looked at some of the commands in the celx script that you included with the pulsar sound test, and well ... they look completely Greek to me :?
The proteaAudio Lua API (list of functions) is available here:
http://www.viremo.de/proteaAudio/proteaaudiolua.html

Also, we could write our own functions and put them in a lua file to make the sound commands look more like the other existing celx commands.

fsgregs wrote:I have tested out the pulsar sound and it works fine on a Windows XP machine with Celestia 1.6.0, including stereo effects as you swing the view left or right
Good ! Thanks for testing.

fsgregs wrote: (1) The sound file is an extension ending in .ogg. How would one convert a wav file to an ogg file, or can we use a .wav in the script instead? If we can use a wav file, what would the line in the celx script look like??
Both wav and ogg/vorbis files can be used. I'd suggest to use ogg files, though, since wav files are quite big (uncompressed format).
Audacity (free audio editor) will easily help you to convert from wav to ogg, and vice versa.

fsgregs wrote: 2. Is it possible to play two or more sound files simultaneously, as is possible with 151-ED?
Yes, you can play up to 8 tracks simultaneously. :)

Re: sound

Posted: 05.10.2009, 21:22
by fsgregs
Vincent:

Thanks so much for your quick reply. I will explore it all ASAP. :D

Frank

Re: sound

Posted: 06.10.2009, 00:16
by eafbsd
Frank,
I eagerly await any info you can provide. I am indebted to you. Thanks

Re: sound

Posted: 06.10.2009, 01:45
by Ricardo
chris wrote:I have the proteaAudio library working on the Mac as well. I will try and release a version of it as soon as I have the time (later today, I think...) This audio library should also work on Linux, but I haven't tested that.

--Chris

Very nice news!

Re: sound

Posted: 08.10.2009, 06:37
by Ricardo
chris wrote:I have the proteaAudio library working on the Mac as well...

How can we get the dll files version Mac?

Re: sound

Posted: 08.10.2009, 11:51
by Chuft-Captain
Thanks Vincent, works fine for me, although I haven't tried any multi-track stuff yet.
A brief read of the proteaAudio documentation doesn't make it obvious what is the correct syntax for assigning sounds to tracks for polyphonic playback.

CC

Re: sound

Posted: 08.10.2009, 15:49
by Vincent
Chuft-Captain wrote:Thanks Vincent, works fine for me, although I haven't tried any multi-track stuff yet.
A brief read of the proteaAudio documentation doesn't make it obvious what is the correct syntax for assigning sounds to tracks for polyphonic playback.

CC
CC,

You're welcome.
To play several samples simultaneously, you just need to load and ...play them.

Code: Select all

track1= proAudio.sampleFromFile(scriptpath.."sound1.ogg")
track2 = proAudio.sampleFromFile(scriptpath.."sound2.wav")
track3 = proAudio.sampleFromFile(scriptpath.."sound3.wav")

proAudio.soundPlay (track1)
proAudio.soundPlay (track2)
proAudio.soundPlay (track3)

Each sample will be automatically assigned to a track.
Do you have an example where you'd need to control the sample/track assignment ?

Re: sound

Posted: 08.10.2009, 16:08
by Fenerit
Vincent, I think that CC's "example" could be sourround. One could to assign the rear channels to a second track once the file audio has been properly encoded. In this manner one track is for the front channels and a second for the rear. I will try to split the pulsar.ogg in two files, one with the front channels encoded and one with the rear channels encoded. When one go to pulsar would to listen also on rear when have the pulsar backface.

Re: sound

Posted: 08.10.2009, 17:40
by Chuft-Captain
Vincent wrote:
Chuft-Captain wrote:Thanks Vincent, works fine for me, although I haven't tried any multi-track stuff yet.
A brief read of the proteaAudio documentation doesn't make it obvious what is the correct syntax for assigning sounds to tracks for polyphonic playback.

CC
CC,

You're welcome.
To play several samples simultaneously, you just need to load and ...play them.

Code: Select all

track1= proAudio.sampleFromFile(scriptpath.."sound1.ogg")
track2 = proAudio.sampleFromFile(scriptpath.."sound2.wav")
track3 = proAudio.sampleFromFile(scriptpath.."sound3.wav")

proAudio.soundPlay (track1)
proAudio.soundPlay (track2)
proAudio.soundPlay (track3)

Each sample will be automatically assigned to a track.
Do you have an example where you'd need to control the sample/track assignment ?
Cheers Vincent,
That may well work for ogg and wav samples Vincent (I haven't tried it yet), however it doesn't seem to work with generated samples.
Here's a simple example which is designed to play a well known 4 note motif (if you follow SciFi movies) simultaneously in an upper and lower octave.
(As posted, it will play just the higher octave by itself --- un-comment the lines marked as "lower octave" to activate the second octave)

Based on what you suggest, then both octaves should play polyphonically as the notes come from 2 different samples (and therefore 2 different tracks), however it appears that the second (lower) octave is unable to play until the first (higher) note has finished in each case.
This suggests to me that both upper, and lower octaves, in this case are being assigned to the same track, which means I've either done something wrong, or the library only allows multi-track playback of static wav/ogg files, but not generated waveforms.

EDIT: Oops! I just read the following sentence in the documentation which expains it.
"There is no equivalent to the C++ AudioSample class in the proteaAudio Lua API. However, mono audio samples may be dynamically created by the following call:

proAudio.sampleFromMemory(data, sampleRate)"


Code: Select all

-- function creating a sine wave sample:
function sampleSine(freq, duration, sampleRate)
   local data = { }
   for i = 1,duration*sampleRate do
      data[i] = math.sin( (i*freq/sampleRate)*math.pi*2)
   end
   return proAudio.sampleFromMemory(data, sampleRate)
end

-- plays a sample shifted by a number of halftones for a definable period of time
function playNote(sample, pitch, duration, volumeL, volumeR, disparity)
   local scale = 2^(pitch/12)
   local sound = proAudio.soundLoop(sample, volumeL, volumeR, disparity, scale)
   proAudio.sleep(duration)
   proAudio.soundStop(sound)
end

-- create an audio device using default parameters and exit in case of errors
require("proAudioRt")
--if not proAudio.create() then os.exit(1) end
if not proAudio.create( 8, 88200, 1024 ) then os.exit(1) end

-- Define target
target = celestia:find("Devils Tower")
--celestia:select(target)
--obs = celestia:getobserver()
--obs:gotodistance(target, 1000, 3)
--wait(3)

-- generate a sample:
local sample = sampleSine(440, 0.5, 88200)
local sample2 = sampleSine(220, 0.5, 88200)

-- play scale (a major):
local duration = 0.5
for d = duration, 0.1 , -0.1 do
   for i,note in ipairs({ 9, 11 }) do
      playNote(sample, note, d)
      --playNote(sample2, note, d) -- same note at a lower octave
      wait()
   end
   for i,note in ipairs({ 7 }) do
      playNote(sample, note, d  )
      --playNote(sample2, note, d) -- same note at a lower octave
      wait()
   end
   for i,note in ipairs({ -5 }) do
      playNote(sample, note, d )
      --playNote(sample2, note, d) -- same note at a lower octave
      wait()
   end
   for i,note in ipairs({ 2 }) do
      playNote(sample, note, d * 3.5 )
      --playNote(sample2, note, d * 3.5 ) -- same note at a lower octave
      wait()
   end
   wait()
end
local d2 = 0.3

-- cleanup
proAudio.destroy()

Re: sound

Posted: 09.10.2009, 10:33
by Fenerit
My project aborted: too much files to play. :roll: Anyhow, this sound feature is really great: does someone knows links at more "cosmic sounds" files?

Re: sound

Posted: 09.10.2009, 13:16
by Chuft-Captain
Fenerit wrote:My project aborted: too much files to play. :roll: Anyhow, this sound feature is really great: does someone knows links at more "cosmic sounds" files?
Scripts in Celestia will crash if they haven't returned control to Celestia within 5 seconds. This can be an issue for example with loops if they are doing a lot of work and/or have many iterations.
Generally you can solve this with judicious use of wait() statements in your code.
This will periodically return control to Celestia, thus avoiding a crash.

Notice how I do a wait() in each iteration of the loops in the script above.
You don't necessarily have to use as many as I've used (one in the outer loop alone would probably do the job in this case, but it does no harm).
If you suspect any part of your code is using a lot of time, try adding a wait().

CC