/**
* main.c
*/
#include <stdio.h>
#include <stdlib.h>
#include "tistdtypes.h"
Uint8 waveHeader[44] = {
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00,
0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20,
0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x40, 0x1F, 0x00, 0x00, 0x80, 0x3E, 0x00, 0x00,
0x02, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61,
0x00, 0x00, 0x00, 0x00
};
#define SIZE 1024
Uint8 ch[SIZE];
int main(void)
{
FILE *fp1, *fp2;
Uint32 i;
printf("Exp. 1.2 --- file IO\n");
fp1 = fopen("..\\data\\C55DSPUSBStickAudioTest.pcm", "rb");
if (fp1 == NULL) {
printf("Failed to open output file 'C55DSPUSBStickAudioTest.pcm'\n");
exit(0);
}
fp2 = fopen("..\\data\\C55DSPUSBStickAudioTest.wav", "wb");
fseek(fp2, 44, 0);
i = 0;
size_t a = fread(ch, sizeof(Uint8), SIZE, fp1);
Uint8 b = sizeof(Uint8);
// while(fread(ch, sizeof(Uint8), SIZE, fp1) == SIZE)
while(a == SIZE)
{
fwrite(ch, sizeof(Uint8), SIZE, fp2);
i += SIZE;
printf("%ld bytes processed\n", i);
}
waveHeader[40] = (Uint8)(i&0xff);
waveHeader[41] = (Uint8)(i >> 8) & 0xff;
waveHeader[42] = (Uint8)(i >> 16) & 0xff;
waveHeader[43] = (Uint8)(i >> 24) & 0xff;
waveHeader[4] = waveHeader[40];
waveHeader[5] = waveHeader[41];
waveHeader[6] = waveHeader[42];
waveHeader[7] = waveHeader[43];
rewind(fp2);
fwrite(waveHeader, sizeof(Uint8), 44, fp2);
fclose(fp1);
fclose(fp2);
printf("\nExp. completed\n");
return 0;
}