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 / Does AGK support looping audio?

Author
Message
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 15th Jul 2013 22:52 Edited at: 15th Jul 2013 22:56
I know I have asked similar questions here, but all I really want to know is the following:

Does AppGameKit support looping of audio files (wav/mp3) and playing more than one audio file at a time?

Is there a synchronized clock that I can use to make sure audio files play at the same time?

If so, can someone kindly point me in the direction of possible code samples in BASIC to help me try a simple test playing anywhere from 2 to 8 small audio files and having them loop forever (or until stopped) in sync with each other?

Thanks.

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 15th Jul 2013 23:17
You can play and loop multiple Sound things (using wav files).

But you can only play and loop one Music (mp3 for everything but Meego, which uses ogg). You can load many files (LoadMusic). But you can only play one at a time, PlayMusic (with loop option).

The best clock you have (in Tier 1) is GetTimer() which will return how long the app has been running.

Looping multiple Sounds and synchronizing should be hard. Just start all of them in the same frame and they will stay in step (assuming they are all exactly the same length). This page has the sound commands.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 16th Jul 2013 00:11
Thank you. Do you know if there is a noticeable pause between loops?

I have grooves and I want them to loop seamlessly - will the user hear the restart of the loop (they are looped PERFECTLY, so if looped properly, it should sound seamless)?

So wav files can be looped and mp3's can only play one at a time.

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 16th Jul 2013 00:51
A pause between loops has been a frequent issue/complaint. But more often than not it comes down to a file that either has a pause at the end or the transition from the first sound to the last is such that it appears to be a pause.

It also may depend on the size of the file (maybe) and the capability of the device being played on.

You need to create your test case and then try it out on multiple devices.

According to the current help, you should use wav files with LoadSound and mp3 ones with LoadMusic.

Sound and Music are two different objects in AGK.

Sound (wav) can have load and play multiple ones. Music (mp3) can only play one at a time, but multiple can be loaded.

Given that framework, yes to "So wav files can be looped and mp3's can only play one at a time.".

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Ranietz
AGK Gold Backer
19
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 16th Jul 2013 02:19
I did some testing a while back and found out that wav files loops seamlessly using playSound(). Mp3 and ogg files does not loop seamlessly using playMusic(). Maybe this will be improved when AppGameKit v2 is released.
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 16th Jul 2013 02:32
I will create a simple test and report back.

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 19th Jul 2013 07:49
Well, I created a super simple app whose main focus was to play several sounds that would loop indefinitely and sound good doing so.

I took several loops from one of my products (wav files) and loaded them all and then set them to play.

It worked 100% perfectly. They all played in sync and the loops were clean. It sounded great.

Now I know I can create a simple editor GUI and let people at least play the sounds.

Now, can I allow people to create new vertical tracks, drag and drop representative rectangles (the sounds) to those tracks and allow them to nudge the rectangles left and right (using the mouse) in tiny increments, show the waveform inside the rectangles so that users can visually allow them to line up across multiple 'tracks' and then have the sounds play when a play button is pressed? I am sure I can create standard playback buttons (play, pause, stop, rewind, fast forward, record).

If this can be done, then I can create what I have wanted to create in a mobile app for GrooveBlox.

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Jul 2013 16:04
One thing that is always worth doing, is when you load a sound - set it's volume to nothing and play it, so it plays silently.
This lets the engine pre-load the sound, otherwise when you play the sound for the first time, it might have to load it up - and that would cause an irritating pause.

It's something I always do, a good habit to get into I think, I haven't had an issue with clicky, glitchy, or paused sounds since I started doing that. Not that I've done much with sound in AppGameKit, I'm going by DBPro and languages in general - but the project myself and Cliff M are working on does that, and it all seems to work fine - no glitches in the sound at least.

I got a fever, and the only prescription, is more memes.
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 19th Jul 2013 16:32 Edited at: 19th Jul 2013 16:34
I guess to play a sound a bit earlier or later, I would need a for/next loop for cycling the sounds based on the time and tempo. Since each GrooveBlock is 2 measures at 4/4 time, this should be quantifiable. Then just have various sounds play a little bit before or after the main tempo sync for next loop based of where the user nudged the GrooveBlock represented rectangle.

