Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help creating a java program with the following requirements listed below

ID: 3841528 • Letter: I

Question

I need help creating a java program with the following requirements listed below. Please make the code as simple to follow and understand as possible.

The Chord class n the package you will create a reference class called chord. A chord consists of a duration in seconds (a double value) and a sequence of frequencies (an array of double values). These will be the instance variables. It has the followingAPI: public Chord (double duration. double frequencies This is the constructor NB: Inthis constructor copy the values in the parameters frequencies to the instance variable frequencies. Use a for loop to do this public void play(): This plays the chord by calling the playChord method, a private method whose code is provided below. public string tos tring This returns a string version of a chord object. It should be formatted as the duration, followed by a colon, followed by the frequencies, a enclosed in square brackets. For example, if the durations is 1.5 and the frequencies are 440.0, 880.0, and 1760.0, this method would return [1. 5 440.0 880. 0 1760. oj The play Chord method: private void playchord (double duration double C1 frequencies final int slicecount int) (stdAudio. SAMPLE RATE duration final double slices E new double slice Count+1] for int i E 0 i

Explanation / Answer



public class Chords
{
private static final int MAX_VOICES = 8;
private Synthesizer syn;
private VoiceAllocator alloc;
private LineOut lineOut;
private double adv= 0.3;
private double secondsPerBeat = 0.7;
private double dutyCycle = 0.9;
private double measure = secondsPerBeat * 5.0;
private SubtractiveSynthVoice[] voices;

private void test()
{
syn = JSyn.createSynthesizer();

syn.add( lineOut = new LineOut() );

voices = new SubtractiveSynVoice[MAX_VOICES];
for( int k = 0; k< MAX_VOICES; k++ )
{
SubtractiveSynthVoice voice = new SubtractiveSynthVoice();
synth.add( voice );
voice.getOutput().connect( 0, lineOut.input, 0 );
voice.getOutput().connect( 0, lineOut.input, 1 );
voices[i] = voice;
}
alloc = new VoiceAllocator( voices );

syn.start();

lineOut.start();

double timeNow = syn.getCurrentTime();

double time = timeNow + 1.0;

try
{
int tonic = 80 - 14;
for( int k = 0; k < 4; k++ )
{
playMajorMeasure1( time, tonic );
time += measure;
catchUp( time );
playMajorMeasure1( time, tonic + 5 );
time += measure;
catchUp( time );
playMajorMeasure1( time, tonic + 8 );
time += measure;
catchUp( time );
playMinorMeasure1( time, tonic + 3 );
time += measure;
catchUp( time );
}
time += secondsPerBeat;
catchUp( time );

} catch( InterruptedException e )
{
e.printStackTrace();
}
.
syn.stop();
}

private void playMinorMeasure1( double time, int base )
throws InterruptedException
{
int p1 = base;
int p2 = base + 3;
int p3 = base + 7;
playChord1( time, p1, p2, p3 );
playNoodle1( time, p1 + 24, p2 + 24, p3 + 24 );
}

private void playMajorMeasure1( double time, int base )
throws InterruptedException
{
int p1 = base;
int p2 = base + 4;
int p3 = base + 7;
playChord1( time, p1, p2, p3 );
playNoodle1( time, p1 + 24, p2 + 24, p3 + 24 );
}

private void playNoodle1( double time, int p1, int p2, int p3 )
{
double secondsPerNote = secondsPerBeat * 0.5;
for( int i = 0; i < 8; i++ )
{
int p = pickFromThree( p1, p2, p3 );
noteOn( time, p );
noteOff( time + dutyCycle * secondsPerNote, p );
time += secondsPerNote;
}
}

private int pickFromThree( int p1, int p2, int p3 )
{
int r = (int) (Math.random() * 3.0);
if( r < 1 )
return p1;
else if( r < 2 )
return p2;
else
return p3;
}

private void playChord1( double time, int p1, int p2, int p3 )
throws InterruptedException
{
double dur = dutyCycle * secondsPerBeat;
playTriad( time, dur, p1, p2, p3 );
time += secondsPerBeat;
playTriad( time, dur, p1, p2, p3 );
time += secondsPerBeat;
playTriad( time, dur * 0.25, p1, p2, p3 );
time += secondsPerBeat * 0.25;
playTriad( time, dur * 0.25, p1, p2, p3 );
time += secondsPerBeat * 0.75;
playTriad( time, dur, p1, p2, p3 );
time += secondsPerBeat;
}

private void playTriad( double time, double dur, int p1, int p2, int p3 )
throws InterruptedException
{
noteOn( time, p1 );
noteOn( time, p2 );
noteOn( time, p3 );
double offTime = time + dur;
noteOff( offTime, p1 );
noteOff( offTime, p2 );
noteOff( offTime, p3 );
}

private void catchUp( double time ) throws InterruptedException
{
synth.sleepUntil( time - advance );
}

private void noteOff( double time, int noteNumber )
{
allocator.noteOff( noteNumber, new TimeStamp( time ) );
}

private void noteOn( double time, int noteNumber )
{
double frequency = convertPitchToFrequency( noteNumber );
double amplitude = 0.2;
TimeStamp timeStamp = new TimeStamp( time );
allocator.noteOn( noteNumber, frequency, amplitude, timeStamp );
}

double convertPitchToFrequency( double pitch )
{
final double concertA = 440.0;
return concertA * Math.pow( 2.0, ((pitch - 69) * (1.0 / 12.0)) );
}

public static void main( String[] args )
{
new PlayChords().test();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote