Skip to content

Commit 00df5f8

Browse files
committed
add wav
1 parent b70eadb commit 00df5f8

15 files changed

+451
-12
lines changed

BMP_Parse/BMPFile.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ bool CBMPFile::LoadFile(const char* strFile)
2828
return false;
2929
}
3030
fseek(pFile, 0, SEEK_END);
31-
m_iSize = ftell(pFile);
32-
byte_ptr pData = new byte[m_iSize];
31+
m_iFileSize = ftell(pFile);
32+
byte_ptr pData = new byte[m_iFileSize];
3333
fseek(pFile, 0, SEEK_SET);
34-
if (m_iSize != fread(pData, sizeof(byte), m_iSize, pFile))
34+
if (m_iFileSize != fread(pData, sizeof(byte), m_iFileSize, pFile))
3535
{
3636
printf("read file is failed. \n");
3737
return false;
3838
}
3939
fclose(pFile);
4040

41-
bool bResult = ReadData(pData, m_iSize);
41+
bool bResult = ReadData(pData, m_iFileSize);
4242
delete[]pData;
4343
pData = NULL;
4444
return bResult;
@@ -72,8 +72,8 @@ void CBMPFile::Display()
7272
printf("\t biClrImportant \t : %d \n", m_bmpInfoHeader.biClrImportant);
7373

7474
printf("************************ BITMAP DATA ************************\n");
75-
int iSize = min(100, m_bmpInfoHeader.biSizeImage);
76-
for (int i = 0; i < iSize; i++)
75+
int iDataSize = min(100, m_bmpInfoHeader.biSizeImage);
76+
for (int i = 0; i < iDataSize; i++)
7777
{
7878
printf(" %02X ", m_pData[i]);
7979
}
@@ -82,9 +82,11 @@ void CBMPFile::Display()
8282

8383
bool CBMPFile::ReadData(byte_ptr pData, int iSize)
8484
{
85+
// BITMAPFILEHEADER;
8586
int iFileHeaderSize = sizeof(m_bmpFileHeader);
8687
memcpy(&m_bmpFileHeader, pData, iFileHeaderSize);
8788
pData += iFileHeaderSize;
89+
// BITMAPINFOHEADER;
8890
int iInfoHeaderSize = sizeof(m_bmpInfoHeader);
8991
memcpy(&m_bmpInfoHeader, pData, iInfoHeaderSize);
9092
pData += iInfoHeaderSize;
@@ -117,4 +119,4 @@ bool CBMPFile::ReadData(byte_ptr pData, int iSize)
117119
bool CBMPFile::WriteData(byte_ptr pData, int &iSize, double dStart, double dEnd)
118120
{
119121
return true;
120-
}
122+
}

BMP_Parse/BMPFile.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ class CBMPFile
2727
BITMAPFILEHEADER m_bmpFileHeader;
2828
BITMAPINFOHEADER m_bmpInfoHeader;
2929
byte* m_pData;
30-
int m_iSize;
31-
};
32-
30+
int m_iFileSize;
31+
};

BMP_Parse/BMP_Parse.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
</ItemGroup>
7676
<ItemGroup>
7777
<ClCompile Include="BMPFile.cpp" />
78+
<ClCompile Include="bytes.cpp" />
7879
<ClCompile Include="main.cpp" />
7980
</ItemGroup>
8081
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

BMP_Parse/BMP_Parse.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@
2929
<ClCompile Include="main.cpp">
3030
<Filter>源文件</Filter>
3131
</ClCompile>
32+
<ClCompile Include="bytes.cpp">
33+
<Filter>源文件</Filter>
34+
</ClCompile>
3235
</ItemGroup>
3336
</Project>

FLV_Parse/bytes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "bytes.h"
22

3-
43
int BytesToInt(byte_ptr pData, int iCount)
54
{
65
int iResult = 0;
@@ -15,4 +14,4 @@ std::string BytesToStr(byte_ptr pData, int iCount)
1514
{
1615
std::string strResult((char*)pData, iCount);
1716
return strResult;
18-
}
17+
}

