Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jlw analyzer2 #148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions CNMAT-Externs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
buildPhases = (
);
dependencies = (
95A539952C35BD0C00D22063 /* PBXTargetDependency */,
9551A2472BCD894C0055B298 /* PBXTargetDependency */,
9551A2452BCB090D0055B298 /* PBXTargetDependency */,
95594933274B6B690059B956 /* PBXTargetDependency */,
A8FD9BEF279B713300DE60AB /* PBXTargetDependency */,
A88E1DFA278DF5B700DFC848 /* PBXTargetDependency */,
Expand Down Expand Up @@ -562,8 +562,7 @@
52FF18FC163B5C5B00F94922 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52FF18CE163B5C5B00F94922 /* CoreServices.framework */; };
52FF18FD163B5C5B00F94922 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52FF18CE163B5C5B00F94922 /* CoreServices.framework */; };
52FF18FE163B5C5B00F94922 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52FF18CE163B5C5B00F94922 /* CoreServices.framework */; };
95A539902C35B60500D22063 /* kiss_fft.c in Sources */ = {isa = PBXBuildFile; fileRef = 95A5398F2C35B60500D22063 /* kiss_fft.c */; };
95C7C0002C334FCE00EF6556 /* fft.c in Sources */ = {isa = PBXBuildFile; fileRef = 52B1557D16A8E7FA000FC2E4 /* fft.c */; };
95861C2E2C418F00009D820D /* kiss_fft.c in Sources */ = {isa = PBXBuildFile; fileRef = 95A5398F2C35B60500D22063 /* kiss_fft.c */; };
95C7C0022C334FCE00EF6556 /* commonsyms.c in Sources */ = {isa = PBXBuildFile; fileRef = 52E44C7C15F4835400C91B67 /* commonsyms.c */; };
95C7C0032C334FCE00EF6556 /* fftnobitrev.c in Sources */ = {isa = PBXBuildFile; fileRef = 52B1557F16A8E7FA000FC2E4 /* fftnobitrev.c */; };
95C7C0052C334FCE00EF6556 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52F10AA515F07157008FC371 /* CoreFoundation.framework */; };
Expand All @@ -572,7 +571,6 @@
95C7C0082C334FCE00EF6556 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52FF18CE163B5C5B00F94922 /* CoreServices.framework */; };
95C7C0092C334FCE00EF6556 /* MaxAudioAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52ADE2361733042E00074C0C /* MaxAudioAPI.framework */; };
95C7C00F2C334FF400EF6556 /* analyzer2~.c in Sources */ = {isa = PBXBuildFile; fileRef = 95C7BFA02C33309800EF6556 /* analyzer2~.c */; };
95C7C0152C33534A00EF6556 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 95C7C0132C3351D200EF6556 /* Info.plist */; };
A4E832E619E8642800C55B20 /* commonsyms.c in Sources */ = {isa = PBXBuildFile; fileRef = 52E44C7C15F4835400C91B67 /* commonsyms.c */; };
A4E832E919E8642800C55B20 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52F10AA515F07157008FC371 /* CoreFoundation.framework */; };
A4E832EA19E8642800C55B20 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52FF186B163B5C3800F94922 /* Accelerate.framework */; };
Expand Down Expand Up @@ -884,13 +882,6 @@
remoteGlobalIDString = 52F10ACE15F071FA008FC371;
remoteInfo = "2threshattack~";
};
9551A2442BCB090D0055B298 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 52F10A9915F07157008FC371 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 52E4479415F1890800C91B67;
remoteInfo = "analyzer~";
};
9551A2462BCD894C0055B298 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 52F10A9915F07157008FC371 /* Project object */;
Expand All @@ -912,6 +903,13 @@
remoteGlobalIDString = 52E44A2615F2881B00C91B67;
remoteInfo = printit;
};
95A539942C35BD0C00D22063 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 52F10A9915F07157008FC371 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 95C7BFFE2C334FCE00EF6556;
remoteInfo = "analyzer2~";
};
A4BA997924E45188006FD002 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 52F10A9915F07157008FC371 /* Project object */;
Expand Down Expand Up @@ -3028,7 +3026,8 @@
95C7BFA02C33309800EF6556 /* analyzer2~.c */,
95C7C0132C3351D200EF6556 /* Info.plist */,
);
path = "analyzer2~";
name = "analyzer2~";
path = "src/analyzer2~";
sourceTree = "<group>";
};
A4E832F319E8650200C55B20 /* cambio~ */ = {
Expand Down Expand Up @@ -4625,7 +4624,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
95C7C0152C33534A00EF6556 /* Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -5271,9 +5269,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
95A539902C35B60500D22063 /* kiss_fft.c in Sources */,
95861C2E2C418F00009D820D /* kiss_fft.c in Sources */,
95C7C00F2C334FF400EF6556 /* analyzer2~.c in Sources */,
95C7C0002C334FCE00EF6556 /* fft.c in Sources */,
95C7C0022C334FCE00EF6556 /* commonsyms.c in Sources */,
95C7C0032C334FCE00EF6556 /* fftnobitrev.c in Sources */,
);
Expand Down Expand Up @@ -5506,11 +5503,6 @@
target = 52F10ACE15F071FA008FC371 /* 2threshattack~ */;
targetProxy = 52F10AE015F072C6008FC371 /* PBXContainerItemProxy */;
};
9551A2452BCB090D0055B298 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 52E4479415F1890800C91B67 /* analyzer~ */;
targetProxy = 9551A2442BCB090D0055B298 /* PBXContainerItemProxy */;
};
9551A2472BCD894C0055B298 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 52E44B1615F2887600C91B67 /* thread.join */;
Expand All @@ -5526,6 +5518,11 @@
target = 52E44A2615F2881B00C91B67 /* printit */;
targetProxy = 9578D97D275681C000913739 /* PBXContainerItemProxy */;
};
95A539952C35BD0C00D22063 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 95C7BFFE2C334FCE00EF6556 /* analyzer2~ */;
targetProxy = 95A539942C35BD0C00D22063 /* PBXContainerItemProxy */;
};
A4BA997824E45188006FD002 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 52E4479415F1890800C91B67 /* analyzer~ */;
Expand Down Expand Up @@ -8796,7 +8793,7 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GENERATE_MASTER_OBJECT_FILE = YES;
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "$(SRCROOT)/analyzer2~/Info.plist";
INFOPLIST_FILE = "$(SRCROOT)/src/analyzer2~/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
Expand Down Expand Up @@ -8827,7 +8824,7 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GENERATE_MASTER_OBJECT_FILE = YES;
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "$(SRCROOT)/analyzer2~/Info.plist";
INFOPLIST_FILE = "$(SRCROOT)/src/analyzer2~/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
Expand Down
File renamed without changes.
File renamed without changes.
64 changes: 33 additions & 31 deletions analyzer2~/analyzer2~.c → src/analyzer2~/analyzer2~.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
#include <stdint.h>
//#include "fftw3.h"
//#include "fft.h"
#define kiss_fft_scalar double
#include "../../kissfft/kiss_fft.h"
#define kiss_fft_scalar float
#include "../../../kissfft/kiss_fft.h"

