Changing the Pitch of Waveforms

DirectMusic

Microsoft DirectX 9.0 SDK Update (Summer 2004)

Changing the Pitch of Waveforms

Several techniques can be used to change the pitch of a waveform programmatically.

If you are playing the waveform as a segment, you can obtain the DirectSound buffer through which it is playing and use the IDirectSoundBuffer8::SetFrequency method to change the pitch. Because a pitch change affects all sounds playing through a buffer, you should play the sound on its own audiopath, or its own mix group within an audiopath. Different buffers within a mix group cannot have different frequencies. (For information on mix groups, see the Help for DirectMusic Producer.)

This technique does not work well with looping segments. Because the performance does not take into account the actual time it takes for the sound to finish playing in the buffer, looping continues to happen at intervals based on the normal length of the sound. When the pitch is lower than the original pitch of the sound, the whole sound does not play before it loops; when the pitch is higher than the original, intervals of silence occur between loops. If the entire sound is looping, you can adjust the intervals by using IDirectMusicSegment8::SetLength before playing the segment; however, calling this method while the segment is playing will have unpredictable results.

Another technique is to set a MIDI pitch bend on the performance channel on which the sound is playing. To do so, send a DMUS_MIDI_PMSG message, specifying 0xE0 as the status byte. The lower seven bits of the two data bytes are combined as a 14-bit value, where 0x2000 specifies no pitch bend, lower values represent a lower pitch, and higher values represent a higher pitch. For more information, see the MIDI specification.

Perhaps the most effective way to control the pitch is to play the waveform as a DLS instrument created in DirectMusic Producer. You can use the same WAV sound as the sample for all regions (note ranges), or assign different sounds to different regions for more realistic effects. You can also create articulations such as volume envelopes to make the sound start and stop in a more natural way. To play the sound at different pitches in your application, start and stop different notes by sending DMUS_NOTE_PMSG messages.

See Also


© 2004 Microsoft Corporation. All rights reserved.