Guitar Simulation with Keyboard

Page 1 of 1

1 Replies - 10182 Views - Last Post: 18 April 2009 - 03:20 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=100060&amp;s=eb1ff3527ff15ca59f85d1d7062864d1&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 mandee2422

Reputation: 0
• Posts: 1
• Joined: 17-April 09

Guitar Simulation with Keyboard

Posted 17 April 2009 - 05:22 PM

I am taking a beginner Computer Science class in college, focusing on Java. We have to create a guitar simulation, supporting 37 notes, which are:

String keyboard = "1234567890qwertyuiopasdfghjklzxcvbnm,";

The ith character must correspond to a frequency of 440 x 2^((i-24)/12). We already have access to StdAudio, StdDraw, RingBuffer and GuitarString (the last 2 model the string vibration) Here is my code so far. We need to use an array of 37 GuitarString objects:

```

public class GuitarHero {
public static void main(String[] args) {

String keyboard ="1234567890qwertyuiopasdfghjklzxcvbnm,";
int index;

double sample = 0.0;

GuitarString[] strings = new GuitarString [37];

for(int a =0; a<37; a++){
double concert = 440.0 * Math.pow(2, (a - 24)/12);
strings[a] = new GuitarString(concert); }

while (true) {

// check if the user has typed a key; if so, process it
if (StdDraw.hasNextKeyTyped()) {
char key = StdDraw.nextKeyTyped();
index = keyboard.indexOf(key);
if	  (index >= 0 && index < 37)  { strings[index].pluck(); }
}

// compute the superposition of samples
for(int a=0; a < 37; a++){
sample = strings[a].sample();

// send the result to the sound card
StdAudio.play(sample);}

// advance the simulation of each guitar string by one step
for(int a=0; a < 37; a++){
strings[a].tic(); }

}
}
}

```

When I run the program, and press keys all I get is this static sound that never ends. I understand that for the first for loop, the int a must correspond to the index, as should int i and int j, but I am not sure how to go about this. Also I know the increasing operator ++ isn't quite right, but I'm not sure what else to use. This is my first (and hopefully only) Java class. Any help would be greatly appreciated!!!!

Amanda

This post has been edited by mandee2422: 17 April 2009 - 05:24 PM

Is This A Good Question/Topic? 0

Replies To: Guitar Simulation with Keyboard

#2 pbl

• There is nothing you can't do with a JTable

Reputation: 8365
• Posts: 31,956
• Joined: 06-March 08

Re: Guitar Simulation with Keyboard

Posted 18 April 2009 - 03:20 PM

mandee2422, on 17 Apr, 2009 - 04:22 PM, said:

I am taking a beginner Computer Science class in college, focusing on Java.

And you qualified your post as "intermediate" ?
On the other hand your frequency stuff is "expert" stuff to me
And where is the definition of your GuitarString class ?

This post has been edited by pbl: 18 April 2009 - 03:25 PM