• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Glass_Knife

Sound Programming from Scratch

14 posts in this topic

I previously posted the question here, but got the muscian response.  http://www.gamedev.net/topic/637873-sound-programming-from-scratch/

 

I'd also like the programmer response.

 

 

Not sure if this question is better asked here or in the programming forum.  I've been playing with sound programming, but I find the APIs hide too much stuff.  When I learned 3D graphics, I started by learning from scratch.  I would like to know if anyone has any resources (books or online) that teach audio programming from scratch.  Much like writing a software renderer from scratch to learn about the algorithms.

 

I've googled and amazoned, but I don't really know enough about the subject to make a decision if the books I found are any good.  And man, I though software books were expensive.  Audio books are not cheap.  smile.png

 

Thanks,

0

Share this post


Link to post
Share on other sites

"Audio programming from scratch" is a very broad term and if you want more specific advice, I'm afraid you're going to have to be more specific with your question!

 

I guess what I would like to understand is how to write Direct Sound or OpenAL from scratch.

0

Share this post


Link to post
Share on other sites

DirectSound is essentially a driver that bridges the gap between third party libraries (such as OpenGL, FMOD, etc) and hardware. DSound does emulate some effects and provides access to hardware acceleration if possible, but at ground level it's precisely that and nothing more: a driver.
 
Now, I'm not too familiar with OpenAL overall, but it's likely just a library like FMOD, which builds on top of native drivers depending on what operating system you're compiling on and what is available. OpenAL and FMOD (and other libraries) also provide additional functionality, like time-to-frequency domain conversion (essentially raw FFT and IFFT calls), effects (reverb, delay, etc) and format support (easy loading of audio file formats).
 
