-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# Visual Studio | ||
.vscode | ||
|
||
# Build | ||
bin/ | ||
build/ | ||
|
||
|
||
# Prerequisites | ||
*.d | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.0.0) | ||
project(new_project VERSION 0.1.0) | ||
|
||
include(CTest) | ||
enable_testing() | ||
|
||
include_directories(./include) | ||
file(GLOB TARGET_SRC "./src/*.cpp" ) | ||
|
||
add_executable(main ${TARGET_SRC}) | ||
|
||
|
||
set(CPACK_PROJECT_NAME ${PROJECT_NAME}) | ||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) | ||
include(CPack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef WAVE_H | ||
#define WAVE_H | ||
|
||
// Information taken from online at: | ||
// http://soundfile.sapp.org/doc/WaveFormat/ | ||
|
||
struct WaveHeader | ||
{ | ||
char chunkID[4] = {'R','I','F','F'}; // Contains the letters "RIFF" in ASCII form | ||
long chunkSize; // 4 + (8 + SubChunk1Size) + (8 + SubChunk2Size) | ||
char format[4] = {'W','A','V','E'}; // Contains the letters "WAVE" in ASCII form | ||
|
||
char subchunk1ID[4] = {'f','m','t',' '}; // Contains the letters "fmt " in ASCII form | ||
long subchunk1Size = 16; // 16 for PCM | ||
short audioFormat; // PCM = 1 Values other than 1 indicate some form of compression | ||
short numChannels; // Mono = 1, Stereo = 2, etc | ||
long sampleRate; // 8000, 44100, etc. | ||
long byteRate; // SampleRate * NumChannels * BitsPerSample/8 | ||
short blockAlign; // NumChannels * BitsPerSample/8 | ||
short bitsPerSample; // 8 bits = 8, 16 bits = 16, etc | ||
|
||
char subchunk2ID[4] = {'d','a','t','a'}; // Contains the letters "data" in ASCII form | ||
long subchunk2Size; // This is the number of bytes in the data | ||
}; | ||
|
||
bool isCorrectHeader(struct WaveHeader *hdr); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <adpcm-lib/wave.h> | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
int main() | ||
{ | ||
struct WaveHeader hdr; | ||
std::ifstream in("test.wav", std::ios::binary); | ||
|
||
in.read((char*)&hdr, sizeof(struct WaveHeader)); | ||
std::cout<< isCorrectHeader(&hdr) << "\n"; | ||
system("PAUSE"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <adpcm-lib/wave.h> | ||
#include <string.h> | ||
|
||
bool isCorrectHeader(struct WaveHeader *hdr) | ||
{ | ||
if(memcmp(hdr->chunkID, "RIFF", 4) == 0) | ||
{ | ||
if(memcmp(hdr->format, "WAVE", 4) == 0) | ||
{ | ||
if(memcmp(hdr->subchunk1ID, "fmt ", 4) == 0) | ||
{ | ||
if(memcmp(hdr->subchunk2ID, "data", 4) == 0) | ||
{ | ||
int expectedSize = 4 + (8 + hdr->subchunk1Size) + (8 + hdr->subchunk2Size); | ||
if(hdr->subchunk1Size == 16 && hdr->chunkSize == expectedSize) | ||
{ | ||
int expectedAlign = hdr->numChannels * hdr->bitsPerSample/8; | ||
int expectedByteRate = expectedAlign * hdr->sampleRate; | ||
if(hdr->blockAlign == expectedAlign && hdr->byteRate == expectedByteRate) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} |