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

Indie Devs

1,385 members Hobbies & Interests

A group dedicated to indie and standalone game development.

Indie DB

Indie DB

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

Desura

Desura

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

Spotlight

Spotlight

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

Post comment Comments
Garyn Dakari

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

Reply Good karma Bad karma+2 votes
AcidBarrel
AcidBarrel

Hey how are you doing buddy!

Reply Good karma Bad karma+2 votes
Original_Speeder Creator
Original_Speeder

Doing the game \o/

Reply Good karma+2 votes
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:

Level
Avatar
Avatar
Last Online
Country
Brazil Brazil
Gender
Male
Friends
Become friends
Member watch
Start tracking
Indie DBDesuraSpotlight
Statistics
Rank
8,623 of 570,993
Visitors
3,770 (1 today)
Time Online
60 seconds
Activity Points
333
Watchers
1 member
Comments
33
Site visits
2,063
Contact
Contact
Send Message
Homepage
Agfgames.com
Steam
kelvinhart
Google Talk
orspeeder@gmail.com
Friends
iQew
iQew Online
Gamieon
Gamieon Online
shaulhadar
shaulhadar Online
hirato
hirato Online
AcidBarrel
AcidBarrel Online
JamV Online
Shadowscythe
Shadowscythe Online