Copyright © 2011-2023 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 Sound Editor API 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 having performed a recording session, we need to analyze the sound's waveform through the WaveformAnalyzer object so we need to perform a call to the WaveformAnalyzer.AnalyzeFullSound method. The analysis can be more or less accurate depending upon the resolution passed to the nResolution parameter of the WANALYZER_GENERAL_SETTINGS structure; higher resolutions will allow a better quality because more peaks will be detected: as a side effect, higher resolutions will require more memory; further details about sound's waveform analysis can be found inside the How to use the Waveform Analyzer tutorial.

 

Once the waveform analysis has been completed, 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 method, the waveform scroller would automatically update the waveform view to keep the current position updated.

 

The waveform scroller can also display eventual graphic items previously added to the waveform analyzer through one of the following methods:

 

WaveformAnalyzer.GraphicItemVerticalLineAdd method for vertical lines
WaveformAnalyzer.GraphicItemHorizontalLineAdd method for horizontal lines
WaveformAnalyzer.GraphicItemWaveRangeAdd method for wave ranges

 

You are free to decide which type of these graphic items you want to display, for example you could need displaying wave ranges only and omitting the rendering of vertical and horizontal lines; this behaviour can be set through the nGraphicItemsMask field of the WSCROLLER_SETTINGS data structure.

 

For further details about graphic items management you can refer to the How to add graphic items to the Waveform analyzer tutorial.

 

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 container application is informed about the new position through the CallbackWaveformScrollerManualScroll delegate set through the CallbackWaveformScrollerManualScrollSet method. 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 CallbackWaveformScrollerMouseNotif delegate set through the CallbackWaveformScrollerMouseNotifSet method.

 

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.

 

 

Samples of usage of the waveform scroller applied to the waveform analyzer in Visual C# and Visual Basic.NET can be found inside the following samples installed with the product's setup package:

- SoundEditor

- VolumeAutomation (available also in Unmanaged Visual C++ and Visual Basic 6)

- WaveformAnalyzer (available also in Unmanaged Visual C++ and Visual Basic 6)