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

Worked on documentation for WAV example!

parent 971cea6d
...@@ -4,13 +4,6 @@ CC = g++ ...@@ -4,13 +4,6 @@ CC = g++
# path(s) to include files # path(s) to include files
CFLAGS = -I. CFLAGS = -I.
DEBUG ?= 1
ifeq ($(DEBUG), 1)
DBFLAGS = -g -Wall -Werror
else
DBFLAGS =
endif
# libraries to link # libraries to link
LDFLAGS = -ljack -llo -lsndfile LDFLAGS = -ljack -llo -lsndfile
...@@ -24,7 +17,7 @@ all: wav_example ...@@ -24,7 +17,7 @@ all: wav_example
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
wav_example: main.o wav_example.o oscman.o singlesample.o wav_example: main.o wav_example.o oscman.o singlesample.o
$(CC) $(DBFLAGS) -o wav_example main.o wav_example.o oscman.o singlesample.o $(LDFLAGS) $(CC) -o wav_example main.o wav_example.o oscman.o singlesample.o $(LDFLAGS)
clean: clean:
......
PROJECT_NAME = "Gain_Example" PROJECT_NAME = "Wav_Example"
PROJECT_BRIEF = "Stereo gain manipulation through OSC!" PROJECT_BRIEF = "Simple wav file looper with adjustable playback speed!"
OUTPUT_DIRECTORY = "./" OUTPUT_DIRECTORY = "./"
INPUT = "../" INPUT = "../" README.md
FILE_PATTERNS = *.cpp *.h FILE_PATTERNS = *.cpp *.h
...@@ -15,3 +15,5 @@ EXTRACT_PRIVATE = YES ...@@ -15,3 +15,5 @@ EXTRACT_PRIVATE = YES
HAVE_DOT = YES HAVE_DOT = YES
UML_LOOK = YES UML_LOOK = YES
USE_MOFILE_AS_MAINPAGE = README.md
\ No newline at end of file
/**
* \file singlesample.cpp
* \class SingleSample
*
* \brief Class which holds the waveform of a sample in an array.
*
* This class holds the waveform of a sample in an array and provides
* all necessary methods for reading and accessing it.
*
* \author Henrik von Coler
*
* \version $Revision: 0.52$
*
* \date 2016-11-22
*
*
*/
#include "singlesample.h" #include "singlesample.h"
SingleSample::SingleSample(std::string filePath, int fs) SingleSample::SingleSample(std::string filePath, int fs)
{ {
// set default values
rate = 1; rate = 1;
pos = 0.0; pos = 0.0;
FS = fs;
FS = fs; // read the data
read_wavefile(filePath); read_wavefile(filePath);
} }
SingleSample::~SingleSample()
{
}
double SingleSample::get_rate()
{
return rate;
}
void SingleSample::set_rate(double r)
{
rate = r;
}
double SingleSample::get_pos()
{
return pos;
}
void SingleSample::set_pos(double p)
{
}
int SingleSample::get_L()
{
return L;
}
double** SingleSample::get_x()
{
return x;
}
void SingleSample::set_f(int in)
{
nFrames = in;
}
void SingleSample::set_sr(int in)
{
fs_sample = in;
}
void SingleSample::set_L(int in)
{
L = in;
}
void SingleSample::set_nChannels(int in)
{
nChannels = in;
}
int SingleSample::get_nChannels()
{
return nChannels;
}
void SingleSample::initialize()
{
}
double SingleSample::get_sample(int chan, int pos)
{
return x[chan][pos];
}
int SingleSample::getFS()
{
return info.samplerate;
}
double SingleSample::get_sample(int chan, double pos) double SingleSample::get_sample(int chan, double pos)
{ {
...@@ -125,10 +61,11 @@ double SingleSample::get_sample(int chan, double pos) ...@@ -125,10 +61,11 @@ double SingleSample::get_sample(int chan, double pos)
cout << "Out of range!: " << endl; cout << "Out of range!: " << endl;
} }
} }
void SingleSample::step() void SingleSample::step()
{ {
double R = rate * GR; double R = rate * resFac;
pos = pos+R; pos = pos+R;
...@@ -148,7 +85,7 @@ void SingleSample::read_wavefile(std::string filePath) ...@@ -148,7 +85,7 @@ void SingleSample::read_wavefile(std::string filePath)
cout << "Reading: " << filePath << endl; cout << "Reading: " << filePath << endl;
/// Open the audio file using sndfile! // Open the audio file using sndfile!
info.format = 0; info.format = 0;
sf = sf_open(filePath.c_str(),SFM_READ,&info); sf = sf_open(filePath.c_str(),SFM_READ,&info);
...@@ -158,16 +95,16 @@ void SingleSample::read_wavefile(std::string filePath) ...@@ -158,16 +95,16 @@ void SingleSample::read_wavefile(std::string filePath)
//exit(-1); //exit(-1);
} }
// // write wav parameters to member variables
nFrames = info.frames; nFrames = info.frames;
fs_sample = info.samplerate; fs_sample = info.samplerate;
nChannels = info.channels; nChannels = info.channels;
L = info.frames * info.channels; L = info.frames * info.channels;
// //
GR = ((double) fs_sample / (double) FS ); resFac = ((double) fs_sample / (double) FS );
cout << "GR: " << GR << endl; cout << "GR: " << resFac << endl;
cout << "Fs:\t\t" << fs_sample << endl; cout << "Fs:\t\t" << fs_sample << endl;
cout << "Num Channels:\t" << nChannels << endl; cout << "Num Channels:\t" << nChannels << endl;
cout << "Num Samples:\t" << nFrames << endl; cout << "Num Samples:\t" << nFrames << endl;
...@@ -199,3 +136,82 @@ void SingleSample::read_wavefile(std::string filePath) ...@@ -199,3 +136,82 @@ void SingleSample::read_wavefile(std::string filePath)
} }
SingleSample::~SingleSample()
{
}
double SingleSample::get_rate()
{
return rate;
}
void SingleSample::set_rate(double r)
{
rate = r;
}
double SingleSample::get_pos()
{
return pos;
}
void SingleSample::set_pos(double p)
{
}
int SingleSample::get_L()
{
return L;
}
double** SingleSample::get_x()
{
return x;
}
void SingleSample::set_f(int in)
{
nFrames = in;
}
void SingleSample::set_sr(int in)
{
fs_sample = in;
}
void SingleSample::set_L(int in)
{
L = in;
}
void SingleSample::set_nChannels(int in)
{
nChannels = in;
}
int SingleSample::get_nChannels()
{
return nChannels;
}
double SingleSample::get_sample(int chan, int pos)
{
return x[chan][pos];
}
int SingleSample::getFS()
{
return info.samplerate;
}
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
* *
* This class holds the waveform of a sample in an array and provides * This class holds the waveform of a sample in an array and provides
* all necessary methods for reading and accessing it. * all necessary methods for reading and accessing it.
* It serves as a state machine by holding a playback speed and position.
* *
* *
* *
* \author Henrik von Coler * \author Henrik von Coler
* *
* \version $Revision: 0.52$ * \version $Revision: 0.527$
* *
* \date 2016-11-22 * \date 2016-11-22
* *
...@@ -30,8 +31,6 @@ ...@@ -30,8 +31,6 @@
#include <string> #include <string>
#include <cmath> #include <cmath>
using std::cout; using std::cout;
using std::endl; using std::endl;
...@@ -39,37 +38,72 @@ class SingleSample ...@@ -39,37 +38,72 @@ class SingleSample
{ {
public: public:
///
/// \brief SingleSample
/// the standard constructor
/// \param filePath
/// \param fs
/// the jack sample rate
SingleSample(std::string filePath, int fs); SingleSample(std::string filePath, int fs);
///
/// \brief ~SingleSample
/// ths should be the destructor
virtual ~SingleSample(); virtual ~SingleSample();
///
/// \brief read_wavefile
/// \param filePath
///
void read_wavefile(std::string filePath); void read_wavefile(std::string filePath);
int get_L(); ///
/// \brief get_sample
/// get sample values at exact integer postions
/// \param chan
/// \param pos
/// \return
///
double get_sample(int chan, int pos);
///
/// \brief get_sample return interpolated value
/// this is an overloaded function!
/// \param chan the cahnnel to access
/// \param pos the floating point position
/// \return the sample's interpolated value
///
double get_sample(int chan, double pos);
///
/// \brief step
/// this function sets a new position,
/// regarding the speed, and the resampleFactor
void step();
///
/// \brief get_x
/// \return returns a pointer to the sample data arrays
///
double **get_x(); double **get_x();
// A couple of getters and setters, mostly unused in this example
void set_f(int in); void set_f(int in);
void set_sr(int in); void set_sr(int in);
void set_nChannels(int in); void set_nChannels(int in);
int get_nChannels(); int get_nChannels();
void set_L(int in); void set_L(int in);
int get_L();
void initialize();
double get_sample(int chan, int pos);
double get_sample(int chan, double pos);
double get_rate(); double get_rate();
void set_rate(double r); void set_rate(double r);
double get_pos(); double get_pos();
void set_pos(double p); void set_pos(double p);
void step();
//void setResampleRate(double resRate);
int getFS(); int getFS();
...@@ -80,17 +114,33 @@ private: ...@@ -80,17 +114,33 @@ private:
int FS; int FS;
/// The resampling factor between ///
/// audio sample and interface. /// \brief resampleFactor
/// rescales the playback speed according to
/// the sample rate of the wav file and the JACK server
double resFac; double resFac;
int num_channels;
///
/// \brief nFrames
/// The number of frames in the wav file /// The number of frames in the wav file
/// which is the length in samples
int nFrames; int nFrames;
/// ///
/// \brief fs_sample
/// sampling rate of the wav file
int fs_sample; int fs_sample;
///
/// \brief nChannels
/// number of channels in this wav
int nChannels; int nChannels;
///
/// \brief L
/// length of the interleaved wav data
/// (number of frames times number of channels)
int L; int L;
/// ///
...@@ -99,12 +149,16 @@ private: ...@@ -99,12 +149,16 @@ private:
/// arranged as a matrix. /// arranged as a matrix.
double** x; double** x;
///
/// \brief pos
/// the recent postion within the sample
double pos; double pos;
/// the playback rates /// the playback rate
double rate; double rate;
double resampleFactor = 1;
}; };
#endif // SINGLESAMPLE_H #endif // SINGLESAMPLE_H
/** /**
* *
* \file WavExample.cpp * \file wav_example.cpp
* \class WavExample * \class WavExample
* *
* \brief Read a wave file and play it back in a loop. * \brief Read a wave file and play it back in a loop.
...@@ -32,7 +32,7 @@ WavExample::WavExample(std::string filename){ ...@@ -32,7 +32,7 @@ WavExample::WavExample(std::string filename){
nChannels = sample->get_nChannels(); nChannels = sample->get_nChannels();
cout << "Starting Jack Client with " << nChannels << " outputs!" << endl; cout << "Starting Jack Client! " << endl;
jack_set_process_callback(this->client, this->callback_process, this); jack_set_process_callback(this->client, this->callback_process, this);
...@@ -47,8 +47,6 @@ WavExample::WavExample(std::string filename){ ...@@ -47,8 +47,6 @@ WavExample::WavExample(std::string filename){
JackPortIsOutput, 0); JackPortIsOutput, 0);
} }
jack_activate(this->client); jack_activate(this->client);
jack_connect(client, jack_port_name(output_port[0]), "system:playback_1"); jack_connect(client, jack_port_name(output_port[0]), "system:playback_1");
......
/** /**
* \file GainExample.h * \file wav_example.h
* \class GainExample * \class WavExample
* *
* \brief Simple example, passing the input to the output * \brief Simple example, passing the input to the output
* with gain modification through OSC. * with gain modification through OSC.
...@@ -33,24 +33,38 @@ private: ...@@ -33,24 +33,38 @@ private:
SingleSample *sample; SingleSample *sample;
///
/// \brief fs
/// sample rate of the jack server
int fs = 0; int fs = 0;
///
/// \brief nOutputs
/// number off jack output ports
int nOutputs = 2; int nOutputs = 2;
///
/// \brief nChannels
/// number of cahnnels in the sample
int nChannels; int nChannels;
///
/// \brief ports
/// the jack output ports
const char **ports; const char **ports;
jack_client_t *client; jack_client_t *client;
jack_status_t status; jack_status_t status;
jack_port_t **output_port; jack_port_t **output_port;
/// The OSC manager object /// The OSC manager object
OscMan *oscman; OscMan *oscman;
/// ///
/// \brief process /// \brief process
/// get the next buffer from the sample and playback
/// \param nframes /// \param nframes
/// \return /// \return
/// ///
...@@ -68,7 +82,7 @@ public: ...@@ -68,7 +82,7 @@ public:
/// ///
/// \brief GainExample /// \brief GainExample
/// Default constructor! /// Constructor!
WavExample(std::string filename); WavExample(std::string filename);
}; };
......
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