Try something like this:
#include <math.h>
#include <stdlib.h>
#include "dos.h"
int main(int argc, char *argv[]) {
short samples[ 22050 ]; // at 11025hz sample rate, we need 22050 samples for two seconds
float tonefreq = 440.0; // 440hz sine wave tone (note A4)
for( int i = 0; i < 22050; ++i) { // two seconds
float s = sinf( i * 2.0f * 3.14159f * tonefreq / 11025.0f ); // 11025hz sample rate
samples[ i ] = (short)( s * 32000.0f ); // convert from -1 to 1 range
}
struct sound_t* beep = createsound( 1 /* mono */, 11025, 22050, samples );
playsound( 1, beep, 0 /* no looping */, 127 /* half volume */ );
while(!shuttingdown()) {
waitvbl();
if( keystate( KEY_ESCAPE ) ) {
break;
}
}
return 0;
}
The `framecount` is a bit of a weird term in audio. depending on how many channels you are playing, a single sample can have 1 value (for mono) or 2 values (for stereo) or even more for things like 5.1 sound (but not supported by dos-like). a "frame" in this context, is simply 1 sample for mono or 2 samples for stereo. so in the case above, where I have 22050 mono samples, i pass the samples buffer and a framecount of 22050. If i decided to do stereo, i would have a samples buffer of 44100, but still pass a framecount of 22050 (but i will pass a channel count of 2 so the createsound function knows that the samples buffer contains framecount*2 values)