Appologies if this is obvious, but it isn't to me and i cannot find it here or in the manuals.
I am trying to write to a mono, 24 bit, 96 kHz wav file. Stereo works absolutely fine.
When recording the file is the correct size, length and the header looks good. However, what has happened is 5 seconds of audio has been stretched out to 10 seconds. There is some mirroring when the wav is viewed as a spectrogram when viewed as a waveform there is clear alternating between samples between two channels. my header looks like this.
Code: Select all
s_int16 SetRiff(s_int32 sampleRate, s_int32 stereoSamples) {
s_int32 fileBytes = 44+(CHANS*(BITR/8)*stereoSamples); // Stereo=2, 16 bits=2 **44+2*2*stereoSamples
SetLE32(riffWavHeader, RIFF_SAMPLE_RATE_OFFSET,SRATE);
SetLE16(riffWavHeader, RIFF_NUMBER_OF_CHANNELS_OFFSET, CHANS);
SetLE32(riffWavHeader, RIFF_BYTES_PER_SEC_OFFSET, CHAN*(BITR/8)*SRATE);//2*2*sampleRate)
SetLE16(riffWavHeader, RIFF_ALIGN_OFFSET,CHANS*BITR/8);///was 24/4
SetLE16(riffWavHeader, RIFF_BITS_PER_SAMPLE_OFFSET, BITR);
SetLE32(riffWavHeader, RIFF_FILE_SIZE_OFFSET, fileBytes- 8);
SetLE32(riffWavHeader, RIFF_DATA_SIZE_OFFSET, fileBytes-44);
return 0;
}
Code: Select all
// Configure standard audio input
ioctl(stdaudioin, IOCTL_AUDIO_SET_IRATE, (void *)(&sampleRate));
ioctl(stdaudioin, IOCTL_AUDIO_SET_BITS, (void *)ModBit);
// ioctl(stdaudioin, IOCTL_AUDIO_SET_RATE_AND_BITS,(void *)(&sampleRateAndBits));//just added
ioctl(stdaudioin, IOCTL_AUDIO_GET_OVERFLOWS, (void *)(&overflows));
if (ioctl(stdaudioin, IOCTL_AUDIO_SET_INPUT_BUFFER_SIZE, (void *)4096)) {
printf("Couldn't set input biffer size\n");
goto finally;
}
SetRiff(sampleRate, samplesLeft/CHANS);//this was samplesLeft/2 which was shortenting this for single channels
samplesLeft = (samplesLeft*(ModBit/16));
fwrite(&riffWavHeader, sizeof(riffWavHeader), 1, outFile);
while (samplesLeft) {
s_int16 i;
s_int16 samples = (s_int16)MIN(samplesLeft, BUFSIZE);
u_int16*bp = buff16;
fread(buff16, sizeof(buff16[0]), samples, stdaudioin);
if (bitR==24) {
Convert32BitVSDSPTo24BitLE(buff16, (u_int32 *)buff16, samples/4); // 256-word buffer contains 64 32-bit stereo samples ***was samples divided by 4
fwrite(buff16, sizeof(buff16[0]), samples*3/4, outFile); // Write 32-bit little-endian data */
} else {
for (i=0; i<samples; i++) {
*bp = Swap16(*bp);
bp++;
}
fwrite(buff16, sizeof(buff16[0]), samples, outFile);
}
Also the config file is AUIADC s 96000 line1_3
Thanks in advance
Rob