Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 945 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Basic thread safety question #476024
01/19/19 16:43
01/19/19 16:43
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline OP
Senior Expert
Superku  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I've written my own DirectSound8 implementation and load most of the sounds at game start into memory. As music in wav format can get quite big (20-30MB per file) I only load it when required during gameplay and free it after it has been played.
Even on my rather fast PC this leads to some stutter (loading from my custom container file from the hard disk, then CreateSoundBuffer and QueryInterface (which creates the final buffer)), which will be much worse on lower end machines.

Therefore - as DirectSound seems to be multithreading safe -, I both load the file in a separate thread (using fopen/... instructions and sys_malloc) and create the soundbuffer as well.
This seems to be working fine, however I want to make sure it's actually thread safe.

I assume sys_malloc(size) is just something like malloc(size+8) during development, which writes the sys_marker in the first 3 bytes and some security byte at 3(4) and after size.
When I google thread safety of malloc I get a bunch of "it depends" answers, such as here: https://stackoverflow.com/questions/855763/is-malloc-thread-safe
Are (sys_)malloc and free thread safe in acknex/ lite-C?
Using the forum search I've found that add_buffer seems to be thread safe, which probably does at least one malloc itself as well but I want to be sure.
Thanks.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Basic thread safety question [Re: Superku] #476029
01/20/19 09:04
01/20/19 09:04
Joined: Nov 2009
Posts: 201
Logitek Offline
Member
Logitek  Offline
Member

Joined: Nov 2009
Posts: 201
Are you still using wav for music? Instead of mp3?

Re: Basic thread safety question [Re: Logitek] #476030
01/20/19 09:36
01/20/19 09:36
Joined: Apr 2017
Posts: 106
3
3dgamelight Offline
Member
3dgamelight  Offline
Member
3

Joined: Apr 2017
Posts: 106
I readed that Ogg Vorbis is smaller and have better quality.

Re: Basic thread safety question [Re: 3dgamelight] #476031
01/20/19 09:40
01/20/19 09:40
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
I use Fmod for sounds and music for some years. There you can easily decide what is loaded into memory and what gets streamed from disk.

Re: Basic thread safety question [Re: pegamode] #476033
01/20/19 17:15
01/20/19 17:15
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline OP
Senior Expert
Superku  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I'm not using wav files "still" but again, ever since making my own DirectSound implementation. I don't want to use media_play so I'd have to decode mp3 myself before I could feed it into the sound buffers.

Ogg files are (/ can be) smaller when you use compression. Compressed audio is lossy audio, thus having worse quality (although on high quality settings rather unnoticeable). However, I'd have to use an ogg decoding library as well for that. I looked into it for a bit but didn't feel like implementing it.

Although frequently used, FMOD has a ton of issues (and used to have bad licensing for indies). Some projects are stuck with audio issues for months because of FMOD.

Previously I had used irrKlang (65 bucks license) which worked fine with automatic streaming/ memory management. There was a bug with the Windows/ DirectSound implementation though, messing sounds up when you played more than one instance of them at the same time. I had reported it and worked with the dev but he took over half a year or so to fix it, so I just wrote my own "sound engine".


It's all working fine, I just need to know that lite-C's malloc is threadsafe.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Basic thread safety question [Re: Superku] #476076
01/25/19 16:41
01/25/19 16:41
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
I remember using BASS DLL. I remember I didn't have any problems and licensing was affordable for indie projects. But this was several years ago, things might have changed.

Re: Basic thread safety question [Re: FBL] #476084
01/25/19 20:02
01/25/19 20:02
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
sys_malloc does indeed allocate at least 4 more bytes and aligns to qword boundaries. As to my knowledge, in lite-C it should be thread safe.

Re: Basic thread safety question [Re: jcl] #476091
01/26/19 05:22
01/26/19 05:22
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline OP
Senior Expert
Superku  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Thank you for the response. I'll just go with it then and hope for the best.

@Firoball: Had not heard of that sound library before, interesting. It's notably more expensive than irrKlang though, so if I had to I think I'd rather use the latter again.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

Moderated by  old_bill, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1