This GitLab instance reached the end of its service life. It won't be possible to create new users or projects.

Please read the deprecation notice for more information concerning the deprecation timeline

Visit migration.git.tu-berlin.de (internal network only) to import your old projects to the new GitLab platform 📥

Commit e44f4eb0 by Henrik von Coler

Gain example working!

parent 57151e41
!*.*
.bash_history
.bash_logout
.bashrc
.bashrc~
.cache/
.config/
.local/
.mplayer/
.profile
.ssh/
.viminfo
Klangsynthese_PI/
gain.pd
liblo/
wav/
*~
*.o
*html/
*latex/
# define the compiler
CC = g++
# path(s) to include files
CFLAGS = -I.
# libraries to link
LDFLAGS = -ljack -llo
SRCS = gain_example.cpp oscman.cpp
DEPS = oscman.h gain_example.h
all: gain_example
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
gain_example: gain_example.o oscman.o
$(CC) -o gain_example gain_example.o oscman.o $(LDFLAGS)
clean:
rm *.o gain_example
#!/bin/sh
g++ -std=c++11 gain_example.cpp oscman.cpp -ljack -llo -o gain_example
PROJECT_NAME = "Gain_Example"
PROJECT_BRIEF = "Stereo gain manipulation through OSC!"
OUTPUT_DIRECTORY = "./"
INPUT = "../"
FILE_PATTERNS = *.cpp *.h
RECURSIVE = YES
FILTER_SOURCE_FILES = NO
# deactivate when done with major changes
EXTRACT_PRIVATE = YES
HAVE_DOT = YES
UML_LOOK = YES
/**
* \file GainExample.cpp
* \class GainExample
*
* \brief Simple example, passing the input to the output
* with gain modification through OSC.
*
* \author Henrik von Coler
*
* \date $Date: 2019/03/18 $
*
*/
#include"gain_example.h"
using std::cout;
using std::endl;
GainExample::GainExample(){
// creating an OSC manager instance
oscman = new OscMan(5111);
cout << "Starting Jack Client!" << endl;
this->client = jack_client_open("Gain_Example", JackNullOption, &status, NULL);
jack_set_process_callback(this->client, this->callback_process, this);
// allocate array
input_port = new jack_port_t*[nChannels];
for (int i=0; i<nChannels; i++)
{
std::string tmp_str = "input_" + std::to_string(i+1);
input_port[i] = jack_port_register (client, tmp_str.c_str(),
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsInput, 0);
}
output_port = new jack_port_t*[nChannels];
for (int i=0; i<nChannels; i++)
{
std::string tmp_str = "output_" + std::to_string(i+1);
output_port[i] = jack_port_register (client, tmp_str.c_str(),
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput, 0);
}
out = new jack_default_audio_sample_t*;
in = new jack_default_audio_sample_t*;
jack_activate(this->client);
jack_connect (client, "system:capture_1", jack_port_name(input_port[0]));
jack_connect (client, "system:capture_2", jack_port_name(input_port[1]));
jack_connect (client, jack_port_name(output_port[0]), "system:playback_1");
jack_connect (client, jack_port_name(output_port[1]), "system:playback_2");
sleep (-1);
}
int GainExample::process (jack_nframes_t nframes)
{
double gain = oscman->get_gain();
// get buffers
for ( int i=0 ; i<nChannels; i++)
{
out[i] = (jack_default_audio_sample_t *) jack_port_get_buffer(this->output_port[i], jack_get_buffer_size(client));
in[i] = (jack_default_audio_sample_t *) jack_port_get_buffer(this->input_port[i], jack_get_buffer_size(client));
}
for(int chanCNT=0; chanCNT<nChannels; chanCNT++)
{
for(int sampCNT=0; sampCNT<nframes; sampCNT++)
{
out[chanCNT][sampCNT] = in[chanCNT][sampCNT] * gain;
}
}
return 0;
}
int GainExample::callback_process(jack_nframes_t x, void* object)
{
return static_cast<GainExample*>(object)->process(x);
}
int main(int argc, char *argv[]){
/// initial ports from constructor created here.
GainExample * t = new GainExample();
}
/**
* \file GainExample.h
* \class GainExample
*
* \brief Simple example, passing the input to the output
* with gain modification through OSC.
*
* \author Henrik von Coler
*
* \date $Date: 2019/03/18 $
*
*/
#include<iostream>
#include<stdlib.h>
#include<unistd.h>
#include<jack/jack.h>
#include"oscman.h"
using std::cout;
using std::endl;
class GainExample{
private:
int nChannels = 2;
const char **ports;
jack_client_t *client;
jack_status_t status;
jack_port_t **input_port;
jack_port_t **output_port;
jack_default_audio_sample_t **in, **out;
/// The OSC manager object
OscMan *oscman;
///
/// \brief process
/// \param nframes
/// \return
///
int process (jack_nframes_t nframes);
///
/// \brief callback_process
/// \param x
/// \param object
/// \return
///
static int callback_process(jack_nframes_t x, void* object);
public:
///
/// \brief GainExample
/// Default constructor!
GainExample();
};
/**
* \file oscman.cpp
* \class OscMan
*
* \brief Class which parses the incoming OSC messages.
*
* \author Henrik von Coler
*
* \date 2019/03/18
*
*/
#include "oscman.h"
///
/// \brief OscMan::OscMan
/// \param p
///
OscMan::OscMan(int p)
{
port = p;
gain = 1.0;
try
{
st = new lo::ServerThread(port);
}
catch (int e)
{
std::cout << "Possibly a bad port!" << std::endl;
}
// Add the example handler to the server!
st->add_method("/gain", "f", gain_callback, this);
st->start();
std::cout << "Started OSC Server!" << std::endl;
}
///
////// \brief OscMan::gain_callback
////// \param path
////// \param types
////// \param argv
////// \param argc
////// \param data
////// \param user_data
////// \return
int OscMan::gain_callback(const char *path, const char *types, lo_arg ** argv,
int argc, void *data, void *user_data )
{
// Do a static cast
OscMan* statCast = static_cast<OscMan*>(user_data);
std::cout << "Changed volume to: " << argv[0]->f << std::endl;
statCast->gain = argv[0]->f;
}
///
/// \brief OscMan::get_gain
/// \return
///
double OscMan::get_gain()
{
return gain;
}
/**
* \file oscman.h
* \class OscMan
*
* \brief Class which parses the incoming OSC messages.
*
* \author Henrik von Coler
*
* \date 2019/03/18$
*
*/
#ifndef OSCMAN_H
#define OSCMAN_H
// works with 'self built'
#include <lo/lo.h>
#include <lo/lo_cpp.h>
#include<iostream>
#include<vector>
#include<string>
class OscMan
{
private:
/// the port to be opened
int port;
lo::ServerThread *st;
double gain;
static int gain_callback(const char *path, const char *types, lo_arg ** argv,
int argc, void *data, void *user_data);
public:
OscMan(int p);
double get_gain();
};
#endif
#!/bin/sh
#
# called by synth-user.service
#
/home/student/examples/gain_example/gain_example
#
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment