Question: Intro To Java Programming, debug method help. I'm not sure why this method isn't working the way I want it to. public void concatenateSound(Sound firstSound,
Intro To Java Programming, debug method help.
I'm not sure why this method isn't working the way I want it to.
public void concatenateSound(Sound firstSound, Sound secondSound, int switchPoint) { int endOfOriginal = this.getLength(); int endOfFirstSound = firstSound.getLength(); int endOfSecondSound = secondSound.getLength(); for (int index = 0; index < endOfOriginal; index++) { if (endOfFirstSound < switchPoint) { for (int shortFirstSound = 0; shortFirstSound < endOfFirstSound; shortFirstSound++) { this.setSampleValueAt(shortFirstSound, firstSound.getSampleValueAt(shortFirstSound)); } for (int secondSoundA = endOfFirstSound, secondSoundLength = 0; secondSoundA < endOfOriginal && secondSoundLength < endOfSecondSound; secondSoundA++, secondSoundLength++) { this.setSampleValueAt(secondSoundA, secondSound.getSampleValueAt(secondSoundLength)); } } else if (switchPoint < endOfFirstSound) { for (int longFirstSound = 0; longFirstSound < switchPoint; longFirstSound++) { this.setSampleValueAt(longFirstSound, firstSound.getSampleValueAt(longFirstSound)); } for (int secondSoundB = switchPoint, secondSoundLength = 0; secondSoundB < (endOfOriginal - 1) && secondSoundLength < endOfSecondSound; secondSoundB++, secondSoundLength++) { this.setSampleValueAt(secondSoundB, secondSound.getSampleValueAt(secondSoundLength)); } } } }
This method is similar to the first concatenateSound method, except that it takes a third argument, switchPoint, which specifies the number of samples that should be copied from the first sound before switching to the second sound. For example, if switchPoint is 100, then the method will copy the first 100 samples from firstSound into the first 100 positions in the SoundSample array in the calling object, and then copy the complete secondSound (all of its SoundSamples) starting at index 100 in the SoundSample array in the calling object.
Some notes:
If the switchPoint is longer than the firstSound, the whole firstSound should be copied, followed immediately by the whole secondSound. I.e. it should behave exactly like the first version of this method.
If the switchPoint is negative or 0, this method should not copy any of the firstSound and copy only the secondSound, starting at position 0 in the calling object.
The calling object might not be long enough to hold the sounds to be copied. Whenever enough samples have been copied to fill the calling objects Sound, the copying should simply stop. This means that the method might not copy any of the secondSound, or it might even copy fewer than switchPoint samples from the firstSound.
If the total number of samples copied into the calling object (from both firstSound and secondSound) is less than the length of the calling objects SoundSample array, the rest of the calling objects SoundSample array should be filled with 0s (to make it silent).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
