Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita78a4c3

Browse files
committed
WAV>WAVE Conversion.
1 parent970c9c6 commita78a4c3

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

‎WAVE2WAV/RIFF.cpp‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void ConvertWAVEToWAV(const char* filePath)
1111
//If there was a failure to open the file we must exit
1212
if (!ifs.good())
1313
{
14+
std::cout <<"Error: failed to open the file!" << std::endl;
1415
ifs.close();
1516
return;
1617
}
@@ -103,9 +104,106 @@ void ConvertWAVToWAVE(const char* filePath)
103104
{
104105
std::ifstreamifs(filePath, std::ios::binary);
105106

107+
//If there was a failure to open the file we must exit
106108
if (!ifs.good())
107109
{
110+
std::cout <<"Error: failed to open the file!" << std::endl;
111+
ifs.close();
112+
return;
113+
}
114+
115+
unsignedint 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+
unsignedint riffSize =ReadUInt(ifs);
124+
if (riffMagic <=0)
125+
{
126+
std::cout <<"Error: RIFF size <= 0!" << std::endl;
108127
ifs.close();
109128
return;
110129
}
130+
131+
ifs.seekg(12, SEEK_CUR);
132+
133+
unsignedshort 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+
unsignedint riffSampleRate =ReadUInt(ifs);
144+
145+
ifs.seekg(20, SEEK_CUR);
146+
147+
unsignedint riffUnk00 =ReadUInt(ifs);
148+
149+
char* waveData =newchar[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+
unsignedint 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
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp