From 29fa1a5dd6a1988073bd35edbede074fe112535f Mon Sep 17 00:00:00 2001 From: Vindicator645 <45960487+Vindicator645@users.noreply.github.com> Date: Thu, 27 Dec 2018 10:03:40 +0800 Subject: [PATCH] Added. This section contains the fft part which is used to transform sound signal into color more accurately but due to time and knowledge constraint is sadly unused. --- .gitattributes | 63 ++++++++++++++++++++++++++++++++++++++++++++++ include/graphs.hpp | 2 ++ include/type.hpp | 12 ++++++++- include/wav.hpp | 1 + src/fields.cpp | 3 +++ src/graphs.cpp | 36 ++++++++++++++++++++++++++ src/hsv.cpp | 2 ++ src/wav.cpp | 9 +++++++ windows/main.cpp | 31 +++++++++++++++++++++++ 9 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 .gitattributes create mode 100644 windows/main.cpp diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/include/graphs.hpp b/include/graphs.hpp index e709d27..73711b8 100644 --- a/include/graphs.hpp +++ b/include/graphs.hpp @@ -26,6 +26,8 @@ unsigned long fresh_screen(int signal); //计算函数声明 void draw_fields(int signal); +int create_fields(int hw); + /************************************************ 颜色的抽象 ***/ diff --git a/include/type.hpp b/include/type.hpp index 7905dfc..3942fc2 100644 --- a/include/type.hpp +++ b/include/type.hpp @@ -1,6 +1,7 @@ #ifndef type_h #define type_h + #include #include #include @@ -11,9 +12,18 @@ #include #include #include +#define _CRT_SECURE_NO_WARNINGS #endif + +#ifdef WIN32 +#include +#include +#pragma warning(disable:4996) +#endif + + #include #include #include -#endif /* type_h */ +#endif diff --git a/include/wav.hpp b/include/wav.hpp index 3a70640..7b34c24 100644 --- a/include/wav.hpp +++ b/include/wav.hpp @@ -9,6 +9,7 @@ using std::string; using std::vector; FILE * readWAVInfo(void); +int init_test_wav(int); struct WAV_Format{ uint32_t ChunkID; /* "RIFF" */ diff --git a/src/fields.cpp b/src/fields.cpp index 7c544fb..3f404ba 100644 --- a/src/fields.cpp +++ b/src/fields.cpp @@ -1 +1,4 @@ #include + + + diff --git a/src/graphs.cpp b/src/graphs.cpp index f62036d..4389ce6 100644 --- a/src/graphs.cpp +++ b/src/graphs.cpp @@ -3,12 +3,34 @@ #include + extern int if_fresh, if_draw; extern vector fields; extern Window *p_nwd; extern WAV twav; extern Shape *p_avg; +#ifdef WIN32 +int gettimeofday(struct timeval *tp, void *tzp) +{ + time_t clock; + struct tm tm; + SYSTEMTIME wtm; + GetLocalTime(&wtm); + tm.tm_year = wtm.wYear - 1900; + tm.tm_mon = wtm.wMonth - 1; + tm.tm_mday = wtm.wDay; + tm.tm_hour = wtm.wHour; + tm.tm_min = wtm.wMinute; + tm.tm_sec = wtm.wSecond; + tm.tm_isdst = -1; + clock = mktime(&tm); + tp->tv_sec = clock; + tp->tv_usec = wtm.wMilliseconds * 1000; + return (0); +} +#endif + void draw_fields(int signal){ if (if_fresh == 1 && if_draw == 0){ timeval timer_a, timer_b; @@ -57,3 +79,17 @@ unsigned long fresh_screen(int signal){ return -1; } +int create_fields(int hw) { + for (int y = 0; y < hw; y++) { + for (int x = 0; x < hw; x++) { + double dx = x / 16.8, dy = y / 16.8; + Field *p_field = new Field({ {-0.9 + dx,0.9 - dy,0},{-(0.848) + dx,(0.848) - dy,0} }); + p_nwd->draw_shape(p_field); + fields.push_back(p_field); + } + } + fields[0]->color.setColor({ 0,0,0 }); + p_avg->setRetangle({ {0.98,-0.98},{0.85,-0.85} }); + p_nwd->draw_shape(p_avg); + return 0; +} \ No newline at end of file diff --git a/src/hsv.cpp b/src/hsv.cpp index bd16bb5..12e69b9 100644 --- a/src/hsv.cpp +++ b/src/hsv.cpp @@ -2,6 +2,8 @@ #include #include + + hsv rgb2hsv(rgb in) { hsv out; diff --git a/src/wav.cpp b/src/wav.cpp index 74c96a4..77ddc35 100644 --- a/src/wav.cpp +++ b/src/wav.cpp @@ -1,5 +1,7 @@ #include +extern WAV twav; + FILE * readWAVInfo(void){ FILE *fp = NULL; struct WAV_Format wav; @@ -8,3 +10,10 @@ FILE * readWAVInfo(void){ return fp; } + + +int init_test_wav(int ms) { + twav.getInfo(); + twav.setTimer(ms); + return sqrt(twav.m_pss.step); +} \ No newline at end of file diff --git a/windows/main.cpp b/windows/main.cpp new file mode 100644 index 0000000..9de8492 --- /dev/null +++ b/windows/main.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +int if_fresh = 1, if_draw = 0; +list Window::shapes = {}; +map Window::menus = {}; +vector fields; +unsigned long fresh_screen(int signal); + +FILE *fp; +Window *p_nwd = NULL; + +WAV twav("data/test.wav"); +Shape *p_avg = new Shape(); + +int main(int argc, char * argv[]) { + Window nwd(argc, argv); + p_nwd = &nwd; + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + glutInitWindowPosition(100, 100); + glutInitWindowSize(700, 700); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + int hw = init_test_wav(60); + create_fields(hw); + nwd.create("Fields"); + nwd.show(); + + return 0; +} \ No newline at end of file