Partager via


Changing the Pitch and Playback Rate

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

Some waveform audio I/O devices can vary the pitch and the playback rate of waveform audio data. As with other device capabilities, you can query your waveform audio I/O device by using the waveOutGetDevCaps function to determine if your device supports either of these capabilities.

The following table describes the functions that you can use to query and set the waveform audio pitch and playback rate.

Function Description

waveOutGetPitch

Retrieves the pitch for the specified waveform audio output device.

waveOutGetPlaybackRate

Retrieves the playback rate for the specified waveform audio output device.

waveOutSetPitch

Sets the pitch for the specified waveform audio device.

waveOutSetPlaybackRate

Sets the playback rate for the specified waveform audio output device.

These functions change the pitch and the playback rate by a factor that is specified with a fixed-point number that is packed into a DWORD value. The upper 16 bits specify the integer part of the number; the lower 16 bits specify the fractional part of the number. A value of 0x8000 in the low-order word represents one-half, and 0x4000 represents one-quarter. The following table shows three examples of this style of packaging.

Value Packaged value

1.5

0x00018000L

0.75

0x0000C000L

1.0

0x00010000L

A value of 1.0 means that the pitch or playback rate is unchanged.

If your application relies on floating point values for its pitch and playback rate controls, you can create a macro to convert your floating point values to the 16.16 fixed point values used by these functions. The following code shows one way to set the playback rate in this manner.

#define FL2FX(x) ((ULONG) (32768.0 * (x)))

// set playback rate using a floating point multiplier
MMRESULT SetRate(HWAVEOUT hwo, double rate)
{
   return waveOutSetPlaybackRate(hwo, FL2FX(rate));
} 

Although changing the pitch and changing the playback rate seem similar to the user, they are implemented quite differently. Because the device driver controls the playback rate, altering the playback rate does not require any specialized hardware. However, the driver does not change the sample rate. Instead, the driver skips or synthesizes samples. For example, the driver could skip every other sample if an application changed the playback rate by a factor of two. In contrast, changing the pitch requires specialized hardware. When an application alters the pitch, the application does not alter specifically the playback or the sample rate.

See Also

Concepts

Playing Waveform Audio Files