Audio + Animation problem

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Audio + Animation problem

Post by sritcp » Sun Dec 13, 2015 8:45 pm

I have a somewhat inconsistent problem I hope someone can help with.

In my program, when the user (typically a toddler) touches/clicks the screen, a random sound is chosen; within the sound a random variation is chosen. Then, this sound is played along with the appropriate animation (an image moving along a path).

Here's the relevant part of the code:

Code: Select all

   set the filename of player "Player1" to gAudioFolder & "/aahuh11KMono.aiff"
   put (the duration of player "Player1" / the timeScale of player "Player1") into tDuration
   start player "Player1"
   move image pImage to the points of graphic "LevelLine" in tDuration seconds 
1. When I run it, there is no sound, but the animation works.
(When I trapped the "playStarted" message sent to the Player, I see that the player has started to play. But the "playStopped" message never gets sent.)

2. If I set a breakpoint at "start Player ..." and step through it, the sound plays and the animation works.
(Both "playStarted" and "playStopped" messages get sent)

3. If I comment out the animation, the sound plays.

4. If I isolate the above code and put in a new stack it works; it doesn't work in the context of my program (but there are no logic issues; stepping through works, as I have mentioned)

Could it be something other than the program? Like my 6-year old MacBookPro17"?
I use LC 6.7.6

Thank you for any help,
Sri

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Audio + Animation problem

Post by Klaus » Sun Dec 13, 2015 9:52 pm

Hi Sri,

please spread the word: ALWAYS use parens when concatenating strings for use as object names, filepath names, URLs etc...
I'm sure now you know what the problem is in your script :D


Best

Klaus

P.S.
I knew we have been there before:
http://forums.livecode.com/viewtopic.ph ... ing#p70072
8)

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Audio + Animation problem

Post by sritcp » Mon Dec 14, 2015 12:57 am

Klaus:

Thanks for the reminder! You have a terrific memory! :D

I should have mentioned the gAudioFolder is a global variable containing the string
(the defaultFolder) & "/Audio"

And, pImage is a parameter of a handler and the name of the imported image is passed to the handler.

Also, the program works when I step through.

Regards,
Sri

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Audio + Animation problem

Post by dunbarx » Mon Dec 14, 2015 1:16 am

Sri.

Did you say the thing works when you step through? Does that mean it does not when you simply run it?

I have seen this as well, now and then, going back to HC. Somehow it all works out, though I am not sure why.

Craig

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Audio + Animation problem

Post by Simon » Mon Dec 14, 2015 1:52 am

Hi Sri,
Generally if it works when you step through but not when you run it, adding a short "wait with messages" fixes the problem.
It's something about letting the engine catch up.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Audio + Animation problem

Post by dunbarx » Mon Dec 14, 2015 3:39 am

Simon.
adding a short "wait with messages" fixes the problem.
For sure. But HC did not have such a (really wonderful) tool.

But is it possible that system timing, supporting other processes which change from instant to instant, allow some runs to finish and not others? But then why would they seem to "get better"? They always eventually do.

Craig

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Audio + Animation problem

Post by Klaus » Mon Dec 14, 2015 12:19 pm

Hi Sri,
sritcp wrote:Klaus:

Thanks for the reminder! You have a terrific memory! :D
Yes, I know, but that can also be a curse sometimes 8)
sritcp wrote:...I should have mentioned the gAudioFolder is a global variable containing the string
(the defaultFolder) & "/Audio"
Whatever, it should read:
...
set the filename of player "Player1" to (gAudioFolder & "/aahuh11KMono.aiff")
...

Try what Simon suggested, add a little "wait X with messages", that really helps sometimes!


Best

Klaus

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Audio + Animation problem

Post by sritcp » Tue Dec 15, 2015 4:33 am

Thank you Simon, Craig, and Klaus!

After much hair pulling, I have identified the point at which it is breaking down!

Although putting a breakpoint at
start player "Player1"
and stepping through it plays the sound (running it doesn't; see my original post),
that was not the problem line in the code. (Placing a 'wait with messages' statement after it didn't make any difference).

The bottleneck was
set the filename of player "Player1" to (gAudioFolder & "/aahuh11KMono.aiff")

If I set the filename of the player beforehand (in the inspector), it works without any problem.

So, I placed a
wait for 50 milliseconds with messages
after the "set the filename" statement.
That worked, too, but a shorter time (10 milliseconds) was too short (the player started, but there was a lag).

In conclusion, it seems to me that setting the filename of a player is time-intensive, and can trip a program up.
May be it is easier to have 50 different players that are pre-set with their filenames rather than setting the filename on the fly.

Thanks to everyone for your help,
Sri

Post Reply