add binaural beats to processing and UI

This commit is contained in:
essej
2022-04-27 22:52:40 -04:00
parent 313de42d6c
commit 57b62141f5
10 changed files with 187 additions and 39 deletions

View File

@ -95,6 +95,18 @@ struct BinauralBeatsParameters{
FreeEdit free_edit;
//void add2XML(XMLwrapper *xml);
//void getfromXML(XMLwrapper *xml);
bool operator == (const BinauralBeatsParameters& other) const noexcept
{
return stereo_mode == other.stereo_mode &&
mono == other.mono &&
free_edit.get_enabled() == other.free_edit.get_enabled() &&
// todo proper equality test for filter
free_edit.get_posy(0) == other.free_edit.get_posy(0) &&
free_edit.get_posy(1) == other.free_edit.get_posy(1)
;
}
};
class BinauralBeats{

View File

@ -40,6 +40,7 @@ FreeEdit::FreeEdit(){
curve.data=NULL;
curve.size=0;
curve.allocsize = 0;
};
void FreeEdit::deep_copy_from(const FreeEdit &other){
@ -55,9 +56,14 @@ void FreeEdit::deep_copy_from(const FreeEdit &other){
};
curve.size=other.curve.size;
if (other.curve.data&&other.curve.size){
curve.data=new REALTYPE[curve.size];
if (curve.data) delete [] curve.data;
curve.data=new REALTYPE[curve.size];
curve.allocsize = curve.size;
for (int i=0;i<curve.size;i++) curve.data[i]=other.curve.data[i];
}else curve.data=NULL;
} else {
if (curve.data) delete [] curve.data;
curve.data=NULL;
}
extreme_x=other.extreme_x;
extreme_y=other.extreme_y;
};
@ -140,10 +146,16 @@ void FreeEdit::get_curve(int datasize,REALTYPE *data,bool real_values){
};
void FreeEdit::update_curve(int size){
if (curve.data) delete []curve.data;
if (size<2) size=2;
curve.size=size;
curve.data=new REALTYPE[size];
if (size > curve.allocsize || !curve.data) {
if (curve.data) delete []curve.data;
curve.data = new REALTYPE[size];
curve.allocsize = size;
}
curve.size = size;
get_curve(curve.size,curve.data,true);

View File

@ -152,10 +152,10 @@ class FreeEdit{
//void getfromXML(XMLwrapper *xml);
//Enabled functions
bool get_enabled(){
bool get_enabled() const{
return enabled;
};
void set_enabled(bool val){
void set_enabled(bool val){
enabled=val;
};
@ -164,7 +164,7 @@ class FreeEdit{
};
//manipulation functions
inline bool is_enabled(int n){
inline bool is_enabled(int n) const{
if ((n<0)||(n>=npos)) return false;
return pos[n].enabled;
};
@ -174,11 +174,11 @@ class FreeEdit{
};
inline REALTYPE get_posx(int n){
inline REALTYPE get_posx(int n) const{
if ((n<0)||(n>=npos)) return 0.0;
return pos[n].x;
};
inline REALTYPE get_posy(int n){
inline REALTYPE get_posy(int n) const{
if ((n<0)||(n>=npos)) return 0.0;
return pos[n].y;
};
@ -198,7 +198,7 @@ class FreeEdit{
};
//interpolation mode
INTERP_MODE get_interp_mode(){
INTERP_MODE get_interp_mode() const{
return interp_mode;
};
void set_interp_mode(INTERP_MODE interp_mode_){
@ -206,7 +206,7 @@ class FreeEdit{
};
//smooth
REALTYPE get_smooth(){
REALTYPE get_smooth() const{
return smooth;
};
void set_smooth(REALTYPE smooth_){
@ -230,6 +230,7 @@ class FreeEdit{
struct{
REALTYPE *data;
int size;
int allocsize;
}curve;
private:
inline REALTYPE clamp1(REALTYPE m){

View File

@ -34,6 +34,7 @@ StretchAudioSource::StretchAudioSource(int initialnumoutchans,
setNumOutChannels(initialnumoutchans);
m_xfadetask.buffer.setSize(8, 65536);
m_xfadetask.buffer.clear();
}
StretchAudioSource::~StretchAudioSource()
@ -333,7 +334,9 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer
{
int readsize = 0;
double in_pos = (double)m_inputfile->getCurrentPosition() / (double)m_inputfile->info.nsamples;
if (m_firstbuffer)
float in_pos_100 = in_pos*100.0;
if (m_firstbuffer)
{
readsize = m_stretchers[0]->get_nsamples_for_fill();
m_firstbuffer = false;
@ -375,6 +378,12 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer
for (int i = 0; i < m_stretchers.size(); ++i)
m_stretchers[i]->here_is_onset(onset_max);
int outbufsize = m_stretchers[0]->get_bufsize();
if (m_stretchers.size() > 1) {
m_binaural_beats->process(m_stretchers[0]->out_buf.data(),m_stretchers[1]->out_buf.data(),
outbufsize, in_pos_100);
}
int nskip = m_stretchers[0]->get_skip_nsamples();
if (nskip > 0)
m_inputfile->skip(nskip);
@ -578,6 +587,9 @@ void StretchAudioSource::initObjects()
fill_container(m_stretchers[i]->out_buf, 0.0f);
m_stretchers[i]->m_spectrum_processes = m_specproc_order;
}
m_binaural_beats = std::make_unique<BinauralBeats>(m_inputfile->info.samplerate);
m_binaural_beats->pars = m_bbpar;
m_file_inbuf.setSize(m_num_outchans, 3 * inbufsize);
}
@ -652,13 +664,18 @@ void StretchAudioSource::setRate(double rate)
}
}
void StretchAudioSource::setProcessParameters(ProcessParameters * pars)
void StretchAudioSource::setProcessParameters(ProcessParameters * pars, BinauralBeatsParameters * bbpars)
{
if (*pars == m_ppar)
if (*pars == m_ppar && (!bbpars || m_bbpar == *bbpars))
return;
if (m_cs.tryEnter())
{
m_ppar = *pars;
if (bbpars) {
m_bbpar = *bbpars;
m_binaural_beats->pars = m_bbpar;
}
for (int i = 0; i < m_stretchers.size(); ++i)
{
m_stretchers[i]->set_parameters(pars);

View File

@ -7,6 +7,7 @@
#include "../JuceLibraryCode/JuceHeader.h"
#include "Input/AInputS.h"
#include "ProcessedStretch.h"
#include "BinauralBeats.h"
#include <mutex>
#include <array>
#include "../WDL/resample.h"
@ -49,7 +50,7 @@ public:
return m_playrate;
}
double getOutputSamplerate() const { return m_outsr; }
void setProcessParameters(ProcessParameters* pars);
void setProcessParameters(ProcessParameters* pars, BinauralBeatsParameters * bbpars=0);
const ProcessParameters& getProcessParameters();
void setFFTSize(int size, bool force=false);
int getFFTSize() { return m_process_fftsize; }
@ -111,7 +112,9 @@ private:
LinearSmoothedValue<double> m_vol_smoother;
std::unique_ptr<AInputS> m_inputfile;
std::vector<std::shared_ptr<ProcessedStretch>> m_stretchers;
std::unique_ptr<BinauralBeats> m_binaural_beats;
std::function<void(StretchAudioSource*)> SourceEndedCallback;
bool m_firstbuffer = false;
bool m_output_has_begun = false;
@ -122,7 +125,8 @@ private:
double m_main_volume = 0.0;
double m_loopxfadelen = 0.0;
ProcessParameters m_ppar;
BinauralBeatsParameters m_bbpar;
double m_playrate = 1.0;
double m_lastplayrate = 0.0;
double m_onsetdetection = 0.0;