From 3c42d8a7af6979c9b589046cb1bf2afeea637a81 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 14 Mar 2013 17:35:54 +0000 Subject: [PATCH] More testing, start base64 code fix --- source/backend/native/Makefile | 2 +- source/backend/native/zynaddsubfx.cpp | 5 ++- .../backend/native/zynaddsubfx/Misc/Stereo.h | 2 +- source/tests/ANSI.cpp | 40 +------------------ source/tests/Base64.cpp | 35 ++++++++++++---- source/tests/Makefile | 5 ++- source/utils/CarlaBase64Utils.hpp | 11 ++--- 7 files changed, 44 insertions(+), 56 deletions(-) diff --git a/source/backend/native/Makefile b/source/backend/native/Makefile index 60512cc2e..99230d093 100644 --- a/source/backend/native/Makefile +++ b/source/backend/native/Makefile @@ -78,7 +78,6 @@ OBJS += \ zynaddsubfx/Misc/Microtonal.cpp.o \ zynaddsubfx/Misc/Part.cpp.o \ zynaddsubfx/Misc/Recorder.cpp.o \ - zynaddsubfx/Misc/Stereo.cpp.o \ zynaddsubfx/Misc/Util.cpp.o \ zynaddsubfx/Misc/WavFile.cpp.o \ zynaddsubfx/Misc/WaveShapeSmps.cpp.o \ @@ -101,6 +100,7 @@ OBJS += \ zynaddsubfx/Synth/Resonance.cpp.o \ zynaddsubfx/Synth/SUBnote.cpp.o \ zynaddsubfx/Synth/SynthNote.cpp.o +# zynaddsubfx/Misc/Stereo.cpp.o endif SHARED = ../libcarla_native.so diff --git a/source/backend/native/zynaddsubfx.cpp b/source/backend/native/zynaddsubfx.cpp index 36afe9b7f..0817c0ecc 100644 --- a/source/backend/native/zynaddsubfx.cpp +++ b/source/backend/native/zynaddsubfx.cpp @@ -32,6 +32,7 @@ // TODO - free sPrograms // Dummy variables and functions for linking purposes +const char* instance_name = nullptr; class WavFile; namespace Nio { bool start(void){return 1;} @@ -283,7 +284,7 @@ public: config.init(); config.cfg.SoundBufferSize = synth->buffersize; config.cfg.SampleRate = synth->samplerate; - config.cfg.GzipCompression = 0; + //config.cfg.GzipCompression = 0; sprng(std::time(nullptr)); denormalkillbuf = new float[synth->buffersize]; @@ -317,6 +318,7 @@ public: doSearch = false; + pthread_mutex_lock(&master->mutex); #if 0 // refresh banks master->bank.rescanforbanks(); @@ -339,6 +341,7 @@ public: } } #endif + pthread_mutex_unlock(&master->mutex); } CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ZynAddSubFxPlugin) diff --git a/source/backend/native/zynaddsubfx/Misc/Stereo.h b/source/backend/native/zynaddsubfx/Misc/Stereo.h index 996d19a02..516d31870 100644 --- a/source/backend/native/zynaddsubfx/Misc/Stereo.h +++ b/source/backend/native/zynaddsubfx/Misc/Stereo.h @@ -36,5 +36,5 @@ struct Stereo { //data T l, r; }; - +#include "Stereo.cpp" #endif diff --git a/source/tests/ANSI.cpp b/source/tests/ANSI.cpp index c3f187a83..a212e3c84 100644 --- a/source/tests/ANSI.cpp +++ b/source/tests/ANSI.cpp @@ -15,47 +15,9 @@ * For a full copy of the GNU General Public License see the GPL.txt file */ -// still need qt classes check -//#include "plugin/CarlaPluginInternal.hpp" -//#include "plugin/DssiPlugin.cpp" -//#include "../widgets/digitalpeakmeter.cpp" - -#include "CarlaUtils.hpp" - -#if 0 -#include "CarlaDefines.hpp" -#include "CarlaMIDI.h" -#include "ladspa_rdf.hpp" -#include "lv2_rdf.hpp" - -#include "CarlaBackend.hpp" -#include "CarlaEngine.hpp" -#include "CarlaNative.h" -#include "CarlaNative.hpp" -#include "CarlaPlugin.hpp" -#include "CarlaStandalone.hpp" - -#include "CarlaUtils.hpp" -#include "CarlaBackendUtils.hpp" #include "CarlaBase64Utils.hpp" -#include "CarlaJuceUtils.hpp" -#include "CarlaLibUtils.hpp" -#include "CarlaOscUtils.hpp" -//#include "CarlaStateUtils.hpp" -#include "CarlaLadspaUtils.hpp" -//#include "CarlaLv2Utils.hpp" -#include "CarlaVstUtils.hpp" - -#include "CarlaMutex.hpp" -#include "CarlaString.hpp" -#include "CarlaThread.hpp" -//#include "Lv2AtomQueue.hpp" -#include "RtList.hpp" -#endif - -#include "Utils.cpp" -int main2() +int main() { return 0; } diff --git a/source/tests/Base64.cpp b/source/tests/Base64.cpp index cd94fc0cc..3283017d3 100644 --- a/source/tests/Base64.cpp +++ b/source/tests/Base64.cpp @@ -16,11 +16,33 @@ */ #include "CarlaBase64Utils.hpp" -#include "CarlaString.hpp" +//#include "CarlaString.hpp" int main() { - CARLA_ASSERT(std::strlen(kBase64) == 64); + // First check, cannot fail + assert(std::strlen(kBase64) == 64); + + // Test regular C strings + { + const char strHelloWorld[] = "Hello World\n\0"; + const char b64HelloWorld[] = "SGVsbG8gV29ybGQK\0"; + + // encode "Hello World" to base64 + size_t bufSize = std::strlen(strHelloWorld); + char bufEncoded[carla_base64_encoded_len(bufSize) + 1]; + carla_base64_encode((const uint8_t*)strHelloWorld, bufSize, bufEncoded); + assert(std::strcmp(b64HelloWorld, bufEncoded) == 0); + + // decode base64 "SGVsbG8gV29ybGQK" back to "Hello World" + uint8_t bufDecoded[carla_base64_decoded_max_len(b64HelloWorld)]; + size_t bufDecSize = carla_base64_decode(b64HelloWorld, bufDecoded); + char strDecoded[bufDecSize+1]; + std::strncpy(strDecoded, (char*)bufDecoded, bufDecSize); + strDecoded[bufDecSize] = '\0'; + assert(std::strcmp(strHelloWorld, strDecoded) == 0); + assert(bufSize == bufDecSize); + } struct Blob { char s[4]; @@ -34,13 +56,11 @@ int main() : s{'1', 's', 't', 0}, i(228), d(3.33333333333), - ptr((void*)0x500) - { - carla_zeroMem(padding, sizeof(char)*100); - } - + padding{0}, + ptr((void*)0x500) {} } blob; +#if 0 // binary -> base64 void* const test0 = &blob; size_t test0Len = sizeof(Blob); @@ -105,6 +125,7 @@ int main() CARLA_ASSERT(blob3->ptr == blob.ptr); delete blob3; +#endif // ----------------------------------------------------------------- diff --git a/source/tests/Makefile b/source/tests/Makefile index 56fdea144..baf816828 100644 --- a/source/tests/Makefile +++ b/source/tests/Makefile @@ -18,7 +18,7 @@ BUILD_CXX_FLAGS += -I../backend -I../includes -I../libs -I../utils -Wall -Wextra ANSI_CXX_FLAGS = -ansi -pedantic -pedantic-errors -Wunused-parameter -Wuninitialized -Wno-vla ANSI_CXX_FLAGS += -Wcast-qual -Wconversion -Wsign-conversion -Wlogical-op -Waggregate-return ANSI_CXX_FLAGS += -std=c++11 -Wzero-as-null-pointer-constant -ANSI_CXX_FLAGS += -DVESTIGE_HEADER -shared -fPIC +ANSI_CXX_FLAGS += -DVESTIGE_HEADER -fPIC TARGETS = ANSI Base64 CarlaString RtList Thread Print Utils @@ -48,7 +48,8 @@ Utils: Utils.cpp $(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ RUN: $(TARGETS) - valgrind ./Utils + valgrind ./Base64 +# ./ANSI # ./CarlaString && ./RtList && ./Thread # ./Print # ./Base64 diff --git a/source/utils/CarlaBase64Utils.hpp b/source/utils/CarlaBase64Utils.hpp index cfc8bf1b5..fa44d4639 100644 --- a/source/utils/CarlaBase64Utils.hpp +++ b/source/utils/CarlaBase64Utils.hpp @@ -70,7 +70,7 @@ size_t carla_base64_decoded_max_len(const char* const encoded) static inline void carla_base64_encode(const uint8_t* const raw, const size_t len, char* const encoded) { - const uint8_t* rawBytes = (const uint8_t*)raw; + const uint8_t* rawBytes = raw; uint8_t* encodedBytes = (uint8_t*)encoded; size_t rawBitLen = 8*len; size_t bit, tmp; @@ -79,6 +79,7 @@ void carla_base64_encode(const uint8_t* const raw, const size_t len, char* const { tmp = static_cast((rawBytes[bit/8] << (bit % 8)) | (rawBytes[bit/8 + 1] >> (8 - (bit % 8)))); tmp = static_cast((tmp >> 2) & 0x3f); + CARLA_ASSERT(tmp < 64); *(encodedBytes++) = static_cast(kBase64[tmp]); } @@ -110,13 +111,13 @@ static inline unsigned int carla_base64_decode(const char* const encoded, uint8_t* const raw) { const uint8_t* encodedBytes = (const uint8_t*)encoded; - uint8_t* rawBytes = (uint8_t*)raw; + uint8_t* rawBytes = raw; uint8_t encodedByte; unsigned int bit = 0; unsigned int padCount = 0; /* Zero the raw data */ - std::memset(raw, 0, carla_base64_decoded_max_len(encoded)); + carla_zeroMem(raw, carla_base64_decoded_max_len(encoded)); /* Decode string */ while ((encodedByte = *(encodedBytes++)) > 0) @@ -146,7 +147,7 @@ unsigned int carla_base64_decode(const char* const encoded, uint8_t* const raw) } /* Process normal characters */ - const char* match = std::strchr(kBase64, encodedByte); + const char* const match = std::strchr(kBase64, encodedByte); if (match == nullptr) { @@ -172,7 +173,7 @@ unsigned int carla_base64_decode(const char* const encoded, uint8_t* const raw) unsigned int len = bit/8; - carla_debug("Base64-decoded \"%s\" to: \"%s\"\n", encoded, raw); + carla_debug("Base64-decoded \"%s\"", encoded); CARLA_ASSERT(len <= carla_base64_decoded_max_len(encoded)); /* Return length in bytes */