Поделиться через


Using Timed Levels

[The feature associated with this page, Windows Media Player SDK, is a legacy feature. It has been superseded by MediaPlayer. MediaPlayer has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer instead of Windows Media Player SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The TimedLevel structure is composed of two two-dimensional arrays, a state value, and a time stamp value.

Frequency Array

The frequency array is a two-dimensional array. The first dimension of each array corresponds to the stereo audio channel (left or right), and the second corresponds to the frequency levels (in bytes) of the snapshot, where the audio spectrum is divided up into 1024 regions.

You can get the frequency array data supplied from the Windows Media Player in the following manner:

TimedLevel *pLevels;
int snapshot = pLevels->frequency[0][0];

The value of snapshot is for the left channel and contains the value of the lowest part of the frequency spectrum. For example, if snapshot has a large value, it indicates that the lowest 1024th part of the frequency spectrum is rich in frequency. A value of zero indicates no low frequency values in that part of the spectrum for the left channel. If you have a monophonic signal, only the first dimension has valid values.

If the signal is non-stereo, then the second array will contain a copy of the mono signal. That is, frequency[0][n] and frequency[1][n] will contain the same data, where n is the index into a particular cell.

Waveform Array

The waveform array is also a two-dimensional array. The first dimension of the array corresponds to the channel (left or right), and the second corresponds to the power levels (in bytes) of the snapshot, where the audio power is broken up into 1024 contiguous time segments.

You can get the waveform array data from Windows Media Player in the following manner:

TimedLevel *pLevels;
int snapshot = pLevels->waveform[0][0];

The value of snapshot is for the left channel and contains the first value of the quantized snapshot of the power values. When a snapshot is taken, it consists of 1024 tiny incremental measurements of the audio power. The lowest value of the array is generated by the first incremental measurement of audio power. Note that the values of the power are measured from -128 to +127 but the values in the array range from 0 to 255. If you have a monophonic wave, only the first dimension will have valid values.

If the signal is non-stereo, then the second array will contain a copy of the mono signal. That is, waveform[0][n] and waveform[1][n] will contain the same data, where n is the index into a particular cell.

State

The state variable reflects the audio playback state of Windows Media Player. The PlayerState enumeration values are

    stop_state              = 0,    // audio is currently stopped
    pause_state             = 1,    // audio is currently paused
    play_state              = 2     // audio is currently playing

You can use this variable to take different actions depending on the audio playback state. For example, you can play one kind of visualization when the audio is playing and another when it is stopped.

Time Stamp

The timeStamp variable reflects the current time when the snapshot is taken. This can be used to measure how frequently the snapshots are taken.

You can use this variable to time your animations. If the snapshots are too frequent, you can gracefully degrade your image to display in the manner you choose.

Implementing Render