Speed of sound

Sample rate?

Page 1 of 1

10 Replies - 1280 Views - Last Post: 22 November 2009 - 04:39 AM Rate Topic: -----

#1 Bullitt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-November 09

Speed of sound

Post icon  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?

I've been lost all week :)

Cheers

Is This A Good Question/Topic? 0
  • +

Replies To: Speed of sound

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

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.
Was This Post Helpful? 0
  • +
  • -

#3 Bullitt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-November 09

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 :(

Thanks again.
Was This Post Helpful? 0
  • +
  • -

#4 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

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.
Was This Post Helpful? 0
  • +
  • -

#5 Bullitt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-November 09

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.

Cheers
Was This Post Helpful? 0
  • +
  • -

#6 Bullitt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-November 09

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?

Cheers
Was This Post Helpful? 0
  • +
  • -

#7 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Re: Speed of sound

Posted 21 November 2009 - 10:21 AM

View PostBullitt, 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!
Was This Post Helpful? 0
  • +
  • -

#8 Bullitt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-November 09

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 :(

Again thanks for help so far.
Was This Post Helpful? 0
  • +
  • -

#9 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Speed of sound

Posted 21 November 2009 - 03:55 PM

Cant really say anything without a bit of code. When you say you read it in from a text file, how is the text file formatted, and how are you reading it in? Are you just using a scanner?
Was This Post Helpful? 0
  • +
  • -

#10 Bullitt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-November 09

Re: Speed of sound

Posted 22 November 2009 - 03:37 AM

Use FileReader, BufferedReader and StreamTokenizer. It's just a txt file. I type say 5(ENTER) then 10(ENTER) etc. Code is like this:

if (dist >= 0 && dist <= 5) {
tab[i] = st.nval;
} else if (dist >= 6 && dist <= 10) {
i++;
ret_code = st.nextToken();
tab[i] = st.nval;
}else if (dist >= 11 && dist <= 15) {
i++;
ret_code = st.nextToken();
tab[i] = st.nval;

After dist is 10 I get either error or it goes to 0, dependning on where I put "int i=0;"

Thanks again.
Was This Post Helpful? 0
  • +
  • -

#11 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2555
  • View blog
  • Posts: 10,655
  • Joined: 20-September 08

Re: Speed of sound

Posted 22 November 2009 - 04:39 AM

Just use a DateFormat to format your display. Use "H:mm:ss"

As for sound, you could just use an array of tone files. There would be a correlation between pitch and engine revs
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1