Any multi-channel audio tips?

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hatchfactory
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8
Joined: Sun Jan 15, 2012 6:55 am

Any multi-channel audio tips?

Post by hatchfactory » Tue Feb 05, 2013 8:50 am

I'm trying to take the leap from hobbyist to commercial developer and I'm nearing completion of code for a set of children's interactive e-book apps. I'm to the point of heavy stress testing on multiple devices. Where my app seems fairly stable (but not perfect when pushed) on a Nexus 7, Kindle Fire HD, HTC G2, Viewsonic Gtablet and a Huawei Fusion. Testing on a Samsung Galaxy SII however playing audio on a particular channel repeatedly consistently causes the app to lock up and crash, and on a Samsung Infuse app goes black and fails to launch.

The apps weak spots on all devices seem to be when 2 sounds seem to play on top of each other on the same track. For the last 16 hours I've been trying to find ways to make my audio code a little more android friendly, so I post here hoping that some of you more experienced livecoders could nudge me in the right direction.

The first app uses some 120 .mp3 sounds throughout, so I made a function for simplicitys sake. Sometimes sounds are played mid- animation loops etc. but nothing seems intensive or too tight for messages. Is a function the best way to accomplish this? My other thought after reading various threads was to add a little breathing room between sounds played for os/livecode communication hence the "wait for 0 millisecs with messages". Any thoughts for increased stability?

In a button:

Code: Select all

 do playSound(dolphin)

 do playSound(ocean, channel3, looping)

--> ? or should it be ?

return playSound(ocean, channel3, looping)
In the stack script:

Code: Select all

function playSound whatSound, whatChannel, whatType
   if whatChannel is empty then
      put "channel1" into whatChannel
   end if
   if whatType is empty then
      if mobileSoundChannelStatus(whatChannel) is "playing" then
         mobileStopPlayingOnChannel whatChannel
         wait 0 millisecs with messages
      end if
          put "now" into whatType
   end if
    if the environment is not "mobile" then
      put  "audio/"&whatsound&".wav" into tSndpath
      if whattype is "looping" then
         play tSndPath looping
      else
         play tSndPath
      end if
   else
      put specialFolderPath("engine")&"/maudio/"&whatsound&".mp3" into tSndpath
      mobilePlaySoundOnChannel tSndpath, whatChannel, whatType
   end if
   return empty
end playsound

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

Re: Any multi-channel audio tips?

Post by Klaus » Tue Feb 05, 2013 1:12 pm

Hi hatchfactory,

1. welcome to the forum! :D

2. You created a function, so you need to write:
...
put playSound("ocean", "channel3", "looping") into tValueReturnedFromTheFunction
## "ocean", "channel3" and "looping" are in fact and need to be treated as STRINGS, so we need to QUOTE them.
...

But you better use a command here like this and a WAIT should not be neccessary:
Try this:

Code: Select all

command playSound whatSound, whatChannel, whatType
  
  ##!!!
  if the environment is not "mobile" then
    put  "audio/"& whatsound &".wav" into tSndpath
    if whattype is "looping" then
      play tSndPath looping
    else
      play tSndPath
    end if
    
    ## Everything else only works on MOBILE, so we simply get out of here NOW!
    ## This avoids unneccesary long an nested IF... TEHN... clauses and makes 
    ## the code better readable!
    exit playSound
  end if
  
  if whatChannel = empty then
    put "channel1" into whatChannel
  end if
  if whatType = empty then
    if mobileSoundChannelStatus(whatChannel) is "playing" then
      mobileStopPlayingOnChannel whatChannel
    end if
    put "now" into whatType
  end if
   
  put specialFolderPath("engine")&"/maudio/"&whatsound&".mp3" into tSndpath
  mobilePlaySoundOnChannel tSndpath, whatChannel, whatType
end playsound
You should check and work through these stack to get the basics of Livecode (very important!):
http://www.runrev.com/developers/lesson ... nferences/

Hint:
The only documantation for the mobile platform are the "Android/iOS Release Note"
This is a PDF that you can access in Livecode: Menu: Help!


Best

Klaus

hatchfactory
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8
Joined: Sun Jan 15, 2012 6:55 am

Re: Any multi-channel audio tips?

Post by hatchfactory » Tue Feb 05, 2013 7:32 pm

Thanks for the welcome and help Klaus :D , good points you bring up. I will change things and report. I will study the scripting conference links, the release notes, to me, are already an invaluable resource.

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

Re: Any multi-channel audio tips?

Post by Klaus » Tue Feb 05, 2013 7:52 pm

Okie Dokie :D

hatchfactory
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8
Joined: Sun Jan 15, 2012 6:55 am

Re: Any multi-channel audio tips?

Post by hatchfactory » Tue Feb 05, 2013 8:16 pm

in changing

Code: Select all

function playSound whatSound, whatChannel, whatType 
to

Code: Select all

command playSound whatSound, whatChannel, whatType 
it seems whatChannel and whatType are ignored, sounds with "looping" no longer play

inserting for diagnotics :

Code: Select all

put whatChannel&&whatType into msg box 
currently yields nothing

should I be making whatChannel and whatType global variables?

I guess I need to read more on the difference between functions and commands...

edit: got it working after reading up some of those scripting conference docs.

I changed the calls from:

Code: Select all

playsound (Gullscry, channel2, now)
to:

Code: Select all

playsound "Gullscry", "channel2", "now"
now with quotes instead of parenthesis for commands.

now on to mobile testing...

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

Re: Any multi-channel audio tips?

Post by Klaus » Tue Feb 05, 2013 10:40 pm

Hi hatchfactory,
hatchfactory wrote:...
should I be making whatChannel and whatType global variables?
No, these are just "parameters" so not neccessary!
hatchfactory wrote:I changed the calls from:

Code: Select all

playsound (Gullscry, channel2, now)
Yep, that's FUNCTION syntax!
hatchfactory wrote:

Code: Select all

playsound "Gullscry", "channel2", "now"
Correct!
hatchfactory wrote:

Code: Select all

playsound "Gullscry", "channel2", "now"
now with quotes instead of parenthesis for commands
Not that I mentioned this in my first answer... 8)

Hint: QUOTES are not a replacement for PARENS here!
You are passing STRINGS, so QUOTES are a MUST!


Best

Klaus

hatchfactory
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8
Joined: Sun Jan 15, 2012 6:55 am

Re: Any multi-channel audio tips?

Post by hatchfactory » Wed Feb 06, 2013 12:08 am

Not that I mentioned this in my first answer...

Hint: QUOTES are not a replacement for PARENS here!
You are passing STRINGS, so QUOTES are a MUST!
Yes, you did, and that was the hint I needed to get it fixed :oops:

End results:
Klaus, I made all the changes you suggested and fixed some 120 calls. which has greatly increased the stability of the app on almost all of the devices. No crashes except the Samsung SII, on which the app was highly unstable, will still crash the app but only %10 as much as it used to on stress testing.
All in all I am very happy with the results, Thank you for your much needed Help. :D I would offer to bake you some cookies. The app seems now publish-able.

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

Re: Any multi-channel audio tips?

Post by Klaus » Wed Feb 06, 2013 1:31 pm

My pleasure! :D
Good luck with your app!

Post Reply