Cocoa: How do I get a tone out of my game?

Apprentice
Posts: 8
Joined: 2006.08
Post: #1
So I know how to use the NSSound class, but that's not what I need; it just plays back sounds files.

What if I want to simply play a super basic tone based on like pitch and frequency?
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #2
So you want procedurally generated tones?
You might need to fiddle with OpenAL, and feed it your own generated buffer data.
Or use CoreAudio, I have no knowledge of using this though...
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
You'll want to generate the data yourself into a buffer and pass it to an audio subsystem to be played. OpenAL and CoreAudio can both do this. OpenAL is reasonably straightforward, but CoreAudio is pretty arcane; if you want to go the CoreAudio route, I found MTCoreAudio tremendously helpful as reference code.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #4
Yeah, you can use CoreAudio for this. As ThemsAllTook mentions, it's pretty thick stuff to dig through; specifically, the documentation and sample code sucks rotten donkey eggs. I seem to recall that the SDL source code has some pretty good stuff to look at for this. You'll be using the Audio Units API of CoreAudio.

The Cliff's notes goes something like this:

- set up a ComponentDescription
- find a matching component with FindNextComponent
- open the component with OpenAComponent
- call AudioUnitInitialize
- set up a AURenderCallbackStruct to set up an output callback for your audio buffer
- set the rendering callback on your component with AudioUnitSetProperty
- then call AudioOutputUnitStart to set things in motion
- then in your audio rendering callback you just fill in the data as it gets requested
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #5
The Shoot Things source shows procedural tone generation (e.g. shmup sound effects), building on DefaultOutputUnit from the CoreAudio SDK.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #6
arekkusu Wrote:The Shoot Things source shows procedural tone generation (e.g. shmup sound effects), building on DefaultOutputUnit from the CoreAudio SDK.

Ha, cool! I never noticed that. There seems to be no end to your hackitude arekkusu. Smile
Quote this message in a reply
Post Reply