-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwav.cpp
More file actions
89 lines (69 loc) · 1.89 KB
/
wav.cpp
File metadata and controls
89 lines (69 loc) · 1.89 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "wav.h"
string wav::ReadCharValue(int bytes){ //funkcja czytaj¹ca znaki z pliku WAV
string RetValue="";
for(int i=0;i<bytes;i++)
RetValue+=file.get();
return RetValue;
}
string wav::dec2bin(int val){
string wyn;
while(val>0){
if(val%2==0)wyn+="0";
else wyn+="1";
val/=2;
}
while(wyn.size()<8)wyn+="0";
reverse(wyn.begin(),wyn.end());
return wyn;
}
long long wav::bin2dec(string A){
long long d=1;
long long wyn=0;
for(int i=A.size()-1;i>=0;i--){
if(A[i]=='1'){
wyn+=d;
}
d*=2;
}
return wyn;
}
long long wav::ReadIntValue(int bytes){ //funkcja czytajaca z pliku WAV wartosci calkowite
vector<int> BYTES;
for(int i=0;i<bytes;i++)
BYTES.push_back(file.get());
string WYN;
for(int i=BYTES.size()-1;i>=0;i--)
WYN+=dec2bin(BYTES[i]);
return bin2dec(WYN);
}
void wav::load(string FileName){
char *s = new char[FileName.size()+1];
for(int i=0;i<FileName.size();i++)
s[i]=FileName[i];
s[FileName.size()]=0;
file.open(s,fstream::in |fstream::binary);
}
void wav::translate(){
long long size, bits;
cout<<ReadCharValue(4)<<endl; //wczytwanie slowa "RIFF"
cout<<ReadIntValue(4)<<endl; //wczytanie rozmiaru pliku
cout<<ReadCharValue(4)<<endl; //wczytanie slowa "WAVE"
cout<<ReadCharValue(4)<<endl; //wczytanie slowa "fmt "
bits=ReadIntValue(4); //ilosc bitow
cout<<ReadIntValue(2)<<endl; //sposob przechowywania; z kompresja czy bez (nie mam pojecia, o co z tym chodzi)
cout<<ReadIntValue(2)<<endl; //kanaly; 1->mono, 2->stereo
cout<<ReadIntValue(4)<<endl; //sample rate
cout<<ReadIntValue(4)<<endl; //avg_bytes_sec
cout<<ReadIntValue(2)<<endl; //block_align
cout<<ReadIntValue(2)<<endl; //bits_per_sample
cout<<ReadCharValue(4)<<endl; //slowo "data"
size=ReadIntValue(4); //ile bitow dzwieku mamy
while(!file.eof()){
double A=ReadIntValue(bits/8);
Trans.push_back(A);
}
}
wav::wav(string FileName){
load(FileName);
translate();
}