Here is the code. It is written in PureBasic.
It works fine if the gain is unity (1). Any other gain value results in breakup.
The 16-bit version works well when any value of gain is applied. Not so with 24 bits (packed).
It only gives me trouble with 24-bit samples and when the gain is other than unity, say, 2 (6 dB). Otherwise it works fine.
Does the problem have something to do with quantization error?
recordedBytes = frameCount * bytesPerFrame
For ct = 0 To sampleRate/10 Step 3
CopyMemory(*recordBuffer + ct, @samp24,3) ;COPY 3 BYTES FROM BUFFER INTO VARIABLE
temp.f = samp24 ;CONVERT 24-BIT SAMPLE TO FLOAT
temp.f = temp.f * 1 ;APPLY GAIN
samp24 = temp.f ;CONVERT FLOAT TO 24-BIT INTEGER
CopyMemory(@samp24,*recordBuffer + ct,3) ;COPY 3 BYTES BACK TO BUFFER
Next
Pa_WriteStream (*outStream, *recordBuffer,recordedBytes / bytesPerFrame) ;WRITE TO PORTAUDIO