summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/drumgizmo.cc4
-rw-r--r--src/drumgizmo.h2
-rw-r--r--src/memchecker.cc30
-rw-r--r--src/memchecker.h18
-rw-r--r--test/memcheckertest.cc30
5 files changed, 46 insertions, 38 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 44cd73c..e47cab7 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -87,8 +87,8 @@ bool DrumGizmo::loadkit(std::string file)
// Check if there is enough free RAM to load the drumkit.
if(!memchecker.enoughFreeMemory(kit))
{
- ERR(drumgizmo, "Not enough free RAM to load the drumkit.");
- return false;
+ printf("WARNING: There doesn't seem to be enough RAM available to load the kit.\n"
+ "Trying to load it anyway...\n");
}
loader.loadKit(&kit);
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 3f84fdd..f1f570a 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -102,7 +102,7 @@ protected:
AudioCache audioCache;
DrumKit kit;
- Memchecker memchecker;
+ MemChecker memchecker;
size_t framesize;
bool freewheel;
diff --git a/src/memchecker.cc b/src/memchecker.cc
index b26603a..8c8c183 100644
--- a/src/memchecker.cc
+++ b/src/memchecker.cc
@@ -27,25 +27,25 @@
#include "memchecker.h"
#ifdef WIN32
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
#else
- #include <sys/sysinfo.h>
+#include <sys/sysinfo.h>
#endif
#include <sndfile.h>
#include <hugin.hpp>
-bool Memchecker::enoughFreeMemory(const DrumKit& drumkit) const
+bool MemChecker::enoughFreeMemory(const DrumKit& drumkit) const
{
- size_t freeMemory = calcFreeMemory();
- size_t neededMemory = calcNeededMemory(drumkit);
+ uint64_t free_memory = calcFreeMemory();
+ uint64_t needed_memory = calcNeededMemory(drumkit);
- return freeMemory >= neededMemory;
+ return free_memory >= needed_memory;
}
-size_t Memchecker::calcFreeMemory() const
+uint64_t MemChecker::calcFreeMemory() const
{
- size_t free_memory(0);
+ uint64_t free_memory = 0;
// Platform specific calculation of the amount of free memory.
#ifdef WIN32
@@ -55,18 +55,18 @@ size_t Memchecker::calcFreeMemory() const
free_memory = status.ullAvailPhys;
#else
struct sysinfo sys_info;
- sysinfo (&sys_info);
+ sysinfo(&sys_info);
free_memory = sys_info.freeram * sys_info.mem_unit;
#endif
- DEBUG(memchecker, "Calculated %llu free memory.\n", (long long unsigned int)free_memory);
+ DEBUG(memchecker, "Calculated %" PRIu64 " free memory.\n", free_memory);
return free_memory;
}
-size_t Memchecker::calcNeededMemory(const DrumKit& drumkit) const
+uint64_t MemChecker::calcNeededMemory(const DrumKit& drumkit) const
{
- size_t needed_memory(0);
+ uint64_t needed_memory = 0;
// Calculate memory usage of all instruments of drumkit.
for(auto instrument : drumkit.instruments)
@@ -80,12 +80,12 @@ size_t Memchecker::calcNeededMemory(const DrumKit& drumkit) const
}
}
- DEBUG(memchecker, "Calculated %llu needed memory.\n", (long long unsigned int)needed_memory);
+ DEBUG(memchecker, "Calculated %" PRIu64 " needed memory.\n", needed_memory);
return needed_memory;
}
-size_t Memchecker::calcBytesPerChannel(const std::string& filename) const
+uint64_t MemChecker::calcBytesPerChannel(const std::string& filename) const
{
SF_INFO sf_info;
diff --git a/src/memchecker.h b/src/memchecker.h
index c3e13c2..f12c3d2 100644
--- a/src/memchecker.h
+++ b/src/memchecker.h
@@ -29,20 +29,24 @@
#include "drumkit.h"
#include <string>
+// includes cstdint automatically and is needed for the PRIu64 macro
+#include <cinttypes>
-class Memchecker
+class MemChecker
{
public:
- //! Checks if there is enough memory left to load drumkit into RAM.
- //! \param drumkit The drumkit for which it is checked if there's enough memory left.
- //! \return True iff there is enough memory left.
+ //! Checks if there is enough memory left to load drumkit into RAM.
+ //! \param drumkit The drumkit for which it is checked if there's enough memory left.
+ //! \return True iff there is enough memory left.
bool enoughFreeMemory(const DrumKit& drumkit) const;
protected:
// Computes how much RAM (in bytes) is left.
- size_t calcFreeMemory() const;
+ uint64_t calcFreeMemory() const;
+
// Computes how much memory the drumkit takes when loaded into RAM (in bytes).
- size_t calcNeededMemory(const DrumKit& drumkit) const;
+ uint64_t calcNeededMemory(const DrumKit& drumkit) const;
+
// Computes the number of bytes per channel of <filename> using libsnd.
- size_t calcBytesPerChannel(const std::string& filename) const;
+ uint64_t calcBytesPerChannel(const std::string& filename) const;
};
diff --git a/test/memcheckertest.cc b/test/memcheckertest.cc
index b2aab27..abeac91 100644
--- a/test/memcheckertest.cc
+++ b/test/memcheckertest.cc
@@ -41,11 +41,11 @@
#include "../src/drumkit.h"
#include "../src/drumkitparser.h"
-class test_memchecker
+class MemCheckerTest
: public CppUnit::TestFixture
- , public Memchecker
+ , public MemChecker
{
- CPPUNIT_TEST_SUITE(test_memchecker);
+ CPPUNIT_TEST_SUITE(MemCheckerTest);
CPPUNIT_TEST(small_drumkit);
CPPUNIT_TEST(huge_drumkit);
CPPUNIT_TEST(correct_size);
@@ -54,8 +54,8 @@ class test_memchecker
private:
DrumKit kit;
- const std::string smallKitPath = "kit/small_kit.xml";
- const std::string hugeKitPath = "kit/huge_kit.xml";
+ const std::string small_kit_path = "kit/small_kit.xml";
+ const std::string huge_kit_path = "kit/huge_kit.xml";
const std::string audiofile = "kit/ride-multi-channel.wav";
public:
void setUp()
@@ -70,7 +70,7 @@ public:
void small_drumkit()
{
// load the small kit
- DrumKitParser parser(smallKitPath, kit);
+ DrumKitParser parser(small_kit_path, kit);
CPPUNIT_ASSERT(!parser.parse());
// check if the memchecker thinks it fits into memory
@@ -80,7 +80,7 @@ public:
void huge_drumkit()
{
// load the huge kit
- DrumKitParser parser(hugeKitPath, kit);
+ DrumKitParser parser(huge_kit_path, kit);
CPPUNIT_ASSERT(!parser.parse());
// check if the memchecker thinks it doesn't fit into memory
@@ -90,23 +90,27 @@ public:
void correct_size()
{
// check if the memchecker reports the right audiofile size
- CPPUNIT_ASSERT_EQUAL((size_t)2199332, calcBytesPerChannel(audiofile));
+ uint64_t bytes_per_channel = 2199332;
+ CPPUNIT_ASSERT_EQUAL(bytes_per_channel, calcBytesPerChannel(audiofile));
// load the huge kit
- DrumKitParser parser(hugeKitPath, kit);
+ DrumKitParser parser(huge_kit_path, kit);
CPPUNIT_ASSERT(!parser.parse());
// check if the protected method of the memchecker reports the correct size
- CPPUNIT_ASSERT_EQUAL((size_t)71478290000, calcNeededMemory(kit));
+ uint64_t needed_memory = 71478290000;
+ CPPUNIT_ASSERT_EQUAL(needed_memory, calcNeededMemory(kit));
}
void check_free_ram()
{
// check if the protected method reports a sane value of free ram
- size_t free_memory = calcFreeMemory();
- CPPUNIT_ASSERT(free_memory >= (size_t)1000 && free_memory <= (size_t)50000000000);
+ uint64_t free_memory = calcFreeMemory();
+ uint64_t min_free_memory = 1000;
+ uint64_t max_free_memory = 50000000000;
+ CPPUNIT_ASSERT(free_memory >= min_free_memory && free_memory <= max_free_memory);
}
};
// Registers the fixture into the 'registry'
-CPPUNIT_TEST_SUITE_REGISTRATION(test_memchecker);
+CPPUNIT_TEST_SUITE_REGISTRATION(MemCheckerTest);