119 lines
5.6 KiB
C++
Executable File
119 lines
5.6 KiB
C++
Executable File
#include <SDL2/SDL.h>
|
|
#include "tonegen.h"
|
|
#include "audio.h"
|
|
#include "draw.h"
|
|
|
|
#define SOUND_DURATION 0.25f
|
|
#define SOUND_NUM_SAMPLES SOUND_DURATION*SAMPLES_PER_SECOND
|
|
#define SOUND_SIZE_IN_BYTES SOUND_NUM_SAMPLES*AUDIO_FORMAT_SIZE
|
|
|
|
SDL_AudioSpec audioSpec{SAMPLES_PER_SECOND, AUDIO_FORMAT, 1, 0, 512, 0, 0, NULL, NULL};
|
|
|
|
int main(int argc, char* argv[]) {
|
|
SDL_Init(SDL_INIT_EVERYTHING);
|
|
SDL_AudioDeviceID sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
|
|
|
AUDIO_FORMAT_TYPE beeps[int(SOUND_NUM_SAMPLES*8)];
|
|
AUDIO_FORMAT_TYPE beeps2[int(SOUND_NUM_SAMPLES*8)];
|
|
AUDIO_FORMAT_TYPE *pointer = beeps;
|
|
|
|
toneGen tonegen(SOUND_NUM_SAMPLES);
|
|
|
|
tonegen.setup(22, CHIPTUNE_INSTRUMENT_TRIANGLE, 13, CHIPTUNE_EFFECT_DROP);
|
|
int numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(32, CHIPTUNE_INSTRUMENT_SQUARE, 0, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(32, CHIPTUNE_INSTRUMENT_NOISE, 4, CHIPTUNE_EFFECT_FADEOUT);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(32, CHIPTUNE_INSTRUMENT_SQUARE, 0, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(22, CHIPTUNE_INSTRUMENT_TRIANGLE, 13, CHIPTUNE_EFFECT_DROP);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(22, CHIPTUNE_INSTRUMENT_TRIANGLE, 13, CHIPTUNE_EFFECT_DROP);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(32, CHIPTUNE_INSTRUMENT_NOISE, 4, CHIPTUNE_EFFECT_FADEOUT);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(32, CHIPTUNE_INSTRUMENT_SQUARE, 0, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
|
|
pointer = beeps2;
|
|
tonegen.setup(35, CHIPTUNE_INSTRUMENT_SQUARE, 1, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(37, CHIPTUNE_INSTRUMENT_SQUARE, 1, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(39, CHIPTUNE_INSTRUMENT_SQUARE, 1, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(40, CHIPTUNE_INSTRUMENT_SQUARE, 1, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(42, CHIPTUNE_INSTRUMENT_SQUARE, 1, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(44, CHIPTUNE_INSTRUMENT_SQUARE, 1, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(46, CHIPTUNE_INSTRUMENT_SQUARE, 1, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
tonegen.setup(47, CHIPTUNE_INSTRUMENT_SQUARE, 1, CHIPTUNE_EFFECT_NONE);
|
|
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, pointer); pointer += int(SOUND_NUM_SAMPLES);
|
|
|
|
for (int i=0; i<SOUND_NUM_SAMPLES*8;++i) {
|
|
beeps[i] += beeps2[i];
|
|
}
|
|
|
|
draw_init();
|
|
draw_clear(color_dark_grey);
|
|
draw_fill(3, 14, 138, 225, color_black);
|
|
draw_inset(2, 13, 35, 226, color_light_peach, color_dark_blue);
|
|
draw_inset(37, 13, 35, 226, color_light_peach, color_dark_blue);
|
|
draw_inset(72, 13, 35, 226, color_light_peach, color_dark_blue);
|
|
draw_inset(107, 13, 35, 226, color_light_peach, color_dark_blue);
|
|
draw_dotted(4, 71, 35, color_lavender);
|
|
|
|
int xp = 4, yp = 15;
|
|
for (int x=0; x<4; ++x) {
|
|
yp = 15;
|
|
for (int y=0; y<32; ++y) {
|
|
if (x==0 && y==0) {
|
|
draw_string("G#", xp, yp, color_white);
|
|
draw_char('1', 10+xp, yp, color_light_grey);
|
|
draw_char('5', 16+xp, yp, color_pink);
|
|
draw_char('2', 21+xp, yp, color_blue);
|
|
draw_char('3', 26+xp, yp, color_lavender);
|
|
} else {
|
|
draw_string("...", xp, yp, color_dark_blue);
|
|
draw_string("...", 16+xp, yp, color_dark_blue);
|
|
}
|
|
yp += 7;
|
|
if ((y%8)==7) {
|
|
draw_dotted(xp, yp, xp+31, color_lavender);
|
|
yp++;
|
|
}
|
|
}
|
|
xp += 35;
|
|
}
|
|
//draw_string("......", 4, 15, color_dark_blue);
|
|
//draw_string("......", 38, 15, color_dark_blue);
|
|
/*int last_x = 0, last_y = 120;
|
|
for (int x=0; x<1102; ++x) {
|
|
int y = 700 - (350+300*(float(beeps[x*10])/float(AUDIO_FORMAT_MAX_VALUE)));
|
|
SDL_RenderDrawLine(sdlRenderer, x, y, last_x, last_y);
|
|
last_x = x; last_y = y;
|
|
}*/
|
|
|
|
//draw_string("HOLA", 11, 11, color_black);
|
|
//draw_string("HOLA", 10, 10, color_white);
|
|
draw_present();
|
|
|
|
//SDL_QueueAudio(sdlAudioDevice, &beeps[0], SOUND_SIZE_IN_BYTES*8);
|
|
//SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
|
|
|
bool exit = false;
|
|
SDL_Event sdlEvent;
|
|
while (!exit) {
|
|
while (SDL_PollEvent(&sdlEvent)) {
|
|
if (sdlEvent.type == SDL_QUIT) { exit = true; break;}
|
|
}
|
|
}
|
|
|
|
draw_quit();
|
|
SDL_Quit();
|
|
return 0;
|
|
} |