SUZUKI PLAN - Video Game System - Sound Processing Unit
Abstracts the following sound APIs:
- DirectSound (Windows)
- OpenSL/ES (Android)
- OpenAL (MacOSX and iOS)
- ALSA; Advanced Linux Sound Architecture (Linux)
- start
- callback
- end
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <stdio.h>
#include "vgsspu.h"
#ifdef _WIN32
static void usleep(int usec)
{
Sleep(usec / 1000);
}
#endif
static unsigned int hz;
static unsigned int pw = 22050;
static void buffering(void* buffer, size_t size)
{
short* sbuf = (short*)buffer;
size_t s2 = size >> 1;
size_t s1;
for (s1 = 0; s1 < s2; s1++, sbuf++, hz++) {
if (hz % 50 < 25) {
*sbuf = (short)((16384 * pw) / 22050);
} else {
*sbuf = (short)((-16384 * pw) / 22050);
}
if (pw) pw--;
}
}
int main(int argc, char* argv[])
{
void* context = vgsspu_start(buffering);
if (NULL == context) {
puts("failed");
return -1;
}
usleep(1000000);
vgsspu_end(context);
return 0;
}
void* vgsspu_start(void (*callback)(void* buffer, size_t size));
void* vgsspu_start2(int sampling, int bit, int ch, size_t size, void (*callback)(void* buffer, size_t size));
NOTE: vgsspu_start
specifies 22050Hz, 16bit, 1ch and 4410 bytes as size.
sampling
: sampling rate (48000, 44100, 22050, 11025, 8000 etc)bit
: bit rate (24, 16, 8 etc)ch
: number of channel (1:monoral, 2:stereo)size
: size of buffercallback
: buffering callback
!NULL
: context (succeed)NULL
: failed
void vgsspu_end(void* context)
context
: context