#include "i2s.h"
#include <windows.h>
#include <stdio.h>
#include <shlwapi.h>
DWORD*buffer;
BYTE*fill;
void i2s_begin() {
buffer=new DWORD[16*1024]; // 64 KByte
buffer[0]='FFIR'; // RIFF
buffer[2]='EVAW'; // WAVE
buffer[3]=' tmf'; // fmt
buffer[4]=4*4;
buffer[5]=MAKELONG(1/*PCM*/,1/*channels*/);
buffer[8]=MAKELONG(1/*channels*bits>>3*/,8/*bits*/);
buffer[9]='atad'; // data
fill=(BYTE*)(buffer+11);
}
void i2s_set_rate(unsigned saps) {
buffer[7]=buffer[6]=saps;
}
extern "C" void i2s_write_sample_b(unsigned char sa) {
*fill++=sa;
}
void i2s_end() {
DWORD len=fill-(BYTE*)buffer; // Anzahl Bytes
TCHAR fname[MAX_PATH];
GetTempFileName(".","wav",0,fname);
lstrcpy(PathFindExtension(fname)+1,"wav");
HANDLE h=CreateFile(fname,GENERIC_WRITE,0,0,CREATE_NEW,0,0);
if (h!=INVALID_HANDLE_VALUE) {
WriteFile(h,buffer,len,&len,0);
CloseHandle(h);
}
buffer[1]=len-=2*sizeof(DWORD); // Chunk-Längen eintragen
buffer[10]=len-=9*sizeof(DWORD);
#ifdef _DEBUG
printf("%u samples\n",len);
#endif
sndPlaySound((PCSTR)buffer,SND_MEMORY|SND_SYNC);
delete[] buffer;
}
Detected encoding: UTF-8 | 0
|