#define OSC 1
#ifdef OSC
Expand Down Expand Up @@ -710,9 +710,11 @@ void analyzer_tick(t_analyzer *x, t_symbol *msg, int argc, t_atom *argv)
// this function is only ever called by the scheduler (via schedule_delay() in the perform
// routine), so we don't need to enter a critical section to mess with the data stored
// in our struct
// memset(x->BufFFT_in, '\0', FFTSize * sizeof(kiss_fft_cpx)); // takes care of zero padding
//memset(x->BufFFT_in, '\0', FFTSize * sizeof(kiss_fft_cpx)); // takes care of zero padding
x->BufFFT_in = (kiss_fft_cpx*)KISS_FFT_MALLOC(FFTSize * sizeof(kiss_fft_cpx));
for(int i=0;i<FFTSize;i++){
x->BufFFT_in[i].r = x->BufFFT_in[i].i = 0;
x->BufFFT_in[i].r = 0;
x->BufFFT_in[i].i = 0;
}
if(window_index == Recta){
for(int i = 0; i < argc; i++){
Expand All @@ -722,10 +724,11 @@ void analyzer_tick(t_analyzer *x, t_symbol *msg, int argc, t_atom *argv)
for(int i = 0; i < argc; i++){
//x->BufFFT_in[i] = atom_getfloat(argv + i) * x->windows[window][i];
x->BufFFT_in[i].r = atom_getfloat(argv + i) * window[i];
x->BufFFT_in[i].i = 0;
}
}
// fftw_execute(fft_plan);
kiss_fft(x->fft_cfg, x->BufFFT_in, x->BufFFT_out);
kiss_fft(fft_cfg, x->BufFFT_in, x->BufFFT_out);

// double *BufFFT = x->BufFFT_out;
// Squared Absolute
Expand Down Expand Up @@ -1136,63 +1139,63 @@ void pitch_getit(t_analyzer *x)
for (i=MINBIN, fp1=spec+MINBIN, fp2=powSpec+MINBIN; (i<n-3) && (npeak<npeaktot); i++, fp1++, fp2++) {
double height = fp2[0], h1 = fp2[-1], h2 = fp2[1]; // Bin power and adjacents
double totalfreq, pfreq, f1, f2, m, var, stdev;

// Get worried if you see this
if (fp1+7 >= spec+x->FFTSize) {
object_post((t_object *)x, "*** fp1 %p, fp1+7 %p, spec %p, spec+FFTsize %p", fp1, fp1+7, spec, spec+x->FFTSize);
}

if (height<h1 || height<h2 || h1*coeff<POWERTHRES*total_power || h2*coeff<POWERTHRES*total_power) continue; // Go to next

// Use an informal phase vocoder to estimate the frequency
pfreq = ((fp1[-2].r - fp1[2].r) * (2.0f * fp1[0].r - fp1[2].r - fp1[-2].r) +
(fp1[-2].i - fp1[2].i) * (2.0f * fp1[0].i - fp1[2].i - fp1[-2].i)) / (2.0 * height);
(fp1[-2].i - fp1[2].i) * (2.0f * fp1[0].i - fp1[2].i - fp1[-2].i)) / (2.0 * height);

// Do this for the two adjacent bins too
f1 = ((fp1[-3].r - fp1[1].r) * (2.0f * fp1[-1].r - fp1[1].r - fp1[-3].r) +
(fp1[-3].i - fp1[1].i) * (2.0f * fp1[-1].i - fp1[1].i - fp1[-3].i)) / (2.0 * h1) - 1;
f2 = ((fp1[-1].r - fp1[3].r) * (2.0f * fp1[1].r - fp1[3].r - fp1[-1].r) +
(fp1[-1].i - fp1[3].i) * (2.0f * fp1[1].i - fp1[3].i - fp1[-1].i)) / (2.0 * h2) + 1;

// get sample mean and variance of the three
m = 0.333333 * (pfreq + f1 + f2);
var = 0.5 * ((pfreq-m)*(pfreq-m) + (f1-m)*(f1-m) + (f2-m)*(f2-m));

totalfreq = i + m;

// BAD HACK TO BE CHANGED IN NEXT VERSION !!!!
if (coeff > 1) {
switch ((long)coeff) {
case 2:
mult = 0.005;
break;
case 4:
mult = 0.125;
break;
case 8:
mult = 0.2;
break;
case 16:
mult = 0.25; // weird values found by trying to get npeak around 6-7
break;
default:
mult = 0.25;
case 2:
mult = 0.005;
break;
case 4:
mult = 0.125;
break;
case 8:
mult = 0.2;
break;
case 16:
mult = 0.25; // weird values found by trying to get npeak around 6-7
break;
default:
mult = 0.25;
}
threshold = KNOCKTHRESH * height * mult;
} else {
threshold = KNOCKTHRESH * height;
}

if ((var * total_power) > threshold || (var < 1e-30)) continue;

stdev = sqrt(var);
if (totalfreq < 4) totalfreq = 4;

// Store the peak info in the list of peaks
pk1->p_width = stdev;
pk1->p_pow = height;
pk1->p_loudness = sqrt(sqrt(height));
pk1->p_fp = fp1;
// pk1->p_fp = fp1; //not sure if this is needed
pk1->p_freq = totalfreq;

npeak++;
Expand Down Expand Up @@ -1919,7 +1922,7 @@ void *analyzer_new(t_symbol *s, short argc, t_atom *argv) {
x->BufFFT_in = (kiss_fft_cpx*)KISS_FFT_MALLOC(sizeof(kiss_fft_cpx) * MAXBUFSIZE);
// x->BufFFT_out = (double *)fftw_malloc(sizeof(double) * MAXBUFSIZE * 2);
x->BufFFT_out = (kiss_fft_cpx*)KISS_FFT_MALLOC(sizeof(kiss_fft_cpx) * MAXBUFSIZE);
// memset(x->BufFFT_in, kiss_fft_cpx(0,0), MAXBUFSIZE * sizeof(double));
memset(x->BufFFT_in, '\0' , sizeof(kiss_fft_cpx) * MAXBUFSIZE);
// memset(x->BufFFT_out, '\0', MAXBUFSIZE * 2 * sizeof(double));
for(int i=0;i<MAXBUFSIZE;i++){
x->BufFFT_in[i].r = x->BufFFT_in[i].i = x->BufFFT_out[i].r = x->BufFFT_out[i].i = 0.0;
Expand Down Expand Up @@ -2237,4 +2240,3 @@ int main(void)
class_register(CLASS_BOX, analyzer_class);
return 0;
}

File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions analyzer2~/kiss_fft.h → src/analyzer2~/kiss_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern "C" {
# define kiss_fft_scalar __m128
# ifndef KISS_FFT_MALLOC
# define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16)
# define KISS_FFT_ALIGN_CHECK(ptr)
# define KISS_FFT_ALIGN_CHECK(ptr)
# define KISS_FFT_ALIGN_SIZE_UP(size) ((size + 15UL) & ~0xFUL)
# endif
# ifndef KISS_FFT_FREE
Expand All @@ -74,7 +74,7 @@ extern "C" {
#include <stdint.h>
# if (FIXED_POINT == 32)
# define kiss_fft_scalar int32_t
# else
# else
# define kiss_fft_scalar int16_t
# endif
#else
Expand All @@ -91,9 +91,9 @@ typedef struct {

typedef struct kiss_fft_state* kiss_fft_cfg;

/*
/*
* kiss_fft_alloc
*
*
* Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
*
* typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
Expand All @@ -103,14 +103,14 @@ typedef struct kiss_fft_state* kiss_fft_cfg;
*
* If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
* The returned value should be free()d when done to avoid memory leaks.
*
*
* The state can be placed in a user supplied buffer 'mem':
* If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
* then the function places the cfg in mem and the size used in *lenmem
* and returns mem.
*
*
* If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
* then the function returns NULL and places the minimum cfg
* then the function returns NULL and places the minimum cfg
* buffer size in *lenmem.
* */

Expand All @@ -133,16 +133,16 @@ void KISS_FFT_API kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx
* */
void KISS_FFT_API kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);

/* If kiss_fft_alloc allocated a buffer, it is one contiguous
/* If kiss_fft_alloc allocated a buffer, it is one contiguous
buffer and can be simply free()d when no longer needed*/
#define kiss_fft_free KISS_FFT_FREE

/*
Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
your compiler output to call this before you exit.
*/
void KISS_FFT_API kiss_fft_cleanup(void);

/*
* Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
Expand All @@ -154,7 +154,7 @@ int KISS_FFT_API kiss_fft_next_fast_size(int n);
(kiss_fft_next_fast_size( ((n)+1)>>1)<<1)

#ifdef __cplusplus
}
}
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@



#endif /* kiss_fft_log_h */
#endif /* kiss_fft_log_h */
8 changes: 4 additions & 4 deletions src/thread.join/thread.join.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ void thread_join_assist (thread_join *x, void *box, long msg, long arg, char *ds
}

void thread_join_anything(thread_join *x, t_symbol* s, int argc, t_atom* argv) {
schedule_defer(x, thread_join_outlet_anything, 0, s, argc, argv);
schedule_defer(x, (method)thread_join_outlet_anything, 0, s, argc, argv);
}

void thread_join_outlet_anything(thread_join *x, t_symbol* s, int argc, t_atom* argv) {
outlet_anything(x->out_p[0], s, argc, argv);
}

void thread_join_bang(thread_join* x) {
schedule_defer(x, thread_join_outlet_bang, 0, ps_bang, 0, NULL);
schedule_defer(x, (method)thread_join_outlet_bang, 0, ps_bang, 0, NULL);
}

void thread_join_outlet_bang(thread_join *x, t_symbol* s, int argc, t_atom* argv) {
Expand All @@ -168,7 +168,7 @@ void thread_join_outlet_bang(thread_join *x, t_symbol* s, int argc, t_atom* argv
void thread_join_float(thread_join* x, double f) {
t_atom a;
atom_setfloat(&a, f);
schedule_defer(x, thread_join_outlet_float, 0, ps_float, 1, &a);
schedule_defer(x, (method)thread_join_outlet_float, 0, ps_float, 1, &a);
}

void thread_join_outlet_float(thread_join *x, t_symbol* s, int argc, t_atom* argv) {
Expand All @@ -178,7 +178,7 @@ void thread_join_outlet_float(thread_join *x, t_symbol* s, int argc, t_atom* arg
void thread_join_int(thread_join* x, int i) {
t_atom a;
atom_setlong(&a, i);
schedule_defer(x, thread_join_outlet_int, 0, ps_int, 1, &a);
schedule_defer(x, (method)thread_join_outlet_int, 0, ps_int, 1, &a);
}

void thread_join_outlet_int(thread_join *x, t_symbol* s, int argc, t_atom* argv) {
Expand Down