/* 
    Spectrum Analyzer
    (C) 2007 Jason Hunt
    GPL

    file: display.cpp
*/

#include <windows.h>

#include "display.h"
#include "types.h"
#include "sound.h"

extern HWND main_win;                       // handel to main window
extern HDC main_dc;                         // main device context

double tmp_data[max_sample];

/* Update display */
void display(void)
{
    RECT r;

    GetClientRect(main_win, &r);

    int samples;

    copy_sample_data(tmp_data, samples);

    samples /= 4;   // Ignore upper half of data
     
    Rectangle(main_dc, r.left, r.top, r.right, r.bottom);

    MoveToEx(main_dc, 0, display_y, 0);

    // Graph results
    for (unsigned int x = 0; x < display_x; x++)
    {
        int index = (int)((x/(double)display_x) * samples);

        int sample = (int)tmp_data[index];
        
        if (sample > display_y-1) sample = display_y-1;
       
        int pos = (int)(display_y - sample); 

        LineTo(main_dc, x, pos);     
    }

    ValidateRect(main_win, NULL);
}
/* End of display */







