LADSPATestSuite.cpp 1.66 KB
Newer Older
1
#include "IFormatTestSuite.hpp"
2
#include "ladspa.h"
3
#include "tools/LibLoading.hpp"
4
#include <vector>
5
using namespace APAL;
6
7
8
/**
 * @brief LADSPA Test Suite for XValidate/system_tests
 */
9
10
class LADSPATestSuite : public FormatTestSuiteBase
{
11
public:
12
  virtual std::string getFormatName() override { return "LADSPA"; }
13

14
15
16
17
18
19
20
21
22
23
  virtual bool isSupported(std::string pluginPath) override
  {
    auto lib = LoadLib(pluginPath.c_str());
    if (lib == nullptr)
      return false;
    bool isSupp =
      LoadFunc<LADSPA_Descriptor_Function>(lib, "ladspa_descriptor") != nullptr;
    UnloadLib(lib);
    return isSupp;
  }
24

25
26
27
28
29
30
31
32
33
34
35
  virtual SucceedState run() override
  {
    size_t sampleRate = 512;
    SucceedState ret = TEST_SUCCEEDED;
    auto lib = LoadLib(data.pluginPath.c_str());
    if (lib == nullptr)
      return false;
    auto ladspa_descriptor_fnc =
      LoadFunc<LADSPA_Descriptor_Function>(lib, "ladspa_descriptor");
    size_t index = 0;
    const LADSPA_Descriptor* desc = nullptr;
36
    // All things loaded. Than Run normal execution of Plugin.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    while (desc = ladspa_descriptor_fnc(index++), desc != nullptr) {
      auto handle = desc->instantiate(desc, sampleRate);
      desc->activate(handle);
      auto portData = std::vector<LADSPA_Data*>(desc->PortCount);
      for (unsigned long i = 0; i < desc->PortCount; i++) {
        portData[i] = new LADSPA_Data[sampleRate];
        desc->connect_port(handle, i, portData[i]);
      }
      desc->run(handle, sampleRate);
      for (unsigned long i = 0; i < desc->PortCount; i++) {
        delete[] portData[i];
      }
      desc->deactivate(handle);
      desc->cleanup(handle);
51
    }
52
53
54

    return ret;
  }
55
56
};
REGISTER_TEST_SUITE(LADSPATestSuite);