Browse Source

More testing, start base64 code fix

tags/1.9.4
falkTX 11 years ago
parent
commit
3c42d8a7af
7 changed files with 44 additions and 56 deletions
  1. +1
    -1
      source/backend/native/Makefile
  2. +4
    -1
      source/backend/native/zynaddsubfx.cpp
  3. +1
    -1
      source/backend/native/zynaddsubfx/Misc/Stereo.h
  4. +1
    -39
      source/tests/ANSI.cpp
  5. +28
    -7
      source/tests/Base64.cpp
  6. +3
    -2
      source/tests/Makefile
  7. +6
    -5
      source/utils/CarlaBase64Utils.hpp

+ 1
- 1
source/backend/native/Makefile View File

@@ -78,7 +78,6 @@ OBJS += \
zynaddsubfx/Misc/Microtonal.cpp.o \ zynaddsubfx/Misc/Microtonal.cpp.o \
zynaddsubfx/Misc/Part.cpp.o \ zynaddsubfx/Misc/Part.cpp.o \
zynaddsubfx/Misc/Recorder.cpp.o \ zynaddsubfx/Misc/Recorder.cpp.o \
zynaddsubfx/Misc/Stereo.cpp.o \
zynaddsubfx/Misc/Util.cpp.o \ zynaddsubfx/Misc/Util.cpp.o \
zynaddsubfx/Misc/WavFile.cpp.o \ zynaddsubfx/Misc/WavFile.cpp.o \
zynaddsubfx/Misc/WaveShapeSmps.cpp.o \ zynaddsubfx/Misc/WaveShapeSmps.cpp.o \
@@ -101,6 +100,7 @@ OBJS += \
zynaddsubfx/Synth/Resonance.cpp.o \ zynaddsubfx/Synth/Resonance.cpp.o \
zynaddsubfx/Synth/SUBnote.cpp.o \ zynaddsubfx/Synth/SUBnote.cpp.o \
zynaddsubfx/Synth/SynthNote.cpp.o zynaddsubfx/Synth/SynthNote.cpp.o
# zynaddsubfx/Misc/Stereo.cpp.o
endif endif


SHARED = ../libcarla_native.so SHARED = ../libcarla_native.so


+ 4
- 1
source/backend/native/zynaddsubfx.cpp View File

@@ -32,6 +32,7 @@
// TODO - free sPrograms // TODO - free sPrograms


// Dummy variables and functions for linking purposes // Dummy variables and functions for linking purposes
const char* instance_name = nullptr;
class WavFile; class WavFile;
namespace Nio { namespace Nio {
bool start(void){return 1;} bool start(void){return 1;}
@@ -283,7 +284,7 @@ public:
config.init(); config.init();
config.cfg.SoundBufferSize = synth->buffersize; config.cfg.SoundBufferSize = synth->buffersize;
config.cfg.SampleRate = synth->samplerate; config.cfg.SampleRate = synth->samplerate;
config.cfg.GzipCompression = 0;
//config.cfg.GzipCompression = 0;


sprng(std::time(nullptr)); sprng(std::time(nullptr));
denormalkillbuf = new float[synth->buffersize]; denormalkillbuf = new float[synth->buffersize];
@@ -317,6 +318,7 @@ public:


doSearch = false; doSearch = false;


pthread_mutex_lock(&master->mutex);
#if 0 #if 0
// refresh banks // refresh banks
master->bank.rescanforbanks(); master->bank.rescanforbanks();
@@ -339,6 +341,7 @@ public:
} }
} }
#endif #endif
pthread_mutex_unlock(&master->mutex);
} }


CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ZynAddSubFxPlugin) CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ZynAddSubFxPlugin)


+ 1
- 1
source/backend/native/zynaddsubfx/Misc/Stereo.h View File

@@ -36,5 +36,5 @@ struct Stereo {
//data //data
T l, r; T l, r;
}; };
#include "Stereo.cpp"
#endif #endif

+ 1
- 39
source/tests/ANSI.cpp View File

@@ -15,47 +15,9 @@
* For a full copy of the GNU General Public License see the GPL.txt file * 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 "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; return 0;
} }

+ 28
- 7
source/tests/Base64.cpp View File

@@ -16,11 +16,33 @@
*/ */


