C# generate soundwave at real time - c#

i would like to start some project for fun, and found my interest in sounds.
So i would like to make some things move with sound rhythm. But i don't know, e.g., how winamp (in image) generates values to draw those bars. How could i make it happen in C#? Can anybody give me some tips ?
edit: i will figure out this: http://wpfsvl.codeplex.com/

You should read up on Fast Fourier Transforms.
A fast Fourier transform (FFT) is an efficient algorithm to compute the discrete Fourier transform (DFT) and its inverse.
and
A DFT decomposes a sequence of values into components of different frequencies
With the FFT, you can split up a soundwave into it's component frequencies, ie: you can see the levels of different frequencies in the original soundwave, and then graph them in some sort of fancy bar chart, like in your image.
The following question is related to FFT's and C#:
An implementation of the fast Fourier transform (FFT) in C#

Related

What 3D rendering technic/algorithm is most effective to draw beams by edges?

I'm trying to construct a program in C# that generates a 3D model of a structure composed of beams, and then creates some views of the object (front, side, top and isometric).
As I don't need to draw surfaces (the edges are enough), I've been calculating each line to draw, and then do it with
GraphicObject.DrawLine(myPen, x1, y1, x2, y2)
This worked fine so far, but as I get adding parts to the structure, the refresh of GraphicObject takes too much time. So I'm getting into line visibility check to reduce the amount of lines to draw.
I've searched Wikipedia and some PDFs on the subject, but all I found is oriented by surfaces. So my question: Is there a simplified algorithm to check visibility of object edges, or should i go for a different approach, like considering surfaces?
Any suggestions would be appreciated, thanks for your help.
Additional notes/questions:
My current approach:
calculate every beam in a local axis (all vertices)
=> move them to their global position
=> create a list with pairs of points (projected and scaled to the view)
=> GraphicObject.DrawLine the list of point pairs)
would the whole thing be faster if I'd calculate the view by pixels rather than using the DrawLine method?
Screenshots follow with the type of structure it's going to do (not fully complete yet):
Structure view
Structure detail
There are 2 solutions to improve the performance.
a) switch the computation to the graphics card.
b) Use a kd-tree or some other similar data structure to quickly remove the non visible edges.
Here's more details:
For a), a lot of you computations are multiplying many vertices (vectors of length 3) by some matrix. The CPUs are slow because they only do a couple of these operations at a time. Switch to a GPU, for example using CUDA, which will allow you to do them more in parallel, with better memory access infrastructure. You can also use OpenGL/DirectX/Vulkan or whatever to render the lines themselves to skip having to get the results back from the graphics card and whatever other hiccups get introduced by windows code/libraries. This will help in almost all cases to improve performance.
For b), it only helps when you are not looking at the entire scene (in that case you really need to draw everything). In this cases you can store you scene in a kd-tree or some other data structure and use it to quickly remove things that are for sure outside of the view area. You usually need to intersect some cuboid with a pyramid/fustrum so there's more math involved.
As a compromise that should help in a large scenes where you want to see everything you can consider adjusting the level of detail. From your example, the read beans across are composed of 8 or so components. If you are far enough you are not going to be able to distinguish the 8, so just draw one. This will work great if you have a large number of rounded edges as you can simplify a lot of them.

pattern recognition inside a matrix

say I have these boxes, some of which are black and some white.
The image shows a U shape drawn with the black boxes. Now say I have a matrix of 1s and 0s (it can be a huge matrix) like this:
111111111111111111
111111111111111111
111111111111111111
111111111101111111
111111111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111100000011111111
111111111111111111
which shows zeros forming roughly the shape shown in the image. The image and the matrix are just examples. The image is a screen shot of a software where we should draw patterns, which would then need to be located in given matrices (inside simple text files).
What I'm looking for is a guidance on how to get started on this, cuz I have never programmed anything related to pattern recognitions, which this problem clearly seems to be related to. This is all that I have to do, a pattern given, to be matched with matrix of 0s and 1s. I dont think I can write it on my own in a few days, I'm writing code in c# vs 2013, so hoping I can find some libraries that would let me achieve this with minimal dependencies. Thanks
I think you need to provide a bit more information on what exactly you're looking for. Are the shapes all letters or arbitrary shapes?
Whatever you're looking for I'd start with emguCV. It's a pretty comprehensive library that isn't too difficult to use.
EmguCV has a lot of OCR (optical character recognition) functions which should be able to pick out letters pretty well.
I don't have as much experience using it for arbitrary shape detection but I think SURF detection, something which emguCV also does, might be a good way to go. It attempts to match a given image with features in another image.
People never draw at the exact same place and scale as your stored data.
The things you want are often done with neural networks (its also in aforge).
But it might be hard to A understand it and B use it in your code.
So maybe you could try it like this, get the first position, then record the delta position.
Try to find long lines, and their next direction; store the general direction changes.
above sample would be "down right up", you might also store some length info.
Then there is some math to check how much different sets are, for example string comparisons distance of strings (like in php the levenshtein function); cant think of a levenshtein func in c# dough i dont think c# is that rich with string functions but once you see that i'm sure you can derive something for C#.

What is good image processing algorithm for comparing differences in video frames?

