summaryrefslogtreecommitdiff
path: root/audiotest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'audiotest.cpp')
-rw-r--r--audiotest.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/audiotest.cpp b/audiotest.cpp
index f6b5a92..81c6d84 100644
--- a/audiotest.cpp
+++ b/audiotest.cpp
@@ -1,6 +1,7 @@
//emcc -o test.html main.cpp -O2 -s USE_SDL=2
#include <stdlib.h>
+#include <iostream>
#if defined(_MSC_VER)
#include "SDL.h"
@@ -16,19 +17,33 @@
#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++)
+ for (i = 0; i < samples*2; i+=2)
{
- buf[i] = i * 655;
+ 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;
@@ -43,6 +58,11 @@ int sdlstatic_init(unsigned int aSamplerate, unsigned int aBuffer)
{
return -1;
}
+ std::cout << "desired:" << std::endl;
+ show_AudioSpec(&as);
+ std::cout << "obtained:" << std::endl;
+ show_AudioSpec(&as2);
+
SDL_PauseAudio(0);
@@ -77,13 +97,12 @@ void mainloop()
int main(int argc, char *argv[])
{
- printf("SDL INIT OK\n");
if ( SDL_Init(SDL_INIT_EVERYTHING) < 0 )
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
- printf("SDL INIT OK\n");
+ std::cout << "SDL INIT OK" << std::endl;
atexit(SDL_Quit);