spectrogram flag is working -- there are some color considerations to make

nix
Ted Moore 4 years ago
parent 7d6107d9cc
commit 59009d9a5b

@ -16,12 +16,12 @@ FluidWaveform : FluidViewer {
var <win; var <win;
*new { *new {
arg audioBuffer, slicesBuffer, featureBuffer, bounds, lineWidth = 1, waveformColor, stackFeatures = false; arg audioBuffer, slicesBuffer, featureBuffer, bounds, lineWidth = 1, waveformColor, stackFeatures = false, spectrogram = false;
^super.new.init(audioBuffer,slicesBuffer, featureBuffer, bounds, lineWidth, waveformColor,stackFeatures); ^super.new.init(audioBuffer,slicesBuffer, featureBuffer, bounds, lineWidth, waveformColor,stackFeatures,spectrogram);
} }
init { init {
arg audio_buf, slices_buf, feature_buf, bounds, lineWidth, waveformColor,stackFeatures = false; arg audio_buf, slices_buf, feature_buf, bounds, lineWidth, waveformColor,stackFeatures = false, spectrogram = false;
Task{ Task{
var sfv, categoryCounter = 0; var sfv, categoryCounter = 0;
@ -34,6 +34,43 @@ FluidWaveform : FluidViewer {
win.background_(Color.white); win.background_(Color.white);
if(audio_buf.notNil,{ if(audio_buf.notNil,{
if(spectrogram,{
var magsbuf = Buffer(audio_buf.server);
var condition = Condition.new;
var colors;
if(File.exists("/Users/macprocomputer/Desktop/_flucoma/code/flucoma-sc/test/CETperceptual_csv_0_1/CET-L16.csv").not,{
"Sorry, colors file doesn't exist...... where can I put this file so it exists for everyone!!!?!?!?!?!?".warn;
});
colors = CSVFileReader.readInterpret("/Users/macprocomputer/Desktop/_flucoma/code/flucoma-sc/test/CETperceptual_csv_0_1/CET-L16.csv").collect{
arg row;
Color.fromArray(row);
};
FluidBufSTFT.processBlocking(audio_buf.server,audio_buf,magnitude:magsbuf,action:{
magsbuf.loadToFloatArray(action:{
arg mags;
fork({
var img = Image(magsbuf.numFrames,magsbuf.numChannels);
mags = (mags / mags.maxItem).ampdb.linlin(-120.0,0.0,0,255).asInteger;
mags.do{
arg mag, index;
img.setColor(colors[mag], index.div(magsbuf.numChannels), magsbuf.numChannels - 1 - index.mod(magsbuf.numChannels));
};
UserView(win,Rect(0,0,win.bounds.width,win.bounds.height))
.drawFunc_{
img.drawInRect(Rect(0,0,win.bounds.width,win.bounds.height));
};
condition.unhang;
},AppClock)
});
});
condition.hang;
},{
var path = "%%_%_FluidWaveform.wav".format(PathName.tmp,Date.localtime.stamp,UniqueID.next); var path = "%%_%_FluidWaveform.wav".format(PathName.tmp,Date.localtime.stamp,UniqueID.next);
audio_buf.write(path,"wav"); audio_buf.write(path,"wav");
@ -50,6 +87,7 @@ FluidWaveform : FluidViewer {
File.delete(path); File.delete(path);
}); });
});
if(slices_buf.notNil,{ if(slices_buf.notNil,{
slices_buf.numChannels.switch( slices_buf.numChannels.switch(

@ -21,14 +21,14 @@ s.waitForBoot{
m.loadToFloatArray(action:{ m.loadToFloatArray(action:{
arg mags; arg mags;
mags.clump(m.numChannels)[105].plot; // mags.clump(m.numChannels)[105].plot;
mags = (mags / mags.maxItem).ampdb.linlin(-120.0,0.0,0,255).asInteger; mags = (mags / mags.maxItem).ampdb.linlin(-120.0,0.0,0,255).asInteger;
[0,1,2].do{ // [0,1,2].do{
arg amt; // arg amt;
"# of %s in mags: %".format(amt,mags.count({arg val; val == amt})).postln; // "# of %s in mags: %".format(amt,mags.count({arg val; val == amt})).postln;
}; // };
~img = Image(m.numFrames,m.numChannels); ~img = Image(m.numFrames,m.numChannels);
@ -37,7 +37,16 @@ s.waitForBoot{
~img.setColor(~colors[mag], index.div(m.numChannels), m.numChannels - 1 - index.mod(m.numChannels)); ~img.setColor(~colors[mag], index.div(m.numChannels), m.numChannels - 1 - index.mod(m.numChannels));
}; };
~img.plot; // ~img.plot;
w = Window("est",Rect(0,0,1200,300));
u = UserView(w,w.bounds)
.drawFunc_{
~img.drawInRect(u.bounds);
};
w.front;
}); });
}; };
) )

@ -6,7 +6,7 @@ s.waitForBoot{
var slicepoints = Buffer(s); var slicepoints = Buffer(s);
FluidBufAmpSlice.process(s,buf,indices:slicepoints,fastRampUp:10,fastRampDown:2205,slowRampUp:4410,slowRampDown:4410,onThreshold:10,offThreshold:5,floor:-40,minSliceLength:4410,highPassFreq:20,action:{ FluidBufAmpSlice.process(s,buf,indices:slicepoints,fastRampUp:10,fastRampDown:2205,slowRampUp:4410,slowRampDown:4410,onThreshold:10,offThreshold:5,floor:-40,minSliceLength:4410,highPassFreq:20,action:{
FluidWaveform(buf,slicepoints,Rect(0,0,1600,400)); FluidWaveform(buf,slicepoints,bounds:Rect(0,0,1600,400));
}); });
}.play(AppClock); }.play(AppClock);

Loading…
Cancel
Save