It's confusing, but I am sure it can be done.

Anyone care to share what the numbers would be to play loops at a constant rate of two measures at 4/4 time?

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Jul 2013 16:55
Ideally you'd change the pitch, like if you have a loop recorded at 120bpm, and one at 121, there's no reason why you couldn't play those together with the same BPM. You will know, or be able to find out the sample rate of the sound, from that you could work out the number of milliseconds that the sound plays for, and that's probably the most straightforward method.

But... again, the old chestnut that is one major bugbear for me with AppGameKit - no pitch control. If you could change the pitch, you could get each sound playing at the perfect rate so the loops are all the same length (in time). Right now, all you could do is add in a delay, but that might be fine for the first time the sound is played - but then it'll become noticeable within just a few bars.

TGC, dudes! - Add in a pitch control for sounds please! - you know it's just lazyness that we don't have it already
For once, show the sound commands a little love - it's restricting users on a daily basis, it's decrementing how awesome we can make them music apps.

I got a fever, and the only prescription, is more memes.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 19th Jul 2013 17:34
Quote: "Anyone care to share what the numbers would be to play loops at a constant rate of two measures at 4/4 time?"

Your first problem is that not all devices are going to run at the same rates (frames per second, FPS). Otherwise you could simply set the target FPS and then do calculations, knowing how long each frame takes.

But, it go for a target FPS of 30, you are close to what everything but the worst offenders can handle.

Then you use the GetFrameTime command to check the elapsed time for the last frame and adjust how long all the sounds have actually been running.

