Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / LoadSound() & PlaySound

Author
Message
polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 4th Jun 2012 22:42
I use the following code :



yet, I get no sound at all. The mp3's are in the correct folder and named as above. Volume is turned up, and agk:layMusic() works fine.
I have also tried the sound files as .ogg too..

Blackberry App Development & ZX Spectrum Game Development.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jun 2012 23:05
You can't do LoadSound with an mp3 file. It only works with wav files.

At least that is what I discovered and have seen elsewhere in this forum.

You use LoadMusic and PlayMusic with mp3 files.

Cheers,
Ancient Lady
polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 4th Jun 2012 23:12
Ahh, thanks Lady, I never knew that.. Wish the documentation was more thorough, it would have saved me an hour of messing about converting files etc...

Blackberry App Development & ZX Spectrum Game Development.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 4th Jun 2012 23:14
You can only play 1 mp3 at a time.

You can play multiple Sounds at a time, but they can be only WAV.

WAV format is really HUGE filesize when compare with MP3, making the AppGameKit sound system not very effective for real life games.
polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 5th Jun 2012 10:35 Edited at: 5th Jun 2012 10:35
Aye, a simple shoot sound I am using at the moment goes from 23k mp3 to 180k wav,

I am still trimming the sound though, so that should reduce a little.

Blackberry App Development & ZX Spectrum Game Development.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jun 2012 11:39 Edited at: 5th Jun 2012 14:21
This is a platform limitation as much as an AppGameKit problem. iOS will only support ONE streaming format (like MP3) at a time. This is because the de-compressor uses a lot of CPU.

Consequently, for sound effects you must use uncompressed linear PCM files, like WAV. Many Android devices will NOT play mono files. So the smallest file you can use will be 8-bit, 8000 samples/second.

The iOS technical spec does not mention 8-bit, but it may well play. Don't have a device to test on.

I downloaded a 220K gunshot wav file. It's in 16-bit stereo at 44100 samples/ sec. Using Audacity I down-sampled to 8-bit stereo at 8000 samples/sec. It is now 20K in length. I've attached it here, and it would be good if a few people could test for playback on Android and iOS, so that we can establish a standard and give clear guidance in the documentation.

If the 8-bit will not play, the 16-bit file would be 40K, which is not a lot.

-- Jim

Attachments

Login to view attachments
polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 5th Jun 2012 12:15 Edited at: 5th Jun 2012 12:16
I don't have any iOS or Android devices but I tested that .wav on BlackBerry Playbook and it works fine,

Blackberry App Development & ZX Spectrum Game Development.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jun 2012 13:24
I'm having similar issues with format choice. I had a few seconds outro to my game and it was 500K in size as a wav file. Reduced to Mono, and 11KHz it lost too much quality.

I tried it as MP3, and I've found that you need to anticipate a small delay as it loads, just a few hundred milliseconds, but it's noticeable.

If we can come up with a good guide to using Sound/Music, with guides on quality and when to switch, I can create a tutorial article on the news site. In fact, if anyone wants to lead it then I am happy to publish your article on the site.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jun 2012 13:51 Edited at: 5th Jun 2012 13:52
I don't have a range of test devices, but audio has been my speciality right back to the Amiga days. Be happy to help, and maybe make some optimisation tools.

Tip: don't use mono, even on PCs, because you will not get 100% volume on left and right - you will get 50% on each. As a result, it will sound a bit quiet, so you are tempted to amplify the waveform, and introduce peak distortion. It's very important that your original waveform has a good amplitude - maybe 90% peak - because if it's relatively low-level, reducing the sample rate will make it noisier and less satisfying. Apply any effects like normalisation or compression to the highest-precision format before down-sampling. Etc.

It needs a bit of team effort and contributions like polomint's so that we can create a grid.

BatVink - if you upload your audio I'll have a look at it!

-- Jim
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jun 2012 14:36
Additional note: MP3/Ogg will always be slower to start because the compressed files are very complex to decode, and every audio buffer requires two or more stages: (1) read compressed segment; (2) decompress into playback buffer in suitable linear PCM format; (3) hand buffer to audio subsystem to play.

Stage (1) can use an awful lot of CPU cycles. Apart from the fact that a lot of systems don't support multiple simultaneous compressed files, you probably want your gunshot to sound as soon after the gun is fired as possible. Meanwhile the probably sad little CPU in your phone is trying to manage all your sprites etc. So give it a chance by reducing its workload!

-- Jim
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Jun 2012 16:59
I have been using 8bit mono wav files (8000-44100Hz, 64-352kps) and they work fairly well on all my devices (Windows, Mac, iPod Touch, iPad2, Vizio Honeycomb based Android table).

I have pretty bad ears, but they sound good to me.

I also go with fairly short sounds and haven't loaded anything longer than a little over 3 seconds.

I don't plan to have music in my game. This is based on a personal preference. The first thing I do in any game I play is turn off the music, if the option exists. Although I might reconsider if I come across just the right thing to go with the theme of the game and definitely have the option to not play it.

Cheers,
Ancient Lady
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 5th Jun 2012 17:05 Edited at: 5th Jun 2012 17:08
I solved all my sound problems by using FMOD in T2. Works perfectly on iOS and Windows and I can play AS MANY steaming MP3s as I want, and loop SEAMLESSLY, and my game still plays at 60fps on the iphone 3gs. However there is no FMOD on Playbook, and hence my interest in AppGameKit playsound/music.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jun 2012 21:54
FMOD is very expensive unless you are giving away your software for nothing. The site quotes a minimum of $500 per platform (Windows, iOS etc) for a low-budget game, and states that you must purchase a licence BEFORE you release your game.

