Skip to content

Commit

Permalink
add wav
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsunc committed Jul 25, 2017
1 parent b70eadb commit 00df5f8
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 12 deletions.
16 changes: 9 additions & 7 deletions BMP_Parse/BMPFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ bool CBMPFile::LoadFile(const char* strFile)
return false;
}
fseek(pFile, 0, SEEK_END);
m_iSize = ftell(pFile);
byte_ptr pData = new byte[m_iSize];
m_iFileSize = ftell(pFile);
byte_ptr pData = new byte[m_iFileSize];
fseek(pFile, 0, SEEK_SET);
if (m_iSize != fread(pData, sizeof(byte), m_iSize, pFile))
if (m_iFileSize != fread(pData, sizeof(byte), m_iFileSize, pFile))
{
printf("read file is failed. \n");
return false;
}
fclose(pFile);

bool bResult = ReadData(pData, m_iSize);
bool bResult = ReadData(pData, m_iFileSize);
delete[]pData;
pData = NULL;
return bResult;
Expand Down Expand Up @@ -72,8 +72,8 @@ void CBMPFile::Display()
printf("\t biClrImportant \t : %d \n", m_bmpInfoHeader.biClrImportant);

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

bool CBMPFile::ReadData(byte_ptr pData, int iSize)
{
// BITMAPFILEHEADER;
int iFileHeaderSize = sizeof(m_bmpFileHeader);
memcpy(&m_bmpFileHeader, pData, iFileHeaderSize);
pData += iFileHeaderSize;
// BITMAPINFOHEADER;
int iInfoHeaderSize = sizeof(m_bmpInfoHeader);
memcpy(&m_bmpInfoHeader, pData, iInfoHeaderSize);
pData += iInfoHeaderSize;
Expand Down Expand Up @@ -117,4 +119,4 @@ bool CBMPFile::ReadData(byte_ptr pData, int iSize)
bool CBMPFile::WriteData(byte_ptr pData, int &iSize, double dStart, double dEnd)
{
return true;
}
}
5 changes: 2 additions & 3 deletions BMP_Parse/BMPFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ class CBMPFile
BITMAPFILEHEADER m_bmpFileHeader;
BITMAPINFOHEADER m_bmpInfoHeader;
byte* m_pData;
int m_iSize;
};

int m_iFileSize;
};
1 change: 1 addition & 0 deletions BMP_Parse/BMP_Parse.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="BMPFile.cpp" />
<ClCompile Include="bytes.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
3 changes: 3 additions & 0 deletions BMP_Parse/BMP_Parse.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
<ClCompile Include="main.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="bytes.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions FLV_Parse/bytes.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "bytes.h"


int BytesToInt(byte_ptr pData, int iCount)
{
int iResult = 0;
Expand All @@ -15,4 +14,4 @@ std::string BytesToStr(byte_ptr pData, int iCount)
{
std::string strResult((char*)pData, iCount);
return strResult;
}
}
111 changes: 111 additions & 0 deletions WAV_Parse/WAVFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include "WAVFile.h"

CWAVFile::CWAVFile()
{
m_pData = NULL;
}

CWAVFile::~CWAVFile()
{
if (m_pData)
{
delete[]m_pData;
m_pData = NULL;
}
}

bool CWAVFile::LoadFile(const char* strFile)
{
if (!strFile)
{
printf("strFile is null. \n");
return false;
}
FILE* pFile = fopen(strFile, "rb");
if (!pFile)
{
printf("fopen is failed. \n");
return false;
}
fseek(pFile, 0, SEEK_END);
m_iSize = ftell(pFile);
byte_ptr pData = new byte[m_iSize];
fseek(pFile, 0, SEEK_SET);
if (m_iSize != fread(pData, sizeof(byte), m_iSize, pFile))
{
printf("read file is failed. \n");
return false;
}
fclose(pFile);

bool bResult = ReadData(pData, m_iSize);
delete[]pData;
pData = NULL;
return bResult;
}

bool CWAVFile::SaveFile(const char* strFile, RECT rt)
{
return true;
}

