Introduction
This is another simple Spectrum/Bar Histogram control which can be easily incorporated in your multimedia project or something similar. They usually display an array of FFT generated value from decoded PCM sequence value of compressed audio data.
How to use it
There are only few steps to use this control:
- Include two files, SpectrumCtrl.h and SpectrumCtrl.cpp in your project
- Create a Picture box (Frame) in your form/dialog
- Change it's ID to whatever you want
- Include SpectrumCtrl.h in the class declaration of your form/dialog
- Put this in your dialog/form class:
CSpectrumCtrl m_spectrumboard;
- Create an instance of
CSpectrumCtrl
class in your applicationCWnd *m_pWnd;
- Initialize the control, usually within
OnInitDialog()
in dialog or OnInitialUpdate()
in form:m_pWnd = (CWnd*) GetDlgItem(IDC_STATIC_PICTURE_BOX_ID);
m_spectrumboard.Create(JUMLAH_ELEMENT_ARRAY, 20, &CSize(4, 1),
WS_VISIBLE | WS_CHILD | WS_TABSTOP, m_pWnd, this, 1000);
CSize(4, 1)
means the size of the block/cell element in the spectrum board is 4 pixel width and 1 pixel height
- Call the following method to visualize an integer array:
m_spectrum.DisplayArray(iPtrNilai);
You can modify the following constants in the source code for visual appearance customization:
#define SPASI_ANTAR_CELL 1
#define PEAK_DROP_SPEED 1
#define PEAK_HEIGHT 1
#define MAX_PEAK_LIVE_TIME 7
#define PEAK_TOLERANT 2
Description of each constant
SPASI_ANTAR_CELL
is the blank space between cells/blocks in the spectrum board
PEAK_DROP_SPEED
is the gravitation value for the peaks
PEAK_HEIGHT
is height of the peaks in pixel
MAX_PEAK_LIVE_TIME
is the number to suspend peaks before get affected by gravitation
PEAK_TOLERANT
is the restricted blocks/cells area at top of the spectrum board
Conclusion
This class will have it's own window size by modifying your picture box place holder at run-time. Cheers!