Web Audio filter node popping [closed] - web

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am getting popping when modulating a filter nodes frequency with an LFO when the filter frequency bottoms out.
I suspect this is due to the amplitude not being at the time of cutoff. Is it necessary to modulate the gain as well? I was hoping not to have to and I'm not really sure how I would anyway.
Edit: forgot link to example code http://jsfiddle.net/hyf5N/
var context = new webkitAudioContext();
var lfo = context.createOscillator();
lfo.frequency.value = 10;
var saw = context.createOscillator();
saw.type = 'sawtooth';
var filter = context.createBiquadFilter();
filter.type = 'lowpass';
var gain = context.createGainNode();
gain.gain.value = 500;
saw.connect(filter);
lfo.connect(gain);
gain.connect(filter.frequency);
filter.connect(context.destination);
lfo.start(0);
saw.start(0)

I think you're getting pops (would have to analyze waveform to see exactly why) because your LFO is modulating the frequency from -490 to 510. (freq.value = 10, + LFO ([-1,1]) * 500.) I expect the negative frequency is causing an issue.
If you want it to modulate from 0 to 1kHz, you set the frequency.value to 500, and the gain.value to 500. (The key here is that an oscillator is going to go from -1 to 1, not 0 to 1.)
Code for a rectifier:
var waveshaper = audioContext.createWaveShaper();
var curve = new Float32Array(65536);
for (var i=0; i<32768; i++)
curve[i] = 0.0;
for (var i=32768; i<65536; i++)
curve[i] = (i/32768) - 1;
waveshaper.curve = curve;

I couldn't figure out how to make the waveshaper work for me since I didn't want to bottom out the lfo signal at 0 but rather make it so the modulation wouldn't push the filter frequency below 0. I ended up using a scriptProcessorNode like so
modulationProcessor = this.context.createScriptProcessor(4096);
modulationProcessor.onaudioprocess = function(e) {
// bottom out frequency modulation at filter.frequency == 0 to avoid popping
var input = e.inputBuffer.getChannelData(0);
var output = e.outputBuffer.getChannelData(0);
var frequency = filter.frequency.value;
for (var i = 0; i < input.length; i++) {
output[i] = (input[i] + frequency) > 0 ? input[i] : input[i] - (input[i] + frequency);
}
}
It isn't perfect since it seems like if you are adjusting the filter frequency a lot you can still get popping sometimes. I think it is because the filter value can get stale while the buffers are being written. It seems to work fine if you aren't live editing the filter frequency though.

Related

How to format number in node js? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 months ago.
Improve this question
I want that if i am given a value like 1k then it should be converted to 1000 or 1m to 100000 and so on..
1k - 10000
100k - 100000
1m - 1000000
1b - 1000000000
I have searched a lot on the internet, but I can't find any npm package that can do it as well.
i just want a code solution or a npm package to help me in it.
Maybe you can try this
var thousand = '1k'
var hundredThousand = '100k'
var hundredThousandComa = '13.5k'
var million = '1m'
var billion = '1b'
var arrayFormat = [thousand, hundredThousand, hundredThousandComa, million, billion]
arrayFormat.map((value) => {
var number = value.slice(0, -1)
var last = value.slice(-1)
if (last == 'k') {
console.log(number * 1000)
} else if (last == 'm') {
console.log(number * 1000000)
} else if (last == 'b') {
console.log(number * 1000000000)
}
})
Create a map of units to coefficients.
Parse each input string into its value and unit.
Multiply the value by the corresponding unit's coefficient to get the product.
Example:
const map = {
k: 1e3,
m: 1e6,
b: 1e9,
// etc.
};
const inputs = [
'1k',
'100k',
'1m',
'1b',
];
for (const input of inputs) {
const value = input.slice(0, -1);
const unit = input.slice(-1);
const product = value * map[unit];
console.log(value, unit, product);
}

