Machine Sounds in C# - c#

I want add machine sounds to my router table simulator program. The idea is to hear the stepper motors accelerate and decelerate with a change in pitch synced with my graphics. Same with the spindle motor, it has a pitch change as its rpm goes up and down. I thought of either adding real recorded motor sounds and modifying the pitch at run time or create synthetic sounds simulating the motors. Can anyone suggest the easiest way to achieve this? I have hardly any experience in sound programming besides the most basic stuff. I am programming in C# in Visual Studio.net

check these links out:
http://www.codeproject.com/KB/audio-video/cswavplayfx.aspx
http://channel9.msdn.com/coding4fun/articles/Generating-Sound-Waves-with-C-Wave-Oscillators
These should give an idea for the options (playing pre-recorded audio with some effects versus generating the sound synthetically) you mentioned, either way...

Related

Is it possible to use a Sony smartwatch as an airmouse by gyrometer?

I want to use a Sony smart watch to imitate an air mouse like Logitech MX Air. I am completely addicted to that mouse, and I have a really good feeling that having it attached to my wrist would be the most user friendly mouse ever.
The question is: Is it possible?
I can code anything in c#, I just want to do my proper research before I start, so I don't waste 20+ hours to find out it's not possible.
It should be a Bluetooth connection to the pc, using an app on the watch and an app/driver on the pc. The data flow must be very stable, that's probably the weak link in the project.
Can I get some feedback? Possible, not possible and why?
The SmartWatch comes with an accelerometer giving you z y and z coordinate values. Check out this link to setup your development environment and try out the HelloSensors example.
https://developer.sony.com/develop/wearables/smartwatch-2-apis/get-started/

Input of a Rhythm Game