void CWAVFile::Display()
{
printf("************************ RIFF HEADER ************************\n");
printf("\t RiffID \t : %s \n", BytesToStr(m_RiffHeader.szRiffID, 4).c_str());
printf("\t RiffSize \t : %d \n", m_RiffHeader.dwRiffSize);
printf("\t RiffFormat \t : %s \n", BytesToStr(m_RiffHeader.szRiffFormat, 4).c_str());

printf("************************ FMT BLOCK ************************\n");
printf("\t szFmtID \t : %s \n", BytesToStr(m_FmtBlock.szFmtID, 4).c_str());
printf("\t dwFmtSize \t : %d \n", m_FmtBlock.dwFmtSize);
printf("\t wFormatTag \t : %d \n", m_FmtBlock.wavFormat.wFormatTag);
printf("\t wChannels \t : %d \n", m_FmtBlock.wavFormat.wChannels);
printf("\t dwSamplesPerSec \t : %d \n", m_FmtBlock.wavFormat.dwSamplesPerSec);
printf("\t dwAvgBytesPerSec \t : %d \n", m_FmtBlock.wavFormat.dwAvgBytesPerSec);
printf("\t wBlockAlign \t : %d \n", m_FmtBlock.wavFormat.wBlockAlign);
printf("\t wBitsPerSample \t : %d \n", m_FmtBlock.wavFormat.wBitsPerSample);

printf("************************ DATA HEADER ************************\n");
printf("\t szDataID \t : %s \n", BytesToStr(m_DataHeader.szDataID, 4).c_str());
printf("\t dwDataSize \t : %d \n", m_DataHeader.dwDataSize);

printf("************************ WAVE DATA ************************\n");
int iSize = min(100, m_DataHeader.dwDataSize);
for (int i = 0; i < iSize; i++)
{
printf(" %02X ", m_pData[i]);
}
printf(" ...");
}

bool CWAVFile::ReadData(byte_ptr pData, int iSize)
{
// RIFF_HEADER;
int iRiffHeaderSize = sizeof(m_RiffHeader);
memcpy(&m_RiffHeader, pData, iRiffHeaderSize);
pData += iRiffHeaderSize;
// FMT_BLOCK;
int iFmtBlockSize = sizeof(m_FmtBlock);
memcpy(&m_FmtBlock, pData, iFmtBlockSize);
pData += iFmtBlockSize;
// DATA_HEADER;
int iDataHeaderSize = sizeof(m_DataHeader);
memcpy(&m_DataHeader, pData, iDataHeaderSize);
pData += iDataHeaderSize;

if (m_pData)
{
delete []m_pData;
}
int iDataSize = m_DataHeader.dwDataSize;
m_pData = new byte[iDataSize];
memcpy(m_pData, pData, iDataSize);

return true;
}

bool CWAVFile::WriteData(byte_ptr pData, int &iSize, double dStart, double dEnd)
{
return true;
}
62 changes: 62 additions & 0 deletions WAV_Parse/WAVFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once
#include "bytes.h"
#include <windows.h>

struct RIFF_HEADER
{
byte szRiffID[4]; // 'R','I','F','F'
DWORD dwRiffSize;
byte szRiffFormat[4]; // 'W','A','V','E'
};

struct WAVE_FORMAT
{
WORD wFormatTag;
WORD wChannels;
DWORD dwSamplesPerSec;
DWORD dwAvgBytesPerSec;
WORD wBlockAlign;
WORD wBitsPerSample;
};

struct FMT_BLOCK
{
byte szFmtID[4]; // 'f','m','t',' '
DWORD dwFmtSize;
WAVE_FORMAT wavFormat;
};

struct DATA_HEADER
{
byte szDataID[4]; // 'd','a','t','a '
DWORD dwDataSize;
};

class CWAVFile
{
public:
CWAVFile();
~CWAVFile();

public:
// 加载文件,读取数据;
bool LoadFile(const char* strFile);

bool SaveFile(const char* strFile, RECT rt = { 0 });

// 显示;
void Display();

protected:
// 解析数据;
bool ReadData(byte_ptr pData, int iSize);
// 打包数据;
bool WriteData(byte_ptr pData, int &iSize, double dStart, double dEnd);

public:
RIFF_HEADER m_RiffHeader;
FMT_BLOCK m_FmtBlock;
DATA_HEADER m_DataHeader;
byte* m_pData;
int m_iSize;
};
28 changes: 28 additions & 0 deletions WAV_Parse/WAV_Parse.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WAV_Parse", "WAV_Parse.vcxproj", "{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BMP_Parse", "..\BMP_Parse\BMP_Parse.vcxproj", "{40DF3618-E7AE-4272-A075-B2CB810EFFCC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}.Debug|Win32.ActiveCfg = Debug|Win32
{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}.Debug|Win32.Build.0 = Debug|Win32
{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}.Release|Win32.ActiveCfg = Release|Win32
{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}.Release|Win32.Build.0 = Release|Win32
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Debug|Win32.ActiveCfg = Debug|Win32
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Debug|Win32.Build.0 = Debug|Win32
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Release|Win32.ActiveCfg = Release|Win32
{40DF3618-E7AE-4272-A075-B2CB810EFFCC}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
84 changes: 84 additions & 0 deletions WAV_Parse/WAV_Parse.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8B8D8E52-408E-4596-ADC8-B586ECE18DA1}</ProjectGuid>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Keyword>ManagedCProj</Keyword>
<RootNamespace>WAV_Parse</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>../bin_d</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="bytes.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="WAVFile.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bytes.h" />
<ClInclude Include="WAVFile.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading

0 comments on commit 00df5f8

Please sign in to comment.