From abca7b640783a8fbc12c59fc80775be01df64b66 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 17 Nov 2019 05:53:02 -0500 Subject: [PATCH] new shot at androidbase --- .gitmodules | 3 ++ colorchord2/DisplayNetwork.c | 1 + colorchord2/configs.c | 44 +++++++++++++++++++++++++ colorchord2/main.c | 64 ++++++++++++++++++++++++++++++++++++ colorchord2/os_generic.c | 5 +++ colorchord2/quickwash.conf | 13 ++++---- colorchord2/rawdraw | 1 + colorchord2/sound_alsa.c | 1 + 8 files changed, 126 insertions(+), 6 deletions(-) create mode 160000 colorchord2/rawdraw diff --git a/.gitmodules b/.gitmodules index ed48a58..35e4876 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "embedded8266/esp82xx"] path = embedded8266/esp82xx url = https://github.com/cnlohr/esp82xx.git +[submodule "colorchord2/rawdraw"] + path = colorchord2/rawdraw + url = https://github.com/cntools/rawdraw diff --git a/colorchord2/DisplayNetwork.c b/colorchord2/DisplayNetwork.c index b2bb3e3..a2eb6d4 100644 --- a/colorchord2/DisplayNetwork.c +++ b/colorchord2/DisplayNetwork.c @@ -5,6 +5,7 @@ #include #include "parameters.h" #include +#include #include #include #include "color.h" diff --git a/colorchord2/configs.c b/colorchord2/configs.c index 61c0acf..db3b1c2 100644 --- a/colorchord2/configs.c +++ b/colorchord2/configs.c @@ -62,7 +62,50 @@ void SetEnvValues( int force ) if( !hits && !force ) return; //Otherwise, something changed. +#ifdef ANDROID + SetParametersFromString( "cpu_autolimit=1" ); + SetParametersFromString( "set_screenx=720" ); + SetParametersFromString( "set_screeny=480" ); + SetParametersFromString( "buffer=384" ); + SetParametersFromString( "play=0" ); + SetParametersFromString( "rec=1" ); + SetParametersFromString( "channels=2" ); + SetParametersFromString( "samplerate=44100" ); + SetParametersFromString( "sourcename=default" ); + SetParametersFromString( "amplify=2.0" ); + SetParametersFromString( "base_hz=55" ); + SetParametersFromString( "dft_iir=0.6" ); + SetParametersFromString( "dft_q=20.0000" ); + SetParametersFromString( "dft_speedup=1000.0000" ); + SetParametersFromString( "octaves=5" ); + + SetParametersFromString( "do_progressive_dft=4" ); + + SetParametersFromString( "filter_iter=2" ); + SetParametersFromString( "filter_strength=.5" ); + SetParametersFromString( "freqbins = 24" ); + SetParametersFromString( "do_progressive_dft=4" ); + SetParametersFromString( "note_attach_amp_iir=0.3500" ); + SetParametersFromString( "note_attach_amp_iir2=0.250" ); + + SetParametersFromString( "note_combine_distance=0.5000" ); + SetParametersFromString( "note_jumpability=1.8000" ); + SetParametersFromString( "note_minimum_new_distribution_value=0.0200" ); + SetParametersFromString( "note_out_chop=0.05000" ); + SetParametersFromString( "outdrivers=OutputVoronoi,DisplayArray" ); + SetParametersFromString( "note_attach_amp_iir2=0.250" ); + + SetParametersFromString( "lightx=64" ); + SetParametersFromString( "lighty=32" ); + SetParametersFromString( "fromsides=1" ); + SetParametersFromString( "shape_cutoff=0.03" ); + + SetParametersFromString( "satamp=5.000" ); + SetParametersFromString( "amppow=2.510" ); + SetParametersFromString( "distpow=1.500" ); + +#else LoadFile( InitialFile[0] ); for( i = 1; i < gargc; i++ ) @@ -78,6 +121,7 @@ void SetEnvValues( int force ) LoadFile( gargv[i] ); } } +#endif } void ProcessArgs() diff --git a/colorchord2/main.c b/colorchord2/main.c index adc00c6..c8a7ba3 100644 --- a/colorchord2/main.c +++ b/colorchord2/main.c @@ -18,6 +18,36 @@ #include "hook.h" #include "configs.h" +#ifdef ANDROID +#include +#include +#include +#include +#include +#include + +static int pfd[2]; +static pthread_t loggingThread; +static const char *LOG_TAG = "colorchord"; +static void *loggingFunction(void*v) { + ssize_t readSize; + char buf[128]; + + while((readSize = read(pfd[0], buf, sizeof buf - 1)) > 0) { + if(buf[readSize - 1] == '\n') { + --readSize; + } + + buf[readSize] = 0; // add null-terminator + + __android_log_write(ANDROID_LOG_DEBUG, LOG_TAG, buf); // Set any log level you want + } + + return 0; +} + +#endif + struct SoundDriver * sd; #if defined(WIN32) || defined(USE_WINDOWS) @@ -162,9 +192,40 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun *samplesp = samplesr; } +#ifdef ANDROID +void HandleSuspend() +{ + //Unused. +} + +void HandleResume() +{ + //Unused. +} +#endif + int main(int argc, char ** argv) { int i; + +#ifdef ANDROID + setvbuf(stdout, 0, _IOLBF, 0); // make stdout line-buffered + setvbuf(stderr, 0, _IONBF, 0); // make stderr unbuffered + + /* create the pipe and redirect stdout and stderr */ + pipe(pfd); + dup2(pfd[1], 1); + dup2(pfd[1], 2); + + /* spawn the logging thread */ + if(pthread_create(&loggingThread, 0, loggingFunction, 0) == -1) { + return -1; + } + + pthread_detach(loggingThread); + +#endif + #ifdef TCC void ManuallyRegisterDevices(); ManuallyRegisterDevices(); @@ -181,6 +242,8 @@ int main(int argc, char ** argv) WSAStartup(0x202, &wsaData); strcpy( sound_source, "WIN" ); +#elif defined( ANDROID ) + strcpy( sound_source, "ANDROID" ); #else strcpy( sound_source, "PULSE" ); #endif @@ -263,6 +326,7 @@ int main(int argc, char ** argv) double Last = Now; while(1) { + printf( ".\n" ); char stt[1024]; //Handle Rawdraw frame swappign diff --git a/colorchord2/os_generic.c b/colorchord2/os_generic.c index da281e3..2b4321e 100644 --- a/colorchord2/os_generic.c +++ b/colorchord2/os_generic.c @@ -228,7 +228,12 @@ void OGCancelThread( og_thread_t ot ) { return; } +#ifdef ANDROID + void * fakeret; + pthread_join( *(pthread_t*)ot, &fakeret ); +#else pthread_cancel( *(pthread_t*)ot ); +#endif free( ot ); } diff --git a/colorchord2/quickwash.conf b/colorchord2/quickwash.conf index ab598e8..e83d38f 100644 --- a/colorchord2/quickwash.conf +++ b/colorchord2/quickwash.conf @@ -1,10 +1,10 @@ This is a vornoi thing: -outdrivers = DisplayArray, OutputProminent -lightx = 2 -lighty = 2 -leds = 4 -fromsides = 1 +outdrivers = DisplayArray, OutputCells +lightx = 3 +lighty = 3 +leds = 9 +fromsides = 0 shape_cutoff = 0.03 satamp = 5.000 amppow = 2.510 @@ -13,7 +13,8 @@ distpow = 1.500 samplerate = 11025 buffer = 64 -sourcename = default +sourcename = alsa_output.pci-0000_00_1f.3.analog-stereo.monitor + #default amplify = 2.5 note_attach_amp_iir = 0.9000 diff --git a/colorchord2/rawdraw b/colorchord2/rawdraw new file mode 160000 index 0000000..e5acb75 --- /dev/null +++ b/colorchord2/rawdraw @@ -0,0 +1 @@ +Subproject commit e5acb751f337f3ae9e558e98907be8e3d6f8381f diff --git a/colorchord2/sound_alsa.c b/colorchord2/sound_alsa.c index e3c986d..3771752 100644 --- a/colorchord2/sound_alsa.c +++ b/colorchord2/sound_alsa.c @@ -4,6 +4,7 @@ #include "os_generic.h" #include "parameters.h" #include +#include #define BUFFERSETS 4