Then, assuming that you know how long two measures at 4/4 time is (because I certainly don't), then you can decide if the sounds have been on long enough.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Jul 2013 18:02
I think the math can be worked out like this:

44100khz means 44100 bytes per second replayed in 16-bit stereo, so 4 bytes per 'segment'.
So if a 44100khz sample is 1000000 bytes, divide by 4 to give 250,000 - then divide by the sample rate of 44100 giving 5.6689342403628117913832199546485 seconds of replay for 1mb. In terms of milliseconds that's about 5669, so if you stored milliseconds() as a variable when playing a sound, by the time the difference is 5669, the sound should be just about to loop.

I'm guessing at this - it's difficult without memblock sound commands, or knowing the exact format etc - all I'm saying is that something along those lines should let you work out the frame time in milliseconds that a sound should play for.

I got a fever, and the only prescription, is more memes.
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 19th Jul 2013 19:22 Edited at: 19th Jul 2013 19:25
Just so you know, I sampled each and every GrooveBlock (wave file) and they are all EXACTLY the same size down to the millisecond. I used the same template for every single sound, so they start and stop at exactly the same size. Every file is exactly the same size.

They are all 44.1khz, 16bit stereo. I think I used PCM for rendering them.

That should make it much easier to deal with since they are all mix and match. Figuring out the math for one figures the math for all.

The math is the one part I will really need help with.

I do NOT want to change the pitch, since that will change the timing - unless we use some kind of elastic audio algorithm (like Melodyne) and I DOUBT AppGameKit can do that (and never will). Changing the pitch is not an option. I want to be able to nudge the sounds horizontally and drag them vertically and then play them. Essentially, a multitrack audio player.

Right now, I am concerned with getting it working for PC and maybe Mac. Once that is done, I can then attempt to make it work on Android and IOS devices.

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 20th Jul 2013 17:57
Since this is my specialist area, I'd love to help. But I am currently sitting on a balcony overlooking the Ionian Sea in Greece, and only wearing a towel, so I'll keep it brief:

* The duration of a WAV playback is completely deterministic unless the audio sub-system is rubbish. What may be a problem is the accuracy of the timer used to determine when playback has started finished. The start time may be later than simple maths predicts.

* Not all hardware will allow tweaking the playback rate outside the usual "windows" - 8,000, 12,000, 22,050, 44,100. Consequently, the waveform needs to be modified, or a suitable range of samples at different frequencies used.

* For effective music production with virtual synthesizers you need to able to determine the attack, hold and decay sections of the waveform and probably loop inside the area between the attack and decay.

* Ideally, any mixing is done in high precision in a system of ring buffers.

Personally, I don't think it's AGK's job to provide this in Tier 1. It's all possible in T2 or Pascal, using platform-specific code.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 20th Jul 2013 18:55
...OK. However, I really hate c++ and its been ages since I programmed anything in Delphi (plus the software is too expensive now).

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
fog
20
Years of Service
User Offline
Joined: 5th Oct 2003
Location: Newcastle, England
Posted: 20th Jul 2013 20:41
Quote: "TGC, dudes! - Add in a pitch control for sounds please! - you know it's just lazyness that we don't have it already
For once, show the sound commands a little love - it's restricting users on a daily basis, it's decrementing how awesome we can make them music apps."

Listen to this man. I know sound commands don't get you sexy bullet points to stick on the back of the box like 3D and shader support, but they are far more essential for many people. The more sound options the better.

Anyway, not long now hopefully.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 21st Jul 2013 09:50
Quote: " its been ages since I programmed anything in Delphi (plus the software is too expensive now)."


You can use Free Pascal, which ism strangely enough, free.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 22nd Jul 2013 22:39
Quote: "You can use Free Pascal, which ism strangely enough, free. "


Uh . . . No. They are not the same. I attempted to create a virtual instrument using Lazarus (free Pascal) with code that works 100% in Delphi - all I would have to do is copy and paste - and it refused to compile. The commands are not 100% compatible.

I am not willing to learn the idiosyncracies of one IDE over another and one version of Pascal over the other and . . . i'm freakin rusty as hell. The last time I coded in Pascal for over a few days was 20 years ago.

I'll stick with Basic, Visual Basic and the like.

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 23rd Jul 2013 18:01
Which version of Delphi?

I assume you are not using any VCL stuff, or you will run into problems with FPC.

What are the error messages?

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 24th Jul 2013 00:31 Edited at: 24th Jul 2013 00:34
two versions ago.

No, the controls were made by TobyBear and self contained.

Don't remember the errors.

I'll be honest - I was not exactly a GENIUS coder with Pascal - ever - but I was able to get around and create utilities and such.

I've wanted to create my own custom vsti's (virtual instruments) forever and that requires knowing either c++ or Delphi to make a good quality vsti. I never succeeded.

If I could create a vsti in basic or a basic-like language like Pure Basic (tried it and so far, no can do), then it would be awesome.

When it comes to audio programming, i'm afraid i'm not very good. I'd love to be, but I just can't seem to find a language I know that would allow me to use Steinberg's SDK to create a virtual instrument. Simply put, you need to know either c++ or Delphi.

But creating a small, fun music app based on my sounds is do-able in AppGameKit, hence this thread.

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 24th Jul 2013 08:16
Mike - If you use the AppGameKit for Pascal the code will definitely compile in Delphi of all flavours and FPC.

I just downloaded TobyBear's VST template and it compiled fine in Lazarus/FPC. But if you have Delphi and are only interested in Windows, you can use it.

The problem with AppGameKit and apps that require very tight timing is that you have to hand the message pump to AppGameKit when it starts up.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
World Class Multimedia
15
Years of Service
User Offline
Joined: 15th Aug 2008
Location: Florida, USA
Posted: 24th Jul 2013 16:01
Jim,

Would you be interested in collaborating to create a VST in Delphi? I really need to create some custom VSTi's and simply do not have the know-how to get it done currently.

Mike

YOU DREAM IT - WE CREATE IT!
www.world-class-multimedia.com
For world-class virtual instruments - www.supersynths.com
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 24th Jul 2013 17:42
Mike - that would be fun. I'm currently lounging about on Corfu, so I'll get in touch when I'm back.

As they say here - "Yammas!" - cheers.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL

Login to post a reply

Server time is: 2024-05-02 12:54:09
Your offset time is: 2024-05-02 12:54:09