Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gr4 #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/harmony.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<ClCompile Include="..\notes\Style.cpp" />
<ClCompile Include="..\util\ArpegPlayer.cpp" />
<ClCompile Include="..\util\AudioMath.cpp" />
<ClCompile Include="..\util\gray_code\LargeGapGrayCode.cpp" />
<ClCompile Include="..\util\quant\NoteConvert.cpp" />
<ClCompile Include="..\util\quant\Scale.cpp" />
<ClCompile Include="..\util\quant\ScaleQuantizer.cpp" />
Expand All @@ -174,6 +175,7 @@
<ClCompile Include="testArpegRhythmPlayer.cpp" />
<ClCompile Include="testChord4Manager.cpp" />
<ClCompile Include="testGrayCode.cpp" />
<ClCompile Include="testGrayCode2.cpp" />
<ClCompile Include="testHarmonyChords2.cpp" />
<ClCompile Include="testHarmonyChordsRandom.cpp" />
<ClCompile Include="testNoteBuffer.cpp" />
Expand Down
9 changes: 9 additions & 0 deletions tests/harmony.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<Filter Include="Header Files\util\gray_code">
<UniqueIdentifier>{33bc1beb-6b98-40ec-a0ad-ed4a23df653a}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\util\gray_code">
<UniqueIdentifier>{4f8ff142-0156-475b-9e53-e481d10a2464}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
Expand Down Expand Up @@ -189,6 +192,12 @@
<ClCompile Include="testAdditiveModLogic.cpp">
<Filter>Source Files\tests</Filter>
</ClCompile>
<ClCompile Include="testGrayCode2.cpp">
<Filter>Source Files\tests</Filter>
</ClCompile>
<ClCompile Include="..\util\gray_code\LargeGapGrayCode.cpp">
<Filter>Source Files\util\gray_code</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\notes\HarmonyNote.h">
Expand Down
5 changes: 3 additions & 2 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ extern void testRingBuffer();
extern void testChord4Manager();
extern void testTempo();
extern void testGrayCode();
extern void testGrayCode2();
extern void testAdditivePitchLogic();
extern void testSines();
extern void testAdditive();
extern void testAdditiveGainLogic();
extern void testAdditiveModLogic();

int main(const char**, int) {
// testGrayCode();
// std::exit(0);
testGrayCode2();
std::exit(0);
#if 0
specialDumpList();
#else
Expand Down
87 changes: 87 additions & 0 deletions tests/testGrayCode2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "LargeGapGrayCode.h"
#include "asserts.h"


void printBinaryCode(const std::vector<std::bitset<20> >& code, int bitWidth)
{
printf("vector has %zd elements\n", code.size());
assert(bitWidth < 20);
const auto trim = 20 - bitWidth;
for (auto i = 0; i < code.size(); ++i) {
const std::bitset<20>& x = code[i];
const std::string s = x.to_string();
const std::string s2 = s.substr(trim, bitWidth);
printf("word %3d = %s\n", i, s2.c_str());

}

#if 0
for (int j = 0; j < bitWidth; ++j)
{
for (int i = 0; i < pow(2, bitWidth); i++)
{
std::cout << code[i][j];
}
std::cout << std::endl;
}
std::cout << std::endl;
#endif
}

static void test0() {
LargeGapGrayCode lggc;
std::cout << "####################################################################" << std::endl;
std::cout << "####### 1) Printing statistics for all Large-Gap Gray Codes #######" << std::endl;
std::cout << "####################################################################" << std::endl << std::endl;
lggc.printAllStatistics();

std::cout << std::endl << std::endl;
std::cout << "####################################################################" << std::endl;
std::cout << "####### 2) Printing statistics for different 16-bit codes #######" << std::endl;
std::cout << "####################################################################" << std::endl << std::endl;
lggc.printStatisticsHeader();

std::cout << "####################################################################" << std::endl;
std::cout << "####### 3) stats for 14, 2, 3, 1 #######" << std::endl;
std::cout << "####################################################################" << std::endl << std::endl;
lggc.createCodeFromTheorem1(14, 2, 3, 1);
std::cout << std::endl << std::endl;
lggc.printStatistics(16);

std::cout << "####################################################################" << std::endl;
std::cout << "####### 3) stats for 8, 8, 129, 127 #######" << std::endl;
std::cout << "####################################################################" << std::endl << std::endl;

std::cout << std::endl << std::endl;
lggc.createCodeFromTheorem1(8, 8, 129, 127);
lggc.printStatistics(16);


std::cout << "####################################################################" << std::endl;
std::cout << "####### 3) stats for 9, 7, 65, 63 #######" << std::endl;
std::cout << "####################################################################" << std::endl << std::endl;

std::cout << std::endl << std::endl;
lggc.createCodeFromTheorem1(9, 7, 65, 63);
lggc.printStatistics(16);

std::cout << "####################################################################" << std::endl;
std::cout << "####### 3) stats for 11, 5, 21, 11 #######" << std::endl;
std::cout << "####################################################################" << std::endl << std::endl;
std::cout << std::endl << std::endl;
lggc.createCodeFromTheorem1(11, 5, 21, 11);
lggc.printStatistics(16);

std::cout << std::endl << std::endl;
std::cout << "####################################################################" << std::endl;
std::cout << "####### 3) Printing generated 7-bit binary code #######" << std::endl;
std::cout << "####### Note: MinGap = 5 and MaxGap = 11 #######" << std::endl;
std::cout << "####################################################################" << std::endl << std::endl;
//printBinaryCode(lggc.getBinaryCode(7), 7);
printBinaryCode(lggc.getBinaryCode(6), 6);
}

void testGrayCode2() {
test0();
assert(false);
}