Sound patch

The place to discuss creating, porting and modifying Celestia's source code.
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Post #41by Vincent » 13.05.2006, 19:12

Ok, It's done. :)

I've added a nopause parameter (exactly the same idea as you, CC :wink: ) which can take the values :
0 -> nopause is off : the sound is paused if the spacebar is pressed.
1 -> nopause is on : the sound is not paused if the spacebar is pressed.
If the nopause parameter is not precised in the play function, the default value is 0.

Here's a .cel script example :

Code: Select all

{
play { channel 1 volume 1 loop 1 filename "music.wav" nopause 1 }
wait { duration 1 }

play { channel 2 volume 1 loop 1 filename "comment.wav" }
wait { duration 50 }
}


And Here's the same script in .celx format :

Code: Select all

celestia:play(1, 1, 1, "music.wav", 1)
wait(1)
celestia:play(2, 1, 1, "comment.wav")
wait(50)


I had to change several files to add this fifth parameter to the playSoundFile function. I won't post all the changes here since you can download the updated celestia_1.4.1_patch2.zip file with new modified source files...

I also noticed a little issue that doesn't come from my code : a looping file which is paused during its second loop doesn't resume playing. That's strange because during the 1st, 3rd, 4th, etc... loops, the pause/resume functions work perfectly. 8O
That may come from the AL_PAUSED state definition in the openAL code. I will post a message for this issue on the OpenAL dev forum...
Last edited by Vincent on 15.05.2006, 17:01, edited 1 time in total.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 9 months

Post #42by Chuft-Captain » 13.05.2006, 20:10

Vincent wrote:Ok, It's done. :)

Here's the new .exe test file : http://vincent.gian.club.fr/celestia/ce ... atch22.zip

I've added a nopause parameter (exactly the same idea as you, CC :wink: ) which can take the values :
0 -> nopause is off : the sound is paused if the spacebar is pressed.
1 -> nopause is on : the sound is not paused if the spacebar is pressed.
If the nopause parameter is not precised in the play function, the default value is 0.

Awesome Vincent!!

Just a minor point about programming style. When I named this parameter "nopause", I was thinking in C++ terms, where nopause would be a boolean constant and would only be used to disable pause.

