1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
// An unsigned char can store 1 Bytes (8bits) of data (0-255)
typedef unsigned char BYTE;
// Get the size of a file
long getFileSize(FILE *file)
{
long lCurPos, lEndPos;
lCurPos = ftell(file);
fseek(file, 0, 2);
lEndPos = ftell(file);
fseek(file, lCurPos, 0);
return lEndPos;
}
int main()
{
const char *filePath = "t2.wav";
BYTE *fileBuf; // Pointer to our buffered data
//BYTE *amp;
FILE *file = NULL; // File pointer
FILE *data;
FILE *bin;
if ((file = fopen(filePath, "rb")) == NULL)
cout << "Could not open specified file" << endl;
else
cout << "File opened successfully" << endl;
long fileSize = getFileSize(file);
fileBuf = new BYTE[fileSize];
//amp = new BYTE[fileSize];
fread(fileBuf, fileSize, 1, file);
data = fopen("data.txt", "w");
bin = fopen("bin.txt", "w");
for (int i = 44; i <20000; i+=1){
int bit = 0;
int sum = 0;
if (fileBuf[i]>251){
sum = sum + 1;
//printf("%d", sum);
if (sum>20)
fprintf(bin, "1");
else
fprintf(bin, "0");
}
//int amp = fileBuf[i];
int amp =fileBuf[i];
//printf("%d ",amp);
fprintf(data,"%i\n", amp);
}
cin.get();
delete[]fileBuf;
fclose(data);
fclose(file); // Almost forgot this
fclose(bin);
cout << "Done" << endl;
return 0;
}
|