#include "CarlaBase64Utils.hpp" #include "CarlaBase64Utils.hpp"
#include "CarlaString.hpp"
//#include "CarlaString.hpp"


int main() 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 { struct Blob {
char s[4]; char s[4];
@@ -34,13 +56,11 @@ int main()
: s{'1', 's', 't', 0}, : s{'1', 's', 't', 0},
i(228), i(228),
d(3.33333333333), d(3.33333333333),
ptr((void*)0x500)
{
carla_zeroMem(padding, sizeof(char)*100);
}

padding{0},
ptr((void*)0x500) {}
} blob; } blob;


#if 0
// binary -> base64 // binary -> base64
void* const test0 = &blob; void* const test0 = &blob;
size_t test0Len = sizeof(Blob); size_t test0Len = sizeof(Blob);
@@ -105,6 +125,7 @@ int main()
CARLA_ASSERT(blob3->ptr == blob.ptr); CARLA_ASSERT(blob3->ptr == blob.ptr);


delete blob3; delete blob3;
#endif


// ----------------------------------------------------------------- // -----------------------------------------------------------------




+ 3
- 2
source/tests/Makefile View File

@@ -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 = -ansi -pedantic -pedantic-errors -Wunused-parameter -Wuninitialized -Wno-vla
ANSI_CXX_FLAGS += -Wcast-qual -Wconversion -Wsign-conversion -Wlogical-op -Waggregate-return 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 += -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 TARGETS = ANSI Base64 CarlaString RtList Thread Print Utils


@@ -48,7 +48,8 @@ Utils: Utils.cpp
$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ $(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@


RUN: $(TARGETS) RUN: $(TARGETS)
valgrind ./Utils
valgrind ./Base64
# ./ANSI
# ./CarlaString && ./RtList && ./Thread # ./CarlaString && ./RtList && ./Thread
# ./Print # ./Print
# ./Base64 # ./Base64


+ 6
- 5
source/utils/CarlaBase64Utils.hpp View File

@@ -70,7 +70,7 @@ size_t carla_base64_decoded_max_len(const char* const encoded)
static inline static inline
void carla_base64_encode(const uint8_t* const raw, const size_t len, char* const encoded) 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; uint8_t* encodedBytes = (uint8_t*)encoded;
size_t rawBitLen = 8*len; size_t rawBitLen = 8*len;
size_t bit, tmp; 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<size_t>((rawBytes[bit/8] << (bit % 8)) | (rawBytes[bit/8 + 1] >> (8 - (bit % 8)))); tmp = static_cast<size_t>((rawBytes[bit/8] << (bit % 8)) | (rawBytes[bit/8 + 1] >> (8 - (bit % 8))));
tmp = static_cast<size_t>((tmp >> 2) & 0x3f); tmp = static_cast<size_t>((tmp >> 2) & 0x3f);
CARLA_ASSERT(tmp < 64);


*(encodedBytes++) = static_cast<uint8_t>(kBase64[tmp]); *(encodedBytes++) = static_cast<uint8_t>(kBase64[tmp]);
} }
@@ -110,13 +111,13 @@ static inline
unsigned int carla_base64_decode(const char* const encoded, uint8_t* const raw) unsigned int carla_base64_decode(const char* const encoded, uint8_t* const raw)
{ {
const uint8_t* encodedBytes = (const uint8_t*)encoded; const uint8_t* encodedBytes = (const uint8_t*)encoded;
uint8_t* rawBytes = (uint8_t*)raw;
uint8_t* rawBytes = raw;
uint8_t encodedByte; uint8_t encodedByte;
unsigned int bit = 0; unsigned int bit = 0;
unsigned int padCount = 0; unsigned int padCount = 0;


/* Zero the raw data */ /* 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 */ /* Decode string */
while ((encodedByte = *(encodedBytes++)) > 0) while ((encodedByte = *(encodedBytes++)) > 0)
@@ -146,7 +147,7 @@ unsigned int carla_base64_decode(const char* const encoded, uint8_t* const raw)
} }


/* Process normal characters */ /* Process normal characters */
const char* match = std::strchr(kBase64, encodedByte);
const char* const match = std::strchr(kBase64, encodedByte);


if (match == nullptr) 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; 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)); CARLA_ASSERT(len <= carla_base64_decoded_max_len(encoded));


/* Return length in bytes */ /* Return length in bytes */


Loading…
Cancel
Save