0

I tried to create bars, but the output is just bars, and I want to move the bars up and down like a visual equalizer, but I don't know the exact code for that. Does anyone know it?

Here's a picture:

And my attempt:

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#include <graphics.h>

void main(){
    int gd = DETECT, gm;
    initgraph(&gd,&gm, “D:\\TC\\BGI”);
    randomize();
    int x = 100;
    int y,a; 
    setfillstyle(2,GREEN);

    do{
        delay(100);
        y = random(150);
        if ((200-y) >=a){ 
            setfillstyle(2,BLACK);
            bar (x,200-y,x+20,a); 
        } 
        else { 
            bar (x,200,x+20,200-y); 
        }  
        a = 200-y; 
    }
    while(!kbhit());
    getch(); 
    closegraph(); 
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • well with `random` input this will be hard to achieve. because without initializing seed each frame it would flicker a lot and with it it will be static. For smooth simulation you can create set of random sinwaves at start and then just iterate them each frame ... Another option would be use your current implementation and interpolate between states over time ... – Spektre Aug 07 '17 at 08:15

1 Answers1

0

You should do this repetitively in your main loop:

  1. compute position of bars

    You did not provide any info of the input nor output. mixer device mix more signals together and equalizer is array of adjustable bandpass filters. So what the bars represent?

    if they are the filters GUI for setting the band pass filters then you need to add interface for them for example "move" them with mouse or something. for that we need more info ...

    If the bars represents spectrogram then you need to do the DFT on some input signal window which is moving with time.

  2. clear buffer

    this is called back buffering or double buffering. If I remember correctly BGI can do this. The idea is to render into memory to avoid flickering and when the image s complete then copy it to screen.

  3. render bars to buffer

    this part you claim you have already implemented so no need for explanations.

  4. render buffer to screen

    This is the last step of back/double buffering to avoid flickering

  5. wait/sleep for some time

  6. detect exit condition

    if active then stop the loop otherwise go to #1 again ...

If you want to make a mouse GUI then you need to add mouse event handlers. I think there was some libs for that in Borland Turbo C++ but in case I am mistaken you can use INT 33h to periodically scan the mouse state on your own via polling (which is far from ideal but will work for starters) or hook up your own mouse handler.

Here some related stuff to read:

Spektre
  • 49,595
  • 11
  • 110
  • 380