diff options
| author | miguel <miguel@localhost> | 2017-09-23 23:03:21 +0200 |
|---|---|---|
| committer | miguel <miguel@localhost> | 2017-09-23 23:03:21 +0200 |
| commit | dc71cc317b960c5320cdd00171e4d1b37d4144bd (patch) | |
| tree | 7c9e4ae5b754be599e17fbb09be6dc81b43fd986 | |
| parent | 32c0cacac2f30047908643c9c83e7658233eb104 (diff) | |
added noise stuff and removed some old audiotest
| -rw-r--r-- | audiotest.cpp | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/audiotest.cpp b/audiotest.cpp deleted file mode 100644 index 81c6d84..0000000 --- a/audiotest.cpp +++ /dev/null @@ -1,120 +0,0 @@ -//emcc -o test.html main.cpp -O2 -s USE_SDL=2 - -#include <stdlib.h> -#include <iostream> - -#if defined(_MSC_VER) -#include "SDL.h" -#else -#include "SDL2/SDL.h" -#endif - -#include <math.h> -#include <stdio.h> - -#ifdef __EMSCRIPTEN__ -#include "emscripten.h" -#endif - - -void audiomixer(void *userdata, Uint8 *stream, int len) -{ - static int sample=0; - int volume=15000; - - int samples = len / 4; - short *buf = (short*)stream; - - int i; - for (i = 0; i < samples*2; i+=2) - { - buf[i]=buf[i+1] = volume*sin(sample*440/4410/2); - if((sample/44100)%2==1)buf[i]=buf[i+1]=0; - buf[i]+=volume*sin(sample*261/4410/2); - sample++; - } -} - -void show_AudioSpec(SDL_AudioSpec *as) -{ - std::cout << as->freq << std::endl; - std::cout << as->format << std::endl; - std::cout << as->channels << std::endl; - std::cout << as->samples << std::endl; - std::cout << as->callback << std::endl; -} - -int sdlstatic_init(unsigned int aSamplerate, unsigned int aBuffer) -{ - SDL_AudioSpec as; - as.freq = aSamplerate; - as.format = AUDIO_S16; - as.channels = 2; - as.samples = aBuffer; - as.callback = audiomixer; - - SDL_AudioSpec as2; - if (SDL_OpenAudio(&as, &as2) < 0) - { - return -1; - } - std::cout << "desired:" << std::endl; - show_AudioSpec(&as); - std::cout << "obtained:" << std::endl; - show_AudioSpec(&as2); - - - SDL_PauseAudio(0); - - return 0; -} - -void mainloop() -{ - // Poll for events, and handle the ones we care about. - SDL_Event event; - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_KEYUP: - // If escape is pressed, return (and thus, quit) - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - { - exit(0); - } - break; - } - break; - case SDL_QUIT: - SDL_CloseAudio(); - exit(0); - } - } -} - -int main(int argc, char *argv[]) -{ - if ( SDL_Init(SDL_INIT_EVERYTHING) < 0 ) - { - fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); - exit(1); - } - std::cout << "SDL INIT OK" << std::endl; - - atexit(SDL_Quit); - - sdlstatic_init(44100, 1024); - -#ifdef __EMSCRIPTEN__ - emscripten_set_main_loop(mainloop, 60, 0); -#else - while (1) - { - mainloop(); - } -#endif - return 0; -} |
