Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading Wave File Using C++

tshabza's Avatar
Newbie
 
Join Date: Oct 2006
Location: Southern Africa
Posts: 2
#1: Oct 11 '06
Could anyone give me idea on how to read a wave and convert in into an integer array file using C++, for now I can successfullly read text file.

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,195
#2: Oct 11 '06

re: Reading Wave File Using C++


You will have to open the file in binary mode.

There is a small header which will give the format for the wav file (mono/stero, bits per sample, sample rate etc). After that it's just a long string of binary data that can be read in using fread
tshabza's Avatar
Newbie
 
Join Date: Oct 2006
Location: Southern Africa
Posts: 2
#3: Oct 13 '06

re: Reading Wave File Using C++


This is for example, a small code where i read array in a file. My problem is, i want to read a wave file and convert its binany form to array of integer, Please help....

#include <iostream>
#include <fstream>
using namespace std;

int i(0), array_index(0);
int *p1 = new int[BUFSIZ];
ifstream readfile;

void Read_File(){
readfile.open("file.txt");
while(!readfile.eof()) {
readfile >> p1[array_index];
array_index++;
}
array_index--;
readfile.close();

for(i = 0; i < array_index; i++){
cout<<" "<<p1[i];
}cout<<endl;
}

int main(int argc, char* argv[]){
Read_File();
delete[] p1;
}
Reply


Similar C / C++ bytes