Another Spectrum Board






4.78/5 (14 votes)
Oct 17, 2003
1 min read

83187

2771
MFC Spectrum Board control
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 orOnInitialUpdate()
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 // 2 blocks
Description of each constant
SPASI_ANTAR_CELL
is the blank space between cells/blocks in the spectrum boardPEAK_DROP_SPEED
is the gravitation value for the peaksPEAK_HEIGHT
is height of the peaks in pixelMAX_PEAK_LIVE_TIME
is the number to suspend peaks before get affected by gravitationPEAK_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!