Sample rate?

Speed of sound

Posted 14 November 2009 - 12:38 PM

Hi

I'm creating a very basic program that's going to calculate fuel usage for a car. I've made a throttle slider with swing, and I would like to connect an engine sound to the throttle. I've managed to get the engine sound just loop inside the While loop the program runs in, but that's only the engine idle sound looping. I belive I need to change sample rate to simulate changes in engine rpm?

While I am it. Another problem I'm having. I have a RPM Bar and Speed Bar to represent speed and rpm. I started connecting all the factors to rpm and let speed just be a ratio of rpm. This worked, but when I change gear, the speed jumps up and down while the rpm is the binding part between gears. This is not realistic off course, so I changed all the paramters like throttle, drag etc to the speed bar and let rpm be speed/ratio. Problem now is that everything happens to fast now?
I have to set " speed = speed + throttle -drag" etc, but now everything happens way top fast? With "rpm = rpm + throttle - drag" etc the speed of things happening seemed more normal?? I assume because rpm has bigger range 0-8000, while speed is 0-200 km/h?

Replies To: Speed of sound

Re: Speed of sound

Posted 14 November 2009 - 12:51 PM

Not to sure about your second issue. With you first question, do you just want to add a sound which changes to the change of the rpm? Just like how a revving car sounds? You do realise that this is going to be a pain in the *&^% in java, as the java sound api is not very good and has not been updated in six years. It would mean that you need to perform all the fourier transforms yourself. I dont know if changing just the sample rate will do anything, you may have to deal with frequency and other things aswell. There is a good website out there for you to go through. I thinks its jsresources.com or somthing. Just type in java sound resources into google, and you should get it. There are a lot of examples on there, which might help you out.

Re: Speed of sound

Posted 15 November 2009 - 07:57 AM

Thanks for help. I wasn't aware that it was that tricky in Java, so it's probably not worth the trouble for my assignment. Java it's not the main purpose of the project, so I just wanted to add it as bonus. Yes I just wanted the sound to follow the revs of the enginge.

Thanks for the link.

Was hard to explain my second issue, but bascially in Java swing I figured that to get the progress bar to update itself, say the progressbar for speed(simulate a speedometer) if have to put "speed = speed + other". This means I guess that since speed is in a while loop, it just goes to fast because it multiplies itself. If I type just like this " speed = other + " then the progress bar does not update itself? So I haven't figured it out yet

Re: Speed of sound

Posted 15 November 2009 - 08:41 AM

Not too sure if the progress bar is the answer to your problem, as I assume it would only ever go in one direction, as it is to show the progress of a task through 100% (never used them before though). You could try a few things though. Instead of a straight assignment each time, you could try using +=. but then you would need some if statements, so that if the speed decreased, you can use -=. But as I say, I dont really think a progress bar is intended for this type of thing. Someone else may be able to give you a hand on this though.

Back to your other issue, there are always ways around a tricky situation. You could find yourself multiple sounds of an increase rev, and just set a new rev sound to play at a certain point. It might not be as smooth sounding as you hoped, but suppose it is better than nothing. Alternatively, you could consider using a different language, like C++, where the sound api is far easier to use.

Re: Speed of sound

Posted 18 November 2009 - 12:55 PM

Thanks for help. This is just a small project at school. I've only learned programming in Java, and programming is about 50% of the project, so I have to keep it simple. I just wanted to add sound as a bonus.

Re: Speed of sound

Posted 21 November 2009 - 05:41 AM

Another question My teacher's been sick for over a week, so we had some problems getting progress with our project

Based on speed, I make a formula for distance. I know want to display the distance in a text box. Problem is that when I accelerate the distance counts in meters, but when I slow down the distance count backwards? I tried say "distance = distance + distance++;"? Do I have to use time?

Another problem while I'm at it I've made a timer. T1 get date.... and T2 get dat, then Time=T2-T1. I then divide this by 1000 and it now counts seconds, I think. Any easy way to format this so when over 60 sec it says 1 min? The only Date/time format we did was System out Print Dateformat something, but not sure if that works?

Re: Speed of sound

Posted 21 November 2009 - 10:21 AM

Bullitt, on 21 Nov, 2009 - 04:41 AM, said:

Another question My teacher's been sick for over a week, so we had some problems getting progress with our project

Based on speed, I make a formula for distance. I know want to display the distance in a text box. Problem is that when I accelerate the distance counts in meters, but when I slow down the distance count backwards? I tried say "distance = distance + distance++;"? Do I have to use time?

Another problem while I'm at it I've made a timer. T1 get date.... and T2 get dat, then Time=T2-T1. I then divide this by 1000 and it now counts seconds, I think. Any easy way to format this so when over 60 sec it says 1 min? The only Date/time format we did was System out Print Dateformat something, but not sure if that works?

Cheers

No the Dataformat you used for system.out wouldn't solve your problem. What comes to my mind is make your own custom timer that adds +1 every second, and when it reaches 60, reset it, and add +1 to min. If you have a sec, min, and hour integer you can make it work like clock work, but this would require you to make your own special timer. There are plenty of tutorials out there on timers and they are pretty simple to learn! Again, theres probably other ways of going about a timer but my first thought is making your own clock via what i said above!

Re: Speed of sound

Posted 21 November 2009 - 03:29 PM

Thanks for quick reply. I just keep it counting at counting the seconds.

Another question. Gonna read the rise of the road ahead say every 100 meters. I made a txt file with only 1 table down, and I put in 5 numbers downward to se if I can read them every 100 count. So the 100 count would be dist traveled and for every 100 read down to next table and get say 5 degree.

I have a distance reading, and with a IF from 0 to 5 meters it reads the first TAB pos, then IF ELSE for 6-100 meters it reads TAB pos2, IF ELSE 101m 200m TAB pos 3 etc.

After TAB pos 2 I get error? The index for my table is INT I, and if I put I=0; outside the WHILE I get error when it wants to read TAB pos 3. If I have INT I =0; inside WHILE, it just goes to 0 after TAB pos 2.

Tried to make FOR to add every 100 m instead of lots of IF ELSE for every 100 m, but no luck with that either