Advertisement
Spark01

LADSPA plugin

Feb 28th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #include "ladspa.h"
  2. #include <math.h>
  3. #include <string.h>
  4.  
  5. #define INPUT 0
  6. #define OUTPUT 1
  7.  
  8. static LADSPA_Descriptor * descriptor;
  9.  
  10. struct Distorter
  11. {
  12. LADSPA_Data * input;
  13. LADSPA_Data * output;
  14. unsigned long sample_rate;
  15. unsigned long position;
  16. LADSPA_Data run_adding_gain;
  17. };
  18.  
  19. LADSPA_Handle instantiate_distorter(const LADSPA_Descriptor * descriptor, unsigned long sample_rate)
  20. {
  21. Distorter * distorter = NULL;
  22. distorter = new Distorter;
  23. distorter->sample_rate = sample_rate;
  24. distorter->run_adding_gain = 1.0f;
  25. LADSPA_Handle handle = distorter;
  26. return handle;
  27. }
  28.  
  29. void connect_port_distorter(LADSPA_Handle instance, unsigned long port, LADSPA_Data * data_location)
  30. {
  31. Distorter * distorter = static_cast<Distorter*>(instance);
  32. switch(port)
  33. {
  34. case INPUT:
  35. distorter->input = data_location;
  36. break;
  37. case OUTPUT:
  38. distorter->output = data_location;
  39. break;
  40. }
  41. }
  42.  
  43. void activate_distorter(LADSPA_Handle instance)
  44. {
  45.  
  46. }
  47.  
  48. void run_distorter(LADSPA_Handle instance, unsigned long sample_count)
  49. {
  50. Distorter * distorter = static_cast<Distorter*>(instance);
  51. for (unsigned long i = 0; i<sample_count; i++)
  52. {
  53. LADSPA_Data input = distorter->input[i];
  54. distorter->output[i] = input * 2.0f;
  55. if (distorter->output[i] > 0.5f)
  56. {
  57. distorter->output[i] = 0.5f;
  58. }
  59. if (distorter->output[i] < -0.5f)
  60. {
  61. distorter->output[i] = -0.5f;
  62. }
  63. if ((distorter->output[i] < 0.2f) && (distorter->output[i] > -0.2f))
  64. {
  65. distorter->output[i] = 0.0f;
  66. }
  67. }
  68. }
  69.  
  70. void set_run_adding_gain_distorter(LADSPA_Handle instance, LADSPA_Data gain)
  71. {
  72. Distorter *distorter = static_cast<Distorter*>(instance);
  73. distorter->run_adding_gain = gain;
  74. }
  75.  
  76. void cleanup_distorter(LADSPA_Handle instance)
  77. {
  78. Distorter * distorter = static_cast<Distorter*>(instance);
  79. delete distorter;
  80. }
  81.  
  82. void
  83. delete_descriptor(LADSPA_Descriptor * descriptor) {
  84. delete descriptor->PortDescriptors;
  85. delete descriptor->PortNames;
  86. delete descriptor;
  87. }
  88.  
  89. extern "C" __declspec(dllexport) const LADSPA_Descriptor * ladspa_descriptor(unsigned long Index) {
  90. switch (Index) {
  91. case 0:
  92. static const char * label = "spark_distortion";
  93. static const char * maker = "Nick";
  94. static const char * copyright = "None";
  95. static const char * input_string = "Input";
  96. static const char * output_string = "Output";
  97. descriptor = new LADSPA_Descriptor;
  98. descriptor->UniqueID = 7778;
  99. descriptor->Label = label;
  100. descriptor->Properties= LADSPA_PROPERTY_HARD_RT_CAPABLE;
  101. descriptor->Name = label;
  102. descriptor->Maker = maker;
  103. descriptor->Copyright = copyright;
  104. descriptor->PortCount = 2;
  105. static LADSPA_PortDescriptor port_descriptors[2];
  106. descriptor->PortDescriptors = port_descriptors;
  107. port_descriptors[INPUT] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
  108. port_descriptors[OUTPUT] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
  109. static const char * port_names[2];
  110. descriptor->PortNames = port_names;
  111. port_names[INPUT] = input_string;
  112. port_names[OUTPUT] = output_string;
  113. descriptor->instantiate = &instantiate_distorter;
  114. descriptor->connect_port = &connect_port_distorter;
  115. descriptor->activate = &activate_distorter;
  116. descriptor->run = &run_distorter;
  117. descriptor->run_adding = NULL;
  118. descriptor->set_run_adding_gain = NULL;
  119. descriptor->deactivate = NULL;
  120. descriptor->cleanup = &cleanup_distorter;
  121.  
  122. return descriptor;
  123. default:
  124. return NULL;
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement