LADSPA-FIR/ 0000777 0000000 0000000 00000000000 14320023102 007315 5 ustar LADSPA-FIR/compile_FIR_engine.sh 0000777 0000000 0000000 00000001660 13640432736 013361 0 ustar #!/bin/bash
if [ "$#" -ne 1 ]; then
echo "You must supply float or double as a command line parameter"
echo " to indicate the FFTW precision for the FIR engine."
echo "The level of precision should be supported by FFTW (see"
echo " configuring FFTW in the FFTW installation docs."
echo "Please try again."
exit 2
fi
if [ "$1" = "float" ] || [ "$1" = "single" ]; then
echo "compiling the FIR engine in single precision..."
g++ --std=c++11 -march=native -O2 -ffast-math -DFFT_DATATYPE=1 ./FIR_convolution_engine.cpp -lfftw3f -lm -o FIR_engine.exe
else
echo "compiling the FIR engine in double precision..."
g++ --std=c++11 -march=native -O2 -ffast-math -DFFT_DATATYPE=2 ./FIR_convolution_engine.cpp -lfftw3 -lm -o FIR_engine.exe
fi
if [ $? = 0 ]; then
echo "The FIR engine was successfully compiled into the executable file FIR_engine.exe"
else
echo "An error was encountered. Please try again."
fi
echo
LADSPA-FIR/FIR_convolution_engine.cpp 0000777 0000000 0000000 00000101530 14320022702 014435 0 ustar /* FIR_CONVOLUTION ENGINE, VERSION 1.01
LADSPA INTERFACE TO AN FIR FILTER ENGINE USING TMPFS-BASED I/O
written by: Charlie Laub, 2020
For information about installation and usage, please see the instruction file.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
CREDITS:
I would like to thank Dan Cyr for helping me understand and implement FIR convolution with FFTW.
*/
//FFT_DATATYPE sets the data type used by FFTW
// double precision data type --> #define FFT_DATATYPE 2
// default: single precision float type --> #define FFT_DATATYPE 1
#ifndef FFT_DATATYPE
#define FFT_DATATYPE 1
#endif
const unsigned int NO_DATA_TIMEOUT = 60;
const unsigned int NO_MESSAGE_TIMEOUT = 2;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//needed for FIFOs
#include
#include
#include
#include
#include
#include
#include
//needed for FFTW
#include
#include
using namespace std;
using namespace std::chrono;
class RunningStat {
public:
RunningStat() : m_n(0) {}
void Clear() {
m_n = 0;
}
void Push(double x) {
m_n++;
// See Knuth TAOCP vol 2, 3rd edition, page 232
if (m_n == 1) {
m_oldM = m_newM = x;
m_oldS = 0.0;
} else {
m_newM = m_oldM + (x - m_oldM)/m_n;
m_newS = m_oldS + (x - m_oldM)*(x - m_newM);
// set up for next iteration
m_oldM = m_newM;
m_oldS = m_newS;
}
}
int NumDataValues() const {
return m_n;
}
double Mean() const {
return (m_n > 0) ? m_newM : 0.0;
}
double Variance() const {
return ( (m_n > 1) ? m_newS/(m_n - 1) : 0.0 );
}
double StandardDeviation() const {
return sqrt( Variance() );
}
private:
int m_n;
double m_oldM, m_newM, m_oldS, m_newS;
};
int put_processed_data ( int fd, float * data_container, size_t num_floats ) {
signal(SIGPIPE, SIG_IGN); //ignore sigpipe errors
int ret_val;
//put num_floats*sizeof(float) bytes into FIFO from the data_container
ret_val = write(fd, data_container, num_floats*sizeof(float) );
return ret_val;
}
int get_unprocessed_data ( int fd, float * data_container_ptr, size_t num_bytes ) {
int ret_val;
//read num_floats*sizeof(float) bytes into data_container from the FIFO
ret_val = read(fd, data_container_ptr, num_bytes );
//messages of size >0 contain data. ret_val = -1 indicates empty FIFO
return ret_val;
} //end function get_unprocessed_data
void send_ready_signal ( int fd ) {
//By sending one float over the processed_data FIFO the plugin is signaled
// that the FIR engine is ready to receive unprocessed data
signal(SIGPIPE, SIG_IGN); //ignore sigpipe errors
int ret_val;
const char * char_array = "READY";
ret_val = write(fd, char_array, strlen( char_array ));
}
bool wait_for_unprocessed_data ( int fd,
unsigned long update_interval,
size_t data_length,
vector< float > &data_container ) {
//repeatedly attempt to read the FIFO to see if any data has been delivered
// returns true after data_length data has been received.
// if an insufficient amount of data is received after a long time, returns false
auto timer_begin = std::chrono::high_resolution_clock::now();
std::chrono::seconds elapsed_time;
unsigned long int initial_interval, wait_interval;
int ret_val;
size_t bytes_to_read, samples_read = 0;
bytes_to_read = 4 * data_length;
//if update_interval has not yet been set, use a 500 usec wait interval
//the interval is specified in microseconds
if ( update_interval == 0 ) {
wait_interval = 100;
} else {
wait_interval = update_interval / 20;
}
initial_interval = wait_interval;
while ( 1 ) {
//Attempt to get new unprocessed data from the unprocessed data FIFO. Return values may be:
// >0: the number of bytes read
// 0: no WRITER connected
// -1: writer connected but FIFO is empty
ret_val = get_unprocessed_data( fd, &data_container[samples_read], bytes_to_read );
if ( ret_val > 0 ) {
//some data was received. Update read counters and return if data_length samples have been obtained
bytes_to_read -= ret_val;
samples_read += ret_val/4;
if ( bytes_to_read <= 0) return true;
wait_interval = initial_interval;
} else {
// no data received or writer disconnected...
auto timer_end = std::chrono::high_resolution_clock::now();
//calculate elapsed time and cast to seconds
elapsed_time = duration_cast(timer_end - timer_begin);
if ( elapsed_time > std::chrono::seconds( NO_DATA_TIMEOUT ) ) {
//elapsed time exceeds timeout time, return with false
return false;
}
//double the wait_interval
wait_interval *= 2;
} //end if..else
//timer < 60 second timeout, sleep for 1 wait_interval then check for data again
this_thread::sleep_for( std::chrono::microseconds( wait_interval ) );
} //end while loop
} //end function wait_for_unprocessed_data
std::string& ltrim(std::string& s) {
auto it = std::find_if(s.begin(), s.end(),
[](char c) {
return !std::isspace(c, std::locale::classic());
});
s.erase(s.begin(), it);
return s;
}
std::string& rtrim(std::string& s) {
auto it = std::find_if(s.rbegin(), s.rend(),
[](char c) {
return !std::isspace(c, std::locale::classic());
});
s.erase(it.base(), s.end());
return s;
}
std::string& trim(std::string& s) {
return ltrim(rtrim(s));
}
void split( deque &res, string s, string delimiter) {
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
string token;
while ((pos_end = s.find (delimiter, pos_start)) != string::npos) {
token = s.substr (pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
if (token != "" ) {
trim( token );
res.push_back (token);
}
}
token = s.substr (pos_start);
trim( token );
res.push_back ( token );
} //end function split
int read_from_control_FIFO ( int fd, deque &messages ) {
int ret_val;
char char_array[256];
ret_val = read(fd, char_array, sizeof(char_array) );
//messages of size 1 are empty, >1 contain text. ret_val < 1 indicates an error
if (ret_val > 1 ) {
string text, delimiter = "|";
for ( int i=0; i &messages ) {
//periodically read the FIFO to see if any messages have been delivered
// returns true after messages have been received.
// if no messages are received for a long time, returns false
auto timer_begin = std::chrono::high_resolution_clock::now();
std::chrono::seconds elapsed_time;
unsigned long int wait_interval;
int ret_val;
//if update_interval has not yet been set, use a 1 msec wait interval
//the interval is specified in microseconds
if ( update_interval == 0 ) {
wait_interval = 1000;
} else {
wait_interval = update_interval;
}
while ( 1 ) {
//Check for a new control message:
// attempt to read from FIFO and get return value
// on success, the value returned is the number of bytes read
// 0: no WRITER connected
// -1: writer connected but FIFO is empty
ret_val = read_from_control_FIFO ( fd, messages );
if ( ret_val > 0 ) {
// got a message. Return true
return true;
} else {
// no message received...
auto timer_end = std::chrono::high_resolution_clock::now();
//calculate elapsed time and cast to seconds
elapsed_time = duration_cast(timer_end - timer_begin);
if ( elapsed_time > std::chrono::seconds( NO_MESSAGE_TIMEOUT ) ) {
//elapsed time exceeds timeout time, return with false
return false;
} else {
//timer < timeout, sleep for 1 wait_interval
this_thread::sleep_for( std::chrono::microseconds(wait_interval) );
}
} //end if..else
} //end while loop
} //end function wait_for_new_message
bool process_control_messages ( deque &FIFO_message_queue,
deque &saved_messages,
string &FIR_filter_filename,
string &file_extension,
unsigned long &filter_length,
unsigned long &data_length,
unsigned long &FFT_length,
unsigned long &cycle_latency,
unsigned long &update_interval,
bool &doing_filter_change ) {
string one_line, keyword, value;
deque tokens;
// Process a message into tokens and set program variables
one_line = FIFO_message_queue[0]; //get the next message from the queue
split( tokens, one_line, "="); //split the message into tokens
//there was only one token. The message is not in the keyword = value format, so discard it
if ( tokens.size() < 2 ) {
deque< string >().swap( tokens );
FIFO_message_queue.pop_front(); //eject the message from the message queue
return true; //done with this message, skip to end of do..while loop
}
// Received a valid message, so process the information
keyword = tokens[0];
value = tokens[1];
if ( keyword == "action" ) {
if ( value == "terminate" ) {
return false;
}
//save other action messages until initialization has been finished
saved_messages.push_back( one_line );
//remove the saved message from the message queue and return
FIFO_message_queue.pop_front();
return true;
}
if ( keyword == "filter_file" ){
FIR_filter_filename = value;
size_t delimiter_position = value.find_last_of(".");
file_extension = value.substr(delimiter_position+1);
}
if ( keyword == "filter_length" ) {
filter_length = strtoul( value.c_str(),nullptr,0 );
}
if ( keyword == "data_length") {
data_length = strtoul( value.c_str(),nullptr,0 );
}
if ( keyword == "FFT_length") {
FFT_length = strtoul( value.c_str(),nullptr,0 );
}
if ( keyword == "cycle_latency") {
//number of samples that can be accommodated in each I/O file
cycle_latency = strtoul( value.c_str(),nullptr,0 );
}
if ( keyword == "update_interval") {
//update interval = samples per frame / samples per second, given in microseconds.
update_interval = stof( value );
}
if ( value == "filter_change" ) {
//set the doing_filter_change flag
doing_filter_change = true;
}
//remove the message from the message queue
FIFO_message_queue.pop_front();
return true;
} //end function process_control_messages
int set_FIFO_buffer_size( int fd, size_t capacity, string &message ) {
//set FIFO buffer capacity in bytes. check, then set, and check again
long pipe_size = (long)fcntl(fd, F_GETPIPE_SZ);
if (pipe_size == -1) {
message = " could not get FIFO size!";
return 1;
}
int ret = fcntl(fd, F_SETPIPE_SZ, capacity);
if (ret < 0) {
message = " could not set new FIFO size!";
return 1;
}
pipe_size = (long)fcntl(fd, F_GETPIPE_SZ);
if (pipe_size == -1) {
message = " could not confirm new FIFO size.";
return 1;
}
return 0;
}
void cleanup_and_exit (
ofstream &engine_stats_file,
string working_directory ) {
//This function performs cleanup tasks and then exits
// Close files that are open for I/O
if ( engine_stats_file.is_open() ) engine_stats_file.close();
//delete working directory and all files in it using rm -rf
if ( working_directory != "" ) {
//use system call to remove directory and files within it
string rmdir_cmd = "rm -rf " + working_directory;
int ret_val;
ret_val = system( rmdir_cmd.c_str() );
}
//terminate FIR engine
exit(0);
} //end function cleanup_and_exit
//Compile-time error checking of the FFT_DATATYPE
#ifndef FFT_DATATYPE
#error The FFT_DATATYPE must be defined at the top of the code and assigned the value 1 or 2.
#endif
#if FFT_DATATYPE != 2
#if FFT_DATATYPE != 1
#error ERROR: the FFT_DATATYPE value must be either 1 or 2!
#endif
#endif
/* ############################################################################
-------------------------- BEGIN MAIN PROGRAM -----------------------------
######################################################################### */
int main( int argc, char* argv[] ) {
string working_directory;
//Make sure that working directory filepath was supplied as first command line parameter
if (argc > 1) {
working_directory = argv[1];
} else {
//Fatal error: the program was not called with at least one parameter. Exit
exit(1);
}
//make sure that directory actually exists...
int i;
string temp_string;
temp_string = "ls " + working_directory + " > /dev/null 2>&1";
i = system( temp_string.c_str() );
if ( i != 0 ) {
//Fatal error: the supplied working directory does not exit. Exit
exit(2);
}
RunningStat rs; //declare new running stats instance
//timing related vars
std::chrono::microseconds longest_cycle_time = std::chrono::microseconds::zero();
std::chrono::microseconds cycle_time;
std::chrono::seconds elapsed_time;
ifstream config_file, FIR_filter_file;
ofstream engine_stats_file, error_file;
unsigned long int data_length, filter_length, FFT_length, cycle_latency, update_interval;
int ret_val, control_fifo_fd, unprocessed_data_fd, processed_data_fd;
unsigned int line_number;
string one_line, FIR_filter_filename, file_extension;
float normalization_factor;
bool doing_filter_change = false;
bool is_first_cycle = true; //this flag is set to false after the first convolution has been performed
bool doing_initial_startup = true; //this flag is set to false at the end of the initial startup code
//STL containers:
deque< string > FIFO_message_queue, saved_messages, tokens;
vector< float > unprocessed_data;
vector< float > processed_data;
vector< float > FIR_filter;
//set the data type based on the value of FFT_DATATYPE
#if FFT_DATATYPE == 2
typedef double FFT_data_type;
#else
typedef float FFT_data_type;
#endif
//declare the STL containers that will hold real valued data
vector< FFT_data_type > overlap_data;
//declare the STL containers that will hold complex data
vector< complex< FFT_data_type > > outfftwOne;
vector< complex< FFT_data_type > > outfftwTwo;
vector< complex< FFT_data_type > > fftMulti;
//declare plans based on the FFT_DATATYPE:
#if FFT_DATATYPE == 2
//Declare double precision forward FFT plans
fftw_plan audio_fFFT;
fftw_plan filter_fFFT;
//Declare double precision backward (inverse) FFT plan
fftw_plan filterXaudio_iFFT;
#else
//Declare single precision forward FFT plans
fftwf_plan audio_fFFT;
fftwf_plan filter_fFFT;
//Declare single precision backward (inverse) FFT plan
fftwf_plan filterXaudio_iFFT;
#endif
//FILE to which errors are reported
temp_string = "/dev/shm/FIR_engine.log";
error_file.open( temp_string.c_str(), ios_base::app );
//Initialize FIFOs:
//NOTE: the FIFO files must have already been created in the OS before calling this program
//Create and open control FIFO read-only , non-blocking. Retuns with file descriptor
temp_string = working_directory + "/control";
control_fifo_fd = open(temp_string.c_str(), O_RDONLY | O_NONBLOCK);
//now ready to receive parameters and action commands over the FIFO.
//open processed_data FIFO as writer in blocking mode. A write will block if the FIFO is full
temp_string = working_directory + "/processed_data";
processed_data_fd = open(temp_string.c_str(), O_WRONLY );
//open unprocessed_data FIFO read-only , non-blocking. Retuns with file descriptor
temp_string = working_directory + "/unprocessed_data";
unprocessed_data_fd = open(temp_string.c_str(), O_RDONLY | O_NONBLOCK);
//set FIFO capacity in bytes.
// NOTE: 1048576 bytes = 1 MiB is the largest allowed by the kernel
temp_string = "";
ret_val = set_FIFO_buffer_size( unprocessed_data_fd, 1048576, temp_string );
if ( temp_string != "" ) error_file << temp_string << endl;
// if function returns 1 an error occurred, so terminate
if ( ret_val != 0 ) cleanup_and_exit( engine_stats_file, working_directory );
//open the cycle time information file
if ( ! engine_stats_file.is_open() ) {
temp_string = working_directory + "/cycle_time_stats";
engine_stats_file.open( temp_string.c_str() );
}
//initialize critical FIR engine parameters
FIR_filter_filename = "";
file_extension = "";
filter_length = 0;
data_length = 0;
FFT_length = 0;
cycle_latency = 0;
update_interval = 0;
unsigned long longest_cycle_number, cycle_counter = 0;
//begin main loop
while ( 1 ) {
//Get FIR engine parameters from the LADSPA plugin via FIFO
do {
// This do..while loop runs until all critical params have been received
if ( FIFO_message_queue.size() == 0 ) {
//the message queue is empty. Waiting until new messages arrive
if ( ! wait_for_messages( update_interval, control_fifo_fd, FIFO_message_queue ) ) {
// if function returns false, too much time has elapsed, so terminate
cleanup_and_exit( engine_stats_file, working_directory );
}
}
// Received one or more messages, so process them
if ( ! process_control_messages( FIFO_message_queue,
saved_messages,
FIR_filter_filename,
file_extension,
filter_length,
data_length,
FFT_length,
cycle_latency,
update_interval,
doing_filter_change ) ) {
//process_control_messages returned false. This means that action = terminate was received,
// so do cleanup and terminate
cleanup_and_exit( engine_stats_file, working_directory );
}
} while (
( FIR_filter_filename == "" ) ||
( filter_length == 0 ) ||
( data_length == 0 ) ||
( FFT_length == 0 ) ||
( cycle_latency == 0 )
); //end do loop that waits for all critical FIR engine parameters
// Critical FIR engine parameters have been received. Proceed with initialization...
//computer normalization_factor
normalization_factor = static_cast< FFT_data_type > ( FFT_length );
normalization_factor = 1.0 / normalization_factor;
//create/resize storage for the FIR filter before populating with filter data
// and initialize contents to zeros
if ( FIR_filter.size() < FFT_length ) FIR_filter.resize( FFT_length, 0.0 );
//Read in the FIR filter from file
//open file
FIR_filter_file.open(FIR_filter_filename.c_str());
//reading of file depends on file type:
if ( file_extension == "txt" ) {
//text file: one tap per line, initial comment lines possible
//getline into string; stof converts it to a float
line_number = 0;
//first we check for comment lines
while ( getline( FIR_filter_file, one_line ) ) {
if ( one_line.find("#") != string::npos ) {
//skip comment lines indicated by "#"
continue;
} else {
//first data is found, put it in the filter
FIR_filter[ line_number ] = stof( one_line );
line_number++;
break;
}
}
//no need to check for comment lines after first data is found...
//to prevent array from overwriting its bounds, check against filter length
while ( getline( FIR_filter_file, one_line ) && ( line_number < filter_length ) ) {
FIR_filter[ line_number ] = stof( one_line );
line_number++;
}
}
if ( file_extension == "bin" ) {
//read in binary data file (floats)
FIR_filter_file.read( reinterpret_cast(&FIR_filter[0]), filter_length*sizeof(float) );
}
if ( file_extension == "csv" ) { //NEED TO REDO CSV READ WITH MORE EFFICIENT METHOD..
//read in comma separated values data file (float or doubles)
// idea: read each char and buffer input, when comma is reached convert buffer to float
char one_char;
string str_buffer;
line_number = 0;
while ( FIR_filter_file.get(one_char) && ( line_number < filter_length ) ) {
if ( one_char == ',' ) {
FIR_filter[ line_number ] = stof( str_buffer );
str_buffer = "";
line_number++;
} else {
str_buffer += one_char;
}
}
}
//done reading FIR filter file, so close it.
FIR_filter_file.close();
/**********************************************************************************
set up the convolution
**********************************************************************************/
//if this is during startup, perform FFTW related initializations
if ( doing_initial_startup ) {
//size the STL containers that will hold real valued data and fill with zeros
overlap_data.resize( filter_length-1, 0.0 );
unprocessed_data.resize( FFT_length );
FIR_filter.resize( FFT_length );
processed_data.resize( FFT_length );
//size the STL containers that will hold complex data
outfftwOne.resize( FFT_length );
outfftwTwo.resize( FFT_length );
fftMulti.resize( FFT_length/2 + 1 ); //num_complex_data = FFT_length/2 + 1
// NOTE OCT2022: wisdom not currently used, but this retained for possible future use
// //Import FFTW system wisdom:
// #if FFT_DATATYPE == 2
// //get FFTW System Wisdom from /etc/fftw/wisdom
// ret_val = fftw_import_system_wisdom(); //import double precision wisdom
// #else
// //get FFTW System Wisdom from /etc/fftw/wisdomf
// ret_val = fftwf_import_system_wisdom(); //import single precision wisdom
// #endif
// if ( ret_val != 1 ) {
// //ret_val is 1 on successful wisdom import
// error_file << "An error ocurred when trying to import system Wisdom." << endl;
// cleanup_and_exit( engine_stats_file, working_directory );
// }
#if FFT_DATATYPE == 2
//create the FFT plans in double precision
audio_fFFT = fftw_plan_dft_r2c_1d(
FFT_length,
&unprocessed_data[0],
reinterpret_cast(&outfftwOne[0]),
FFTW_ESTIMATE );
filter_fFFT = fftw_plan_dft_r2c_1d(
FFT_length,
&FIR_filter[0],
reinterpret_cast(&outfftwTwo[0]),
FFTW_ESTIMATE );
filterXaudio_iFFT = fftw_plan_dft_c2r_1d(
FFT_length,
reinterpret_cast(&fftMulti.[0]),
&processed_data[0],
FFTW_ESTIMATE );
#else
//create the FFT plans in single precision
audio_fFFT = fftwf_plan_dft_r2c_1d(
FFT_length,
&unprocessed_data[0],
reinterpret_cast(&outfftwOne[0]),
FFTW_ESTIMATE );
filter_fFFT = fftwf_plan_dft_r2c_1d(
FFT_length,
&FIR_filter[0],
reinterpret_cast(&outfftwTwo[0]),
FFTW_ESTIMATE );
filterXaudio_iFFT = fftwf_plan_dft_c2r_1d(
FFT_length,
reinterpret_cast(&fftMulti[0]),
&processed_data[0],
FFTW_ESTIMATE );
#endif
//make sure all FFTW plans were created sucessfully
if ( (filter_fFFT == NULL) || (filter_fFFT == 0) ||
(audio_fFFT == NULL) || (audio_fFFT == 0) ||
(filterXaudio_iFFT == NULL) || (filterXaudio_iFFT == 0)
) {
error_file << "One or more FFTW plans could not be created!" << endl;
cleanup_and_exit( engine_stats_file, working_directory );
}
} //end if ( doing_initial_startup ) FFTW related initializations
//perform filter related fFFT, done only at startup or upon filter change
if ( ( doing_filter_change ) || ( doing_initial_startup ) ) {
//zero-pad the filter only if filter change
if ( doing_filter_change ) {
for (i = filter_length; i < FFT_length; i++) FIR_filter[i] = 0.0;
}
//compute the forward transform of the filter
#if FFT_DATATYPE == 2
//compute fFFT of the filter in double precision
fftw_execute(filter_fFFT);
#else
//compute fFFT of the filter in single precision
fftwf_execute(filter_fFFT);
#endif
} //end if doing_filter_change or is_first_cycle
//If the initializations came about in response to a filter change, run the convolution again now
// The unprocessed data should not have been altered by the function previously because
// the convolution is not inplace, therefore, the new FIR filter can be run on
// the 'old' data' to generate a new set of overlap-add data for the next cycle
if ( doing_filter_change ) {
// THIS CODE ONLY NEEDS TO GENERATE NEW OVERLAP DATA
i = 0; //A DUMMY STATEMENT FOR NOW...
//THIS IS NOT YET IMPLEMENTED.
}
//clear the doing_filter_change flag
doing_filter_change = false;
// Initialize time variables to current time
auto timer_begin = std::chrono::high_resolution_clock::now();
auto timer_end = std::chrono::high_resolution_clock::now();
auto last_stats_write = std::chrono::high_resolution_clock::now();
if ( doing_initial_startup ) {
send_ready_signal( processed_data_fd );
doing_initial_startup = false;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Done With Initialization.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
//begin loop containing the FIR filter convolution
do {
//check for new messages in the control FIFO, or or existing messages, and process them
if ( ( read_from_control_FIFO ( control_fifo_fd, FIFO_message_queue ) > 0 )
|| ( FIFO_message_queue.size() > 0 )
) process_control_messages(
FIFO_message_queue,
saved_messages,
FIR_filter_filename,
file_extension,
filter_length,
data_length,
FFT_length,
cycle_latency,
update_interval,
doing_filter_change );
//Get a new set of data from the unprocessed_data FIFO.
if ( ! wait_for_unprocessed_data ( unprocessed_data_fd, update_interval, data_length, unprocessed_data ) ) {
// if function returns false, too much time has elapsed, so terminate
cleanup_and_exit( engine_stats_file, working_directory );
}
//set timer_begin to current time. Used to determine convolution cycle time
timer_begin = std::chrono::high_resolution_clock::now();
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Perform the convolution:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
//copy unprocessed_data and zero-pad it to generate sigOnePadded
for (i = data_length; i < FFT_length; i++) unprocessed_data[i] = 0.0;
#if FFT_DATATYPE == 2
//compute fFFT of sigOnePadded in double precision
fftw_execute(audio_fFFT);
#else
//compute fFFT of sigOnePadded in single precision
fftwf_execute(audio_fFFT);
#endif
//Complex multiplication: fFFT(data)*fFFT(filter)
for ( i = 0; i < (FFT_length/2 + 1); i++ ) fftMulti[i] = outfftwOne[i] * outfftwTwo[i];
#if FFT_DATATYPE == 2
//compute iFFT of fFFT(data)*fFFT(filter) in double precision
fftw_execute(filterXaudio_iFFT);
#else
//compute iFFT of fFFT(data)*fFFT(filter) in single precision
fftwf_execute(filterXaudio_iFFT);
#endif
//normalize the output
for (i=0; i(timer_end - timer_begin);
//if this is the longest time ever, replace the previous value
if ( cycle_time > longest_cycle_time ) {
longest_cycle_time = cycle_time;
longest_cycle_number = cycle_counter;
}
//if this is the first cycle, sleep until cycle_latency has elapsed.
//this provides buffering against varying FIR engine cycle times.
if ( is_first_cycle ) {
if ( (cycle_latency - cycle_time.count()) > 0 )
this_thread::sleep_for( std::chrono::microseconds( (cycle_latency - cycle_time.count()) ) );
is_first_cycle = false;
}
//only write stats to file if we will NOT be doing a filter change.
if ( ! doing_filter_change ) {
// push cycle time in usec into running stats
rs.Push( (double)cycle_time.count() );
// Write running stats to file in working directory every 2 minutes
//check times elapsed since last write
elapsed_time = duration_cast(timer_end - last_stats_write);
if ( elapsed_time > std::chrono::seconds(10) ) {
//rewind to beginning of file to overwrite the previous data
engine_stats_file.seekp(0);
//write stats to file
engine_stats_file << "Cycle time running statistics (times in usec):\n";
engine_stats_file << " mean = " << rs.Mean() << "\n";
engine_stats_file << " standard deviation of mean = " << rs.StandardDeviation() << "\n";
engine_stats_file << "longest ever cycle time = " << longest_cycle_time.count() << "\n";
engine_stats_file << " occured during cycle " << longest_cycle_number << endl;
//update last_stats_write time
last_stats_write = std::chrono::high_resolution_clock::now();
}
} //done writing stats
} while ( doing_filter_change == false ); //End loop containing the FIR filter convolution
//only get here if the code is changing over to a new FIR filter
//reset stats related data
rs.Clear();
//clear FIR_filter_filename in anticipation of a new filter
FIR_filter_filename == "";
} //end main loop
} //end program LADSPA-FIR/INSTALLATION AND USE OF LADSPA-FIR.txt 0000777 0000000 0000000 00000050657 13640450114 014642 0 ustar LADSPA-FIR: AN FIR ENGINE WRAPPER AND LADSPA PLUGIN
VERSION 1.0
written by: Charlie Laub, March 2020
BUGS/ERRORS/PROBLEMS:
Please report any bugs or errors to the author at:
ACD@claub.net
WHAT IS LADSPA-FIR?
LADSPA-FIR is a LADSPA plugin for performing FIR filtering as part of a LADSPA host audio processing program like ecasound. The FIR convolution is performed by a separate program, the FIR engine, while the LADSPA plugin handles audio data I/O between the LADSPA host and the FIR engine via FIFOs (named pipes). An example 3-way stereo crossover using ecasound and LADSPA-FIR is provided near the end of this document.
REQUIREMENTS:
1. The gcc compiler, version 4.8 or later, and make utility are used to build the code and must be installed. These are typically installed by default in most Linuxes. You may determine the gcc version by running the command gcc --version.
2. LADSPA-FIR is written for a Linux operating system and requires the presence of a non-permanent memory-based filesystem (tmpfs) mounted at /dev/shm. This is normally found on all modern Linuxes. Simply run the command "ls /dev/shm" to see if this is available on your operating system.
3. This is a LADSPA plugin, which requires that LADSPA has been installed and set up on your machine. Additionally, a LADSPA host (such as ecasound) is required to run the plugin. See the section at the end of this document named "NOTES ON INSTALLING LADSPA AND ECASOUND" for installation help and the REFERENCES section for external links.
INSTALLATION OF FFTW:
This section provides helpful information about configuring and installing FFTW on your computer.
1. Download the FFTW package. See: http://www.fftw.org/download.html
2. Extract the compressed file. This will create a new directory, e.g. FFTW_3.8.3
3. In a browser, navigate to the page:
http://www.fftw.org/fftw3_doc/Installation-on-Unix.html#Installation-on-Unix
4. Decide the precision you wish to use (float/double/both)
For single precision (recommended), use the flag --enable-float
Double precision is the default, so no flag is needed.
If you wish to have both available you must perform the steps TWICE, once for float and once for double.
You may also provide flags based on your computer's architecture such as SSE, NEON, etc. FFTW may be able to detect these automatically. See the descrition at the FFTW installation page linked above. Gcc optimization flags may also be passed in the form CFLAGS=" ... "
5. Examples:
a. single precision and without specifying optimizations:
sudo ./configure --enable-float
sudo make
sudo make install
b. double precision and without specifying optimizations:
sudo ./configure
sudo make
sudo make install
c. single precision, explicitly providing flags for SSE (Intel), and gcc march optimization option:
sudo ./configure --enable-float --enable-sse --enable-sse2 CFLAGS="-march=native"
sudo make
sudo make install
If there are no warming messages produced, FFTW is ready for use.
Setting the appropriate FFTW and Gcc flags will help to make FFTW as fast as possible. It is perfectly fine to omit all optimizations if you desire, and FFTW will still function.
PLUGIN AND FIR ENGINE INSTALLATION:
NOTE: FFTW must have been installed in single or double precision as described above before performing these steps.
1. If you not done so already, download and uncompress the LADSPA-FIR package
2. In a terminal window, navigate to the directory where the LADSPA-FIR package is located
3. Issue the command "make" to build the plugin object file
4. Issue the command "sudo make install" to install the LADSPA plugin on the system
5. To make sure that shell script that builds the FIR engine can be executed, run the command:
chmod +x ./compile_FIR_engine.sh
6. Run the shell script to compile the FIR engine code into an executable file.
If you wish to build the single precision version of the FIR engine, run the following command:
./compile_FIR_engine.sh float
If you wish to build the double precision version of the FIR engine, run the following command:
./compile_FIR_engine.sh double
A new file called FIR_engine.exe will be created. You may move this to a new directory if you wish.
PREPARATION FOR USE:
The plugin and FIR engine require a filter table and two environmental parameters to function.
1. Use a text editor to create the filter table in the following format:
#ID TAPS FILTER_FILE <-- header lines beginning with "#" are skipped
1 2048 ~/somedir/my_filter_file.txt <- non-header lines contain filter files by ID
2 8192 ~/another_dir/some_filter.bin <- IDs must be integers >0 and unique. Non sequential is OK.
List one filter per line. Provide a unique ID number (integer > 0) for each filter in the range 1..9999, the number of taps in each filter, and the path and file name of the filter data file.
NOTE: Supported filter formats include plain text (*.txt) and binary floats (32 bit, *.bin). The plain text filter file may include header/comment lines at the top that start with the "#" character. Once the data section begins, comment lines are no longer allowed.
When you are done, save the filter table file with a logical filename of your choice, e.g. filter_table.txt.
2. Two environmental parameters must be created and made available to the session:
LADSPA_FIR_FILTER_TABLE <- the filepathname of the FIR filter table
LADSPA_FIR_FILTER_ENGINE <- the filepathname of the FIR_engine executable
To export a new variable to the current session, you use the format:
export var_name=value
and substitute the var_name and value as needed. For example:
export LADSPA_FIR_FILTER_TABLE=~/my_FIR_stuff/FIR_filter_table.txt
export LADSPA_FIR_FILTER_ENGINE=~/my_FIR_stuff/FIR_engine.exe
Check that the export was successful by listing all environmental parameters and inspecting the output. Run the commands:
env | grep LADSPA_FIR_FILTER_TABLE
env | grep LADSPA_FIR_FILTER_ENGINE
You should see the var_name and value listed if the export was performed sucessfully.
To automatically export these parameters for all future sessions, edit your .profile file (located in your home dir) and add the export commands at the end of the file. Log out and log back in to force the .profile file to be processed. The variables will be available in each user session thereafter.
The installation is now complete.
USING THE PLUGIN WITH A LADSPA HOST PROGRAM:
A user interacts with the LADSPA plugin via the host. The LADSPA host takes the parameters related to the plugin from the user and passes them on to the plugin. The plugin code then sets up and runs the FIR engine that does the actual processing. Let's look at how to choose the parameters properly:
Some important restrictions:
a. The FFT length must be at least data_length + filter_length - 1 samples.
b. The data length should be at least twice as large as the filter length.
c. FFT lengths that are a power of 2 are the fastest, however, other lengths are possible.
Easy length selection method for beginners:
One easy way to figure out what data length and FFT length to use is to take the filter length and multiply it by three. Use this value for the data length. Then the FFT length can be set to the sum of these, which is also equal to four times the filter length. Example: filter length = 1024; 3 * 1024 = 3072. 4 * 1024 = 4096. Set the data length to 3072 and the FFT length to 4096. Any filter of 1024 taps or less can be used with these values of data and FFT lengths. If a longer filters will be used, repeat the calculation for that filter length. Remember, the filter lengthe and data length can be any number, however, the FFT length must be large enough to accomodate them and its value will impact the speed of the convolution. See the section HOW THE FFT LENGTH INFLUENCES THE CALCULATION SPEED below for specific info on that topic.
The following plugin call syntax is used in ecasound (a LADSPSA host):
-el:LADSPA_FIR,filter_ID,data_length,FFT_length,cycle_latency,filter_label
with the following parameters:
filter_ID: the ID of the filter to be applied to the audio stream, given in the filter table file
data_length: the number of samples that the FIR filter will process each call (see NOTE below)
FFT_length: the length/size of the FFT (see NOTE below)
cycle_latency: the maximum expected execution time for 1 cycle of the FIR convolution
filter_label: This is optional. An integer > 0 that will be used to create the working directory name
For example:
-el:LADSPA_FIR,5,7000,8192,1000,1
This will implement a 8192 length FFT that processes 7000 samples per call and uses the filter listed as filter 5 in the filter table. The filter length must be no longer than 8192-7000+1, e.g. it could be a 1024 tap filter with a few unused bins in the FFT. A filter label of "1" (the last parameter) is supplied so the user can identify any working directory associated with this filter. Ecasound will spawn extra "copies" of this single-channel plugin as needed, e.g. 2 instances for a stereo audio stream, so there may be more than one directory in the form of /dev/shm/FIR_0001.xx.
A complete example can be found below in the section EXAMPLE: A 3-WAY CROSSOVER USING ECASOUND.
OBTAINING A VALUE FOR THE CYCLE LATENCY PARAMETER:
This is an important parameter that is used within the code to avoid underruns. The value is given in microseconds. Initially, the user should choose a value such as 1000-10000 (1-10msec) and run the plugin. With the filter running, the statistics on the actual cycle time of the running filter are found looking with the working directory for that filter. The working directory will have a name of the form:
/dev/shm/FIR_xxxxxx.yy, e.g. /dev/shm/FIR_0001.bW or /dev/shm/FIR_nn23f8.9h
In the first example above, the user supplied "1" for the filter label. The last two characters are randomly chosen for each filter. There may be more than one filter with the same FIR_xxxxx part but different last two characters. In the second example, the user did not supply a filter_label, so all THE "xxxxxx" characters are random.
To find the cycle latency, simply cat the file called "cycle_time_stats" in the working directory, e.g.:
cat /dev/shm/FIR_0001.bW/cycle_time_stats
The output will look like this:
Cycle time running statistics (times in usec):
mean = 3225.16
standard deviation of mean = 50.5652
longest ever cycle time = 3344
occured during cycle 77
The important number within this output file is the "longest ever cycle time". The value that you provide to the LADSPA host for the plugin's cycle_latency parameter should be larger than this value. The value is already in microseconds, so for the example output the user might choose a cycle_latency parameter value of 5000 (5msec). To put this into perspective, these cycle statistics were obtained on an Intel J1900 machine, running a 64k tap FIR filter.
If samples are not returned in time, a buffer underrun will occur and a warning message will be placed in LADSPA-FIR.log. Frames of zeroes will be returned until processed data is again available. At that time the plugin will attempt to recover the correct place in the audio stream by dropping samples returned by the FIR engine in order to make up the accumulated latency. Inspect the LADSPA-FIR.log for reports about this activity. Latency correction can help to keep the audio playback working properly even if the system experiences high CPU demand or is operating near capacity.
ERRORS AND WARNINGS:
All instances of the LADSPA plugin and FIR engine write error and warning messages to files in /dev/shm. These files are persistent until the machine is rebooted. The user can look for error messages to diagnose problems and may delete the files at any time as long as there is no running instance of the plugin. The files are:
/dev/shm/LADSPA-FIR.log : this file contains information produced by all LADSPA-FIR plugins
/dev/shm/FIR_engine.log : this file contains information produced by all FIR engines
Because more than one plugin or FIR engine will be appending info to this file, some lines may be duplicated. This is normal and expected.
A WORD ABOUT LATENCY:
Sources of latency include:
1. The FIR filter kernel
2. The buffering of data_length samples at the current sample rate
3. Latency due to the FIR convolution and I/O between the plugin and FIR engine
The latency for (1) and (2) can be determined. The latency due to (3) is not known a priori, however, it should be possible to force (3) to be the same for all channels by using the same values for data_length, FFT_length, and cycle_latency throughout. As long as (3) is the same for all channels, there is no need to use delay lines to balance latencies since the overall latencies should already be identical.
HOW THE FFT LENGTH INFLUENCES THE CALCULATION SPEED:
The data and filter lengths can be any number - they are zero padded to the FFT length. FFTW has at least O N log N complexity (e.g. speed) for a given FFT length of N, however, longer FFT lengths are not necessarily slower. This is because the FFT length has an influence on the particular decomposition of the FFT calculation and which algorithms are used by FFTW. Powers of 2 are fastest, however, FFTW is also relatively fast for factors of 3 and 5. Even 7 can be included as a factor of the FFT length but the calculation will be slower. LADSPA-FIR includes a check that will automatically refactor the user-requested FFT length into the form:
2^a * 3^b * 5^c * 7^d. If the user-requested values cannot be factored in this way, the next highest integer that can be factored into this form will be used. This feature of LADSPA-FIR makes it possible for the user to request any value for the FFT length, however, the requested value may be modified to meet the requirements of FFTW and to insure that the convolution is as fast as possible.
EXAMPLE: A 3-WAY CROSSOVER USING ECASOUND:
In this example, LADSPA-FIR and ecasound are used to implement a 3-way stereo crossover. You must have ecasound and LADSPA installed and configured on your system. In this example I am using a 7.1 channel audio soundcard that appears in ALSA as card 1 on my system. On your system the appropriate soundcard may have a different number. It is also possible to specify the input and output card by name under ecasound (consult the ecasound man page) using the syntax "-i[:]alsa,pcm_device_name". To see the card names and numbers, run the command "aplay -l" on your system.
First, open for editing a file and paste in the following 8 lines:
#!/bin/bash
ecasound -B:rt -z:mixmode,sum -x -f:s32_le,2,48000 -i:alsahw,1,0 -f:f32_le,2,48000 -o:loop,1 \
-a:woofer,midrange,tweeter -i:loop,1 \
-a:woofer -el:LADSPA_FIR,1,12288,16384,5000,1 -f:s32_le,6,48000 -chorder:1,2,0,0,0,0 \
-a:midrange -el:LADSPA_FIR,2,12288,16384,5000,2 -f:s32_le,6,48000 -chorder:0,0,1,2,0,0 \
-a:tweeter -el:LADSPA_FIR,3,12288,16384,5000,3 -f:s32_le,6,48000 -chorder:0,0,0,0,1,2 \
-a:woofer,midrange,tweeter -o:alsahw,1,0
These ecasound commands take live (realtime) stereo audio from the soundcard, implement six parallel FIR filters, and then output six channels of audio to the same soundcard. Save the file as "example_crossover.sh" and exit the editor. At the command line, make the shell script executable by typing:
chmod +x example_crossover.sh
To run the crossover, type the command:
./example_crossover.sh
To stop processing, type control-C in the terminal.
If it did not work sucessfully, go back and make sure you have completed the installation of the LADSPA plugin and FIR engine, and have exported the environmental parameters LADSPA_FIR_FILTER_TABLE and LADSPA_FIR_FILTER_ENGINE. The error files can be helpful for troubleshooting. Issue the commands:
cat /dev/shm/LADSPA-FIR.log
cat /dev/shm/FIR_engine.log
in order to view the contents of these files. To clear the contents, simply delete the files when the audio processing is not running.
With the crossover running, we look in the tmpfs for the working directories for each FIR engine and the log files:
ls /dev/shm
On my system, the following were listed:
FIR_0001.CN FIR_0001.wd FIR_0002.Aw FIR_0002.GP FIR_0003.HQ FIR_0003.LP FIR_engine.log LADSPA-FIR.log
There are six working directories, one for each channel, and the two error logs.
Next we check the value of the cycle latency. Since all filters are running with the same FFT length, the cycle latencies should be similar so it does not matter which working directory we check. Choose one of the directories shown for your system that has the form "FIR_0001.xx", and substitute whatever characters are shown in place of "xx" when you issue the command:
cat /dev/shm/FIR_0001.xx/cycle_time_stats
On my system, the output is:
Cycle time running statistics (times in usec):
mean = 802.128
standard deviation of mean = 63.1278
longest ever cycle time = 1660
occured during cycle 738
Your numbers may be different. That's not important per se. What is important is that the value that was supplied to each of the plugins for the cycle_latency parameter is at least as large as the value shown for "longest ever cycle time" in the output. If the longest ever cycle time report in the cycle_time_stats file is MORE than the cycle_latency parameter provided to the plugin, the user should increase the cycle latency parameter for the plugins accordingly so that it greater than the actual longest cycle time.
In this case, the value for the longest ever cycle time is 1660 (microseconds) and in the ecasound commands we used a cycle_latency of 5000. Since 5000 is greater than 1660 we know that the cycle latency of the FIR engine will be sufficiently accomodated and there is no risk of buffer underruns. One could go back and reduce the value of the cycle_latency parameter to e.g. 2000, however, that is probably not necessary in this case. It will not have an impact on the overall latency of the audio stream in the large majority of cases. The exception is when the cycle latency exceeds the time of one frame of audio. The frame duration is the number of samples per frame divided by the sample rate. In this case there are 1024 samples per frame, and the sample rate is 48kHz, so the frame duration is approximately 21 milliseconds. Under ecasound, the user can choose the number of samples per frame (must be a power of 2) using the -b parameter, so the frame duration could easily be increased by 2 or 4 times if needed.
NOTES ON INSTALLING LADSPA AND ECASOUND:
LADSPA must be installed for this plugin to be sucessfully compiled, to function, and be used by a LADSPA host. To install LADSPA on your system (e.g. Debian/Ubuntu) run the commands:
sudo apt update
sudo apt install ladspa-sdk
LADSPA requires an environmental variable to be set that identifies the path where LADSPA plugin object files are found. Open for editing your .profile file by typing:
nano ~/.profile
Navigate to the end of the file and paste in the following line:
export LADSPA_PATH=/usr/local/lib/ladspa:/usr/lib/ladspa
Save and exit by typing
control-S
control-X
You will need to log out and log in again for this to take effect. To check that you have sucessfully installed LADSPA, type:
listplugins
You should get a list of some default plugins that looks something like this:
/usr/lib/ladspa/noise.so:
White Noise Source (1050/noise_white)
/usr/lib/ladspa/sine.so:
Sine Oscillator (Freq:audio, Amp:audio) (1044/sine_faaa)
Sine Oscillator (Freq:audio, Amp:control) (1045/sine_faac)
Sine Oscillator (Freq:control, Amp:audio) (1046/sine_fcaa)
Sine Oscillator (Freq:control, Amp:control) (1047/sine_fcac)
/usr/lib/ladspa/filter.so:
Simple Low Pass Filter (1041/lpf)
Simple High Pass Filter (1042/hpf)
/usr/lib/ladspa/amp.so:
Mono Amplifier (1048/amp_mono)
Stereo Amplifier (1049/amp_stereo)
/usr/lib/ladspa/delay.so:
Simple Delay Line (1043/delay_5s)
Next, install ecasound by running the command:
sudo apt install ecasound
Ecasound does not require any configuration before it can be used.
REFERENCES:
This web page contains relevant info about using ecasound with some examples:
http://rtaylor.sites.tru.ca/2013/06/25/digital-crossovereq-with-open-source-software-howto/
The ecasound manpage is a good reference as well, and is found at:
http://eca.cx/ecasound/Documentation/ecasound_manpage.html
LADSPA-FIR/LADSPA_FIR.cpp 0000777 0000000 0000000 00000071573 13636714742 011537 0 ustar /* LADSPA_FIR PLUGIN, VERSION 1.0
LADSPA INTERFACE TO AN FIR FILTER ENGINE USING TMPFS-BASED I/O
written by: Charlie Laub, 2020
For information about installation and usage, please see the instruction file.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
CREDITS:
I would like to thank Dan Cyr for helping me understand and implement FIR convolution with FFTW.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//these c-style headers needed for FIFOs!
#include
#include
#include
#include
#include
#include
#include
// Linux specific fcntl header to set FIFO size
// #include
using namespace std;
//LADSPA parameter order:
#define FILTER_INDEX 0
#define DATA_LENGTH 1
#define FFT_LENGTH 2
#define CYCLE_LATENCY 3
#define FILTER_LABEL 4
#define DATA_INPUT 5
#define DATA_OUTPUT 6
//global variables
ofstream error_file;
unsigned long x_to_the_p(unsigned long x, unsigned long p) {
//exponentiation function for integers: x^p
if (p == 0) return 1;
if (p == 1) return x;
unsigned long tmp = x_to_the_p(x, p/2);
if (p%2 == 0) return tmp * tmp;
else return x * tmp * tmp;
} //end function x_to_the_p
unsigned long get_factors(unsigned long n, vector< unsigned long > &factors ) {
//factor a number by the primes 2, 3, 5, and 7. Return the remainder.
unsigned long z = 2;
while (z * z <= n) {
if (n % z == 0) {
factors[z] += 1;
n /= z;
} else {
z++;
if ( z > 7 ) return n;
}
}
return n;
} //end function get_factors
unsigned long optimize_for_FFTW_DFT( unsigned long trial_num ) {
//check to see if trial_num is a factor of only the prime numbers 2, 3, 5, and 7
// if it is, return trial_num
// if not, find the next highest number that is and return that
unsigned long new_num, num_to_factor;
unsigned long lowest_best = 0;
vector< unsigned long > factors(8,0);
// cout << "OPTIMIZING INPUT VALUE OF :" << trial_num << " FOR FFTW." << endl;
do {
num_to_factor = trial_num;
factors[2] = 0;
factors[3] = 0;
factors[5] = 0;
factors[7] = 0;
new_num = get_factors( num_to_factor, factors );
while (new_num > 7 ) {
num_to_factor = new_num + 1;
new_num = get_factors( num_to_factor, factors );
}
factors[new_num] += 1;
new_num = x_to_the_p( 2, factors[2] );
new_num *= x_to_the_p( 3, factors[3] );
new_num *= x_to_the_p( 5, factors[5] );
new_num *= x_to_the_p( 7, factors[7] );
if ( lowest_best == 0 ) lowest_best = new_num;
if ( new_num < lowest_best ) lowest_best = new_num;
trial_num += 1;
} while ( lowest_best > trial_num );
// cout << "THE NEXT NUMBER OF THE FORM 2^a * 3^b * 5^c * 7^d" << endl;
// cout << " 2 ^ " << factors[2] << " * ";
// cout << "3 ^ " << factors[3] << " * ";
// cout << "5 ^ " << factors[5] << " * ";
// cout << "7 ^ " << factors[7] << endl;
// cout << "IS: " << lowest_best << endl;
return lowest_best;
} //end function optimize_for_FFTW_DFT
//trim whitespace the the left of text
std::string& ltrim(std::string& s)
{
auto it = std::find_if(s.begin(), s.end(),
[](char c) {
return !std::isspace(c, std::locale::classic());
});
s.erase(s.begin(), it);
return s;
}
//trim whitespace the the right of text
std::string& rtrim(std::string& s)
{
auto it = std::find_if(s.rbegin(), s.rend(),
[](char c) {
return !std::isspace(c, std::locale::classic());
});
s.erase(it.base(), s.end());
return s;
}
//trim whitespace the the left and right of text
std::string& trim(std::string& s)
{
return ltrim(rtrim(s));
}
void split( deque &res, string s, string delimiter) {
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
string token;
while ((pos_end = s.find (delimiter, pos_start)) != string::npos) {
token = s.substr (pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
if (token != "" ) {
trim( token );
res.push_back (token);
}
}
token = s.substr (pos_start);
trim( token );
res.push_back ( token );
}//end function split
int get_processed_data ( int fd, float * data_container, size_t num_floats ) {
int ret_val;
//read num_floats*sizeof(float) bytes into data_container from the FIFO
ret_val = read(fd, data_container, num_floats*sizeof(float) );
//messages of size >0 contain data. ret_val = -1 indicates empty FIFO
return ret_val;
} //end function read_from_FIFO
int put_unprocessed_data ( int fd, float * data_container, size_t num_floats ) {
signal(SIGPIPE, SIG_IGN); //ignore sigpipe errors
int ret_val;
//put num_floats*sizeof(float) bytes into FIFO from the data_container
ret_val = write(fd, data_container, num_floats*sizeof(float) );
return ret_val;
}
bool check_for_FIR_engine_ready_signal( int fd ) {
//try to read a short text string from the processed_data FIFO
//"READY" is sent by the FIR engine to indicate it has completed initialization and is ready
int ret_val;
char char_array[16];
ret_val = read(fd, char_array, sizeof(char_array) );
//messages of size >0 contain data. ret_val = -1 indicates empty FIFO
if ( ret_val > 0 ) return true;
return false;
}
void create_FIFO_file( string fifo_filename ) {
const char * myfifo = fifo_filename.c_str();
// Create the named file(FIFO)
// mkfifo(, )
mkfifo(myfifo, 0666);
}
void queue_message_for_FIFO( string &one_message, string &FIFO_messages ) {
if ( FIFO_messages != "" ) FIFO_messages += "|";
FIFO_messages += one_message;
one_message = "";
}
void write_to_control_FIFO ( int fd, string &messages, bool &control_FIFO_open ) {
signal(SIGPIPE, SIG_IGN); //ignore sigpipe errors
int ret_val;
const char * char_array = messages.c_str();
ret_val = write(fd, char_array, strlen( char_array ));
if (ret_val > 0 ) {
messages = ""; //messages successfully sent, so empty the variable
} else {
control_FIFO_open = false;
close(fd);
}
}
void set_FIFO_buffer_size( int fd, size_t capacity ) {
//set FIFO buffer capacity in bytes. check, then set, and check again
long pipe_size = (long)fcntl(fd, F_GETPIPE_SZ);
if (pipe_size == -1) {
error_file << " could not get FIFO size!" << endl;
return;
}
int ret = fcntl(fd, F_SETPIPE_SZ, capacity);
if (ret < 0) {
error_file << " could not set new FIFO size!" << endl;
return;
}
pipe_size = (long)fcntl(fd, F_GETPIPE_SZ);
if (pipe_size == -1) {
error_file << " could not confirm new FIFO size." << endl;
return;
}
}
string get_random_char_str( const int num_chars ) {
/* Decleration and initialization of static constant string type variable */
static bool rand_is_initialized = false;
static const string charList = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ( ! rand_is_initialized ) {
/* srand(): initialize random number generator from the current time */
auto now = std::chrono::system_clock::now();
auto now_us = std::chrono::time_point_cast(now);
auto epoch = now_us.time_since_epoch();
auto epoch_usec = std::chrono::duration_cast(epoch);
unsigned int seed;
seed = static_cast(epoch_usec.count() );
srand(seed);
rand_is_initialized = true;
}
string alphanumeric;
//create 8-character-long string of random alphanumeric characters
for(int i = 0; i < num_chars; i++) {
/* rand() generate random number */
alphanumeric += charList [rand() % charList.size()];
}
return alphanumeric;
}
string GetEnv( const std::string & var ) {
//put the value of an OS environmental variable into a string
const char * val = std::getenv( var.c_str() );
if ( val == nullptr ) { // invalid to assign nullptr to std::string
return "";
}
else {
return val;
}
}
int run_OS_command( string some_command ) {
//run string passed as command in the OS
// Convert string to const char * as system requires
const char *command = some_command.c_str();
int ret_val;
ret_val = system(command);
return ret_val;
}
size_t getFilesize(const std::string& filename) {
struct stat st;
if(stat(filename.c_str(), &st) != 0) {
return 0;
}
return st.st_size;
}
inline bool file_exists (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
static LADSPA_Descriptor *FIR_filter_Descriptor = NULL;
typedef struct {
LADSPA_Data *input;
LADSPA_Data *output;
unsigned long data_length;
unsigned long filter_length;
unsigned long FFT_length;
unsigned long cycle_latency;
unsigned long SR; //the sample rate
unsigned long call_counter;
unsigned long latent_sample_count;
unsigned int user_filter_ID;
unsigned int filter_label;
int control_fifo_fd;
int unprocessed_data_fd;
int processed_data_fd;
char messages[256];
char working_directory[128];
bool already_activated;
bool control_FIFO_open;
bool fatal_errors_encountered;
bool FIR_engine_is_ready;
bool is_startup;
} plugin_data_struct;
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
switch (index) {
case 0:
return FIR_filter_Descriptor;
default:
return NULL;
}
}
LADSPA_Handle instantiate(const LADSPA_Descriptor *descriptor, unsigned long sample_rate) {
plugin_data_struct *FIR = (plugin_data_struct *)malloc(sizeof(plugin_data_struct));
//store the sample rate
FIR->data_length = 0;
FIR->filter_length = 0;
FIR->FFT_length = 0;
FIR->cycle_latency = 0;
FIR->SR = sample_rate;
FIR->call_counter = 0;
FIR->latent_sample_count = 0;
FIR->already_activated = false;
FIR->control_FIFO_open = false;
FIR->fatal_errors_encountered = false;
FIR->FIR_engine_is_ready = false;
FIR->is_startup = true;
return (LADSPA_Handle)FIR;
}
void connectPort(LADSPA_Handle instance, unsigned long port, LADSPA_Data *data) {
plugin_data_struct *FIR = (plugin_data_struct *)instance;
float temp;
string temp_string;
switch (port) {
case 0:
FIR->user_filter_ID = static_cast( *data );
break;
case 1:
temp = *data;
temp = abs( trunc( temp ) ); //truncate to whole number, make sure is >= 0
FIR->data_length = static_cast(temp); //cast to long int
break;
case 2:
temp = *data;
temp = abs( trunc( temp ) ); //truncate to whole number, make sure is >= 0
FIR->FFT_length = static_cast(temp); //cast to long int
break;
case 3:
//latency in microseconds, passed as float
temp = *data;
temp = abs( trunc( temp ) ); //truncate to whole number, make sure is >= 0
FIR->cycle_latency = static_cast(temp); //cast to long int
break;
case 4:
//filter label, whole number part is used as the dir name for the filter, passed as float
temp = *data;
temp = abs( trunc( temp ) ); //truncate to whole number, make sure is >= 0
FIR->filter_label = static_cast(temp); //cast to u_int;
break;
case 5:
FIR->input = data;
break;
case 6:
FIR->output = data;
break;
} //end switch
} //end function connect_port
void activate(LADSPA_Handle instance) {
plugin_data_struct *FIR = (plugin_data_struct *)instance;
if ( ! FIR->already_activated ) {
//PERFORM ONE-TIME FIR ENGINE START-UP TASKS:
FIR->already_activated = true; //set to true so this code does not run again.
string temp_string;
int ret_val;
string dir_name, OS_commands;
// GET VALUES OF ENVIRONMENTAL VARIABLES FOR FILTER TABLE AND FIR ENGINE
string FIR_filter_table_filename, FIR_engine_cmdstr;
FIR_filter_table_filename = GetEnv("LADSPA_FIR_FILTER_TABLE");
FIR_engine_cmdstr = GetEnv("LADSPA_FIR_FILTER_ENGINE");
if ( ( FIR_filter_table_filename == "" ) || ( FIR_engine_cmdstr == "" ) ) {
//At least one critical environmental variable was not found. Set fatal error flag
FIR->fatal_errors_encountered = true;
if ( FIR_filter_table_filename == "" )
error_file << "The environmental variable LADSPA_FIR_FILTER_TABLE was not found. " << endl;
if ( FIR_engine_cmdstr == "" )
error_file << "The environmental variable LADSPA_FIR_FILTER_ENGINE was not found. " << endl;
return;
} else {
//check to make sure that the files exist
temp_string = FIR_filter_table_filename;
if (! file_exists( temp_string ) ){
FIR->fatal_errors_encountered = true;
error_file << "The file " << FIR_filter_table_filename << " was not found. " << endl;
return;
}
temp_string = FIR_engine_cmdstr;
if (! file_exists( temp_string ) ){
FIR->fatal_errors_encountered = true;
error_file << "The file " << FIR_engine_cmdstr << " was not found. " << endl;
return;
}
}
// Read the FIR filter table to obtain the number of taps and filter file pathname
string one_line, filter_file;
deque< string > tokens;
unsigned int ID_value;
//attempt to open the FIR filter file and perform error handling
ifstream FIR_filter_table;
FIR_filter_table.open( FIR_filter_table_filename.c_str() );
if ( ! FIR_filter_table ) {
//an error was thrown when trying to open the filter table. Set fatal error flag
FIR->fatal_errors_encountered = true;
//error message text is contained in the string e.code().message()
error_file << "When trying to open the filter table file, an error occurred ";
error_file << "or the file could not be opened." << endl;
return;
}
while ( getline( FIR_filter_table, one_line ) ) {
if ( ( one_line.find("#") != string::npos ) || ( one_line == "" ) ) continue; //skip comment and blank lines
split( tokens, one_line, " " );
ID_value = atoi( tokens[0].c_str() );
if ( ID_value == FIR->user_filter_ID ) break;
deque< string >().swap( tokens ); //not a match, so discard the tokens
} //end while
//done reading the FIR filter table so close the file
FIR_filter_table.close();
if ( tokens.size() == 3 ) {
FIR->filter_length = stoi( tokens[1] );
filter_file = tokens[2];
} else {
FIR->fatal_errors_encountered = true;
//the filter ID was not found in the filter table or the line did not
// contain three tokens. Set fatal error flag
error_file << "ERROR: The filter ID was not found in the filter table, or ";
error_file << "the line did not contain three tokens." << endl;
return;
}
//check that FFT_length >= data_length + filter_length
if ( ! ( FIR->FFT_length >= (FIR->data_length + FIR->filter_length) ) ) {
FIR->fatal_errors_encountered = true;
error_file << "ERROR: The FFT length must be >= data_length + filter_length" << endl;
return;
}
//check that data_length > filter_length
if ( ! (FIR->data_length >= (2*FIR->filter_length) ) ) {
FIR->fatal_errors_encountered = true;
error_file << "ERROR: the data length must be >= twice the filter length" << endl;
return;
}
//optimize the FFT_length so that it is a factor of only the primes 2, 3, 5, and 7
// This may result in a slightly larger FFT_length than what was requested by the
// user, however, this maximizes the FFTW speed
FIR->FFT_length = optimize_for_FFTW_DFT( FIR->FFT_length );
// Queue up info to be sent over the control FIFO
string a_message, all_messages;
a_message = "filter_length = " + to_string(FIR->filter_length);
queue_message_for_FIFO( a_message, all_messages );
a_message = "filter_file = " + filter_file;
queue_message_for_FIFO( a_message, all_messages );
a_message = "data_length = " + to_string(FIR->data_length);
queue_message_for_FIFO( a_message, all_messages );
a_message = "FFT_length = " + to_string(FIR->FFT_length);
queue_message_for_FIFO( a_message, all_messages );
a_message = "cycle_latency = " + to_string(FIR->cycle_latency);
queue_message_for_FIFO( a_message, all_messages );
strcpy(FIR->messages, all_messages.c_str() );
//create unique working directory in the tmpfs
if ( FIR->filter_label == 0 ) {
dir_name = "/dev/shm/FIR_" + get_random_char_str( 6 );
} else {
temp_string = to_string( FIR->filter_label );
//pad the front of the string with zeroes until the string is four characters long
while ( temp_string.size() < 4 ) {
temp_string.insert(0,"0");
}
dir_name = "/dev/shm/FIR_" + temp_string + "." + get_random_char_str( 2 );
}
OS_commands = "mkdir " + dir_name;
ret_val = run_OS_command( OS_commands );
if ( ret_val != 0 ) {
//an error was thrown when trying to make the unique directory. Set fatal error flag
FIR->fatal_errors_encountered = true;
error_file << "An error was thrown when trying to make the unique directory " << dir_name << endl;
return;
}
strcpy( FIR->working_directory, dir_name.c_str() ); //store for later
//Create control FIFO file
string fifo_filename;
fifo_filename = dir_name + "/control";
create_FIFO_file( fifo_filename );
//Create unprocessed_data FIFO file
fifo_filename = dir_name + "/unprocessed_data";
create_FIFO_file( fifo_filename );
//Create processed_data FIFO file
fifo_filename = dir_name + "/processed_data";
create_FIFO_file( fifo_filename );
//open the processed_data FIFO read-only , non-blocking. Retuns with file descriptor
//this will always succeed unless the fifo file cannot be created.
temp_string = dir_name + "/processed_data";
FIR->processed_data_fd = open( temp_string.c_str(), O_RDONLY | O_NONBLOCK);
//set FIFO capacity in bytes.
// NOTE: 1048576 bytes = 1 MiB is the largest allowed by the kernel
set_FIFO_buffer_size( FIR->processed_data_fd, 1048576 );
// Use system call to launch the FIR engine, pass working_directory as command line parameter
OS_commands = FIR_engine_cmdstr + " " + dir_name + " &";
ret_val = run_OS_command( OS_commands );
if ( ret_val != 0 ) {
//an error was thrown when trying to launch the FIR engine. Set fatal error flag
FIR->fatal_errors_encountered = true;
error_file << "An error was thrown when trying to launch the FIR engine." << endl;
return;
}
} //end activation steps that are prevented from occuring more than once
} //end activate function.
void run(LADSPA_Handle instance, unsigned long sample_count) {
plugin_data_struct *FIR = (plugin_data_struct *)instance;
LADSPA_Data *input = FIR->input;
LADSPA_Data *output = FIR->output;
FIR->call_counter++;
if ( ! FIR->FIR_engine_is_ready ) {
string temp_string;
string working_directory(FIR->working_directory);
//if this is the first call, calculate the update_interval and add it to FIFO messages
if ( FIR->call_counter == 1 ) {
unsigned long update_interval;
//update_interval in microseconds = 1000000 * samples per frame / samples per second
update_interval = 1000000 * sample_count / FIR->SR;
//queue update_interval for transmission via FIFO
string a_message = "update_interval = " + to_string(update_interval);
string all_messages( FIR->messages );
queue_message_for_FIFO( a_message, all_messages );
strcpy(FIR->messages, all_messages.c_str() );
}
if ( ! FIR->control_FIFO_open ) {
//attempt to open the FIR engine control FIFO
temp_string = working_directory + "/control";
FIR->control_fifo_fd = open(temp_string.c_str(), O_WRONLY | O_NONBLOCK);
if (FIR->control_fifo_fd != -1) {
FIR->control_FIFO_open = true;
}
}
bool ready_signal;
ready_signal = check_for_FIR_engine_ready_signal( FIR->processed_data_fd );
if ( ready_signal ) {
FIR->FIR_engine_is_ready = true;
//the unprocessed data FIFO can now be opened as writer safely
temp_string = working_directory + "/unprocessed_data";
FIR->unprocessed_data_fd = open(temp_string.c_str(), O_WRONLY | O_NONBLOCK);
// error_file << "the FIR engine ready signal was received during call " << FIR->call_counter << endl;
}
}
// if the control FIFO is open and there are messages in the queue, attempt to send them
if ( ( FIR->control_FIFO_open == true ) && ( strlen(FIR->messages) > 0 ) ) {
string message_string( FIR->messages );
write_to_control_FIFO(FIR->control_fifo_fd, message_string, FIR->control_FIFO_open );
if ( message_string.size() == 0 ) FIR->messages[0] = '\0';
}
//while the FIR engine is NOT ready...
// or if a fatal error has occured,
// keep the plugin going by returning silence
if ( ( FIR->fatal_errors_encountered ) || ( ! FIR->FIR_engine_is_ready ) ) {
for (unsigned long index=0; index < sample_count; index++ ) {
output[index] = 0.0;
}
return;
}
int ret_val; //used to hold the value returned by a FIFO read or write
//write samples to processed_data FIFO
ret_val = put_unprocessed_data ( FIR->unprocessed_data_fd, input, sample_count );
//read samples from processed_data FIFO
ret_val = get_processed_data ( FIR->processed_data_fd, output, sample_count );
if ( ret_val < 1 ) {
if ( ! FIR->is_startup ) {
error_file << "Buffer Underrun Warning: processed_data was not available during call " << FIR->call_counter;
error_file << "; " << sample_count << " zeros were returned to the host.";
float latency = (float) sample_count;
latency /= (float) FIR->SR;
latency *= 1000.0;
error_file << " Latency increased by " << latency << " msec during call " << FIR->call_counter << endl;
FIR->latent_sample_count += sample_count;
}
//RETURN ZEROS IF NO DATA IS AVAILABLE:
for (unsigned long index=0; index < sample_count; index++ ) output[index] = 0.0;
} else {
if ( FIR->latent_sample_count > 0 ) {
//attempt to correct the latency by reading in FIR->latent_sample_count samples
FIR->latent_sample_count -= sample_count;
unsigned long num_compensated = sample_count;
while ( ( FIR->latent_sample_count > 0 ) && ( ret_val > 0 ) ) {
//read samples from processed_data FIFO
ret_val = get_processed_data ( FIR->processed_data_fd, output, sample_count );
if ( ret_val > 0 ) {
FIR->latent_sample_count -= sample_count;
num_compensated += sample_count;
}
}
float latency = (float) num_compensated;
latency /= (float) FIR->SR;
latency *= 1000.0;
error_file << "Latency was decreased by " << latency << " msec during call " << FIR->call_counter << endl;
latency = (float) FIR->latent_sample_count;
latency /= (float) FIR->SR;
latency *= 1000.0;
error_file << " The latency is now " << latency << " msec." << endl;
//RETURN ZEROS IF NO DATA IS AVAILABLE:
if ( ret_val < 1 ) for (unsigned long index=0; index < sample_count; index++ ) output[index] = 0.0;
}
} //done getting samples and correcting latency
//check for end of startup conditions
if ( ( FIR->is_startup ) && ( ret_val > 0 ) ) {
// error_file << "Startup was completed during call " << FIR->call_counter << ". Begin normal operation." << endl;
FIR->is_startup = false;
}
} //end run function
void cleanup(LADSPA_Handle instance) {
plugin_data_struct *FIR = (plugin_data_struct *)instance;
//send the terminate message to the FIR engine
string message = "action = terminate";
bool is_open = FIR->control_FIFO_open;
if ( is_open )
write_to_control_FIFO ( FIR->control_fifo_fd, message, is_open );
//free memory used by LADSPA_Handle data structure
free(instance);
} //end function cleanup
static class Initialiser {
public:
Initialiser() {
//open the error log file in append mode
string temp_string;
temp_string = "/dev/shm/LADSPA-FIR.log";
error_file.open( temp_string.c_str(), ios_base::app );
//LADSPA SPECIFIC INITIALIZATIONS:
char **port_names;
LADSPA_PortDescriptor *port_descriptors;
LADSPA_PortRangeHint *port_range_hints;
FIR_filter_Descriptor = (LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
if (FIR_filter_Descriptor) {
std::string text;
//plugin descriptor info
FIR_filter_Descriptor->UniqueID = 5225;
FIR_filter_Descriptor->Label = "LADSPA_FIR";
FIR_filter_Descriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
text = "LADSPA_FIR";
FIR_filter_Descriptor->Name = strdup(text.c_str());
FIR_filter_Descriptor->Maker = "Charlie Laub, 2020";
FIR_filter_Descriptor->Copyright = "GPLv3";
FIR_filter_Descriptor->PortCount = 7;
//create storage for port_descriptors, port_range_hints, and port_names
port_descriptors = (LADSPA_PortDescriptor *)calloc(7,sizeof(LADSPA_PortDescriptor));
FIR_filter_Descriptor->PortDescriptors = (const LADSPA_PortDescriptor *)port_descriptors;
port_range_hints = (LADSPA_PortRangeHint *)calloc(7,sizeof(LADSPA_PortRangeHint));
FIR_filter_Descriptor->PortRangeHints = (const LADSPA_PortRangeHint *)port_range_hints;
port_names = (char **)calloc(7, sizeof(char*));
FIR_filter_Descriptor->PortNames = (const char **)port_names;
//done creating storage. now set the descriptor, range_hints, and name for each port:
//port = FILTER_INDEX
port_descriptors[FILTER_INDEX] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
text = "filter_index";
port_names[FILTER_INDEX] = strdup(text.c_str());
port_range_hints[FILTER_INDEX].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_DEFAULT_0;
port_range_hints[FILTER_INDEX].LowerBound = 0;
//port = DATA_LENGTH
port_descriptors[DATA_LENGTH] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
text = "data_length";
port_names[DATA_LENGTH] = strdup(text.c_str());
port_range_hints[DATA_LENGTH].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_DEFAULT_0;
port_range_hints[DATA_LENGTH].LowerBound = 0;
//port = FFT_LENGTH
port_descriptors[FFT_LENGTH] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
text = "FFT_length";
port_names[FFT_LENGTH] = strdup(text.c_str());
port_range_hints[FFT_LENGTH].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_DEFAULT_0;
port_range_hints[FFT_LENGTH].LowerBound = 0;
//port = CYCLE_LATENCY
port_descriptors[CYCLE_LATENCY] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
text = "cycle_latency";
port_names[CYCLE_LATENCY] = strdup(text.c_str());
port_range_hints[CYCLE_LATENCY].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_DEFAULT_0;
port_range_hints[CYCLE_LATENCY].LowerBound = 0;
//port = FILTER_LABEL
port_descriptors[FILTER_LABEL] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
text = "filter_label";
port_names[FILTER_LABEL] = strdup(text.c_str());
port_range_hints[FILTER_LABEL].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_DEFAULT_0;
port_range_hints[FILTER_LABEL].LowerBound = 0;
port_range_hints[FILTER_LABEL].UpperBound = 9999;
//port = DATA_INPUT
port_descriptors[DATA_INPUT] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
text = "Input";
port_names[DATA_INPUT] = strdup(text.c_str());
//port = DATA_OUTPUT
port_descriptors[DATA_OUTPUT] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
text = "Output";
port_names[DATA_OUTPUT] = strdup(text.c_str());
FIR_filter_Descriptor->activate = activate;
FIR_filter_Descriptor->cleanup = cleanup;
FIR_filter_Descriptor->connect_port = connectPort;
FIR_filter_Descriptor->deactivate = NULL;
FIR_filter_Descriptor->instantiate = instantiate;
FIR_filter_Descriptor->run = run;
FIR_filter_Descriptor->run_adding = NULL;
FIR_filter_Descriptor->set_run_adding_gain = NULL;
}
//DONE WITH LADSPA-SPECIFIC INITIALIZATIONS
} //end class initialization
~Initialiser() {
if (FIR_filter_Descriptor) {
free((LADSPA_PortDescriptor *)FIR_filter_Descriptor->PortDescriptors);
free((char **)FIR_filter_Descriptor->PortNames);
free((LADSPA_PortRangeHint *)FIR_filter_Descriptor->PortRangeHints);
free(FIR_filter_Descriptor);
}
}
} g_theInitialiser;
LADSPA-FIR/LICENSE 0000777 0000000 0000000 00000104514 12144107560 010347 0 ustar GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
LADSPA-FIR/Makefile 0000777 0000000 0000000 00000000763 13640425705 011011 0 ustar INSTALL_PLUGINS_DIR = /usr/local/lib/ladspa/
CC = g++
LD = g++
CFLAGS = -std=c++11 -I. -Ofast -Wall -c -fPIC -DPIC
LDFLAGS = -shared
PLUGINS = LADSPA_FIR.so
all: $(PLUGINS)
%.o: %.cpp
$(CC) $(CFLAGS) -o $@ $<
%.so: %.o
$(LD) $(LDFLAGS) -o $@ $<
install: targets
test -d $(INSTALL_PLUGINS_DIR) || mkdir $(INSTALL_PLUGINS_DIR)
cp *.so $(INSTALL_PLUGINS_DIR)
targets: $(PLUGINS)
always:
clean:
-rm -f `find . -name "*.so"`
-rm -f `find . -name "*.o"`
-rm -f `find . -name "*~"`