![]() |
|
#1
|
|||
|
|||
using vector or arrayI have a file of about 446604bytes. I want to know the frequency distribution of the file using a vector or an array. i have already tried using array but i don't think it is write. here is past of the code
CPP / C++ / C Code:
can someone pls help me . thanks |
|
#2
|
||||
|
||||
|
Hi oshiotse. Welcome to GIDForums. I don't see why the array wouldn't work just as good as a vector. However, can you let us know why or what doesn't work with the code? Without having the complete program and a file it is kind of hard to divine what is "wrong" with the code.
Cheers, d |
|
#3
|
|||
|
|||
|
Quote:
we have all seen ur problem but if u could be more specific tell us whats going wrong..u jus never know! |
|
#4
|
|||
|
|||
using vectors or arrayQuote:
This is a copy of the entire program [c] #include "stdafx.h" #include "Wavelet.h" #include <iostream> #include <stdio.h> using namespace std; #include <string> #include <fstream> FILE *input, *output; Wavelet ::wavelet() { } void Wavelet::ReadFromFile() { if ( (input = fopen( "vic2.wav", "rb+")) != NULL) cout<<"In File opened successfully\n"; // r e a d i n g the word "RIFF" fread (csid, 4, 1, input); for (int i=0; i<4; i++) cout<< csid[i]; cout << endl; //R e a d i n g f i l e s i z e fread((char*)&fsize,4,1,input); cout<<"File size is: "<<fsize<<"\n"; //form typeID // r e a d i n g the word "WAVE" fread (csid1, 4, 1, input); for (int j=0; j<4; j++) cout<< csid1[j]; cout <<"\n"; //Second"Chunk"ID // r e a d i n g the word "fmt " fread (csid2, 4, 1, input); for (int a=0; a<4; a++) cout<< csid2[a]; cout<<"\n"; //cout<<(char*)&wfxsize<<"byte"<<"\n"; //Wave Format Size fread((char*)&wfxsize,4,1,input); cout<<"Check it out: "<<wfxsize<<" byte"<<"\n"; //Wave Format Info fread(pwfx,18,1,input); cout<<"Wave Formt Info: "<<pwfx<<" byte"<<"\n"; //Wave Format Info:fact fread (csid3, 4, 1, input); for (int h=0; h<4; h++) cout<< csid3[h]; cout <<"\n"; //Wave Format Info fread((char*)&datasiz,4,1,input); cout<<datasiz<<"byte"<<"\n"; //Wave Format Info databuf = new char [datasiz]; fread (databuf,datasiz, 1, input); cout<<databuf<<"\n"; //Reading the word "data" fread (csid4, 4, 1, input); for (int p=0; p<4; p++) cout<< csid4[p]; cout <<"\n"; //Datasize of the PCM data fread((char*)&datasize,4,1,input); cout<<"The data sample size is:"<<datasize<<" bytes"<<"\n"; datap = new unsigned char[datasize]; fread(datap, datasize, 1, input); min= datap[datasize]; cout<<min<<endl; datatrans = new double[datasize]; int Low,High; Low=0; High=datasize/2; //datatrans[Low] = (datap[0] + datap[1])*0.7071; //min1 = datatrans[Low]; //max1 = datatrans[Low]; //Low =1; // The first part of the wavelet, implemented on datap which contains // the original data for(int y = 0; y < datasize-1 ; y+=2) { datatrans[Low++]=(datap[y] + datap[y+1])*0.7071; datatrans[High++] =(datap[y]-datap[y+1])*0.7071; } // The The second part of the wavelet, implemented on datatrans datatrans2 = new double[datasize]; Low=0; High=datasize/4; for(int yy = 0; yy < (datasize/2)-1 ; yy+=2) { datatrans2[Low++]=(datatrans[yy] + datatrans[yy+1])*0.7071; datatrans2[High++] =(datatrans[yy]-datatrans[yy+1])*0.7071; } for(int yyy = (datasize/2)+1; yyy < datasize ; yyy++) { datatrans2[yyy]=datatrans[yyy]; } // The third part of the wavelet, implemented on datatrans2. datatrans3 = new double[datasize]; Low=0; High=datasize/8; for(int q = 0; q < (datasize/4)-1 ; q+=2) { datatrans3[Low++]=(datatrans2[q] + datatrans2[q+1])*0.7071; datatrans3[High++] =(datatrans2[q]-datatrans2[q+1])*0.7071; } for(int s = (datasize/4)+1; s < datasize ; s++) { datatrans3[s]=datatrans2[s]; } // The fouth part of the wavelet, implemented on datatrans3. datatrans4 = new double[datasize]; Low=0; High=datasize/16; for(int t = 0; t < (datasize/ { datatrans4[Low++]=(datatrans3[t] + datatrans3[t+1])*0.7071; datatrans4[High++] =(datatrans3[t]-datatrans3[t+1])*0.7071; } for(int f = (datasize/ { datatrans4[f]=datatrans3[f]; } // The first part of the coversion.This convert from datatrans4 to datatran3 datat = new double[datasize]; Low=0; High=datasize/16; for(int z = 0; z < (datasize/ { datat[z] = (datatrans4[Low++] + datatrans4[High++])/(2*0.7071); Low = Low - 1; High= High - 1; datat[z+1] = (datatrans4[Low++] - datatrans4[High++])/(2*0.7071); } for(int zz = (datasize/ { datat[zz]=datatrans4[zz]; } // The second part of the coversion.This convert from datatrans3 to datatran2 datat2 = new double[datasize]; Low=0; High=datasize/8; for(int zzz = 0; zzz < (datasize/4)-1 ; zzz+=2) { datat2[zzz] = (datat[Low++] + datat[High++])/(2*0.7071); Low = Low - 1; High= High - 1; datat2[zzz+1] = (datat[Low++] - datat[High++])/(2*0.7071); } for(int w = (datasize/4)+1; w < datasize ; w++) { datat2[w]=datat[w]; } // The third part of the coversion.This convert from datatrans2 to datatran datat3 = new double[datasize]; Low=0; High=datasize/4; for(int ww = 0; ww < (datasize/2)-1 ; ww+=2) { datat3[ww] = (datat2[Low++] + datat2[High++])/(2*0.7071); Low = Low - 1; High= High - 1; datat3[ww+1] = (datat2[Low++] - datat2[High++])/(2*0.7071); } for(int tt = (datasize/2)+1; tt < datasize ; tt++) { datat3[tt]=datat2[tt]; } // The third part of the coversion.This convert from datatrans to datap // Remember that datap contains the original data datat4 = new unsigned char[datasize]; Low=0; High=datasize/2; for(int bb = 0; bb < (datasize)-1 ; bb+=2) { datat4[bb] = (datat3[Low++] + datat3[High++])/(2*0.7071); Low = Low - 1; High= High - 1; datat4[bb+1] = (datat3[Low++] - datat3[High++])/(2*0.7071); } // The two parts below are done to enhanced the listening // it should be removed when doing the other transformation /* //(1) Find the min and max in Low band min1=max1=datatrans[0]; for (int mm=1;mm<datasize/2;mm++) { if (min1>datatrans[mm]) min1 = datatrans[mm]; if (max1<datatrans[mm]) max1 = datatrans[mm]; } cout<<min1<<" min for low "<<endl; cout<<max1<<" max for low "<<endl; //Scale the values to be in [0-255] double m=255/(double)(max1-min1); for (int s=0;s<datasize/2;s++){ datatrans[s]=m*(datatrans[s]-min1); } //(2) Find the min and max in High band min1=max1=datatrans[(datasize/2)+1]; for (int hh=(datasize/2)+1;hh<datasize;hh++) { if (min1>datatrans[hh]) min1 = datatrans[hh]; if (max1<datatrans[hh]) max1 = datatrans[hh]; } cout<<min1<<" min for High "<<endl; cout<<max1<<" max for High "<<endl; //Scale the values to be in [0-255] m=255/(double)(max1-min1); for (int ss=(datasize/2)+1;ss<datasize;ss++){ datatrans[ss]=m*(datatrans[ss]-min1); } */ } void Wavelet ::Write2file() { if( (output = fopen ( "vicout1.wav", "wb+")) != NULL) cout<<"\n\nOut File opened successfully\n"; //fwrite (header, 55200,1,output); fwrite (csid, 4, 1, output); for (int i=0; i<4; i++) cout<< csid[i]; cout <<endl; fwrite((char*)&fsize,4,1,output); cout<<fsize<<"file size"<<"\n"; fwrite(csid1, 4, 1, output); for (int j=0; j<4; j++) cout<< csid1[j]; cout <<"\n"; fwrite (csid2, 4, 1, output); for (int a=0; a<4; a++) cout<< csid2[a]; cout <<"\n"; fwrite((char*)&wfxsize,4,1,output); cout<<wfxsize<<"byte"<<"\n"; fwrite((char*)&pwfx,wfxsize,1,output); cout<<pwfx<<"byte"<<"\n"; fwrite (csid3, 4, 1, output); for (int b=0; b<4; b++) cout<< csid3[b]; cout <<"\n"; fwrite((char*)&datasiz,4,1,output); cout<<datasiz<<"byte"<<"\n"; //databuf = new char [datasiz]; fwrite (databuf,datasiz, 1, output); cout<<databuf<<"\n"; fwrite (csid4, 4, 1, output); for (int c=0; c<4; c++) cout<< csid4[c]; cout <<"\n"; fwrite((char*)&datasize,4,1,output); cout<<datasize<<"byte"<<"\n"; // convert the data from double to bytes for(int f=0;f<datasize;f++) datap[f]=(unsigned char)datatrans[f]; fwrite (datap, datasize,1,output); fclose (output); } void Wavelet::Write2filestg2() { if( (output = fopen ( "vicout2.wav", "wb+")) != NULL) cout<<"\n\nOut File opened successfully\n"; //fwrite (header, 55200,1,output); fwrite (csid, 4, 1, output); for (int i=0; i<4; i++) cout<< csid[i]; cout <<endl; fwrite((char*)&fsize,4,1,output); cout<<fsize<<"file size"<<"\n"; fwrite(csid1, 4, 1, output); for (int j=0; j<4; j++) cout<< csid1[j]; cout <<"\n"; fwrite (csid2, 4, 1, output); for (int a=0; a<4; a++) cout<< csid2[a]; cout <<"\n"; fwrite((char*)&wfxsize,4,1,output); cout<<wfxsize<<"byte"<<"\n"; fwrite((char*)&pwfx,18,1,output); cout<<pwfx<<"byte"<<"\n"; fwrite (csid3, 4, 1, output); for (int b=0; b<4; b++) cout<< csid3[b]; cout <<"\n"; fwrite((char*)&datasiz,4,1,output); cout<<datasiz<<"byte"<<"\n"; //databuf = new char [datasiz]; fwrite (databuf,datasiz, 1, output); cout<<databuf<<"\n"; fwrite (csid4, 4, 1, output); for (int c=0; c<4; c++) cout<< csid4[c]; cout <<"\n"; fwrite((char*)&datasize,4,1,output); cout<<datasize<<"byte"<<"\n"; // convert the data from double to bytes for(int f=0;f<datasize;f++) datap[f]=(unsigned char)datatrans2[f]; fwrite (datap, datasize,1,output); fclose (output); } void Wavelet::Write2filestg3() { if( (output = fopen ( "vicout3.wav", "wb+")) != NULL) cout<<"\n\nOut File opened successfully\n"; //fwrite (header, 55200,1,output); fwrite (csid, 4, 1, output); for (int i=0; i<4; i++) cout<< csid[i]; cout <<endl; fwrite((char*)&fsize,4,1,output); cout<<fsize<<"file size"<<"\n"; fwrite(csid1, 4, 1, output); for (int j=0; j<4; j++) cout<< csid1[j]; cout <<"\n"; fwrite (csid2, 4, 1, output); for (int a=0; a<4; a++) cout<< csid2[a]; cout <<"\n"; fwrite((char*)&wfxsize,4,1,output); cout<<wfxsize<<"byte"<<"\n"; fwrite((char*)&pwfx,18,1,output); cout<<pwfx<<"byte"<<"\n"; fwrite (csid3, 4, 1, output); for (int b=0; b<4; b++) cout<< csid3[b]; cout <<"\n"; fwrite((char*)&datasiz,4,1,output); cout<<datasiz<<"byte"<<"\n"; //databuf = new char [datasiz]; fwrite (databuf,datasiz, 1, output); cout<<databuf<<"\n"; fwrite (csid4, 4, 1, output); for (int c=0; c<4; c++) cout<< csid4[c]; cout <<"\n"; fwrite((char*)&datasize,4,1,output); cout<<datasize<<"byte"<<"\n"; // convert the data from double to bytes for(int f=0;f<datasize;f++) datap[f]=(unsigned char)datatrans3[f]; fwrite (datap, datasize,1,output); fclose (output); } void Wavelet ::Write2filestg4() { if( (output = fopen ( "vicout4.wav", "wb+")) != NULL) cout<<"\n\nOut File opened successfully\n"; //fwrite (header, 55200,1,output); fwrite (csid, 4, 1, output); for (int i=0; i<4; i++) cout<< csid[i]; cout <<endl; fwrite((char*)&fsize,4,1,output); cout<<fsize<<"file size"<<"\n"; fwrite(csid1, 4, 1, output); for (int j=0; j<4; j++) cout<< csid1[j]; cout <<"\n"; fwrite (csid2, 4, 1, output); for (int a=0; a<4; a++) cout<< csid2[a]; cout <<"\n"; fwrite((char*)&wfxsize,4,1,output); cout<<wfxsize<<"byte"<<"\n"; fwrite((char*)&pwfx,18,1,output); cout<<pwfx<<"byte"<<"\n"; fwrite (csid3, 4, 1, output); for (int b=0; b<4; b++) cout<< csid3[b]; cout <<"\n"; fwrite((char*)&datasiz,4,1,output); cout<<datasiz<<"byte"<<"\n"; //databuf = new char [datasiz]; fwrite (databuf,datasiz, 1, output); cout<<databuf<<"\n"; fwrite (csid4, 4, 1, output); for (int c=0; c<4; c++) cout<< csid4[c]; cout <<"\n"; fwrite((char*)&datasize,4,1,output); cout<<datasize<<"byte"<<"\n"; // convert the data from double to bytes for(int f=0;f<datasize;f++) datap[f]=(unsigned char)datatrans4[f]; fwrite (datap, datasize,1,output); fclose (output); } void Wavelet::Write2fileconv() { if( (output = fopen ( "vicoutconv.wav", "wb+")) != NULL) cout<<"\n\nOut File opened successfully\n"; //fwrite (header, 55200,1,output); fwrite (csid, 4, 1, output); for (int i=0; i<4; i++) cout<< csid[i]; cout <<endl; fwrite((char*)&fsize,4,1,output); cout<<fsize<<"file size"<<"\n"; fwrite(csid1, 4, 1, output); for (int j=0; j<4; j++) cout<< csid1[j]; cout <<"\n"; fwrite (csid2, 4, 1, output); for (int a=0; a<4; a++) cout<< csid2[a]; cout <<"\n"; fwrite((char*)&wfxsize,4,1,output); cout<<wfxsize<<"byte"<<"\n"; fwrite((char*)&pwfx,18,1,output); cout<<pwfx<<"byte"<<"\n"; fwrite (csid3, 4, 1, output); for (int b=0; b<4; b++) cout<< csid3[b]; cout <<"\n"; fwrite((char*)&datasiz,4,1,output); cout<<datasiz<<"byte"<<"\n"; //databuf = new char [datasiz]; fwrite (databuf,datasiz, 1, output); cout<<databuf<<"\n"; fwrite (csid4, 4, 1, output); for (int c=0; c<4; c++) cout<< csid4 CPP / C++ / C Code:
Pls Remember that i want to use vector to get the frequency distribution. i have already used an array but i don't think it working properly. Thanks |
|
#5
|
||||
|
||||
|
dsmith wrote: Hi oshiotse. Welcome to GIDForums. I don't see why the array wouldn't work just as good as a vector. However, can you let us know why or what doesn't work with the code? Without having the complete program and a file it is kind of hard to divine what is "wrong" with the code.
vadharah wrote: we have all seen ur problem but if u could be more specific tell us whats going wrong..u jus never know! In response you posted almost 700 lines of code with no comment, no explanation. We aren't likely to try to understand a program this large looking for an unknown problem in an unknown section of code. Be Specific! What is wrong? Where is the problem? What should it be doing instead? __________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
Recent GIDBlog
Toyota - 2008 July Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The