WAV_Parse/WAVFile.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include "WAVFile.h"
2+
3+
CWAVFile::CWAVFile()
4+
{
5+
m_pData = NULL;
6+
}
7+
8+
CWAVFile::~CWAVFile()
9+
{
10+
if (m_pData)
11+
{
12+
delete[]m_pData;
13+
m_pData = NULL;
14+
}
15+
}
16+
17+
bool CWAVFile::LoadFile(const char* strFile)
18+
{
19+
if (!strFile)
20+
{
21+
printf("strFile is null. \n");
22+
return false;
23+
}
24+
FILE* pFile = fopen(strFile, "rb");
25+
if (!pFile)
26+
{
27+
printf("fopen is failed. \n");
28+
return false;
29+
}
30+
fseek(pFile, 0, SEEK_END);
31+
m_iSize = ftell(pFile);
32+
byte_ptr pData = new byte[m_iSize];
33+
fseek(pFile, 0, SEEK_SET);
34+
if (m_iSize != fread(pData, sizeof(byte), m_iSize, pFile))
35+
{
36+
printf("read file is failed. \n");
37+
return false;
38+
}
39+
fclose(pFile);
40+
41+
bool bResult = ReadData(pData, m_iSize);
42+
delete[]pData;
43+
pData = NULL;
44+
return bResult;
45+
}
46+
47+
bool CWAVFile::SaveFile(const char* strFile, RECT rt)
48+
{
49+
return true;
50+
}
51+
52+
void CWAVFile::Display()
53+
{
54+
printf("************************ RIFF HEADER ************************\n");
55+
printf("\t RiffID \t : %s \n", BytesToStr(m_RiffHeader.szRiffID, 4).c_str());
56+
printf("\t RiffSize \t : %d \n", m_RiffHeader.dwRiffSize);
57+
printf("\t RiffFormat \t : %s \n", BytesToStr(m_RiffHeader.szRiffFormat, 4).c_str());
58+
59+
printf("************************ FMT BLOCK ************************\n");
60+
printf("\t szFmtID \t : %s \n", BytesToStr(m_FmtBlock.szFmtID, 4).c_str());
61+
printf("\t dwFmtSize \t : %d \n", m_FmtBlock.dwFmtSize);
62+
printf("\t wFormatTag \t : %d \n", m_FmtBlock.wavFormat.wFormatTag);
63+
printf("\t wChannels \t : %d \n", m_FmtBlock.wavFormat.wChannels);
64+
printf("\t dwSamplesPerSec \t : %d \n", m_FmtBlock.wavFormat.dwSamplesPerSec);
65+
printf("\t dwAvgBytesPerSec \t : %d \n", m_FmtBlock.wavFormat.dwAvgBytesPerSec);
66+
printf("\t wBlockAlign \t : %d \n", m_FmtBlock.wavFormat.wBlockAlign);
67+
printf("\t wBitsPerSample \t : %d \n", m_FmtBlock.wavFormat.wBitsPerSample);
68+
69+
printf("************************ DATA HEADER ************************\n");
70+
printf("\t szDataID \t : %s \n", BytesToStr(m_DataHeader.szDataID, 4).c_str());
71+
printf("\t dwDataSize \t : %d \n", m_DataHeader.dwDataSize);
72+
73+
printf("************************ WAVE DATA ************************\n");
74+
int iSize = min(100, m_DataHeader.dwDataSize);
75+
for (int i = 0; i < iSize; i++)
76+
{
77+
printf(" %02X ", m_pData[i]);
78+
}
79+
printf(" ...");
80+
}
81+
82+
bool CWAVFile::ReadData(byte_ptr pData, int iSize)
83+
{
84+
// RIFF_HEADER;
85+
int iRiffHeaderSize = sizeof(m_RiffHeader);
86+
memcpy(&m_RiffHeader, pData, iRiffHeaderSize);
87+
pData += iRiffHeaderSize;
88+
// FMT_BLOCK;
89+
int iFmtBlockSize = sizeof(m_FmtBlock);
90+
memcpy(&m_FmtBlock, pData, iFmtBlockSize);
91+
pData += iFmtBlockSize;
92+
// DATA_HEADER;
93+
int iDataHeaderSize = sizeof(m_DataHeader);
94+
memcpy(&m_DataHeader, pData, iDataHeaderSize);
95+
pData += iDataHeaderSize;
96+
97+
if (m_pData)
98+
{
99+
delete []m_pData;
100+
}
101+
int iDataSize = m_DataHeader.dwDataSize;
102+
m_pData = new byte[iDataSize];
103+
memcpy(m_pData, pData, iDataSize);
104+
105+
return true;
106+
}
107+
108+
bool CWAVFile::WriteData(byte_ptr pData, int &iSize, double dStart, double dEnd)
109+
{
110+
return true;
111+
}

