s98data.cpp
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- DoProc
- S98_waitsync
- DoProc
- clipsample
#include "s98data.h"
#include <string.h>
#include <unistd.h>
void S98_opnareg::DoProc(unsigned int arg1, unsigned int arg2){
/* [<][>][^][v][top][bottom][index][help] */
opna.opna.SetReg(arg1, arg2);
// fprintf(stderr, "OPNA: %02x %02x\n", arg1,
// arg2);
}
#define SAMPLES_CANDIDATE 5000
S98_waitsync::S98_waitsync(OPNAWRAP& theopna, mymixer* themixer,
/* [<][>][^][v][top][bottom][index][help] */
int thediag = 0) :
opna(theopna), diag(thediag), mixer(themixer)
{
buf = new FM_SAMPLETYPE[SAMPLES_CANDIDATE * 2];
outbuf = new short[SAMPLES_CANDIDATE * 2];
bufsize = SAMPLES_CANDIDATE;
}
void S98_waitsync::DoProc(int msec){
/* [<][>][^][v][top][bottom][index][help] */
int samples = (opna.rate * msec) / 1000;
if(samples > bufsize){ // realloc
fprintf(stderr, "realloc called(%d).\n", samples);
bufsize = samples * 2;
delete[] buf;
buf = new FM_SAMPLETYPE[bufsize * 2];
delete[] outbuf;
outbuf = new short[bufsize * 2];
}
memset(buf, 0, sizeof(FM_SAMPLETYPE) * samples * 2);
opna.opna.Mix(buf, samples);
FM_SAMPLETYPE thissample;
for(int i = 0; i < samples * 2; i += 2){
#define clipsample(count) { \
/* [<][>][^][v][top][bottom][index][help] */
thissample = buf[(count)]; \
if(thissample > 32767) thissample = 32767; \
if(thissample < -32768) thissample = -32768; \
outbuf[(count)] = static_cast<short>(thissample); \
}
clipsample(i);
clipsample(i+1);
}
// fwrite(outbuf, sizeof(short), samples * 2, stdout);
mixer->Mix(outbuf, samples * 2);
if(diag) printf("WAITSYNC(%d)\n", static_cast<int>(msec));
}