Forums > MaxMSP

Scaling a float?

October 15, 2012 | 10:28 pm

Am I missing something easy, maybe……. as maths isn’t my strong suit!

what i want to do is take an incoming amplitude and scale the lowest and highest amplitude value to give me a number between 0-127.

Im guessing my problem is due to taking a float to an int?

I have tried the scale objects but I am getting + and – numbers which is no good!

Any help or input is appreciated.

Thanks!

{
"boxes" : [ {
"box" : {
"maxclass" : "comment",
"text" : "< ---------this bit here",
"fontsize" : 12.0,
"patching_rect" : [ 558.0, 668.0, 150.0, 20.0 ],
"id" : "obj-262",
"textcolor" : [ 1.0, 0.4, 0.4, 1.0 ],
"numinlets" : 1,
"frgb" : [ 1.0, 0.4, 0.4, 1.0 ],
"numoutlets" : 0,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "low/high point of the amplitude",
"fontsize" : 12.0,
"patching_rect" : [ 356.614288, 739.0, 178.0, 20.0 ],
"id" : "obj-260",
"numinlets" : 1,
"numoutlets" : 0,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : " scale the amplitude to 0 – 127 ",
"linecount" : 2,
"fontsize" : 12.0,
"patching_rect" : [ 400.964294, 576.0, 150.0, 34.0 ],
"id" : "obj-213",
"numinlets" : 1,
"numoutlets" : 0,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "FL_DubbedGtr_Chords_60BPM_Amin_04.wav",
"outlettype" : [ "" ],
"fontsize" : 12.0,
"patching_rect" : [ 532.214294, 113.0, 274.0, 18.0 ],
"id" : "obj-202",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "reset",
"outlettype" : [ "" ],
"fontsize" : 12.0,
"patching_rect" : [ 259.714294, 552.0, 37.0, 18.0 ],
"id" : "obj-127",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "button",
"outlettype" : [ "bang" ],
"patching_rect" : [ 344.964294, 590.0, 20.0, 20.0 ],
"id" : "obj-115",
"numinlets" : 1,
"numoutlets" : 1
}

}
, {
"box" : {
"maxclass" : "flonum",
"bgcolor" : [ 1.0, 0.4, 1.0, 1.0 ],
"outlettype" : [ "float", "bang" ],
"fontsize" : 12.0,
"patching_rect" : [ 431.214294, 708.0, 50.0, 20.0 ],
"id" : "obj-113",
"parameter_enable" : 0,
"numinlets" : 1,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "flonum",
"bgcolor" : [ 1.0, 0.4, 1.0, 1.0 ],
"outlettype" : [ "float", "bang" ],
"fontsize" : 12.0,
"patching_rect" : [ 375.190491, 708.0, 50.0, 20.0 ],
"id" : "obj-111",
"parameter_enable" : 0,
"numinlets" : 1,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "number~",
"outlettype" : [ "signal", "float" ],
"fontsize" : 12.0,
"patching_rect" : [ 317.452393, 708.0, 56.0, 20.0 ],
"id" : "obj-109",
"numinlets" : 2,
"sig" : 0.0,
"numoutlets" : 2,
"fontname" : "Arial",
"mode" : 2,
"presentation_rect" : [ 348.0, 695.0, 0.0, 0.0 ]
}

}
, {
"box" : {
"maxclass" : "number~",
"outlettype" : [ "signal", "float" ],
"fontsize" : 12.0,
"patching_rect" : [ 259.714294, 708.0, 56.0, 20.0 ],
"id" : "obj-108",
"numinlets" : 2,
"sig" : 0.0,
"numoutlets" : 2,
"fontname" : "Arial",
"mode" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "minmax~",
"outlettype" : [ "signal", "signal", "float", "float" ],
"fontsize" : 12.0,
"patching_rect" : [ 259.714294, 642.0, 190.5, 20.0 ],
"id" : "obj-105",
"numinlets" : 2,
"numoutlets" : 4,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "button",
"outlettype" : [ "bang" ],
"patching_rect" : [ 431.214294, 33.0, 20.0, 20.0 ],
"id" : "obj-88",
"numinlets" : 1,
"numoutlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "info~ paintwave",
"outlettype" : [ "float", "list", "float", "float", "float", "float", "float", "" ],
"fontsize" : 12.0,
"patching_rect" : [ 431.214294, 68.0, 113.5, 20.0 ],
"id" : "obj-86",
"numinlets" : 1,
"numoutlets" : 8,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"fontsize" : 12.0,
"patching_rect" : [ 484.614288, 244.0, 50.0, 20.0 ],
"id" : "obj-74",
"parameter_enable" : 0,
"numinlets" : 1,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "scale 0 i 0 127",
"outlettype" : [ "" ],
"fontsize" : 12.0,
"patching_rect" : [ 484.614288, 203.0, 88.0, 20.0 ],
"id" : "obj-70",
"numinlets" : 6,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"fontsize" : 12.0,
"patching_rect" : [ 512.214294, 166.0, 50.0, 20.0 ],
"id" : "obj-67",
"parameter_enable" : 0,
"numinlets" : 1,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "set paintwave",
"outlettype" : [ "" ],
"fontsize" : 13.0,
"patching_rect" : [ 868.0, 68.0, 90.0, 19.0 ],
"id" : "obj-72",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "waveform~",
"bgcolor" : [ 0.501961, 0.717647, 0.764706, 1.0 ],
"outlettype" : [ "float", "float", "float", "float", "list", "" ],
"patching_rect" : [ 868.0, 128.405945, 330.0, 135.594055 ],
"id" : "obj-73",
"tickmarkcolor" : [ 0.352941, 0.337255, 0.521569, 1.0 ],
"selectioncolor" : [ 0.313726, 0.498039, 0.807843, 0.0 ],
"numinlets" : 5,
"setunit" : 1,
"buffername" : "paintwave",
"waveformcolor" : [ 0.082353, 0.25098, 0.431373, 1.0 ],
"labelbgcolor" : [ 0.352941, 0.337255, 0.521569, 1.0 ],
"numoutlets" : 6
}

}
, {
"box" : {
"maxclass" : "live.gain~",
"varname" : "live.gain~",
"outlettype" : [ "signal", "", "float", "list" ],
"channels" : 1,
"patching_rect" : [ 37.321411, 519.0, 136.0, 31.0 ],
"id" : "obj-3",
"parameter_enable" : 1,
"showname" : 0,
"orientation" : 1,
"numinlets" : 1,
"numoutlets" : 4,
"presentation_rect" : [ 15.0, 15.0, 50.0, 31.0 ],
"saved_attribute_attributes" : {
"valueof" : {
"parameter_mmax" : 6.0,
"parameter_mmin" : -70.0,
"parameter_initial" : [ -40 ],
"parameter_type" : 0,
"parameter_initial_enable" : 1,
"parameter_shortname" : "live.gain~",
"parameter_longname" : "live.gain~",
"parameter_unitstyle" : 4
}

}

}

}
, {
"box" : {
"maxclass" : "message",
"text" : "loop 1",
"outlettype" : [ "" ],
"fontsize" : 13.0,
"patching_rect" : [ 31.0, 234.0, 46.0, 19.0 ],
"id" : "obj-24",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "-1",
"outlettype" : [ "" ],
"fontsize" : 13.0,
"patching_rect" : [ 93.528931, 346.0, 32.5, 19.0 ],
"id" : "obj-22",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "1",
"outlettype" : [ "" ],
"fontsize" : 13.0,
"patching_rect" : [ 66.636047, 320.0, 32.5, 19.0 ],
"id" : "obj-19",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "0",
"outlettype" : [ "" ],
"fontsize" : 13.0,
"patching_rect" : [ 126.028931, 373.5, 32.5, 19.0 ],
"id" : "obj-15",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "sig~",
"outlettype" : [ "signal" ],
"fontsize" : 13.0,
"patching_rect" : [ 66.636047, 402.0, 35.0, 21.0 ],
"id" : "obj-14",
"numinlets" : 1,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "flonum",
"outlettype" : [ "float", "bang" ],
"fontsize" : 13.0,
"patching_rect" : [ 132.0, 443.5, 47.642822, 21.0 ],
"minimum" : 0.0,
"id" : "obj-13",
"parameter_enable" : 0,
"numinlets" : 1,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "0",
"outlettype" : [ "" ],
"fontsize" : 13.0,
"patching_rect" : [ 44.5, 273.5, 32.5, 19.0 ],
"id" : "obj-7",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "flonum",
"outlettype" : [ "float", "bang" ],
"fontsize" : 13.0,
"patching_rect" : [ 81.5, 443.5, 47.642822, 21.0 ],
"minimum" : 0.0,
"id" : "obj-21",
"parameter_enable" : 0,
"numinlets" : 1,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "ezdac~",
"prototypename" : "helpfile",
"bgcolor" : [ 1.0, 1.0, 1.0, 1.0 ],
"bordercolor" : [ 0.501961, 0.501961, 0.501961, 1.0 ],
"patching_rect" : [ 37.321411, 631.0, 44.0, 44.0 ],
"id" : "obj-33",
"local" : 1,
"numinlets" : 2,
"numoutlets" : 0,
"border" : 1.75
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "groove~ paintwave",
"outlettype" : [ "signal", "signal" ],
"fontsize" : 13.0,
"patching_rect" : [ 31.0, 486.0, 120.0, 21.0 ],
"id" : "obj-5",
"numinlets" : 3,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "read",
"outlettype" : [ "" ],
"fontsize" : 12.0,
"patching_rect" : [ 31.0, 98.0, 35.0, 18.0 ],
"id" : "obj-6",
"numinlets" : 2,
"numoutlets" : 1,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"fontsize" : 12.0,
"patching_rect" : [ 31.0, 166.0, 50.0, 20.0 ],
"id" : "obj-4",
"parameter_enable" : 0,
"numinlets" : 1,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "buffer~ paintwave",
"outlettype" : [ "float", "bang" ],
"fontsize" : 12.0,
"patching_rect" : [ 31.0, 133.0, 105.0, 20.0 ],
"id" : "obj-2",
"numinlets" : 1,
"numoutlets" : 2,
"fontname" : "Arial"
}

}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-5", 0 ],
"destination" : [ "obj-105", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-127", 0 ],
"destination" : [ "obj-115", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-86", 7 ],
"destination" : [ "obj-202", 1 ],
"hidden" : 0,
"midpoints" : [ 535.214294, 99.0, 796.714294, 99.0 ],
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-127", 0 ],
"destination" : [ "obj-105", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-115", 0 ],
"destination" : [ "obj-105", 1 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-105", 3 ],
"destination" : [ "obj-113", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-105", 2 ],
"destination" : [ "obj-111", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-105", 1 ],
"destination" : [ "obj-109", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-105", 0 ],
"destination" : [ "obj-108", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-86", 6 ],
"destination" : [ "obj-67", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-88", 0 ],
"destination" : [ "obj-86", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-67", 0 ],
"destination" : [ "obj-70", 2 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-70", 0 ],
"destination" : [ "obj-74", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-72", 0 ],
"destination" : [ "obj-73", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-7", 0 ],
"destination" : [ "obj-5", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-5", 0 ],
"destination" : [ "obj-3", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-24", 0 ],
"destination" : [ "obj-5", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-21", 0 ],
"destination" : [ "obj-5", 1 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-14", 0 ],
"destination" : [ "obj-5", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-13", 0 ],
"destination" : [ "obj-5", 2 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-15", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-19", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-22", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-3", 0 ],
"destination" : [ "obj-33", 1 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-3", 0 ],
"destination" : [ "obj-33", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-2", 0 ],
"destination" : [ "obj-4", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
, {
"patchline" : {
"source" : [ "obj-6", 0 ],
"destination" : [ "obj-2", 0 ],
"hidden" : 0,
"disabled" : 0
}

}
],
"appversion" : {
"major" : 6,
"minor" : 0,
"revision" : 5
}

}


October 16, 2012 | 3:20 am

Also, check this out as an aid for sharing patches on the forum:

How do I post Max 5 or 6 patches in the condensed format?
Watch this video for instructions: http://youtu.be/34cxCjPU_Ts

• Select the part of the patch you wish to copy
• Choose Copy Compressed from the Edit menu to copy the selected objects to the clipboard.
• Switch to your browser and paste the contents of the clipboard into your post window.


October 16, 2012 | 7:11 am

Hi Guys,

Thanks for the replays,

I have tried to use the scale~ object but it gives me negative numbers an positive numbers.

any ideas whys?

– Pasted Max Patch, click to expand. –

I dont know why it didn’t post in the copy compressed format last time?!

Thanks!


October 16, 2012 | 1:15 pm

You get a negative minimum from minmax~ because it’s measuring an audio signal which usually gives positive and negative values. Stick a scope~ on it and investigate.

What are you trying to do btw?


October 16, 2012 | 1:28 pm

Yes, it’s not at all clear from your patch what you’re trying to achieve or why; below is a patch using either [abs~] or [meter~] to scale amplitude to 0-127, although [meter~] is just a GUI representation of amplitude. The rightmost outlet of live.gain gives a float representing dB, which you can convert using [dbtoa] – this will give you a float between 0. and 1. Amplitude maths isn’t my strong suit either, but can you tell us where this value will then go and what it will do?

– Pasted Max Patch, click to expand. –

Brendan


October 16, 2012 | 2:18 pm

Are you trying perhaps to extract or determine what the min and max amplitude values of a sample are? You can view sample data in the [waveform~] object; if you need to do this in real time, then it also be posseeblay also.

Brendan


October 16, 2012 | 3:07 pm

Hi Brendan,

Yes you’ve got it!

I then i want to try and read thought the buffer and give each different amplitude at set intervals a color value?

then…i dont know if this is possible or not, I want to try and extract the colours to an lcd.

The general idea is to try and get a picture from a sound clip.

not sure if I’m going about it the right way, but finding outs half the fun!

Thanks,

Oli


October 16, 2012 | 4:20 pm

this might give you some ideas; but search over on the Jitter page too – way more fun to be had with amplitude and colour over there.

– Pasted Max Patch, click to expand. –

Brendan


October 16, 2012 | 5:45 pm

Thanks Brendan,

your patches have got me pointed in the right direction, and the abs~ object cures the negative number problem problem nicely!

Regards,

Oli.


Viewing 9 posts - 1 through 9 (of 9 total)