1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
# lsp-dsp-units
C++ DSP modules
This library provides set of functions and objects that perform different DSP processing of the
audio signal.
Set of modules provided:
* Signal control
* Blink toggle
* Bypass switch
* Counter
* Crossfade switch
* Toggle
* Dynamic processing
* Compressor
* Dynamic processor
* Expander
* Gate
* Limiter
* Filters and equalization
* Dynamic filters
* Equalizer
* Filter
* Miscellaneous functions
* Signal envelope functions
* Interpolation functions
* FFT windows
* Sampling
* Sample
* Sample player
* Utilities
* Chirp Processor
* Convolver
* Crossover
* Delay
* De-popper
* Dither
* Impulse response taker
* Latency detector
* Meter history
* Oscillator
* Oversampler
* Randomizer
* Shift buffer
* Sidechain control
* Spectral processor
* Spectrum analyzer
Supported platforms
======
The build and correct unit test execution has been confirmed for following platforms:
* FreeBSD
* GNU/Linux
* Windows 32-bit
* Windows 64-bit
Requirements
======
The following packages need to be installed for building:
* gcc >= 4.9
* GNU make >= 4.0
Building
======
To build the library, perform the following commands:
```bash
make config # Configure the build
make fetch # Fetch dependencies from Git repository
make
sudo make install
```
To get more build options, run:
```bash
make help
```
To uninstall library, simply issue:
```bash
make uninstall
```
To clean all binary files, run:
```bash
make clean
```
To clean the whole project tree including configuration files, run:
```bash
make prune
```
To fetch all possible dependencies and make the source code tree portable between
different architectures and platforms, run:
```bash
make tree
```
To build source code archive with all possible dependencies, run:
```bash
make distsrc
```
Usage
======
Here's the code snippet of how the library can be initialized and used in C++:
```C++
#include <lsp-plug.in/dsp/dsp.h>
#include <lsp-plug.in/dsp-units/units.h>
#include <lsp-plug.in/dsp-units/sampling/Sample.h>
#include <lsp-plug.in/dsp-units/filters/Filter.h>
#include <string.h>
#include <stdio.h>
static int process_file(const char *in, const char *out)
{
// We will process file as a single audio sample
// That can take many memory for large files
// but for demo it's OK
lsp::dspu::Sample s;
lsp::dspu::Filter f;
lsp::dspu::filter_params_t fp;
lsp::io::Path path;
// We consider pathnames encoded using native system encoding.
// That's why we use io::Path::set_native() method
path.set_native(in);
if (s.load(&path) != lsp::STATUS_OK)
{
fprintf(stderr, "Error loading audio sample from file: %s\n", in);
return -1;
}
// Apply +6 dB hi-shelf filter at 1 kHz
fp.nType = lsp::dspu::FLT_BT_BWC_HISHELF;
fp.fFreq = 1000.0f;
fp.fFreq2 = 1000.0f;
fp.fGain = lsp::dspu::db_to_gain(6.0f);
fp.nSlope = 2;
fp.fQuality = 0.0f;
f.init(NULL); // Use own internal filter bank
f.update(s.sample_rate(), &fp); // Apply filter settings
// Now we need to process each channel in the sample
for (size_t i=0; i<s.channels(); ++i)
{
float *c = s.channel(i); // Get channel data
f.clear(); // Reset internal memory of filter
f.process(c, c, s.samples());
}
// Resample the processed sample to 48 kHz sample rate
s.resample(48000);
// Save sample to file
path.set_native(out);
if (s.save(&path) < 0)
{
fprintf(stderr, "Error saving audio sample to file: %s\n", out);
return -2;
}
return 0;
}
int main(int argc, const char **argv)
{
lsp::dsp::context_t ctx;
if (argc < 3)
{
fprintf(stderr, "Input file name and output file name required");
return -1;
}
// Initialize DSP
lsp::dsp::init();
lsp::dsp::start(&ctx);
int res = process_file(argv[1], argv[2]);
lsp::dsp::finish(&ctx);
return res;
}
```
|