Copyright © 2005-2019 MultiMedia Soft

How to scroll the sound's waveform during playback

Previous pageReturn to chapter overviewNext page

Many multimedia applications allow displaying a waveform scroller whose purpose is to scroll the waveform during playback and to keep the current position centered on the scrolling waveform, with a vertical line that indicates the effective playback position; the screenshot below shows a song's waveform when playback position is 0, meaning that the sound is stopped or paused:

 

 

the screenshot below shows a song's waveform when playback position is 5 seconds:

 

 

Audio DJ Studio for .NET allows implementing a scrolling waveform through the embedded WaveformScroller object accessible through the WaveformScroller property.

 

In order to create a scrolling waveform we need to call the WaveformScroller.Create method and then we need to set how many milliseconds of waveform will be displayed inside the waveform's view: by default this value is set to 10 seconds (5 seconds on the right of the vertical line and 5 seconds on the left of the vertical line) but it can be modified at any time through the WaveformScroller.SetViewLength method.

 

Graphical settings related to a specific waveform scroller can be retrieved and modified through the WaveformScroller.SettingsGet and WaveformScroller.SettingsSet methods: both of them receive in input a WSCROLLER_SETTINGS data structure. You can also set a background picture to be displayed under the waveform through the WaveformScroller.SetBackPictureFromFile and WaveformScroller.SetBackPictureFromHandle methods.

 

At this point, after loading a sound inside a player, through one of the many methods having the "Load" prefix like LoadSound or LoadSoundFromMemory or LoadTrackFromCd methods, we need to analyze the sound's waveform through the Waveform class so we need to perform a call to the Waveform.AnalyzeFullSound method. The analysis can be more or less accurate depending upon the resolution passed to the nResolution parameter; higher resolutions will allow a better quality because more peaks will be detected: as a side effect, higher resolutions will require more memory.

 

Once the waveform analysis has been completed and the WaveAnalysisDone event has been received, the WaveformScroller object will automatically display the waveform of the sound with the current playback position centered and displayed by a vertical line, exactly as seen on the screenshot above. In case playback should be started through the PlaySound method or in case the current playback position should be moved through the SeekSound or ForwardSound or RewindSound methods, the waveform scroller would automatically update the waveform view to keep the current position updated.

 

The waveform scroller can also display custom vertical lines added to the waveform's view through the Waveform.BitmapViewVerticalLineAdd method. Below an example of two vertical lines, rendered in red color, when the current center position of the bitmap view is set to 5000 ms.

 

 

Below the same exact red lines when the current center position has been moved to 6000 ms.

 

 

 

The waveform scroller supports direct mouse interaction: through the left button of your mouse you can modify the current position by pressing the left button, moving the mouse horizontally and finally by releasing the button when the needed playback position is reached. During playback, pressing the left mouse button will also put the player in paused state; by releasing the mouse playback will be automatically resumed.

 

When playback position is moved through the mouse, the control fires the WaveScrollerManualScroll event that notifies the container application about the new position. As a further feature, any mouse event generated on the waveform scroller, for example when the right mouse button is clicked, will be notified to the container application through the WaveformScrollerMouseNotification event.

 

By default, during the waveform scrolling the sound is muted: you can modify this behaviour through the WaveformScroller.PlaybackOnScrollEnable method: when playback is enabled, the control will render audio data at the same rate of the scrolling speed.

 

 

Examples of usage of the waveform scroller can be seen inside the DjStudioDemo and WaveformScroll samples.