@@ -11,6 +11,7 @@ void ConvertWAVEToWAV(const char* filePath)
1111// If there was a failure to open the file we must exit
1212if (!ifs.good ())
1313{
14+ std::cout <<" Error: failed to open the file!" << std::endl;
1415ifs.close ();
1516return ;
1617}
@@ -103,9 +104,106 @@ void ConvertWAVToWAVE(const char* filePath)
103104{
104105std::ifstreamifs (filePath, std::ios::binary);
105106
107+ // If there was a failure to open the file we must exit
106108if (!ifs.good ())
107109{
110+ std::cout <<" Error: failed to open the file!" << std::endl;
111+ ifs.close ();
112+ return ;
113+ }
114+
115+ unsigned int riffMagic =ReadUInt (ifs);
116+ if (riffMagic != RIFF_MAGIC)
117+ {
118+ std::cout <<" Error: RIFF magic mis-match!" << std::endl;
119+ ifs.close ();
120+ return ;
121+ }
122+
123+ unsigned int riffSize =ReadUInt (ifs);
124+ if (riffMagic <=0 )
125+ {
126+ std::cout <<" Error: RIFF size <= 0!" << std::endl;
108127ifs.close ();
109128return ;
110129}
130+
131+ ifs.seekg (12 , SEEK_CUR);
132+
133+ unsigned short riffFormat =ReadUShort (ifs);
134+ if (riffFormat !=0x11 )
135+ {
136+ std::cout <<" Error: unsupported wave format! Got:" << riffFormat <<" Expected: 18" << std::endl;
137+ ifs.close ();
138+ return ;
139+ }
140+
141+ ifs.seekg (2 , SEEK_CUR);
142+
143+ unsigned int riffSampleRate =ReadUInt (ifs);
144+
145+ ifs.seekg (20 , SEEK_CUR);
146+
147+ unsigned int riffUnk00 =ReadUInt (ifs);
148+
149+ char * waveData =new char [riffSize -44 ];
150+ ifs.read (waveData, (riffSize -4 ));
151+
152+ ifs.close ();
153+
154+ // Write section header
155+ char nameBuff[128 ];
156+ memset (nameBuff,0 ,128 );
157+ sprintf_s (nameBuff," %s%s" , filePath," .wave" );
158+
159+ std::ofstreamofs (nameBuff, std::ios::binary);
160+
161+ if (!ofs.good ())
162+ {
163+ std::cout <<" Error: Failed to open output file for writing!" << std::endl;
164+ ofs.close ();
165+ return ;
166+ }
167+
168+ //
169+ std::stringpath (filePath);
170+ std::string filename;
171+
172+ size_t pos = path.find_last_of (" \\ " );
173+ if (pos != std::string::npos)
174+ {
175+ filename.assign (path.begin () + pos +1 , path.end ());
176+ pos = path.find_last_of (" _" );
177+ filename.assign (path.begin () + pos +1 , path.end ());
178+ filename.erase (filename.find_first_of (" ." ), std::string::npos);
179+ }
180+ else
181+ {
182+ filename = path;
183+ }
184+
185+ unsigned int hash;
186+ sscanf (filename.c_str ()," %x" , &hash);
187+
188+ // "SECT"
189+ WriteUInt (ofs,0x54434553 );
190+ // File size of section data minus header
191+ WriteUInt (ofs, ((riffSize-44 )+16 ));
192+ WriteUByte (ofs, WAVE_SECTION_TYPE);
193+ ofs.seekp (3 , SEEK_CUR);// Unsupported
194+ // Header size (nothing since this asset is not relocated)
195+ WriteUInt (ofs,0 );
196+ // Unique hash of section stored in filename
197+ WriteUInt (ofs, hash);
198+ // Lang/mask
199+ WriteUInt (ofs,0xFFFFFFFF );
200+
201+ // Wave section data
202+ WriteUInt (ofs, riffSampleRate);
203+ ofs.seekp (8 , SEEK_CUR);
204+ WriteUInt (ofs, riffUnk00);
205+ ofs.write (waveData, (riffSize -44 ));
206+
207+ ofs.flush ();
208+ ofs.close ();
111209}