www.pudn.com > FREQUENCYANALYZER.rar > Views.cpp, change:2004-07-24,size:3123b


#include "views.h" 
#include "canvas.h" 
#include "fft.h" 
#include "recorder.h" 
 
COLORREF MapColor (int s) 
{ 
    if ( s < 16 ) 
        return RGB(0, 0, 128); 
    else if ( s < 32) 
        return RGB(0, 0, 255); 
    else if ( s < 64 ) 
        return RGB(0, 255, 0); 
    else if ( s < 128) 
        return RGB(255, 255, 0); 
    else if ( s < 256 ) 
        return RGB(255, 128, 0); 
    else 
        return RGB(255, 0, 0); 
} 
 
void ViewFreq::Clear () 
{ 
    if (Hwnd ()) 
    { 
        UpdateCanvas canvas (Hwnd ()); 
        ClientRect rect (Hwnd ()); 
        canvas.ClearBlack(rect); 
    } 
} 
 
void ViewFreq::Update (Fft const &fftTransformer) 
{ 
    UpdateCanvas canvas (Hwnd ()); 
    ClientRect rect (Hwnd ()); 
 
    { 
        // Erase background for current spectrum 
        BlackPen pen(canvas); 
        canvas.Line (_xRecord, 0, _xRecord, rect.bottom); 
        canvas.Line (_xRecord + 1, 0, _xRecord + 1, rect.bottom); 
    } 
 
    for (int i = 0;  
             i < fftTransformer.Points() / 2 && i < rect.bottom;  
             i++ ) 
    { 
        int s = int (fftTransformer.GetIntensity(i) / 256); 
         
        COLORREF color; 
        if (s > 8) 
        { 
            color = MapColor (s); 
 
            canvas.Point (_xRecord, rect.bottom - i - 1, color); 
            canvas.Point (_xRecord + 1, rect.bottom - i - 1, color); 
        } 
    } 
 
    _xRecord += 2; 
    if (_xRecord >= rect.right) 
        _xRecord = 0; 
 
    { 
        // Draw white vertical mark 
        WhitePen pen(canvas); 
        canvas.Line (_xRecord, 0, _xRecord, rect.bottom); 
    } 
} 
 
void ViewFreq::Fake () 
{ 
    UpdateCanvas canvas (Hwnd ()); 
    ClientRect rect (Hwnd ()); 
 
    { 
        // Erase background for current spectrum 
        BlackPen pen(canvas); 
        canvas.Line (_xRecord, 0, _xRecord, rect.bottom); 
        canvas.Line (_xRecord + 1, 0, _xRecord + 1, rect.bottom); 
    } 
 
 
    _xRecord += 2; 
    if (_xRecord >= rect.right) 
        _xRecord = 0; 
 
    { 
        // Draw white vertical mark 
        WhitePen pen(canvas); 
        canvas.Line (_xRecord, 0, _xRecord, rect.bottom); 
    } 
} 
 
void ViewWave::Update (Fft const &fftTransformer) 
{ 
    UpdateCanvas canvas (Hwnd ()); 
    ClientRect rect (Hwnd ()); 
    canvas.ClearBlack(rect); 
    int cMaxPoints = min (fftTransformer.Points(), _poly.Points()); 
    for ( int i = 0; i < cMaxPoints; i++ ) 
    { 
        int s  = fftTransformer.Tape(i) / 512 + (rect.bottom - 1) / 2; 
		 
		// 
	    int ns = -fftTransformer.Tape(i) / 512 + (rect.bottom - 1) / 2; 
 
        if (i >= rect.right) 
        { 
            _poly.Add( i, rect.right - 1, (rect.bottom - 1) / 2); 
        } 
        else 
        { 
            if ( s < 0 ) 
			{ 
                _poly.Add (i, i, 0);							 
			} 
            else if (s >= rect.bottom) 
			{ 
                _poly.Add (i, i, rect.bottom - 1);				 
			} 
            else 
			{ 
                _poly.Add (i, i, s);				 
			} 
 
		 
 
 
        } 
    } 
 
    PenHolder pen (canvas, _penGreen);	 
    _poly.Paint (canvas, cMaxPoints);	 
}