#include #include "tonegen.h" #include "audio.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_Window *sdlWindow = nullptr; SDL_Renderer *sdlRenderer = nullptr; SDL_Texture *sdlTexture = nullptr; SDL_AudioSpec audioSpec{SAMPLES_PER_SECOND, AUDIO_FORMAT, 1, 0, 512, 0, 0, NULL, NULL}; void draw_char(const uint8_t character, const int x, const int y) { SDL_Rect src {((character-32)%16)*4, ((character-32)/16)*5, 4, 5}; SDL_Rect dst {x, y, 4, 5}; SDL_RenderCopy(sdlRenderer, sdlTexture, &src, &dst); } void draw_string(const char* str, int x, const int y) { const int l = strlen(str); for (int i = 0; i < l; ++i) { draw_char(str[i], x, y); x += 5; } } 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