Dynamic DSP.setParameter with FMOD - c#

I want to play sound with effect.
In example, I'm using low and highpass, I want to set the parameters of two effect with the mouse location (x, y).
I used DSP.reset() and DSP.setParameter(), but, there is a problem.
If I moved the mouse faster and faster, the Sound is not smooth.
The original sound is played between time of the code reset() and setParameter() .
Therefore I can hear a sound like spark( 'tick! tick!').
I want to make it smooth.
Is there any way??
private void mouse_effect_move(object sender, MouseEventArgs e)
{
int i;
i = e.Y / 10;
dsplowpass.reset();
dsphighpass.reset();
if (i < 9)
{
dsphighpass.setParameter(0, 6310 - 700 * i);
//dsphighpass.setParameter(1, 1);
}
else
{
dsplowpass.setParameter(0, 22000 - 2200 * (i - 9));
//dsplowpass.setParameter(1, 1);
}
}

You don't need the calls to DSP::reset when using DSP::setParameter. Does the problem go away if you remove them?

Related

C# Pong Game Paddle Movement via Microphone input

im trying to build Pong Game with Microphone Input as controls for the paddles. the following part of the code (c#) is moving the paddle.
void Update ()
{
loudness=GetAveragedVolume() * sensitivty;
if (loudness>=8)
{
this.GetComponent<Rigidbody2D>().velocity=new Vector2(this.GetComponent<Rigidbody2D>().velocity.y,4);
}
shouldn´t this code below do the job? however its not working
else (loudness<=8)
{
this.GetComponent<Rigidbody2D>().velocity=new Vector2(this.GetComponent<Rigidbody2D>().velocity.y,-4);
}
Its obviously an easy problem but im kinda stuck in here with this noob question
Thanks in advance
EDIT// what i want to do:
Move the paddle up when the microphone receives Sound and drop back down if there is no sound, just like an value from an visual amp.
Daniel
Given that Update () is called correctly and GetAveragedVolume() returns meaningful values, it would have to look like this:
void Update () {
loudness = GetAveragedVolume() * sensitivty;
if (loudness > 8) {
this.GetComponent<Rigidbody2D>().velocity = new Vector2(this.GetComponent<Rigidbody2D>().velocity.x, 4);
}
else {
this.GetComponent<Rigidbody2D>().velocity = new Vector2(this.GetComponent<Rigidbody2D>().velocity.x, -4);
}
}
Your mistakes:
else (...) is invalid. Use else if(...).
You used this.GetComponent<Rigidbody2D>().velocity.y instead of this.GetComponent<Rigidbody2D>().velocity.x for the x-component of the two new vectors.
Some tips:
Wether you use >= or > does not really matter for floating point numbers in most cases, and definitely not in your one.
else is sufficient here. You don't need to check else if (loudness <= 8), because if it isn't > 8, then it is always <= 8.
Conventionally, you write a = b; / a, b and not a=b; / a,b, to make your code more readable.
I hope that works for you!

Looking for ways to optimize multi poly-lines on canvas in wpf

I'm working on program in WPF that need to plot on one of her screens 50 poly-lines that describes movement of some energy in space. One more demand from the program is to move two lines and a dot to indicate the mouse location when its relevant.
The problem is that when the poly-lines cover a high percent of the canvas and the mouse is fly over the canvas then all start to run really slowly.
I succeeded to improve this a little but its still not good enough so I'm asking for your help please.
So because this canvas related to another one, I spited the work for two - the handler and the movement function:
private void rayTraceCanvas_MouseMove(object sender, MouseEventArgs e)
{
System.Windows.Point pos = e.GetPosition(rayTraceCanvas);
mouseMove(pos);
if (m_MouseMoveCallback != null)
m_MouseMoveCallback(m_CurrentDepth);
}
And then the movement function:
private void mouseMove(Point currentPos)
{
m_CurrentDepth = Math.Round((currentPos.Y) / (m_PixelPerDepthUnit));
m_CurrentRange = Math.Round((currentPos.X) / (m_PixelPerRangeUnit));
DepthPos.Text = "D: " + m_CurrentDepth.ToString();
RangePos.Text = "R: " + m_CurrentRange.ToString();
rayTraceWidthLine.Y1 = currentPos.Y;
rayTraceWidthLine.Y2 = currentPos.Y;
rayTraceHeightLine.X1 = currentPos.X;
rayTraceHeightLine.X2 = currentPos.X;
Canvas.SetLeft(rayTraceDotOnGraph, currentPos.X - (rayTraceDotOnGraph.Width / 2));
Canvas.SetTop(rayTraceDotOnGraph, currentPos.Y - (rayTraceDotOnGraph.Height / 2));
}
I tried this without the deleget from the handler function and its work the same so the problem isn't there.

How Can I Improve The Look Of This Transition?

I am trying to translate two buttons down and off-screen after one is clicked. I have it working, but it is very choppy. How can I make this transition more fluid?
-I am using Microsoft Visual Studio 2015
-The language I am using is c#
Here is my transition code:
private void timer1_Tick(object sender, EventArgs e)
{
int speed_increase = 100;
if(sleep_button.Top <= 800 || calibrate_button.Top <= 800)
{
sleep_button.Top += speed_increase;
calibrate_button.Top += speed_increase;
}
}
I have my timer interval set to 1ms too, just because I am aware the larger interval the choppier it becomes. I have been looking all day for a button transition tutorial and found none. And if this isn't possible can somebody sent me a tutorial for button fade outs? Thanks everyone
Your timing choice is off. 1ms is too granular. Try something around the 20ms mark, this will cause your code to run 50 times per second, which is rather closely aligned with common refresh rates of around 50hz.
How far do the buttons need to scroll? How long should it take?
Assume X is the distance to scroll, and Y is the time in seconds. The number of iterations is Y * 50 (50 times per second), and the distance per step is X / Y.
X = 200 pixels.
Y = 2 seconds.
Distance per step is:
X / (Y * 50)
200 / (2 * 50)
200 / 100
== 2
If you want to scroll 200 pixels over 2 seconds, you want to add 2 to the Y position of each button on each iteration.
I hope that makes sense.
How about hiding it altogether?
private void timer1_Tick(object sender, EventArgs e)
{
sleep_button.Visible = false;
calibrate_button.Visible = false;
}

XNA C# 2D Scrolling Background 3 or More

I've trying to create a scrolling background with 3 background, but everything When the 3rd start to come out. It creates a giant blue screen(Default background of the game) infront of the 3rd and after the 3RD it doesn't show any background. I have no idea how fix this, and I already know it something simple. I've got the 3RD one to work, but .
Code that I'm trying to use.
public void Update(GameTime gameTime)
{
bgPos0.Y += speed;
bgPos1.Y += speed;
bgPos2.Y += speed;
if (bgPos0.Y >= 950)
{
bgPos1.Y = -950;
if (bgPos1.Y >= 950) // Doesn't go fully down.
{
bgPos2.Y = -950;
if (bgPos2.Y >= 950)
{
bgPos0.Y = 0; //(Try to change it to -950 still doesn't work. I guest it due to that bgPos0 is set to 0, 0)
}
}
}
}
And the Vector2 code for the pos are
bgPos0 = new Vector2(0, 0);
bgPos1 = new Vector2(0, -950);
bgPos2 = new Vector2(0, -1900); // Could be the large -1900 number that destroying the code. To make it not work.
So how do I fix this? I wish I could fix it right now, but I can't for some reason.
I don't think you want to have the if-statements nested. The code you posted constantly moves the second background to -950 for as long as the first is past 950. Since the first is constantly moved back to -950 it shouldn't ever manage to move past 950, and so it never gets into the last one. I think what you probably want to do is something more like:
public void Update(GameTime gameTime)
{
bgPos0.Y += speed;
if(bgPos0.Y > 950) {
bgPos0.Y = -950;
}
bgPos1.Y += speed;
if(bgPos1.Y > 950) {
bgPos1.Y = -950;
}
bgPos2.Y += speed;
if(bgPos1.Y > 950) {
bgPos1.Y = -950;
}
}
[EDIT]: As an aside, the number in question isn't nearly large enough to cause problems. XNA's Vector2 class stores the x and y components as floats, and the maximum value for a float in C# is somewhere around 3.4e38 or so, and accurate to 7 digits according to MSDN.

How to animate a simple shape moving vertically?

So, I have a rectangle "rectangle1", at 160,160.
I want it to move smoothly to cordinates 160,30, with a duration of about 1 second. (time delay)
I've figured out that some basic code to move the shape is
rectangle1.Location = new Point(160,30);
However, when I tried doing a for loop with
rectangle1.Location = new Point(160, rectangle1.Location.Y - 100);
it just moved there instantly. Which I should have expected really. Same occurred with
int count = 0;
while(count != 300)
{
rectangle1.Location = new Point(160, rectangle1.Location.Y -1);
count += 2;
}
So, I assume I need some sort of clock / timer loop, that moves it by x pixels every x milliseconds. Not sure how to do this, so help would be appreciated.
Also, I'm going to be animating two other rectangles horizontally, which will then move up at the same time/speed as rectangle1. I think I'll have to "delay" rectangle1's movement until they are in position, correct?
Thanks.
PS: I've googled a fair bit, but since I'm not entirely sure what I'm looking for, it wasn't very fruitful.
If you need smooth movements, it's great to use timers, threads, backgroundworkers.
Here is what you need to do. Assuming you have the code that increment/decrement x,y points for the shape.
Steps:
set timer interval to for e.g. 100
set an integer int count=0; *
in timer_tick event do the moving work
private void timer1_Tick(object sender, EventArgs e)
// no need to use your while loop anymore :))
{
If(count< 300) //set to your own criteria
{
//e.g. myrect.location=new point(x,y);
// rectangle1.Location = new Point(160, rectangle1.Location.Y -1);
}
count += 2;
}

Categories