Playing a Note
(tip: Sound & Music programming forum)
How would I play a single note (like in a MIDI-file) without playing the whole MIDI-file?
.lick
Depends on how you want to play it.
If you''re going to play a single note, it might be easiest to generate it procedurally (procedural sound! yay!)
A simple sound is just a sine wave. All you have to do is adjust the frequence and amplitude of it, and you''ve got your sound. Most sound APIs have a feature by which you provide a callback function that it calls each frame, and that function works out the numerical value of the sample.
Something along the lines of
thisSample = amplitude * sin( timeSinceSoundStart * frequency)
would generate a fairly simple sine wave, I think.
Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
If you''re going to play a single note, it might be easiest to generate it procedurally (procedural sound! yay!)
A simple sound is just a sine wave. All you have to do is adjust the frequence and amplitude of it, and you''ve got your sound. Most sound APIs have a feature by which you provide a callback function that it calls each frame, and that function works out the numerical value of the sample.
Something along the lines of
thisSample = amplitude * sin( timeSinceSoundStart * frequency)
would generate a fairly simple sine wave, I think.
Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement