I am a from Brazil, I like game, I like martial arts, I like computers, I like sci-fi and I LOVE making games.

  • View media
RSS feed My Blogs

The game had a serious problem: The awesome music from xaimus, caused slow-downs and buffer underruns, resulting in the music stuttering (among other undesired effects)

The reason for that, is how ClanLib handles streaming music: It waits for the buffer to end, and then it requests a hardcoded amount of data (1024*16 bytes), if this data is not calculated until the soundcard needs it, the result is a underrun.

The solution then was actually simple in theory, but hard to do for someone that never did it before, I would need to implement a ring buffer, and fill it in the background...

First, explaining what is a ring buffer: A ring buffer, is a buffer of fixed size, that you keep filling data, and reading data from it when necessary, when you read data, you overwrite the data that you just read with new data, it is called ring buffer, because when you reach the end, you start again in the beginning. This solve the problem because I fill it in advance, thus even if the music player slows-down it will take some time until it gets empty.

To fill it without slowing down everything else, or locking-up the game, I decided to make it in the background, so I learned how to use pthreads, a library to make threads (heh, you could not guess it, could you? :P), and it was really simple, all I needed to do was fire-up the player in another thread, and the player constantly fills the buffer, while clanlib reads the buffer, and both of them, before messing with the buffer, check if the other one is using it, so it avoid conflicts.

Although simple to do in theory, I never did that before, and I had several issues, first I accidentally made the buffer misbehave, by forgetting that it had stereo music, thus all addresses should have their values doubled, then I made some logic bugs, and some corner cases that caught me by surprise, like what happened when both pointers went to "0" but the buffer was full, the result was it re-filling again, resulting in the music suddenly skipping forward some seconds. Also I had the usual crashes caused by newbie errors, and etc...

After some extensive testing, seemly this solved all problems regarding music, now the game can play the awesome xaimus music without hassles! And I must say, that xaimus music is AWESOME! (well, for what other reason I would put it in the game?)

Start a group Groups
Awesome Games Factory

Awesome Games Factory

1 member Developer & Publisher

Awesome Games Factory is a newcomer to the game industry, the company (under the name AGF) manufactured car repair equipment, but the current owner decided...



10,127 members Entertainment & Press

Desura is a community driven digital distribution service for gamers, putting the best games, mods and downloadable content from developers at gamers...

Indie DB

Indie DB

2,236 members Official

Indie games are changing the world, one giant pixel at a time. With Indie DB we aim to support independent developers and their games, by providing them...

Indie Devs

Indie Devs

1,282 members Hobbies & Interests

A group dedicated to indie and standalone game development.

Robinson Technologies

Robinson Technologies

1 member Developer & Publisher

Robinson Technologies is operated by the husband and wife team of Seth and Akiko Robinson and is located in Hiroshima, Japan. Seth has made a practice...



571 members Official

Each month we bring to you new and old (updated) game and mod playthroughs, trailers and weekly recaps covering the mod and indie gaming scene, so sit...

Post comment Comments
Garyn Dakari Nov 16 2010 says:

I just wanna say, I really like your game and keep up the good work!

+2 votes     reply to comment
AcidBarrel Jul 27 2010 says:

Hey how are you doing buddy!

+2 votes     reply to comment
Original_Speeder Creator
Original_Speeder Aug 7 2010 replied:

Doing the game \o/

+2 votes   reply to comment
Post a comment

You are not logged in, your comment will be anonymous unless you join the community. Or sign in with your social account:

Last Online
Feb 17 2015
Brazil Brazil
Become friends
Member watch
Start tracking
DesuraIndie DBSpotlight
8,290 of 541,018
3,613 (1 today)
Time Online
1 second
Activity Points
1 member
Site visits
iQew Online 22 hours ago
shaulhadar Online 2 days ago
Gamieon Online 1 month ago
hirato Online 2 years ago
AcidBarrel Online 3 years ago
JamV Online 4 years ago
Shadowscythe Online 4 years ago