Author Topic: Looped overlapping sounds on iphone  (Read 2164 times)

Offline aonyn

  • Mr. Polyvector
  • ***
  • Posts: 136
    • View Profile
Looped overlapping sounds on iphone
« on: 2010-Jul-21 »
Hi all,

I have a general question about sounds on iphone.
I have a project which uses looped sounds, which overlap each other for a smooth loop, with simple cross fading.
The duration of the samples are exactly 1000 ms, and I initiate repeats at 334 ms, so there are never more than 3 instances of a sound at one time.
I currently have the channels parameter set to 4, although based on this timing, I am sure I can also set it to 3.

This is working perfectly and as expected on PC, however the sounds are stuttering on iphone. It sounds as though iphone only handles 2 instances of a sound, rather than 3 or 4.
Is this indeed the case, and I need to adapt my method, or is it more likely something wrong with my code which the PC was handling more elegantly than iphone.

Thanks in advance for any feedback.

Regards,
Dave
For by grace are ye saved through faith, and that not of yourselves: it is the gift of God: Not of works, lest any man should boast. -Ephesians 2:8-9

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10851
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Looped overlapping sounds on iphone
« Reply #1 on: 2010-Jul-21 »
Hm. Might be something else. Try 2 saound slots for that. It might not work, though.

Offline aonyn

  • Mr. Polyvector
  • ***
  • Posts: 136
    • View Profile
Re: Looped overlapping sounds on iphone
« Reply #2 on: 2010-Jul-21 »
Thanks Gernot,

I will try limiting to 2 sound slots, alter my timing so there are never more than two instances of a sound, and see if it resolves the problem.
If that turns out to solve the problem, I will need to rework my sound samples to work well with the altered timing, which is a shame, because the effect was perfect on my PC, but I guess I will have to accept that as limits of the device I am targeting.

I will post back with my results.

Regards,
Dave
For by grace are ye saved through faith, and that not of yourselves: it is the gift of God: Not of works, lest any man should boast. -Ephesians 2:8-9

Offline aonyn

  • Mr. Polyvector
  • ***
  • Posts: 136
    • View Profile
Re: Looped overlapping sounds on iphone
« Reply #3 on: 2010-Jul-22 »
Hi Gernot,

I tried changing my sound instance timing, and reduced my sound slots loaded per sound to 2.
My samples are 1000ms long, and the instance loop is set to >500ms, so I am using no more than 2 instances of a sound at one time.
I still am getting the stuttering on iphone, and my new settings still work well on PC.
I am not certain, but it seems the sound slots are not working properly on iphone.
I am using a 3GS, with the latest update to OS4.

Regards,
Dave
For by grace are ye saved through faith, and that not of yourselves: it is the gift of God: Not of works, lest any man should boast. -Ephesians 2:8-9

Offline aonyn

  • Mr. Polyvector
  • ***
  • Posts: 136
    • View Profile
Re: Looped overlapping sounds on iphone
« Reply #4 on: 2010-Jul-22 »
Hi again Gernot,

I solved my problem, although the solution is not as elegant as I would like.
Instead of loading each sound once with 2 sound slots, I load each sound twice with a single sound slot.
I now just added a phase parameter to my type which holds the data for each sound object, and switch the phase back and forth to play the two loaded instances as an overlapping loop.

It now works as expected, including on iPhone, and as long as I don't encounter memory issues when the app is developed further, I guess it is a reasonable solution.
I do worry though that this method wastes memory unnecessarily though.

regards,
Dave
For by grace are ye saved through faith, and that not of yourselves: it is the gift of God: Not of works, lest any man should boast. -Ephesians 2:8-9