• 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
Vincent_M

Writing DSP Code

11 posts in this topic

One of my friends wants to write lower-level audio tools, and a real-time audio engine, like FMOD, for games. He went to art school for sound effects, and he's learning how to program.

 

We both agreed he'll need to get a solid understanding on how programming works, so he's learning C++. What I'm suggesting for the next step is to learn how to load and uncompress raw audio samples from a file format (most-likely wav or ogg to start with a library), and use OpenAL to send loaded audio samples to the audio hardware to play it.

 

The thing is, he wants to write custom sound effect algorithms to manipulate sounds in a 3D environment similar to FMOD as mentioned above. This means he needs direct access to modify these raw audio samples somehow in real-time --which, of course, gets copied into an OpenAL buffer like an OpenGL texture would. Is there a way to flexibly manipulate samples already loaded into an OpenAL buffer?

 

What he'll start off doing is writing things like a sound interpolation, a way to scale volume to specific sounds, etc --basic stuff. Then, he will move into more complex stuff (I have no clue what he's planning). Whatever he ends up doing, it will involve tons of calculations on a massive amount of samples, which will be very CPU-intensive. Are there any APIs out there where he can write code that'll run directly on the audio hardware similar to shaders on the GPU? It doesn't look like OpenAL offers functionality like that.

0

Share this post


Link to post
Share on other sites

No there will be no shader like manipulation languages for audio.  All the audio calculations will probably have to be run through the CPU.  As far as manipulating the audio he will probably need to write algorithms to manipulate the raw audio bits that are stored in the buffer.  This is rather low level programming but there may be api's out there that glue well with OpenAL to get the effect you want I am not sure.  The best thing is to take a step back and do some research on audio manipulation.  Some tools like audacity allow you to apply filters to the audio to get different effect and it may be worth looking into the source code of the project to see how they implement the filters.  From a general perspective audio is nothing more then voltages converted to audible tone frequencies so without a doubt he is going to have to get good experience with the lower level details of development because at some point he will have to bit twiddle.

1

Share this post


Link to post
Share on other sites

It's not FMOD, but it just so happens that Charles Petzold is tackling a similar topic over at MSDN magazine:

 

Windows 8 Sound Generation with XAudio2

Constructing Audio Oscillators for Windows 8

 

He hasn't gotten to any audio processing stuff, but I suspect it'll go that direction.

 

As far as accessing hardware for audio processing, I'm not aware of any APIs. If the requirements are not realtime, you could use GPU programming APIs like C++ AMP, DirectCompute, OpenCL or CUDA, but for real-time DSP/audio mixing, the latency of communication back and forth across the PCIe bus is probably too high for now, given the typically small chunks of audio you will process in one go. We might see this change soon, as hardware and APIs evolve to support a shared address space (and especially if your CPU has an integrated GPU that can be used), but its not here yet.

 

Its not so bad as it seems though -- Since Vista the entire Windows audio stack has been processed on the CPU, and fancy audio cards are becoming less and less necessary. Some of the less expensive of the fancy audio cards are little more than high-quality DACs and analogue components. With multi-core PCs commonplace, its entirely possible to throw even an entire hardware thread at audio.

1

Share this post


Link to post
Share on other sites

Its not so bad as it seems though -- Since Vista the entire Windows audio stack has been processed on the CPU, and fancy audio cards are becoming less and less necessary.

 