WAV_Parse/WAVFile.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#pragma once
2+
#include "bytes.h"
3+
#include <windows.h>
4+
5+
struct RIFF_HEADER
6+
{
7+
byte szRiffID[4]; // 'R','I','F','F'
8+
DWORD dwRiffSize;
9+
byte szRiffFormat[4]; // 'W','A','V','E'
10+
};
11+
12+
struct WAVE_FORMAT
13+
{
14+
WORD wFormatTag;
15+
WORD wChannels;
16+
DWORD dwSamplesPerSec;
17+
DWORD dwAvgBytesPerSec;
18+
WORD wBlockAlign;
19+
WORD wBitsPerSample;
20+
};
21+
22+
struct FMT_BLOCK
23+
{
24+
byte szFmtID[4]; // 'f','m','t',' '
25+
DWORD dwFmtSize;
26+
WAVE_FORMAT wavFormat;
27+
};
28+
29+
struct DATA_HEADER
30+
{
31+
byte szDataID[4]; // 'd','a','t','a '
32+
DWORD dwDataSize;
33+
};
34+
35+
class CWAVFile
36+
{
37+
public:
38+
CWAVFile();
39+
~CWAVFile();
40+
41+
public:
42+
// 加载文件,读取数据;
43+
bool LoadFile(const char* strFile);
44+
45+
bool SaveFile(const char* strFile, RECT rt = { 0 });
46+
47+
// 显示;
48+
void Display();
49+
50+
protected:
51+
// 解析数据;
52+
bool ReadData(byte_ptr pData, int iSize);
53+
// 打包数据;
54+
bool WriteData(byte_ptr pData, int &iSize, double dStart, double dEnd);
55+
56+
public:
57+
RIFF_HEADER m_RiffHeader;
58+
FMT_BLOCK m_FmtBlock;
59+
DATA_HEADER m_DataHeader;
60+
byte* m_pData;
61+
int m_iSize;
62+
};

WAV_Parse/WAV_Parse.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.21005.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WAV_Parse", "WAV_Parse.vcxproj", "{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}"
7+
EndProject
8+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BMP_Parse", "..\BMP_Parse\BMP_Parse.vcxproj", "{40DF3618-E7AE-4272-A075-B2CB810EFFCC}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Win32 = Debug|Win32
13+
Release|Win32 = Release|Win32
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}.Debug|Win32.ActiveCfg = Debug|Win32
17+
{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}.Debug|Win32.Build.0 = Debug|Win32
18+
{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}.Release|Win32.ActiveCfg = Release|Win32
19+
{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}.Release|Win32.Build.0 = Release|Win32
20+
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Debug|Win32.ActiveCfg = Debug|Win32
21+
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Debug|Win32.Build.0 = Debug|Win32
22+
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Release|Win32.ActiveCfg = Release|Win32
23+
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Release|Win32.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

WAV_Parse/WAV_Parse.vcxproj

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}</ProjectGuid>
15+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
16+
<Keyword>ManagedCProj</Keyword>
17+
<RootNamespace>WAV_Parse</RootNamespace>
18+
</PropertyGroup>
19+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
21+
<ConfigurationType>Application</ConfigurationType>
22+
<UseDebugLibraries>true</UseDebugLibraries>
23+
<PlatformToolset>v120</PlatformToolset>
24+
<CLRSupport>true</CLRSupport>
25+
<CharacterSet>Unicode</CharacterSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>false</UseDebugLibraries>
30+
<PlatformToolset>v120</PlatformToolset>
31+
<CLRSupport>true</CLRSupport>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
35+
<ImportGroup Label="ExtensionSettings">
36+
</ImportGroup>
37+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
38+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
39+
</ImportGroup>
40+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
41+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
42+
</ImportGroup>
43+
<PropertyGroup Label="UserMacros" />
44+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
45+
<LinkIncremental>true</LinkIncremental>
46+
<OutDir>../bin_d</OutDir>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
49+
<LinkIncremental>false</LinkIncremental>
50+
</PropertyGroup>
51+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
52+
<ClCompile>
53+
<WarningLevel>Level3</WarningLevel>
54+
<Optimization>Disabled</Optimization>
55+
<PreprocessorDefinitions>WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
56+
</ClCompile>
57+
<Link>
58+
<GenerateDebugInformation>true</GenerateDebugInformation>
59+
<AdditionalDependencies />
60+
</Link>
61+
</ItemDefinitionGroup>
62+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<ClCompile>
64+
<WarningLevel>Level3</WarningLevel>
65+
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
66+
</ClCompile>
67+
<Link>
68+
<GenerateDebugInformation>true</GenerateDebugInformation>
69+
<AdditionalDependencies />
70+
</Link>
71+
</ItemDefinitionGroup>
72+
<ItemGroup>
73+
<ClCompile Include="bytes.cpp" />
74+
<ClCompile Include="main.cpp" />
75+
<ClCompile Include="WAVFile.cpp" />
76+
</ItemGroup>
77+
<ItemGroup>
78+
<ClInclude Include="bytes.h" />
79+
<ClInclude Include="WAVFile.h" />
80+
</ItemGroup>
81+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
82+
<ImportGroup Label="ExtensionTargets">
83+
</ImportGroup>
84+
</Project>

0 commit comments

Comments
 (0)