Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 86 lines (64 sloc) 2.329 kb
5a109bc @brianloveswords Mirroring paulstretch from http://hypermammut.sourceforge.net/paulstretc...
authored
1 /*
2 Copyright (C) 2008-2009 Nasca Octavian Paul
3 Author: Nasca Octavian Paul
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of version 2 of the GNU General Public License
7 as published by the Free Software Foundation.
8
9 This program 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 (version 2) for more details.
13
14 You should have received a copy of the GNU General Public License (version 2)
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include <math.h>
20 #include <stdio.h>
21 #include "BinauralBeats.h"
22
23 //coefficients of allpass filters are found by Olli Niemitalo
24
25 const REALTYPE Hilbert::coefl[]={0.6923877778065, 0.9360654322959, 0.9882295226860, 0.9987488452737};
26 const REALTYPE Hilbert::coefr[]={0.4021921162426, 0.8561710882420, 0.9722909545651, 0.9952884791278};
27
28 BinauralBeats::BinauralBeats(int samplerate_){
29 samplerate=samplerate_;
30 hilbert_t=0.0;
31 };
32
33
34 void BinauralBeats::process(REALTYPE *smpsl,REALTYPE *smpsr,int nsmps,REALTYPE pos_percents){
35 // for (int i=0;i<nsmps;i++) smpsl[i]=smpsr[i]=sin(30.0*M_PI*i*2.0/nsmps)*0.4;
36
37 //printf(" enabled %d\n",pars.free_edit.get_enabled());
38 if (pars.free_edit.get_enabled()){
39 float mono=pars.mono*0.5;
40 for (int i=0;i<nsmps;i++){
41 REALTYPE inl=smpsl[i];
42 REALTYPE inr=smpsr[i];
43 REALTYPE outl=inl*(1.0-mono)+inr*mono;
44 REALTYPE outr=inr*(1.0-mono)+inl*mono;
45
46 smpsl[i]=outl;
47 smpsr[i]=outr;
48 };
49
50 REALTYPE freq=pars.free_edit.get_value(pos_percents);
51
52 freq*=0.5;//half down for left, half up for right
53 for (int i=0;i<nsmps;i++){
54 hilbert_t=fmod(hilbert_t+freq/samplerate,1.0);
55 REALTYPE h1=0,h2=0;
56 hl.process(smpsl[i],h1,h2);
57
58 REALTYPE x=hilbert_t*2.0*M_PI;
59 REALTYPE m1=h1*cos(x);
60 REALTYPE m2=h2*sin(x);
61 REALTYPE outl1=m1+m2;
62 REALTYPE outl2=m1-m2;
63
64
65 h1=0,h2=0;
66 hr.process(smpsr[i],h1,h2);
67
68 m1=h1*cos(x);
69 m2=h2*sin(x);
70 REALTYPE outr1=m1-m2;
71 REALTYPE outr2=m1+m2;
72
73 if (pars.reverse){
74 smpsl[i]=outl1;
75 smpsr[i]=outr1;
76 }else{
77 smpsl[i]=outl2;
78 smpsr[i]=outr2;
79 };
80
81 };
82
83 };
84 };
85
Something went wrong with that request. Please try again.