Skip to content

suzukiplan/vgs-spu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[WIP] VGS SPU

SUZUKI PLAN - Video Game System - Sound Processing Unit

License

The BSD 2-Clause License

Description

Abstracts the following sound APIs:

  • DirectSound (Windows)
  • OpenSL/ES (Android)
  • OpenAL (MacOSX and iOS)
  • ALSA; Advanced Linux Sound Architecture (Linux)

How to use

  • start
  • callback
  • end

Example

sounds about 440Hz square wave 1sec

#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;
}

Start

prototyping

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.

arguments

  • 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 buffer
  • callback : buffering callback

return value

  • !NULL : context (succeed)
  • NULL : failed

End

prototyping

void vgsspu_end(void* context)

arguments

  • context : context

About

SUZUKI PLAN - Video Game System - Sound Processing Unit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published