However, from your implementation, I assume that the Celestia script languages do not allow use of booleans like this, and therefore the use of "nopause" as a variable name produces an ambiguity (like a double negative) as it creates confusion as to whether pausing is on or off... (or maybe it's just me who finds this confusing :oops:)
Sorry, it's my fault for thinking in terms of booleans rather than script variables. :oops:

eg.
nopause = 1 -> nopause is on : the sound is not paused if the spacebar is pressed
nopause = 0 -> nopause is off : the sound is paused if the spacebar is pressed (default)

This is generally not good programming practice. Given this, (just to make scripts easier to understand) I would recommend reversing the meaning by renaming the variable to "pause" (and the default value would be 1)

eg.
pause = 1 -> pause is on : the sound is paused if the spacebar is pressed (default)
pause = 0 -> pause is off : the sound is not paused if the spacebar is pressed
(this is unambiguous)

So the only use of it in scripts would probably be to disable pausing (pause = 0)

Sorry, I'm being very pedantic, but thought best to mention to you now, before too many scripts written with this syntax.

Do you agree?
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Post #43by Vincent » 13.05.2006, 20:45

CC,

That's interesting because, I first added a 'pause' parameter, as you suggested, since it seemed to be more simple and logical...

But then, I decided to change because the main purpose of this parameter is to avoid to pause the sound. So I find it more natural to ask script writters to activate a nopause function when needed (with 'nopause 1'). I know a double negation is useless in general, but I think it is rather pertinent here...

So, the code is now...

Code: Select all

    if (nopause == 1)
        pause[channel] = FALSE;
    else
        pause[channel] = TRUE;

...that is to say, exactly the contrary of what you suggested... :wink:

Of course, I can easily get back to the previous code with a 'pause' function, but I'd like to know other script writters' opinion before... Would you prefer to add 'nopause 1' or 'pause 0' to unactivate the pause function of a soundtrack ?
Last edited by Vincent on 13.05.2006, 22:23, edited 2 times in total.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
selden
Developer
Posts: 10190
Joined: 04.09.2002
With us: 22 years
Location: NY, USA

Post #44by selden » 13.05.2006, 21:02

why not call it "deactivate_pause" to avoid the confusion.
Selden

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 9 months

Post #45by Chuft-Captain » 13.05.2006, 21:21

... I'm OK with either approach Vincent. I was just pointing out that some people might find it ambiguous.

In fact, I think your "nopause 1" is probably more consistent with the way other on/off switches are set in the scripts. ie. loop 1

Let's see what other people think.

:lol:
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Post #46by Vincent » 15.05.2006, 16:37

selden wrote:why not call it "deactivate_pause" to avoid the confusion.
Well, that would be much more explicit, but a little bit too long to write. Script commands have to be short.

Chuft-Captain wrote:In fact, I think your "nopause 1" is probably more consistent with the way other on/off switches are set in the scripts. ie. loop 1
You're right. I've been influenced by the "loop 1" command and its on/off switch system.

Chuft-Captain wrote:Let's see what other people think.
Well, no other opinion so far, so let's go with the 'nopause 0/1' command... Thanks CC for this great idea and for all your precious help. :D

I've updated the celestia_1.4.1_(win32_)_patch2.zip file [ http://celestiaproject.net/forum/viewtopic.php?t=9503 ]. I've also added some examples of scripts using the 'nopause' command. You'll find at the beginning of each script a summary of the different arguments and the values they can take...
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

mmieczkowski
Posts: 6
Joined: 14.05.2006
With us: 18 years 4 months

Re: Sound patch

Post #47by mmieczkowski » 15.05.2006, 23:00

hi Victor,
I downloaded your patch, however it was corrupted. I get an unexpected EOF, Can you check it?(if you open the file that comes down you can see that it ends abruptly.

erasmo
Posts: 10
Joined: 15.11.2005
With us: 18 years 10 months
Location: Xalapa Veracruz Mexico

Post #48by erasmo » 25.05.2006, 23:19

Hello Victor


I am work with you sound patch, but even i can't do wich work, i have a suse 10.0, but no compile.

at the moment of compile, send a message wich don't can initialize the alut libraries.


how i can do wich this function work.

erasmo
I have the inetrest of generate something o educational material, otherwise I too have the nececities of be at constant actualization of the knowledge about the space.

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 3 months
Location: Rome, ITALY

Post #49by ANDREA » 04.09.2006, 22:45

Hello Vincent (and Victor, obviously!).
I'm using Vincent's patch including Victor's sound addition to Celestia, that's absolutely wonderful.
I appreciate the way to pause/not pause the various wav files, but I just now found a little problem, that probably is a bit difficult to solve.
Writing a new show, I went tired to cut at given time length each sound .wav file, because the times in the .cel script were changing continuosly, due to the many changes I was producing.
So I used the system you show to reduce the volume, but I found that this way the sound decrease has a "steps" behaviour.
Could it be possible to add in the code a "fade X.X time X.X" instruction, that will fade the sound at the given volume in the given time?
E.g.:

play { channel 1 volume 0.8 loop 1 filename "albinoni.wav" nopause 1 }
play { channel 1 fade 0.0- time 6.0 filename "albinoni.wav" nopause 1 }

Sorry for my request, but the actual solution IMHO is not good enough.
Thanks a lot.
Bye

Andrea
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 9 months

Post #50by Chuft-Captain » 05.09.2006, 00:35

Andrea,

Have you tried using many smaller steps with correspondingly smaller time increment/decrement?
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 3 months
Location: Rome, ITALY

Post #51by ANDREA » 05.09.2006, 00:55

Chuft-Captain wrote:Andrea, Have you tried using many smaller steps with correspondingly smaller time increment/decrement?

Yes, as I told I used this system, but it needs truly MANY steps in order to obtain a decent result.
If you have a 0.5 volume, and decrease it with 0.1 steps, the result is ugly. :cry:
Things go better if I use a 0.01 volume decrease steps (!), but this means the need to put in the script 50 lines for EVERY sound I need to fade. 8O
My doubt is if this could be possible with a single line in .cel scripts, instead of so many, as actually is.
Obviously my request may be valid only if Vincent or Victor think that this can be achieved with just a little effort, otherwise I'll go on with mini-steps :wink: .
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 9 months

Post #52by Chuft-Captain » 05.09.2006, 01:09

ANDREA wrote:
Chuft-Captain wrote:Andrea, Have you tried using many smaller steps with correspondingly smaller time increment/decrement?
Yes, as I told I used this system, but it needs truly MANY steps in order to obtain a decent result.
If you have a 0.5 volume, and decrease it with 0.1 steps, the result is ugly. :cry:
Things go better if I use a 0.01 volume decrease steps (!), but this means the need to put in the script 50 lines for EVERY sound I need to fade. 8O
My doubt is if this could be possible with a single line in .cel scripts, instead of so many, as actually is.
Obviously my request may be valid only if Vincent or Victor think that this can be achieved with just a little effort, otherwise I'll go on with mini-steps :wink: .
Bye

Andrea :D


I think the fade suggestion is a good one, fade-in, fade-out, and cross-fade would be good. (although all could be achieved with the right timing of the one command) :lol:

I just suggested the many steps (which you're already using) as a work-around for the meantime.
If you have many steps to generate, how are your spreadsheet skills? I suggest using EXCEL to generate the script entries and then cut and paste the result into the script.
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 3 months
Location: Rome, ITALY

Post #53by ANDREA » 05.09.2006, 07:20

Chuft-Captain wrote: I think the fade suggestion is a good one, fade-in, fade-out, and cross-fade would be good. (although all could be achieved with the right timing of the one command) :lol:
I just suggested the many steps (which you're already using) as a work-around for the meantime.
If you have many steps to generate, how are your spreadsheet skills? I suggest using EXCEL to generate the script entries and then cut and paste the result into the script.

This is a good suggestion, Chuff-Captain, I'm used with Excel, so I will apply it. :wink:
Thank you.
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 9 months

Post #54by Chuft-Captain » 05.09.2006, 14:04

CONCATENATE is a very useful command. :wink: :lol:
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Post #55by Vincent » 05.09.2006, 16:12

Andrea, Chuft-Captain,

Of course, I had already thought about adding the fade in/out functions to the sound patch code. However, even if that would be quite easy, I didn't go further on this because I realized I simply could do it using .celx scripts...
Here are 2 short examples (copy/paste and save as fade_test1.celx, fade_test2.celx). Note that the second script, which is a tiny bit more complicated, allows to fade the sound in/out very easily with a simple line : fade_in (duration) or fade_out (duration)

- first script :

Code: Select all

-- Initialize channel 0
celestia:play ( 0, 0 ,1 ,"music.wav", 1 )
wait (2)

-- Fade the sound in on channel 0
for i = 0, 1, 0.005 do
   celestia:play ( 0, i )
   wait (0.05)
end

-- Play the sound on channel 0
celestia:play ( 0, 1 )
wait (5)

-- Fade the sound out on channel 0
for i = 1, 0, -0.005 do
   celestia:play ( 0, i )
   wait (0.05)
end

-- Stop playing sounds on channel 0
celestia:play ( 0, -1, 0, "" )



- Second script :

Code: Select all

-- Fade in function
function fade_in(duration)
   step = 0.05 / duration
   for i = 0, 1, step do
      celestia:play ( 0, i )
      wait (0.05)
   end
end

 -- Fade out function
function fade_out(duration)
   step = 0.05 / duration
   for i = 1, 0, -step do
      celestia:play ( 0, i )
      wait (0.05)
   end
end

-- Initialize channel 0
celestia:play ( 0, 0 ,1 ,"music.wav", 1 )
wait (2)

-- Fade the sound in during 5 seconds ( = duration )
fade_in (5)

-- Play the sound on channel 0
celestia:play ( 0, 1 )
wait (5)

-- Fade the sound out during 10 seconds ( = duration )
fade_out (10)

-- Stop playing sounds on channel 0.
celestia:play ( 0, -1, 0, "" )


We can also imagine more complex fade in/out functions adding start/end volumes as arguments...

Finally, if using .celx script represents a problem for you, you can just include your .cel script lines inside the .celx script body :

Code: Select all

function CEL(source)
   local script = celestia:createcelscript(source)
   while script:tick() do
      wait(0)
   end
end

CEL([[
{

# Paste here your .cel script lines

}
]])


I Hope this will solve your problem.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 7 months
Location: Seattle, WA USA

Post #56by hank » 05.09.2006, 16:18

ANDREA wrote:
Chuft-Captain wrote:Andrea, Have you tried using many smaller steps with correspondingly smaller time increment/decrement?
Yes, as I told I used this system, but it needs truly MANY steps in order to obtain a decent result.
If you have a 0.5 volume, and decrease it with 0.1 steps, the result is ugly. :cry:
Things go better if I use a 0.01 volume decrease steps (!), but this means the need to put in the script 50 lines for EVERY sound I need to fade. 8O
My doubt is if this could be possible with a single line in .cel scripts, instead of so many, as actually is.
Obviously my request may be valid only if Vincent or Victor think that this can be achieved with just a little effort, otherwise I'll go on with mini-steps :wink: .
Bye

Andrea :D

With CELX, you could use a loop to decrement the sound volume, and a function definition to reuse the code (invoking it with a single line each time you need to fade).

- Hank

EDIT: I see that Vincent was a step ahead of me in pointing this out. And he even went so far as to thoughtfully provide the actual code! But my intended point was really the general one that CELX is very powerful, and anyone with a serious interest in scripting Celestia should invest the time to learn it.
Last edited by hank on 05.09.2006, 16:32, edited 1 time in total.

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 3 months
Location: Rome, ITALY

Post #57by ANDREA » 05.09.2006, 16:24

hank wrote: With CELX, you could use a loop to decrement the sound volume, and a function definition to reuse the code (invoking it with a single line each time you need to fade).- Hank

Thank you hank, but I don't use celx, only .cel files. :oops:
Anyhow using Excel it's easy to obtain the commands sequence automatically, so it's OK, thank you anyhow. :wink:
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 8 months
Location: Nancy, France

Post #58by Vincent » 05.09.2006, 16:26

Andrea, (Hank),

Please have a look at my post above...
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 7 months
Location: Seattle, WA USA

Post #59by hank » 05.09.2006, 16:45

ANDREA wrote:Thank you hank, but I don't use celx, only .cel files.

Yes, I thought so. My purpose was to encourage you to consider using it. You would probably find it useful in many other ways.

Another advantage of CELX is that, once loadlib is enabled, the sound patch could be implemented with a Lua add-on, and would not require a patched version of the Celestia code.

- Hank

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 3 months
Location: Rome, ITALY

Post #60by ANDREA » 05.09.2006, 17:23

hank wrote:
ANDREA wrote:Thank you hank, but I don't use celx, only .cel files.
Yes, I thought so. My purpose was to encourage you to consider using it. You would probably find it useful in many other ways. Another advantage of CELX is that, once loadlib is enabled, the sound patch could be implemented with a Lua add-on, and would not require a patched version of the Celestia code.- Hank

I know, Hank, and I tried more than once to approach the celx functions.
I've only been able to appreciate the very smooth movements, and some other things, but I have one problem with it: its philosophy is way different from mine, while cel's is very close to.
I mean that IMHO cel is more user friendly, doesn't need deep understanding of the why and the how it works, its commands are very easy to remember.
Moreover, while the cel manual is, IMHO, very clear and simple, I had a lot of problems to read and understand the celx one.
So, please, don't blame me if (I'm 62, BTW) I prefer to use what I understand and use daily.
Lazyness?
I don't think so.
In the last three years, using Celestia and following its Forum, I learned a lot of things (Selden, do you remember how many stupid questions from me?), and moreover I applied most of them, learned to work textures, to create new ones, and to write (cel) shows that are a truly success, so I don't believe I'm lazy.
Perhaps only a bit tired to be obliged or compelled to learn more and more new things, and even more if they can be substituted with other ones, with only minor losses.
Friends, nevertheless? :wink:
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO


Return to “Development”