Most indie developers will not really want to go down that route, so defining what will work on all platforms for nothing is surely a good way forward?

-- Jim
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Jun 2012 21:56
@Ancient and Wonderful Lady - as I noted earlier, according to my research not all Android devices will play mono. Just a cautionary note!

-- Jim
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Jun 2012 22:40
I'll have to be aware of that. I'll see if I can get my wav files redone in stereo, just in case.

Cheers,
Ancient Lady
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 5th Jun 2012 23:21 Edited at: 5th Jun 2012 23:22
Jim Hawkins, my project is free with no ads, so i don't have any license complications.

Fmod was the only option for seamless playback. As far as I know AppGameKit will never have the option to totally play back seamlessly.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Jun 2012 15:39
What is the precise need for seamless looping unless you're writing a music app? If it's for background music, then compose the track so that you have a hiatus at the end built in. I can't imagine that Fmod will give you microsecond perfect loop timing on all platforms and all hardware.

-- Jim
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 6th Jun 2012 18:04
On Windows and iOS Fmod has perfect loop timing without any gaps. The music was written that way, so it's not possible to redo all the soundtracks. I see others also asking for seamless playback, so I think it's a common request. In the future I will definitely start asking for music to be built with a break at the end so that gaps won't be noticed.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 7th Jun 2012 08:45
Looks like mono audio is okay on modern Android devices after all.

There's an up-to-date table of supported media here:
http://developer.android.com/guide/appendix/media-formats.html

-- Jim
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 7th Jun 2012 17:25
Cool. That means we can use smaller files. Much better.

Cheers,
Ancient Lady
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jun 2012 18:40
Just to be wary, WAV mentions 8-bit, but it doesn't mention Mono. Other formats (MP3, FLAC, AAC) explicitly state that Mono is acceptable.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 7th Jun 2012 19:41
I now think that some of this originated from people deaf in one ear complaining that Android devices do not permit you to select mono output from stereo files. Given that VOIP is almost certainly mono, I think we can reasonably assume that mono will be fine. Eventually all codecs will have to decode to linear PCM for playback on the hardware.

-- Jim
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 10th Jun 2012 01:25 Edited at: 10th Jun 2012 01:47
I've done some experimentation, and I do agree that looping on music files creates a significant gap. Generally, though, this is not an unreasonable limitation.

But how about infinitely long level tracks? I've attached a zip with an absolutely minimal Pascal program to stitch sound-blocks together in a random order. The source Pascal file has been renamed to uMain.txt as opposed to uMain.pas for ease of reading. When I say minimal, I mean it!

This simple program loads some blocks in memory and then plays them. For big tracks this could use a lot precious memory, so the next experiment will be with double or tripled-buffered dynamic loading.

The sample blocks have been down-sampled from 44100 16-bit to 8000 8-bit, but they sound okay on my big Mission speakers. They are stereo, but actually, like a lot of loops are really mono, so they could use half the memory.

I downloaded these loops and they are not for distribution. They are not perfect in terms of cross-over. Ideally loops should start and end at a zero-crossing point in the waveform, but there are some slight pops - probably as a result of re-sampling.

Notes for non-Pascal people:

The interface section is available to all units which import it. It contains only definitions.

The implementation section contains the actual code.

The TAGKScene class is beautiful (thanks, Erik!) because it handles levels in a seamless way. When you switch scenes (assuming you have more than one) unless you tell it not to do it, all objects will be destroyed without you having to worry about it.

This program compiles in Delphi and Free Pascal, and should work on Windows, OS X and iOS.

If you want the project source, post here and I'll upload it.

-- Jim

Attachments

Login to view attachments
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 10th Jun 2012 01:37
I should have said that to keep the things as small as possible there are no validity checks or try..except statements. These should be there in real code!!!!!

-- Jim
anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 22nd Jun 2012 01:07
So AppGameKit can play multiple sounds, as long as they're in WAV format?...

Music: MP3, one track only
FX: WAV, as many as I want playing at once as long as they're WAV

Anyone test this out on iOS? I know my Water game cuts out sound effects, but that's from 1065, not an updated version of AGK...

Hi there. My name is Dug. I have just met you, and I love you.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 22nd Jun 2012 10:26
I think the limit is 32 - but I may be wrong.

-- Jim
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 23rd Jun 2012 16:07
Quote: "Music: MP3, one track only"


Correct, iOS and Android have a one hardware MP3 decode at a time, so AppGameKit adopts this limit as well.

Quote: "FX: WAV, as many as I want playing at once as long as they're WAV"


AGK does not impose a limit on playing WAV files, but the current platform may have a limit which if reached may either ignore new requests to play a sound until one has finished, or prematurely end an old sound to play a new one. I've never tested the limits here.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 23rd Jun 2012 19:57
I actually tried playing two wav files at the same time, and it only played the second one. If I waited a few syncs between, then they played together.

Cheers,
Ancient Lady
fallen one
18
Years of Service
User Offline
Joined: 7th Aug 2006
Location: My imagination!
Posted: 24th Jun 2012 20:00
Can you play a wav and mp3 at the same time?
Does having wavs at different compresion/bit rate make problems, like if they are played at the same time?


JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 24th Jun 2012 20:33
Yes - MP3 on Music track. Wavs can be any sample-rate.

-- Jim
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 24th Jun 2012 22:06
yes you can play an mp3 and multiple wavs together, works on windows and ios as far as i tested

Login to post a reply

Server time is: 2024-11-23 16:54:25
Your offset time is: 2024-11-23 16:54:25