In short, you're probably not thinking of writing a driver, in which case "writing DirectSound from scratch" doesn't really make much sense. You are probably thinking of implementing various library functionalities, such as effects and the like (just to be clear: if you do - for whatever reason - want to write a driver, then I can't help you).

Yes, I don't really know what I want out of this smile.png. I've done lots of programming, and written a software renderer from scratch to learn about graphics. The last two books I purchased about 3D engine programming didn't cover sound. It seemed strange, because I figured that the sound stuff would be important. The more I learn about this, however, the more it seems like the sound and graphics are very different areas.

So yes, I shouldn't say I was to write Direct Sound. I think I mean I would like to be able to do things in software like mixing, reverb, pan, High and low pass filters, and that kind of thing. I don't really know what I need to learn, because if I already knew that, I wouldn't need to ask. biggrin.png

I will check out the book. It looks like a good place to start. Edited by Glass_Knife
0

Share this post


Link to post
Share on other sites

I have written a software 3D sound engine during college.

As I was targeting windows only, I used waveOutOpen (http://msdn.microsoft.com/en-us/library/windows/desktop/dd743866(v=vs.85).aspx) to send the raw PCM data to the speakers. 

This is a good starting point : http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3.

Once you got a basic sound coming from the speakers, you can simple keep on adding features and build a nice architecture around it.

Mixing sounds is a simple as adding them together, resampling is simply interpolating and effects like echo or low/high pass filter aren't that hard and fairly documented.

 

2

Share this post


Link to post
Share on other sites

I have written a software 3D sound engine during college.

As I was targeting windows only, I used waveOutOpen (http://msdn.microsoft.com/en-us/library/windows/desktop/dd743866(v=vs.85).aspx) to send the raw PCM data to the speakers. 

This is a good starting point : http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3.

Once you got a basic sound coming from the speakers, you can simple keep on adding features and build a nice architecture around it.

Mixing sounds is a simple as adding them together, resampling is simply interpolating and effects like echo or low/high pass filter aren't that hard and fairly documented.

 

YES!!!  This is what I was looking for.  The sound equivalent of getting a buffer and setting each pixel value.  This, along with the DSP book, is a great starting point.

 

Thanks!

0

Share this post


Link to post
Share on other sites

If you are interested in doing raw device I/O, check out the WASAPI. It is intended for use by modern professional audio applications, has low latency, and gives you access to all of the device's channels/sample rates/capabilities. It is the successor to waveOutOpen() and related functions on Vista+.

 

ASIO is another pro-level option supported by a lot of hardware drivers, but it isn't as widely supported as the above.

1

Share this post


Link to post
Share on other sites

I have written a software 3D sound engine during college.

As I was targeting windows only, I used waveOutOpen (http://msdn.microsoft.com/en-us/library/windows/desktop/dd743866(v=vs.85).aspx) to send the raw PCM data to the speakers. 

This is a good starting point : http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3.

Once you got a basic sound coming from the speakers, you can simple keep on adding features and build a nice architecture around it.

Mixing sounds is a simple as adding them together, resampling is simply interpolating and effects like echo or low/high pass filter aren't that hard and fairly documented.

 

Great info, I've been meaning to look into this for awhile myself.

 

A question if you come back around -- did you find it difficult to keep the buffer full for gap-less playback? Even though audio processing isn't terribly intensive, I've always been concerned about Windows' ability to keep up with the real-time constraints while also having fast response time to sound events. Audio is far more susceptible to even tiny gaps in playback -- the ear notices micro-second gaps, while entire video frames can slip by. What were your experiences?

0

Share this post


Link to post
Share on other sites

I have written a software 3D sound engine during college.

As I was targeting windows only, I used waveOutOpen (http://msdn.microsoft.com/en-us/library/windows/desktop/dd743866(v=vs.85).aspx) to send the raw PCM data to the speakers. 

This is a good starting point : http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3.

Once you got a basic sound coming from the speakers, you can simple keep on adding features and build a nice architecture around it.

Mixing sounds is a simple as adding them together, resampling is simply interpolating and effects like echo or low/high pass filter aren't that hard and fairly documented.

 

Great info, I've been meaning to look into this for awhile myself.

 

A question if you come back around -- did you find it difficult to keep the buffer full for gap-less playback? Even though audio processing isn't terribly intensive, I've always been concerned about Windows' ability to keep up with the real-time constraints while also having fast response time to sound events. Audio is far more susceptible to even tiny gaps in playback -- the ear notices micro-second gaps, while entire video frames can slip by. What were your experiences?

 

In my experience with the waveOutOpen() family of functions you need a really big buffer to avoid gapless playback, making low-latency audio impossible. The reason behind this is that this API is not a callback-based API, whereas more advanced APIs like WASAPI on Windows and CoreAudio on OS X allow you to register a callback method which is called from the main system audio thread whenever output audio is needed. The OS/driver maintains the buffer for you and synchronizes the callback so that there is only a few ms of latency between your code and the hardware.

Edited by Aressera
0

Share this post


Link to post
Share on other sites

If you are interested in doing raw device I/O, check out the WASAPI. It is intended for use by modern professional audio applications, has low latency, and gives you access to all of the device's channels/sample rates/capabilities. It is the successor to waveOutOpen() and related functions on Vista+.

 

ASIO is another pro-level option supported by a lot of hardware drivers, but it isn't as widely supported as the above.

 

Thanks.  This is definitely going to help.  :)

0

Share this post


Link to post
Share on other sites

For lowest latency, you should look at WASAPI exclusive mode (with callbacks) or even ASIO (but that will not work with all sound cards).

0

Share this post


Link to post
Share on other sites

 

I have written a software 3D sound engine during college.

As I was targeting windows only, I used waveOutOpen (http://msdn.microsoft.com/en-us/library/windows/desktop/dd743866(v=vs.85).aspx) to send the raw PCM data to the speakers. 

This is a good starting point : http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3.

Once you got a basic sound coming from the speakers, you can simple keep on adding features and build a nice architecture around it.

Mixing sounds is a simple as adding them together, resampling is simply interpolating and effects like echo or low/high pass filter aren't that hard and fairly documented.

 

Great info, I've been meaning to look into this for awhile myself.

 

A question if you come back around -- did you find it difficult to keep the buffer full for gap-less playback? Even though audio processing isn't terribly intensive, I've always been concerned about Windows' ability to keep up with the real-time constraints while also having fast response time to sound events. Audio is far more susceptible to even tiny gaps in playback -- the ear notices micro-second gaps, while entire video frames can slip by. What were your experiences?

 

In my experience with the waveOutOpen() family of functions you need a really big buffer to avoid gapless playback, making low-latency audio impossible. The reason behind this is that this API is not a callback-based API, whereas more advanced APIs like WASAPI on Windows and CoreAudio on OS X allow you to register a callback method which is called from the main system audio thread whenever output audio is needed. The OS/driver maintains the buffer for you and synchronizes the callback so that there is only a few ms of latency between your code and the hardware.

 

WaveOutOpen is callback based (see the last 3 parameters), combined with a dedicated thread, it worked pretty good.

I didn't really had issues with gaps. I used 2 64kb buffers (not sure if that is considered a big buffer for audio programming) and the effects weren't really compute intensive ( low/high pass filter, echo, ...). 

I was able to play 20+ sounds at the same time without a problem. 

Although there is a latency of 1-2 buffers before a sound is actually beeing played, I didn't noticed it. 

0

Share this post


Link to post
Share on other sites

WaveOutOpen is callback based (see the last 3 parameters), combined with a dedicated thread, it worked pretty good.
I didn't really had issues with gaps. I used 2 64kb buffers (not sure if that is considered a big buffer for audio programming) and the effects weren't really compute intensive ( low/high pass filter, echo, ...). 
I was able to play 20+ sounds at the same time without a problem. 
Although there is a latency of 1-2 buffers before a sound is actually beeing played, I didn't noticed it. 

 

Oops, my mistake, I was going from memory. And yes, 64kb is a very large buffer. For 16-bit stereo sound, that's 16384 samples or almost 370ms at 44.1kHz. It's not surprising it only took a few buffers to get gapless playback. In my implementation, I needed a similarly sized delay buffer (but split over multiple smaller buffers) to avoid gaps. Most devices work on <= 512 samples in a buffer (for ~10ms of latency), so you're really not getting anywhere close to good latency.

 

The other reason why that API is not the best option is because it internally does sample rate conversion and other lossy effects on the audio before it is sent to the device. This is probably OK for simple playback but it's not desirable for more complex audio tasks.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0