How to obtain the waveform bitmap of the latest recording session
The first step is to perform the sound's analysis through a call to the
WaveformAnalyzer.AnalyzeFullSound method: the analysis can be more or less accurate depending upon the resolution set into the
nResolution property of the
WAVEFORM_ANALYZER_SETTINGS class: higher resolutions will allow a better quality because more peaks will be detected: as a side effect, higher resolutions will require more memory and will generate larger bitmaps. When the results of an analysis are no more needed, the involved memory can be released through a call to the
WaveformAnalyzer.FreeMemory method.
After calling this method, the control will allow the container application to stay up-to-date about the analysis advancement through the following events:
WaveAnalysisPerc: fired several times during the analysis in order to inform the container application about the percentage of advancement.
After catching the
WaveAnalysisStop event, it will be possible requesting to the control the creation of the waveform's bitmap through a call to the
WaveformAnalyzer.CreateFileBitmapView and
WaveformAnalyzer.CreateMemoryBitmapView methods. It's important to note that the
WaveAnalysisStop event will report the exact number of peaks detected inside the loaded sound and the exact duration in milliseconds of each peak. When generating the bitmap for the full sound's waveform, the reported number of peaks will be exactly equal to the width in pixels of the bitmap. In case you should create a view of a given sound's range, you could obtain the number of pixels needed to display the waveform's view through a call to the
WaveformAnalyzer.GetBitmapViewWidth method.
The generated waveform's bitmap will be rendered using colors set into the
colorWaveLine and
colorWaveBackground properties of the
WAVEFORM_ANALYZER_SETTINGS class.
Below you can see five bitmaps generated using the same sound (whose duration is around 2.4 seconds length) but with five different resolutions (just for your information the song used for generating these bitmaps is available on this
link); all these bitmaps have been created using the same height of 100 pixels:
|
Resolution set into the nResolution property
|
Generated bitmap
|
|
|
|
|
WAVEANALYZER_RES_MAXIMUM
|
|
|
WAVEANALYZER_RES_VERY_HIGH
|
|
|
WAVEANALYZER_RES_HIGH
|
|
|
WAVEANALYZER_RES_MIDDLE
|
|
|
WAVEANALYZER_RES_LOW
|
|
As mentioned before, you can also generate a "view" of a defined portion of the loaded sound: on the bitmap below you can see the original song in its full length (with WAVEFORM_RES_MAXIMUM resolution)
and below you can see the view of the same song for the range between 500 and 1500 milliseconds
On the samples above we have used a very small song limited to 2.4 seconds: in case you should be in need of displaying the full waveform of a longer song on a space much smaller than the total number of required pixels, the
WaveformAnalyzer.CreateFileBitmapView and
WaveformAnalyzer.CreateMemoryBitmapView methods will shrink the waveform in order to fit exactly inside the available space; in the example below you can see a 3 minutes song fitting inside a 455 pixels wide bitmap: the original full length bitmap, using the WAVEFORM_RES_MAXIMUM resolution, would require a width of 243,683 pixels.
VERY IMPORTANT: When using high resolutions and big sound files, keep count that the Windows operating system has limits on the size of bitmaps creation; this means that it would be better avoiding the creation of very large bitmaps: in this case it would be a better approach splitting the total song's bitmap into several smaller bitmaps, for example creating bitmaps whose width in pixels doesn't exceed the current screen width.