I am looking for a good (simple, relatively fast) algorithm for comparing video frames and calculating the difference between the frames. I imagine a function like this:
//Same Scene
diff = ImageDiff(FrameInScene1, nextFrameInScene1);
//diff is low
//Scene Boundary
diff = ImageDiff(FrameInScene2, nextFrameInScene3);
//diff is high
Where diff is a numeric value of the similarity/difference between the frames. For example, two adjacent frames in the same scene would have low values, but a scene change would have very high values.
Note: I am not looking for a scene detection algorithm (some are timecode based), but this would be a good example of the problem.
A library with C# code would be ideal
Consecutive frames ? Mean Squared Error, Mean Absolute Error, PSNR.
Given so little information about your problem it doesn't make sense to suggest anything more.
I am not sure of C#! Have you used openCV? I wrote the code in C and I had used the BHATTACHARYA algorithm for comparing. You can use OpenCV from c# also look at : http://www.emgu.com/wiki/index.php/Main_Page.
All you would be doing is:
Grab the two frames.
Get the histograms of these in two separate pointer.
Pass these two pointers and use a normalization factor and compare the histograms.
I hope this helps.

Image Skeletonization using Medial Axis Transform

My requirement is something like this:
Lets take there is a Bitmap with a big letter 'A'.
The Bitmap is two colors (Either Black or White).
I need to skeletonize the big 'A'. (see: http://en.wikipedia.org/wiki/Topological_skeleton)
Using "Medial Axis Transforming" algorithm.
I tried my best in googling but i ended up being lost in finding a C#, C++ or at least pseudo code implementation of this algorithm.
I would like if someone could help me on this.
This page http://www.cs.sunysb.edu/~algorith/files/thinning.shtml has some sources you may wish to review.
The following two articles are the ones where the Medial Axis Transform was first proposed, so I think that you can find the algorithm to implement there. Do not expect a C++/C# implementation though.
A transformation for extracting new descriptors of shape
Shape description using weighted symmetric axis features
For the first one I was able to find a URL to a pdf. For the second one you will have to have access to ScienceDirect to download.
Another approach that you can use to extract the skeleton of a shape is by the Image Foresting Transform (IFT). It consists in representing the binary image as a graph. I made an implementation of the skeletonization by IFT in Matlab using the following article:
Multiscale skeletons by image foresting transform and its applications to neuromorphometry

Playable Heightmap

I have a game with infinity procedually generated terrain. I'm using 1/f noise for the height (I think this is perlin noise?). Anyway it looks nice, but its not very playable since it doesn't really have flat areas. Just decreasing the amplitude won't work since I still want a large variation in height. Does anyone know of a filter I can apply to the heightmap to encourage flat areas while keeping a large range of heights?
Written in C#
EDIT: I've realised that what I want is for steep gradients to become steeper, and for flat gradients to become flatter. The terrain needn't be realistic, just "fun" for an FPS.
I believe you need to use a smoothing function to get rid of the jaggedness of the terrain, if that seems to be your problem.
I only glanced through this page, but it may be a decent guide: http://www.float4x4.net/index.php/2010/06/generating-realistic-and-playable-terrain-height-maps/
Not sure if this would help, but you could make that a range of your function is transformed into a flat surface with a high probability. For example all results between 0.1 and 0.3 have a 80% probability of end as a 0.1 surface. This way you encourage flat surfaces but keep the high variability you want.
Simple noise is not enough to generate a good looking terrain. It's just one of the intermediate steps in a way more complicated process. You need to simulate some real world phenomena: temperature, erosion, precipitation, that sort of thing. It's a CPU-heavy process, usually, but well worth the effort. Here are some interesting links:
Dungeon League - read all of it. Great stuff.
http://www.dungeonleague.com/
World generation articles on The Chronicles of Doryen:
http://doryen.eptalys.net/2010/01/back-to-the-caves-world-generator/
http://doryen.eptalys.net/2010/01/the-cave-map-with-ice-floe/
http://doryen.eptalys.net/2010/01/the-caves-biome-map/
http://doryen.eptalys.net/2010/01/nifty-debug-maps/
http://doryen.eptalys.net/2010/01/improved-precipitation-map/
http://doryen.eptalys.net/2010/01/biomes-balancing-and-rivers/
http://doryen.eptalys.net/2010/01/rrt-rivers-until-i-get-something-better/
http://doryen.eptalys.net/2010/01/disco-time/
(You can download the generator too, but it's written in C++)
You need a "master random generator" that will decide what a new area should look like, with a frequency of your choosing. For mountains choose what you have already. For flats choose less noise.
You can filter by median filter then. it will flatten your surface. But it will destroy mountains. This is fine for relatively flat areas like hollows and plateaus. If you want sharp mountains (with fast and big height diff) you should apply this filter selectively.
You should look for more materials especialy on procedural textures and noise. Those three are related a lot. You should think about using more than one noise function with different parameters and combine them using different functions or operators.
To help your case, you can use one function to generate high-frequency noise and then multiply it by low-frequency noise. This will result in peaks where low-frequency noise is closer to 1 and flats where it is close to 0. Some kind of smoothing/erosion algorithm is cool too. But you will still need lot of trial and error and fine tuning your parameters to get at least usable results.
Some more complex terains may need over 10 noise functions with alpha blending or smoothing and such. Dont think you will get nice looking terrain from aplying simple filter.
What you can do for an easy and ok looking solution is to Evaluate the height you get from your noise map with a custom curve function.
For example you can make your curve map noise points from 0.1-0.3 to 0.1-0.15 and then from 0.3-1.0 to 0.15-1.0.
This way you still keep the actual roughness of the terrain but make it flatter.

Categories

Resources