To read desired values from file using linux system commands (grep,awk,sed) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have file test.txt contains some variables assigned to some value, i need to read all defined variables for example color = 0;. Basically i am trying to read here is the values which are previous line of parameters()->getParm(" ");
can you please help me out how i can read these values. Also mentioned my expected result.
cat test.txt
color = 0;
parameters()->getParm(&color, "-color");
width = 16;
parameters()->getParm(&width, "-width");
size = 0;
parameters()->getParm(&size, "-size");
species = "Taxon";
parameters()->getParm(&species, "-species");
fly = 100;
parameters()->getParm(&fly, "-fly");
swim = 25;
parameters()->getParm(&swim, "-swim");
expected result:
color = 0;
width = 16;
size = 0;
species = "Taxon";
fly = 100;
swim = 25;
I would do it following way using GNU AWK, let file.txt content be
color = 0;
parameters()->getParm(&color, "-color");
width = 16;
parameters()->getParm(&width, "-width");
size = 0;
parameters()->getParm(&size, "-size");
species = "Taxon";
parameters()->getParm(&species, "-species");
fly = 100;
parameters()->getParm(&fly, "-fly");
swim = 25;
parameters()->getParm(&swim, "-swim");
then
awk '/parameters()/{print line}{line=$0}' file.txt
output
color = 0;
width = 16;
size = 0;
species = "Taxon";
fly = 100;
swim = 25;
Explanation: We need to store previous line so we can print it when we find line meeting condition. I use variable name line for storing it, I instructed awk that for each line: if it does contain parameters() print previous line (stored in variable line), always store current line as line. Beware that this solution assumes that line with parameters() will never be first line and relevant line is always immediately before line with parameters().
(tested in gawk 4.2.1)

Limit drag in gamemaker

