Files
gameboy/audio_viewer.cpp
Raimon Zamora 03631bf235 - [NEW] audio viewer
- [FIX] Sampling rate pujat a 44100Hz, el aliasing quasi desapareix
- [NEW] Canals 2 i 3 implementats
- [FIX] El control de duració en els canals 1 i 2 era incorrecte
2025-01-29 19:33:13 +01:00

40 lines
1.1 KiB
C++

#include "audio_viewer.h"
#include <SDL2/SDL.h>
#define NUM_SAMPLES 256
#define MAX_VOLUME 256
namespace audio_viewer
{
SDL_Window *win = nullptr;
SDL_Renderer *ren = nullptr;
//SDL_Texture *tex = nullptr;
uint8_t buffer[NUM_SAMPLES];
uint8_t pos = 0;
uint8_t screen[NUM_SAMPLES*MAX_VOLUME];
void init()
{
win = SDL_CreateWindow("Audio viewer", 1, 1, 256, 256, SDL_WINDOW_SHOWN);
ren = SDL_CreateRenderer(win, -1, 0);
//tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 256, 256);
for (int i=0; i<NUM_SAMPLES; ++i) buffer[i] = 0;
}
void addsample(uint8_t sample)
{
buffer[pos] = sample;
pos = (pos+1)%NUM_SAMPLES;
}
void refresh()
{
SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
SDL_RenderClear(ren);
SDL_SetRenderDrawColor(ren, 255, 255, 255, 255);
for (int i=0; i<NUM_SAMPLES;++i) {
SDL_RenderDrawLine(ren, i, buffer[(pos+i)%NUM_SAMPLES], i+1, buffer[(pos+i+1)%NUM_SAMPLES]);
}
SDL_RenderPresent(ren);
}
}