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 bbd70ad8 by Henrik von Coler

Changes in osc_manager and documentation!

parent 99fe7636
......@@ -29,4 +29,6 @@ command line arguments:
- the grain size in samples '-l'
- the number of windows to be used '-n
./granular_example -f ../../wav/wos\ der\ chef.wav -l 1000 -n 4
```console
~/examples/granular_example $ ./granular_example -f ../../wav/ALF_8bitDRY.wav -l 1000 -n 4
```
#include "grainplayer.h"
GrainPlayer::GrainPlayer(std::string filePath, int fs, int win_size, int nWin)
......@@ -22,28 +24,32 @@ GrainPlayer::GrainPlayer(std::string filePath, int fs, int win_size, int nWin)
double GrainPlayer::get_sample()
{
double output = 0;
// loop over all windows
for(int windowCNT=0; windowCNT<nWindows; windowCNT++)
{
// get gain of this window
double tmpGain = windows[windowCNT].get_value();
// get the relative position of this window
int tmpPos = windows[windowCNT].get_relative_position();
double tmpOut = 0;
// only if we are within the sample boundaries
if(tmpPos >= 0 && tmpPos <= sample->get_nFrames())
{
tmpOut = tmpGain * sample->get_sample(0,tmpPos);
// add grain value to output
output += tmpGain * sample->get_sample(0,tmpPos);
}
output += tmpOut;
int f = windows[windowCNT].step();
if(f==1)
// if this grain (window) has reached its end
if(windows[windowCNT].step()==1)
{
int tmpVal = windows[windowCNT].increment_relative_position(relative_stepsize,sample->get_nFrames());
// move this grain (window) position
windows[windowCNT].increment_relative_position(relative_stepsize,sample->get_nFrames());
}
}
......@@ -57,7 +63,4 @@ void GrainPlayer::set_relative_distance(double r)
relative_stepsize = r;
}
double GrainPlayer::get_position()
{
}
/**
*
* \file grainplayer.cpp
* \class GrainPlayer
*
* \brief The granular player class,
* holding a SingleSound and an
* array of window functions, representing
* the grains.
*
* \author Henrik von Coler
*
* \date 2019/03/23
*
*/
#ifndef GRAINPLAYER_H
#define GRAINPLAYER_H
......@@ -9,20 +26,41 @@ class GrainPlayer
{
public:
///
/// \brief GrainPlayer
/// the constructor
/// \param filePath path to the wav file to read
/// \param fs sampling rate of the JACK server
/// \param win_size the grain size (size of the window)
/// \param nWin the number of grains to be used
///
GrainPlayer(std::string filePath, int fs, int win_size, int nWin);
///
/// \brief get_sample
/// get a single sample, using all active grains
/// \return
/// a sound sample for the output
double get_sample();
void set_relative_distance(double r);
double get_position();
private:
///
/// \brief sample
/// an instance of the single sample class
SingleSample *sample;
///
/// \brief relative_stepsize
/// relative_stepsize is the
double relative_stepsize;
///
/// \brief windows
/// pointer to an array of windows
TriangularWindow *windows;
int nWindows;
......
......@@ -33,12 +33,15 @@ GranularExample::GranularExample(std::string filename, int win_size, int nWindow
fs = jack_get_sample_rate(client);
// hard coded for now
// create a ne grain player
grainer = new GrainPlayer(filename, fs, win_size, nWindows);
nChannels = 1;
// -----------------------------------------------------------------------
// standard JACK startup:
// -----------------------------------------------------------------------
cout << "Starting Jack Client! " << endl;
jack_set_process_callback(this->client, this->callback_process, this);
......@@ -58,8 +61,12 @@ GranularExample::GranularExample(std::string filename, int win_size, int nWindow
jack_connect(client, jack_port_name(output_port[0]), "system:playback_1");
jack_connect(client, jack_port_name(output_port[1]), "system:playback_2");
// run forever
sleep(-1);
// -----------------------------------------------------------------------
}
......
......@@ -26,10 +26,6 @@ OscMan::OscMan(int p)
if (st->is_valid())
{
// Add the example handler to the server!
st->add_method("/speed", "f", speed_callback, this);
......@@ -38,8 +34,8 @@ OscMan::OscMan(int p)
std::cout << "Started OSC Server!" << std::endl;
}
else
throw std::invalid_argument("OSC server not started - possibly a bad port!");
else
throw std::invalid_argument("OSC server not started - possibly a bad port!");
}
......
......@@ -26,7 +26,7 @@ int TriangularWindow::get_relative_position()
return center_offset - playback_position;
}
int TriangularWindow::increment_relative_position(double p, int maxLength)
void TriangularWindow::increment_relative_position(double p, int maxLength)
{
int v = center_offset + (int) ((double) length * p);
......@@ -40,6 +40,7 @@ int TriangularWindow::step()
int finished = 0;
// the
playback_position+=1;
if(playback_position>=length)
......
/**
*
* \file triangularwindow.cpp
* \class TriangularWindow
*
* \brief A single window (envelope) for granular synthesis.
*
* \author Henrik von Coler
*
* \date 2019/03/23
*
*/
#ifndef TRIANGULARWINDOW_H
#define TRIANGULARWINDOW_H
......@@ -10,26 +23,67 @@ class TriangularWindow
public:
///
/// \brief TriangularWindow
/// the constructor
TriangularWindow();
///
/// \brief initialize
/// \param L window length
/// \param P the relative position of the grain within the sample
/// \param start starting point for the playback position within the frame
/// initialize a window
void initialize(int L, int P, int start);
///
/// \brief get_value
/// get the value of the window at the playback_position
/// \return
///
double get_value();
///
/// \brief get_relative_position
/// \return
///
int get_relative_position();
int increment_relative_position(double p, int maxLength);
///
/// \brief increment_relative_position
/// move window (grain) position in sample
/// \param p the fraction of the window size to shift the position
/// \param maxLength the maximum length of the sample
///
void increment_relative_position(double p, int maxLength);
///
/// \brief step
/// \return returns '1' if end of window (grain) is reached
///
int step();
private:
///
/// \brief length
/// the length of the window
int length;
///
/// \brief m
/// the slope of the triangular window
double m;
///
/// \brief center_offset
/// the position of the grain in the sample
int center_offset;
///
/// \brief playback_position
/// the playback_position is the positio
/// within the grain (window)
int playback_position;
};
......
......@@ -21,15 +21,11 @@ OscMan::OscMan(int p)
speed = 1.0;
try
{
st = new lo::ServerThread(port);
}
catch (int e)
{
std::cout << "Possibly a bad port!" << std::endl;
}
if (st->is_valid())
{
// Add the example handler to the server!
st->add_method("/speed", "f", speed_callback, this);
......@@ -37,8 +33,11 @@ OscMan::OscMan(int p)
st->start();
std::cout << "Started OSC Server!" << std::endl;
}
}
else
throw std::invalid_argument("OSC server not started - possibly a bad port!");
}
int OscMan::speed_callback(const char *path, const char *types, lo_arg ** argv,
int argc, void *data, void *user_data )
......
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