Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have put together a basic sound handler class for use in my game. It uses OpenAL.

It's a simple method at the moment to play sounds - here's an extract from a switch block:

case "EATEN_PILL":
    wavPath = "D:\\Programming\\SFX\\EATEN_PILL\\Hit_43.wav";
    ALfilename = Path.Combine(Path.Combine("Data", "Audio"), wavPath);                          
    sound_data = LoadWave(File.Open(ALfilename, FileMode.Open), out channels, out bits_per_sample, out sample_rate);
    buffer_EATEN_PILL = AL.GenBuffer();
    AL.BufferData(buffer_EATEN_PILL, GetSoundFormat(channels, bits_per_sample), sound_data, sound_data.Length, sample_rate);
    AL.Source(source, ALSourcei.Buffer, buffer_EATEN_PILL);


Problems: 1. An annoying click at the end of each sound. 2. Eventually sound stops playing completely. This is after perhaps playing 100 sounds.

Has anyone hit this problem before?

share|improve this question
The click at the end could be the result of a DC bias on your clip(s), or it could be some incompatibility/bug between your audio driver and OpenAL. Last time I used OpenAL I had no problems with that. As for stopping after 100ish sounds, make sure you're cleaning up your buffers and sources when you're done using them. I'm not familiar with the C# OpenAL bindings but it doesn't look like you're releasing them anywhere. On a side note, you don't want to load the file every time you play it. Load it once, keep the buffer id around, then give it to a source when you want to play it. –  bcrist Mar 8 '14 at 21:43

1 Answer 1

You are leaking memory each time a sound is being played.

You might consider:

  • Making a class for a SoundBuffer.
  • Loading all sounds after OpenAL is initialized (after you have created the AudioContext object)
  • Keep in mind that a SoundBuffer is an unmannaged resource.
  • Implement Disposable pattern for SoundBuffer and call Dispose once the resource is no longer needed.
  • You could also simply store an array of buffer IDs and release them afterwards with AL.DeleteBuffer(BufferID) or AL.DeleteBuffers(BufferIDArray)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.