Hello I am trying to limit how much a user can drag within Gamemaker.
I have created two views within a room.
The first view is the full room width and size 1250x768
The second view is the area which i would like the user to be able to zoom into and drag which is 955x465. x and y position is 40 by 170.
Currently i have set up the zoom for the second view which is:
vmx=(mouse_x-X)-omx;
omx=(mouse_x-X);
vmy=(mouse_y-Y)-omy;
omy=(mouse_y-Y);
if mouse_wheel_up() && view_wview[1] > 600 {
center_of_space_x=view_xview[1]+view_wview[1]/2;
center_of_space_y=view_yview[1]+view_hview[1]/2;
view_wview[1]-=view_wview[1]*0.15;
view_hview[1]-=view_hview[1]*0.15;
view_xview[1]=center_of_space_x-view_wview[1]/2;
view_yview[1]=center_of_space_y-view_hview[1]/2;
}
if mouse_wheel_down(){
view_xview[1] = 40;
view_yview[1] = 170;
view_wview[1] = 955;
view_hview[1] = 465;}
Below is the code for the drag:
if (mouse_check_button_pressed(mb_left)) {
drag_x = mouse_x
drag_y = mouse_y
}
// update:
if (mouse_check_button(mb_left)) && view_wview[1] < 700 {
// actual dragging logic:
view_xview[1] = drag_x - (mouse_x - view_xview[1])
view_yview[1] = drag_y - (mouse_y - view_yview[1])
// make sure view doesn't go outside the room:
view_xview[1] = max(0, min(view_xview[1], room_width - view_wport[1]))
view_yview[1] = max(0, min(view_yview[1], room_height - view_hview[1]))
So the limit works for the view to not leave the room but i want it not to leave the specific view which has been set up.
Please help
I have modified my code to use a clamp function which works but it is not a clean solution:
view_xview[1] = clamp(view_xview[1],40,400);
view_yview[1] = clamp(view_yview[1],170,500);
The user has to be fully zoomed in to have the view restricted. If he is not then they can still see other areas of the room :(
EDIT: I may have misunderstood your question, I will leave the below code for reference if it helps you solve the problem a bit differently.
I would probably check that mouse_x and mouse_y are not outside the view you want.
if (mouse_x > view_limit_x || mouse_y > view_limit_y)
{
return; // Or continue or break however your language of choice goes.
}
If you cannot do a return statement, wrapping your code in a reverse logic of above should work fine.
Old Post:
I am not 100% familiar with game maker. I would implement something like this by skipping the drag logic every x frames. Say you are updating at 60fps, and you want the drag to be 6 times slower, you just need to only update the logic 10 x per frame.
const int framesToSkip = 6;
int frameCount = 0;
update()
{
// Will only call when framecount = 0, 6, 12, 18 etc.
if (frameCount % framesToSkip == 0)
{
// Drag Logic.
}
frameCount++;
}
This way drag logic only occurs 1/6 the rate as before. You could also change this around to happen the first x amount of frames and then skip for the rest (but this may appear a bit choppy).

I'm looking for a particular insertion algorithm but I can't think of the name

Basically I have a method that will take any set of numbers with a selected value and reorder them ascending keeping track of the new selected value.
So {21, 2, 9, 13} selectedVal = 9 becomes { 1, 2, 3, 4 } selectedVal = 2
What I need to do now is be able to swap 2 numbers and keep the order intact. If I want to swap 2 with 4 I need 3->2 and 4->3 but also the other way around like swapping 3 with 1 so 1->2 and 2->3.
I'm sure there is a proven algorithm for this and I will probably create my own for fun tomorrow but I'd like the fastest solution to use in my actual application.
The name of the algorithm or any useful links would be appreciated. I am using C# 4.0 if that matters at all.
EDIT - I came up with my own solution that I believe works on paper but I'd still like a reply if someone knows a better solution.
Assuming ordered list always starts at 1 which it does in my case...
if (newpos < currpos)
for (int i = newpos-1; i < currpos-1; i++)
{
array[i] += 1;
array[currpos-1] = newpos;
}
else if (newpos > currpos)
for (int i = newpos-1; i >= currpos-1; i--)
{
array[i] -= 1;
array[currpos-1] = newpos;
}
else // do nothing since they are trying to swap to the same place

what parameters of CIVignette mean

I check CIVignette of Core Image Filter Reference at
http://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/filter/ci/CIColorControls
and play around a with the parameters:
inputRadius
inputIntensity
and still have not exactly understood what each parameter effects. Could please someone explain?
Take a look at wiki understand what vignetting in photography means.
It is the fall of of light starting from the center of an image towards the corner.
Apple does not explain much about the the params.
obviously the radius specifies somehow where the vignetitting starts
the param intensity i expect to be how fast the light goes down after vignetting starts.
The radius may not be given in points, a value of 1.0 relates to your picture size.
Intensity is definitely something like 1 to 10 or larger number. 1 has some effects, 10 is rather dark already.
The radius seems to be in pixel (or points). I use a portion of image size (says 1/10th of width) and the effect is pretty good! However, if the intensity is strong (says 10), the radius can be small (like 1) and you can still see the different.
Turns out there is an attributes property on CIFilter that explains its properties and ranges.
let filter = CIFilter(name: "CIVignette")!
print("\(filter.attributes)")
Generates the following output:
[
"CIAttributeFilterDisplayName": Vignette,
"CIAttributeFilterCategories": <__NSArrayI 0x6000037020c0>(
CICategoryColorEffect,
CICategoryVideo,
CICategoryInterlaced,
CICategoryStillImage,
CICategoryBuiltIn
),
"inputRadius": {
CIAttributeClass = NSNumber;
CIAttributeDefault = 1;
CIAttributeDescription = "The distance from the center of the effect.";
CIAttributeDisplayName = Radius;
CIAttributeMax = 2;
CIAttributeMin = 0;
CIAttributeSliderMax = 2;
CIAttributeSliderMin = 0;
CIAttributeType = CIAttributeTypeScalar;
},
"CIAttributeFilterName": CIVignette,
"inputImage": {
CIAttributeClass = CIImage;
CIAttributeDescription = "The image to use as an input image. For filters that also use a background image, this is the foreground image.";
CIAttributeDisplayName = Image;
CIAttributeType = CIAttributeTypeImage;
},
"inputIntensity": {
CIAttributeClass = NSNumber;
CIAttributeDefault = 0;
CIAttributeDescription = "The intensity of the effect.";
CIAttributeDisplayName = Intensity;
CIAttributeIdentity = 0;
CIAttributeMax = 1;
CIAttributeMin = "-1";
CIAttributeSliderMax = 1;
CIAttributeSliderMin = "-1";
CIAttributeType = CIAttributeTypeScalar;
},
"CIAttributeFilterAvailable_Mac": 10.9,
"CIAttributeFilterAvailable_iOS": 5,
"CIAttributeReferenceDocumentation": http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIVignette
]
inputRadius is a float between 0 and 2 that affects the 'size' of the shadow.
inputIntensity is a float between -1 and 1 that affects the 'darkness' of the filter.

Resources