• Register

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 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
Indie Devs

Indie Devs

1,675 members Hobbies & Interests

A group dedicated to indie and standalone game development.

Indie DB

Indie DB

2,646 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...



10,089 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...



591 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...

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...

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...

Garyn Dakari

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

Reply Good karma Bad karma+2 votes

Hey how are you doing buddy!

Reply Good karma Bad karma+2 votes
Original_Speeder Creator

Doing the game \o/

Reply Good karma+2 votes
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Last Online
Become friends
Member watch
Indie DBDesuraSpotlight
11,426 of 740,933
4,813 (1 today)
Time Online
28 minutes
Activity Points
1 member
Site visits
Send Message
Google Talk
shaulhadar Online
Gamieon Online
iqew Online
hirato Online
AcidBarrel Online
JamV Online
Shadowscythe Online