So, Unity does not do a lot of rhythm games on android. I decided to find out why, and program one as assignment (the basics of it anyway). My most important hurdle is user input. As we know that input is based on frame rate in unity, and a music game (i assume) would prefer the smallest possible delay between button press and action.
If we look at music, at around 15 to 20ms of delay, the human ear hears something is "off beat".
I heard Android Unity games run at 30FPS (since 60FPS sucks the battery dry), simple math indicates: 1000/30 = 33ms per frame. Calculating in the 15ms we can probably not notice, we are at 18ms of possible disaster. assuming we always reach this 30FPS at any given moment.
When i get input from a user, i can play a sound on that input on the exact same frame. However, we could be 18ms off.
Now there is a way to get DIRECT controls from mouse and keyboard, which uses OnGui() instead of Update(), to get events of the keyboard or mouse clicks on the spot. The problem is, android probably doesn't work with this, (this doesn't work for gamepads either) and the methods sounds downright strange, especially when we try to play sounds from the OnGui() method.
My question:
What would you do, and why? Should we just accept the possible 18ms off, and assume we reach the 30FPS, or should we look for a reliable way to get input directly, instead of waiting for an update to come by?
Thanks for any insight you can give me, i have not found any articles on this that are useful just yet.
-Smiley
EDIT
I just did some basic testing with a metronome, running at 100FPS in the editor (which should be 10ms per frame) tapping my spacebar on a metronome inside unity. The results i got were just horrible.
Tapping rapidly: I get as close as 20ms to my metronome tick, but nothing closer.
Tapping on the beat: I got at least 200ms off my target tick. Unless i am confused with this rhythm, this is just wrong.
Currently i use Debug.Log to get my test data to the log. Can anyone please confirm for me if this may be the cause (causes some long delay? i know debug isn't that optimized), or is the timing actually that bad on it?
Thanks in advance,
-Smiley
First, I'd like to add a few things to your comments and analysis:
There is a hell of a lot more to measuring the latency between the tactile input and what your eyes perceive.
Probably the biggest one I'm seeing missing in your tests is the latency between the graphics card and the PC monitor you're testing on. Many common LCD monitors these days have a latency of between 15-30ms in processing lag. I don't know how much this relates to mobile screens and hardware, but I would suggest you take the time to perform additional tests on your target hardware before drawing further conclusions.
To more directly answer your question:
I would continue to use Unity however I would continue to research the best methods of taking the input and feeding it back to the player as fast as possible. In the above comments #rutter has pointed you to what appears to be a pretty good thread on the issue.
Of specific note I would look at using FixedUpdate() to decouple the framerate of the game from the input processing speed.
I think it is also worth putting time into researching the psychology of the perception of latency. For example, if your game is a sort of Guitar Hero game of matching the playing song, you could simply take into account the lag you know is there and in your game logic take that into account when checking input.
I think you are over-complicating this, and that the accuracy issue is no where near as bad as you think.
People usually hit the buttons a little early in order to sync what they are seeing and hearing.
It also depends alot on if you have some kind of scrolling display that they are trying to match up to... if the display is scrolling smoothly at 30fps (without big jumps) they they are still able to make their timing presses fairly accurate.
I would surmise that although people can hear when their timing is off, their actual timing of hitting the buttons at exactly the right time is not that accurate anyway.
Here is one other simple solution... which I think is what rock band and guitar hero often do...
You start playing the note/sound at the correct time anyway.... then change it to a broken sound if you detect they missed it or goofed up.

Recognizing notes when playing over microphone

I want to make a program that recognizes the notes I play over the microphone with my guitar, but I'm not sure how I will make my program recognize the sounds I play, and then make the program choose between a bunch of notes.
Can I have any help with this? I basically need a library, which is able to recognize sound played over the microphone, and then compare it to different audio files, and see which one is the closest to the played note.
I hope you guys understand this now, it is hard to explain.
As Dan Bryant mentioned, you basically want to do an FFT, which gives you the amount of energy at different frequencies. Find the frequency with maximum energy, then choose the note whose frequency is closest to that. This is what is going in the little digital tuners you buy that help you tune your guitar. There are several available libraries that will do the FFT for you. You just need to specify an FFT size that gives you enough frequency resolution to distinguish between notes.

Get music tempo or BPM?

I'm currently building a game in windows phone 7 using xna
i'm trying to get beat per minute from song that played in background song,
i also not quite sure if what i want is BPM, what i want is something like pace or tempo in music, faster the pace ,faster the sprites is moving. What i'm thinking right now, BPM is how much a frequency from music hits a range of defined constant, e.g 20 Mhz - 30 MHz,
Feel free to correct me if i'm wrong, i'm not really familiar with audio thing, i have tried using VisualizationData from MediaLibrary XNA, but after some googling they said that VisualizationData doesn't work with WP7, i also had tried it and the output is 256 length float array contains 0 value,,or if i could do some fft with it,i'll give it a try
Thank you...
Like you were saying, as for the beats you can't get it directly but you'll have to interpret this data. If you personally can preprocess this music and ship it with your title it would be your best bet
In XNA you really only have MediaPlayer.GetVisualizationData to work with. There isn't anything built in that allows you to predetermine this sort of thing. It's used like the following and gets you information about the different frequencies that are playing.
MediaPlayer.IsVisualizationEnabled = true;
VisualizationData visData = new VisualizationData();
MediaPlayer.GetVisualizationData(visData);
So how do you take this frequency stuff and make it worthwhile for your application? There's a great breakdown of how you can do this that's on the App Hub forums in this thread called "Audio Analysis" in the reply by jwatte. Essentially, you're going to look at the low frequencies and try to figure out when the beats are coming in. Nothing perfect, but hopefully you'll get something that you approve of.
Good luck!

How do I play nsf music in C#? (making a game)

I'm making a game with some friends for our last highschool project .
I'm having trouble finding out how to play the music I've written in c# and I'm turning here for answers.
We're using Microsoft Visual studio 2010, and I've mainly been writing music for the game during this time so I'm quite a beginner at programming in C#.
The Music I've made is made in a program called Famitracker don't know if your familiar with it but I can export the files to NSF which is good since they take up low disk space.
So my real question is how do I make our game play the music and loop it until the play gets to the next stage?
NSF, or the Nintendo Sound Format is not something that Windows nor .NET supports natively... instead you would have to either write or find your own player for it... or redo your music in something more common like MP3 or WAV.
If you want to stick with NSF, I'd suggest looking at one of the open source NES emulators out there and see if you can't use of of their code. (Example 1) (Example 2) (Example 3)
Your easiest solution would probably be to output is as a wav and play it using XNA as Matthew describes. The file size may be larger, but unless you are having file size issues, I think that will by far be the easiest way to go. There doesn't seem to be any easy implementation of a nsf player in C#, although you might look into how NES emulators are doing it.
Use the XNA framework for audio, etc in games.
Here is a good starting point: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=xna+framework+play+audio

Categories