maxFormatSize := 0; // find the biggest format size
acmMetrics(nil, ACM_METRIC_MAX_SIZE_FORMAT, maxFormatSize);
waveFormat := PWAVEFORMATEX(Pointer(LocalAlloc(LPTR, maxFormatSize))); // define desired output format
waveFormat^.wFormatTag := WAVE_FORMAT_PCM;
if Channels = 1 then waveFormat^.nChannels := 1;
if Channels = 2 then waveFormat^.nChannels := 2;
waveFormat^.nSamplesPerSec := SamplesPerSec; // 44.1kHz
waveFormat^.wBitsPerSample := BitsPerSample; // 16 bits
waveFormat^.nBlockAlign := waveFormat^.nChannels * waveFormat^.wBitsperSample div 8; // 4; // 4 bytes of data at a time are useful (1 sample)
waveFormat^.nAvgBytesPerSec := waveFormat^.nBlockAlign * SamplesPerSec; &n