GLBasic forum

Main forum => GLBasic - en => Topic started by: erico on 2019-Jul-17

Title: Playmusic freeze
Post by: erico on 2019-Jul-17
Hello there, quick question:
I have been getting a quick computer freeze every time music is played with that command.
Mp3 is horrible as it takes more than a full second, raw wav takes 1/10 of a second. But all motion freezes.

What the heck, that did not happen on my old machine but happens on my new one, which was a lot of trouble taking win 10 out to use win 7, lots of drive problems.

So, is that only on my side? Is anyone experiencing problems with playmusic and loop?

Tried v16 steam and no good either, tried at 2 friends pc and wav raw had no problem, which leads me to think my drivers are bugged.
One could switch to playsound though. What do you guys think?
Title: Re: Playmusic freeze
Post by: SnooPI on 2019-Jul-21
I remember that I had a lot of problems with the playmusic function (especially on mobile) and finally, I used the playsound function.

Moreover, at the time of launching this function, everything slows down (as in my demo with the music of 2001, when the music stops and restarts, the demo slows down).
Nevertheless, it is a bit normal because the music is not loaded in memory, unlike the playsound function.

Erico, you should convert all yours musics to be compatible with the playsound function. Personally, I think this is the best solution at the moment.
Title: Re: Playmusic freeze
Post by: erico on 2019-Jul-22
Ok, I got some hints about doing that from the forum and will update my framework to use that for future games.
Thanks.
Title: Re: Playmusic freeze
Post by: bigsofty on 2019-Jul-22
Quote from: Snoopy on 2019-Jul-21
I remember that I had a lot of problems with the playmusic function (especially on mobile) and finally, I used the playsound function.

Moreover, at the time of launching this function, everything slows down (as in my demo with the music of 2001, when the music stops and restarts, the demo slows down).
Nevertheless, it is a bit normal because the music is not loaded in memory, unlike the playsound function.

Erico, you should convert all yours musics to be compatible with the playsound function. Personally, I think this is the best solution at the moment.

Playmusic slows your code down, wow. This is a bit of a concern TBH. Have you tried this recently Snoopy?
Title: Re: Playmusic freeze
Post by: SnooPI on 2019-Jul-23
Yes, as in my "2001 Demo" for a contest on the forum.
Or at least, that's the case on my old PC.

But I specify that it's when the music restarts.
Title: Re: Playmusic freeze
Post by: bigsofty on 2019-Jul-24
So the music is streamed of the HD, I never knew that.
Title: Re: Playmusic freeze
Post by: erico on 2019-Jul-24
Yes I noticed if the game is running from a slow speed drive or a pen drive, it struggles when streaming music.
I really wish the music I´m using was IT as I suspect I would not bring all that trouble that way.
Title: Re: Playmusic freeze
Post by: SnooPI on 2019-Jul-25
Personally, I don't find it abnormal.
This allows to have a very good quality of music without cluttering the memory and for the rest there is the playsound function.

It's the same as for the playmovie function.
Title: Re: Playmusic freeze
Post by: erico on 2019-Jul-26
I never had trouble with it, just now that I got this new computer with a very shitty on board sound, it renders games with playmusic unplayable if the music kicks in with action ongoing.
Title: Re: Playmusic freeze
Post by: dreamerman on 2020-Apr-29
It's not only Your pc problem erico, this is still a thing.. ofc will be dependent on file and mostly hard drive that's in use, surely more notable on hdd than on ssd, and this annoys me. Remember days that I wrote some mp3 player with VB6 that was using Win API precisely MCI stuff, there was no visible file loading time as file was read in chunks, and now this... :> So what is the best solution for now? As SnooPI mentioned use only PlaySound even for music (what sound format it currently supports fo have proper results? mp3 will work or only wav's or something :/) or maybe using threads and PlayMusic from separate thread (would that be safe for all platforms and so on)??

btw. any one has that multi-threading code as can't find working attachment on forum with any source..
Title: Re: Playmusic freeze
Post by: erico on 2020-Apr-29
I´m sticking with playsound for now, loading only pure waves.
One thing though is that .IT files might work just fine on playmusic, haven´t tried that but since it is a super small file, it might just work.
Title: Re: Playmusic freeze
Post by: dreamerman on 2020-Apr-29
With playsound there is one problem that You need to load all music files into memory and wav's ale larger that ogg/mp3, so if I have couple music files they will take some time to load and will occupy precious ram :/
Yet I'm checking some other solutions, currently testing SDL2 mixer and it looks that this way mp3 files can be played without visible freezes during gameplay.

ps. *IT files, You mean mod music? this also may be an idea but will need to find such resources that would fit my project.
Title: Re: Playmusic freeze
Post by: erico on 2020-Apr-29
Yep, it and mod files (trackers) works a charm last I tried a while ago.
I try to work with it, but brute force wav is always easier. :)
Title: Re: Playmusic freeze
Post by: SnooPI on 2020-Apr-29
Hey, this is important information Erico! Thks!  :good:

I put here a link to a portable ProTracker 2 and Fasttracker 2 clone https://16-bits.org/index.php

...and a ProTracker tutorial https://www.youtube.com/playlist?list=PLVoRT-Mqwas9gvmCRtOusCQSKNQNf6lTc
Title: Re: Playmusic freeze
Post by: spacefractal on 2020-Apr-29
Just to been Noticed SoundPool on Android (optional in newest beta) does not supports mods, but is more stable than sld mixer is. A least on Android. Yes its a bit strange on Windows as well.

There is some delays to open and fill the buffer when playing music. This is why im allways only start them on a scene change, so a delay does not matter and newer have used a ingame music change.
Title: Re: Playmusic freeze
Post by: dreamerman on 2020-Apr-29
@SnooPI: nice tools but out of my artistic possibilities ;-)

So best advice is to use either small mod files (will check that in next project), use PlaySound with wav's, or changing music track only when in menu, this can be some solution, but only for games that have quite short level time play. Maybe this could be minimized by changing audio buffer size in source or something, btw. is ther way to force using SDL_mixer on Windows, as I assume it's using DxSound as default.

But if someone has similar problem and target platform is Windows you can use SDL2 Mixer, it plays mp3 files without freezes. Surely could be used on other platforms if someone has time to test and fix stuff..
Example lib in attachement, usage:
Code (glbasic) Select

GLOBAL mySDL AS SDL2_helper
SDL_vibes.MusicPlay("music.mp3", 0)
// other commands are similar: MusicIsPlaying(), MusicStop(), MusicPause(pause_it), needs volume control
// and on quit:
mySDL.CleanUp()

SDL2 just needs some setup: check this (https://www.glbasic.com/forum/index.php?topic=11401.0) and You need to add SDL2_mixer stuff to that include/libs/dll..

ps. Maybe those Android issues are due using old SDL? hm..

edit: if target is 60fps with full game logic inbound, it still can freeze game for few frames - on hdd, on ssd didn't noticed drops when previously it could freeze game for 300ms, but this is a fast straight forward solution. Best would be either loading music files from other thread or just use couple SDLmusic object's as tracks, load them once and later just play - don't destroying object and reload it each time..