OpenAL Playing a note

Nibbie
Posts: 2
Joined: 2010.02
Post: #1
I've seen numerous examples on playing back wave files, and even splitting the wav into separate buffers and then queuing them up to play.

But how would one go about creating a note and applying that to a buffer.

Even creating different waveform shapes would be good to know.

Thanks.
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #2
Set its AL_PITCH. You can find lots of tables online of which pitch correlates to which note. The AL_PITCH is relative to the tone of the buffer, so do a bit of maths to work it out. (e.g. if the buffer was middle C, setting the pitch to 2.0 would give you an octave higher and 0.5 an octave lower).
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2010.02
Post: #3
So I would have to start off with a sample, of a guitar, piano, saw wave, square wave at C then change AL_PITCH Smile

Thanks, that's a great idea. as i was thinking of generating the full waveform proceduraly.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #4
Hard to give an easy/straight answer for this. What do you want to use this for?

If you just want to be able to play different notes of the same kind of tone using OpenAL, then as maximile suggested, the easiest is to just load a wav file of one tone, and then use alSourcef(source, AL_PITCH, (ALfloat)pitch); to vary the pitch. Yes, you can start with pretty much anything as you suggested, perhaps at C -- it doesn't matter too much what the starting pitch is, as long as you know what it is and can calculate from there.

If you want to generate (synthesize) your tone in place of the file then you will need to understand a little bit of trigonometry first, to understand simple things like period, frequency, amplitude, etc. Then also need to understand basic DSP concepts like sample rate and sample size. Further, do you just want to play a short sound, or do you want to stream your own audio data? If you want to stream then you can use a streaming buffer in OpenAL. Do you need lower-latency than that? If so, you can use RemoteIO instead.

How much DSP do you need to learn for what you eventually want to do? If you just want the most basic of basic, it's not real easy to gather information on that level, since most documentation assumes some fundamental DSP knowledge and math skills with it. See: What is the best way to learn DSP.

I'm guessing you'd rather not go to the deep depths. Maybe a simple little OpenAL example of this is all you're looking for?

How much do you already know about synthesis? How much math are you into? Did you know that all waveforms can theoretically be built up from sine waves?

As you can see, there are many different depths and directions you can take from your question!
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #5
I've been thinking of making a synth app myself and haven't done a lot of research yet, but I don't think OpenAL is the way to go. For one thing the spec says AL_PITCH is limited to 0.5 to 2.0, but the iPhone stretches way beyond those - that's an implementation detail you shouldn't rely on. You could use a new sample every octave but that could get hairy at the crossover points if you're doing stuff like pitch bending.

I bookmarked this open source iPhone synth a couple days ago but haven't had time to check it out: http://code.google.com/p/mobilesynth/

A quick glance suggests it feeds an AudioUnit with data from its crossplatform oscillators. That's pretty much the route I was thinking of taking, so this code should help out quite a bit Cool
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #6
Frank, you *could* use OpenAL to start a streaming buffer where you pump in your synthesized audio data.

Personally, I use RemoteIO instead, both on iPhone and Mac. Here's a quick example to set up the audio rendering on iPhone: http://www.idevgames.com/forum/showpost....ostcount=4

I haven't checked out that project yet, but thanks for the link Smile
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #7
AnotherJake Wrote:Frank, you *could* use OpenAL to start a streaming buffer where you pump in your synthesized audio data.

True enough - especially if you're mixing the synth with other (e.g. 3D) FX.

Thanks for that easy-to-follow example! Despite being a huge audio/MIDI geek I haven't done much with CoreAudio yet. That synth I mentioned seems to be doing pretty much the same thing.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenAL - loading and playing mp3 Ratty 6 8,384 Jun 12, 2008 12:01 AM
Last Post: OneSadCookie
  Playing A Note or Frequency (Quicktime or other) Joseph Duchesne 1 2,460 Sep 22, 2005 12:52 PM
Last Post: bassplayinMacFiend