summaryrefslogtreecommitdiff
path: root/sys/src/games
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2014-04-12 22:25:26 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2014-04-12 22:25:26 +0200
commitd2618d03f5e17c3deed916e56b5e4f282dc093f2 (patch)
treeadad8b639ed602abcca746da364ae0133b126075 /sys/src/games
parent4ae2015d865a481829b949a171c055c3ec22fa98 (diff)
games/snes: upsample audio to 44100 hz instead of setting audio device frequency
used to set audio device frequency thru /dev/volume tho only ac97 driver supports this. as a quick work arround, upsample the 32000 hz audio signal to 44100 hz (without any interpolation). move the sample buffer room check from audiosample() into dspstep() so that when the buffer is full (shouldnt happen), we wont advance dspstate so samples will not get dropped.
Diffstat (limited to 'sys/src/games')
-rw-r--r--sys/src/games/snes/dsp.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/sys/src/games/snes/dsp.c b/sys/src/games/snes/dsp.c
index 0351d1c01..5ccdb97e6 100644
--- a/sys/src/games/snes/dsp.c
+++ b/sys/src/games/snes/dsp.c
@@ -42,31 +42,30 @@ enum {
enum { RELEASE, ATTACK, DECAY, SUSTAIN };
+enum { Freq = 44100 };
static s16int sbuf[2*2000], *sbufp;
+static int stime;
static int fd;
void
audioinit(void)
{
- int cfd;
- static char c[] = "speed 32000";
-
fd = open("/dev/audio", OWRITE);
if(fd < 0)
- return;
- cfd = open("/dev/volume", OWRITE);
- if(cfd >= 0)
- write(cfd, c, sizeof(c));
+ sysfatal("open: %r");
sbufp = sbuf;
}
static void
audiosample(s16int *s)
{
- if(sbufp < sbuf + nelem(sbuf)){
- *sbufp++ = s[0];
- *sbufp++ = s[1];
- }
+ stime -= 1<<16;
+ do {
+ sbufp[0] = s[0];
+ sbufp[1] = s[1];
+ sbufp += 2;
+ stime += (32000<<16)/Freq;
+ } while(stime < 0);
}
int
@@ -459,7 +458,7 @@ echo(int s)
void
dspstep(void)
{
- if(sbufp == nil)
+ if(sbufp == nil || sbufp >= sbuf+nelem(sbuf)-2)
return;
switch(dspstate++ & 31){
case 0: voice(0, 5); voice(1, 2); break;