gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
MixerTestAudio.C
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 
18 /*
19 Author: Matt Flax <flatmax@flatmax.org>
20 Date: 2015.03.12
21 */
22 
23 #include "DSP/MixerTestAudio.H"
24 
26 {
27  testFrequencies.push_back(100.);
28  testFrequencies.push_back(1000.);
29  testFrequencies.push_back(10000.);
30 }
31 
33 {
34  //dtor
35 }
36 
37 int MixerTestAudio::processAudio(jack_nframes_t nframes) { // The Jack client callback
38  int maxIdx=(audio.rows()>=nframes+samplesProcessed)?nframes:audio.rows()-samplesProcessed;
39  // put output data into the buffers, only one output vector at column 0
40  int outCh=outputPorts.size();
41  if (currentOutputChannel<outCh){
42  jack_default_audio_sample_t *out = ( jack_default_audio_sample_t* ) jack_port_get_buffer ( outputPorts[currentOutputChannel], nframes );
43  for (uint j=0; j<maxIdx; j++)
44  out[j]=audio(samplesProcessed+j,0);
45  }
46 
47  // all input data indexed after column 0
48  int numIn=((audio.cols()-1-currentInputChannel)+1 < numIn)?audio.cols()-1-currentInputChannel+1:inputPorts.size();
49  for (uint i=0; i<numIn; i++) {
50  jack_default_audio_sample_t *in = ( jack_default_audio_sample_t* ) jack_port_get_buffer ( inputPorts[i], nframes );
51  for (uint j=0; j<maxIdx; j++)
53  }
54 
55  samplesProcessed+=nframes;
56  samplesToProcess-=nframes;
57 
58  if (samplesToProcess<=0) {
60  recordLock.unLock(); // this shouldn't cause a problem because unlocking shouldn't cause waiting issues.
61  return -1;
62  }
63  return 0;
64 }
65 
66 
67 int MixerTestAudio::setChannels(int outCnt, int inCnt, int testOutCnt) {
68  int ret=NO_ERROR;
69  if ((ret=destroyPorts())!=NO_ERROR)
70  return ret;
71  if ((ret=recordLock.tryLock())==NO_ERROR) {
72  createPorts("in ", inCnt, "out ", outCnt);
73  audio.resize(audio.rows(), 1+testOutCnt); // the extra one is because the output channel is first
75  }
76  return ret;
77 }
78 
80  int ret=CrossoverAudio::reset();
81  // overwrite CrossoverAudio random data with sinusoidal data
83  Eigen::Array<float, Eigen::Dynamic, 1> sinusoidPhase(N, 1), sinusoid(N, 1);
84  sinusoidPhase=Eigen::Array<float, Eigen::Dynamic, 1>::LinSpaced(N,0.,(double)N/(double)getSampleRate())*2.*M_PI;
85 
86  sinusoid=Eigen::Matrix<float,Eigen::Dynamic, 1>::Zero(N,1);
87  for (int i=0; i<testFrequencies.size(); i++)
88  sinusoid+=(sinusoidPhase*testFrequencies[i]).sin();
89  sinusoid*=gain/(float)testFrequencies.size();
90 
91  audio.col(0).block(0,0,N,1)=sinusoid;
92 
94  return ret;
95 }
int currentOutputChannel
The current output channel to test.
virtual int processAudio(jack_nframes_t nframes)
The Jack client callback.
virtual int createPorts(string inName, int inCnt, string outName, int outCnt)
Definition: JackBase.H:277
virtual int reset()
int N
int currentInputChannel
The current input channel to test.
unsigned int zeroSampleCnt
The number of samples to train with zeros.
MixerTestAudio()
Constructor.
float gain
The gain for the output.
Mutex recordLock
The lock for when the audio is being played/recorded.
#define NO_ERROR
There is no error.
Definition: Debug.H:33
int samplesProcessed
The number of samples already processed.
unsigned int uint
Definition: Box.H:28
vector< float > testFrequencies
Superimposed sinusoidal test frequencies.
int getSampleRate(void) const
Definition: JackBase.H:266
int tryLock()
Definition: Thread.H:310
int unLock()
Definition: Thread.H:325
virtual ~MixerTestAudio()
Destructor.
int samplesToProcess
The number of samples to process, matching the duration.
vector< jack_port_t * > inputPorts
The input ports.
Definition: JackBase.H:118
int setChannels(int outCnt, int inCnt, int testOutCnt)
virtual int reset()
virtual int destroyPorts()
Definition: JackBase.H:306
vector< jack_port_t * > outputPorts
The output ports.
Definition: JackBase.H:119
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic > audio
The first channel is the same data sent over each output channel, then the output channels...
gtkIOStream: /tmp/gtkiostream/src/DSP/MixerTestAudio.C Source File
GTK+ IOStream  Beta