I think this is an upside-down way to look at it. Due to underinvestment (arguably caused by Creative's near-monopoly over PC audio for a decade or so), audio hardware and APIs haven't progressed at even a tenth as much as graphics have since the 90s. In theory audio is a much better candidate for parallelization and moving to dedicated hardware than graphics is:

  • Audio is almost always write-only, unlike graphics where several advanced applications require reads.
  • Separate streams of audio data typically do not interact at all until the final mixing stage, which is purely additive. This simplifies the hardware and software design.
  • Audio needs to produce near-continuous output (rather than X discrete frames per second) which already requires separate hardware.
  • Audio rarely needs any conditional values that can stall or complicate the pipeline.
  • Audio data is homogeneous throughout the pipeline; no need for several different types of shaders (or indeed different types of processor, if that still applies to anything on the market) and the instruction set would be simple.
  • Expensive audio operations such as convolution are still too expensive to perform well on CPUs but are trivial to implement in hardware. You could 'throw even an entire hardware thread' at it and still have nowhere near enough power to handle good reverb for 10 to 20 sound sources.
  • As well as the commercial applications in games, it could be useful for pro audio as well.

Ideally what we'd have is more and better audio hardware, not a plan to push it back onto the CPU - especially not at a time when CPUs are ceasing to improve much year on year.

2

Share this post


Link to post
Share on other sites

Well, I never meant to suggest that the lack of audio hardware was a great state of affairs -- just that the OP's buddy isn't any worse of than anyone else, including Microsoft.

 

There were actually a couple of guys proposing programmable sound hardware, and they had gone as far as to implement a library that provided "sound shaders" running on the CPU.

 

Today, I don't think anyone's going to make the investment, frankly. It'll probably be very soon when we can just dedicate some idle GPU resources with low enough latency to be effective -- sooner than it would take to reintroduce and popularize audio processors, anyhow. The next-gen consoles don't appear to include that kind of audio hardware either, but likely will support low-letency offload to GPU, so it looks like the next 6-10 years or so are already settled.

 

It *would* be nice, but alas it looks like a problem who's opportunity has passed.

0

Share this post


Link to post
Share on other sites
I know very little about audio programming other than "makin' it work" so take this with a pinch of salt ;)

I have been interested in the idea of audio shaders but since sound from a file is always going to be the same, does it have as much need for a shader to alter it at runtime? It can be manipulated offline on the development machine, then stored and ran at runtime. I always assumed this was why sound shaders wern't used.
Similar to why you might not pass a video through a shader during your game. (Novelty video effects in VLC aside ;)

Graphics however is generated on the fly (i.e depending on how the player moves and interacts) so I guess this is why each frame needs to be shaded.

EDIT: Nope, I have thought about this further and decided that the same .wav file (i.e shooting) might want to be used whether you are underwater or not. In which case a shader to make it sound muffled would be great.
0

Share this post


Link to post
Share on other sites

since sound from a file is always going to be the same, does it have as much need for a shader to alter it at runtime?

 

That's the exactly the problem - because we don't have much technical advancement in audio, people find it hard to even imagine that you'd want to do anything other than just play back a sound. It's like we're back in the days of 2D graphics when graphics was literally "copy this picture offscreen to a position on-screen" - but there was always the capability for more. Examples:

  • Muffling sounds underwater, as you said
  • Muffling sounds that are occluded by other surfaces (eg. listening outside a door)
  • Reverberation based on the room's physical characteristics (this already exists on some hardware, though only on a crude level)
  • Echoes based on the room's physical characteristics (which is distinct from reverberation in terms of implementation)
  • Pitch and amplitude variations to allow re-use of one sample without it sounding too repetitive (eg. footsteps)
  • Dynamic compression of all playing sounds so that music automatically gets quieter so that speech can be heard (basically HDR for audio)
  • Doppler shift of sounds going past the listener at high speeds
  • Special effects like chorus/flanger/ring modulation to transform normal voice acting into robots, aliens, etc
  • Realistic sound propagation from room to room to allow players to track enemies audibly

...etc...

 

It'll probably be very soon when we can just dedicate some idle GPU resources with low enough latency to be effective

Unfortunately I don't think the latency will be low enough. GPUs are considered to be doing well if they can generate a frame in 16ms and that assumes that there are no frames being buffered. 16ms is a long time in audio, and 33ms is an especially long time. Admittedly I don't know much about how GPUs will handle non graphical data and whether it will be affected by frame rates, frame buffering, and alternate frame rendering, but I would want to see an actual definition of "low latency" rather than just assume it will be sufficiently low.

2

