i need to edit the size of the data subchunk in a wav file

im using file handling in c++ to edit wav files . this is possible because wav files are uncompressed. so i added some value to the subchunksize in the header file. i was able to create a file which is of 8.1 mb but i cannot create a file bigger than that.i tried adding FF to all the 4 bytes of the subchunksize but still it doesnt go more than 8.1 mb
can anyone help me?

here is the code that i use to edit the wav file.


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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <ios>
#include <iomanip>
#include <fstream>
#include <string>


using namespace std;


int flagh=0;
int count;
int put;
int leng1;

unsigned char readByte(ifstream &thisFile)                                        // function to read each Byte from input file
{
char buffer;
thisFile.get(buffer);
return (unsigned char)buffer;
}

void headerfn()
{


   unsigned char byteA;
 
   ifstream binheaderFile("header",ios::binary);
   ofstream wFile("output.wav",ios::binary);

   binheaderFile.seekg(0,ios::end); 
   leng1 = binheaderFile.tellg();

   binheaderFile.seekg(0,ios::beg);
 
 
 
 for(int i = 0 ; i < leng1 ; i++)       
                                                    // loop to add header file to output.wav
  {
      if(i==leng1-6)
 
      {

         byteA = 255;                                  // to change the size of the data subchunk
         wFile << byteA;
  
      }
      if(i==leng1-5)
     { 
        byteA = 255;
        wFile << byteA;
    }

     else
      {

          byteA = readByte(binheaderFile);
          wFile << byteA;

      }

 } 


      binheaderFile.close();
      put = wFile.tellp();
      wFile.close();

}

void wavmergerfn(char* filename)

{

  ifstream bindataFile(filename,ios::binary) ;      // data from  sound file

  
  ofstream wavFile("output.wav",ios::binary|ios::app);        // output
  wavFile.seekp(put);
 
  unsigned char byteB;



  bindataFile.seekg(0,ios::end);
  int leng2 = bindataFile.tellg();
  
  bindataFile.seekg(0,ios::beg);

  put = wavFile.tellp();

 
  for(int i = 0; i < leng2 ; i++)                
  {

   byteB = readByte(bindataFile);
   wavFile << byteB;

  }

  put=wavFile.tellp();
 
 

  bindataFile.close();
 
 if(count==0)

 {
 
  wavFile.close();

 }


}



int main(int argc, char * argv[])
{ 

 count = argc - 1;
 headerfn();

 int i=1;
 while(count>0)
   {
     count--;
     wavmergerfn(argv[i]); 
     i++;
   }

 return 0;
}
Topic archived. No new replies allowed.