Share this post


Link to post
Share on other sites
Do you really need low latency? The time that would be critical is when a button press generates a sound that you want to process. Even in this case, a small delay may not be noticeable. For everything else, you can process the sound in advance, and buffer it to keep the audio steady.<br /><br />So to the OP, your friend should look into learning CUDA and OpenGL in addition to C++.
0

Share this post


Link to post
Share on other sites

It'll probably be very soon when we can just dedicate some idle GPU resources with low enough latency to be effective

Unfortunately I don't think the latency will be low enough. GPUs are considered to be doing well if they can generate a frame in 16ms and that assumes that there are no frames being buffered. 16ms is a long time in audio, and 33ms is an especially long time. Admittedly I don't know much about how GPUs will handle non graphical data and whether it will be affected by frame rates, frame buffering, and alternate frame rendering, but I would want to see an actual definition of "low latency" rather than just assume it will be sufficiently low.

 

Phil126 above said he's getting 5ms latency, best case, on current hardware, going between graphics and audio devices directly with no CPU intervention, but across PCIe bus still. I agree latency is *the* issue, but I think we already can see low-enough latency, and that it'll be commonplace soon enough. I suspect that the PS4 and XboxNext will be able to support sufficiently-low latencies to make it possible, which will mean that it'll have 5-10 years of incubation if true, plenty of time for the PC to catch up. At AMD's Fusion Developer conference last year they started pushing their HSA aliance, and began talking about how the PCIe bottleneck is a huge issue for certain classes of problems (namely, latency-sensitive, smallish-data problems--like audio), and what they're doing to fix it.

 

Do you really need low latency? The time that would be critical is when a button press generates a sound that you want to process. Even in this case, a small delay may not be noticeable. For everything else, you can process the sound in advance, and buffer it to keep the audio steady.<br /><br />So to the OP, your friend should look into learning CUDA and OpenGL in addition to C++.

 

Latency is super important in audio because we're far more sensitive to audio latency and audio anomolies than visual ones. Our vision systems do a lot of work that we're not even aware of to reconstruct the image we percieve, and it fills in and smoothes over incomplete information. In particular, latency is essential for making audio match the visual info that we percieve in time, and to ensure gapless playback with dynamic mixing of sound elements. Having written audio playback code on an embedded system, I can attest that playback gaps of even a few CPU cycles is quite noticable. In rendering you can (and in fact, regularly do) miss entire frames of information, but with audio you'll notice even when a 'frame' arrives late.

2

Share this post


Link to post
Share on other sites

Ravyne, on 08 Mar 2013 - 14:25, said:
Latency is super important in audio because we're far more sensitive to audio latency and audio anomolies than visual ones. Our vision systems do a lot of work that we're not even aware of to reconstruct the image we percieve, and it fills in and smoothes over incomplete information. In particular, latency is essential for making audio match the visual info that we percieve in time, and to ensure gapless playback with dynamic mixing of sound elements. Having written audio playback code on an embedded system, I can attest that playback gaps of even a few CPU cycles is quite noticable. In rendering you can (and in fact, regularly do) miss entire frames of information, but with audio you'll notice even when a 'frame' arrives late.

Yes, but playback gaps can be avoided by having a buffer. Audio response to user input needs to be quick, but that's still different from noticing a change in sound; it ties in to how precisely we perceive our own motion.
0

Share this post


Link to post
Share on other sites

Yes, but the buffer is the rub :)

 

In order to have quick dynamic response, the buffer is typically very small, maybe a few hundred samples wide. And you've got to have the next one ready before the previous one runs out. You can't just repeat the last frame and catch up later like you can with video. Increase the size of the buffer, and you either introduce more latency, or you throw it out and recompute everything whenever a new sound comes in, the environment dynamics change, etc.

 

Buffers never get very big -- even at 30fps video, and 96ksps audio (which is over 2x CD quality) you've got just over 3k samples per video frame. At 60fps video and 48ksps audio, you've got just 800 samples per frame.

1

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