Results 1 to 5 of 5
- 12-05-2008, 04:40 AM #1
Combining Individual Sounds - Urgent
All right, I don't usually do this, but I've come for you for homework help. I have an assignment due tomorrow, and I can't figure out what's wrong with my program. I'm not asking for an answer -- I don't want to cheat -- I just need a little guidance.
The assignment is to create a "sentence" of Sound objects, each sound being one word. I have the algorithm, but I'm just not coding it right, apparently. First I load the three audio files of the three words I want to make the sentence out of: "always," "and," and "around." I'm looping through each SoundSample in the first word and copying them into a newly created empty Sound object, and I do the same for each word, but my output is simply the first word (with a lot of silence afterward).
I can't figure out why the other two words aren't being copied. Could someone help? My code is below. It uses an outside library (including Sound, SoundSample created by the course creators; I believe my program should be readable without me having to post the separate classes.
Java Code:// A class to create an audio sentence out of individual words // Coded on December 1, 2008 // by Jared Cerbin public class CreateSentence { /** * Run the program. * @param args the command line arguments */ public static void main(String[] args) { Sound word1 = new Sound(FileChooser.getMediaPath("always.wav")); Sound word2 = new Sound(FileChooser.getMediaPath("and.wav")); Sound word3 = new Sound(FileChooser.getMediaPath("around.wav")); Sound[] sentence = {word1, word2, word3}; makeSentence(sentence, 1).explore(); } /** * Make the sentence with specified words and specified pause length * @return the sentence * @param soundArray an array of Sound objects to make the sentence * @param pauseLength the length of the pause between the words, in tens of seconds */ public static Sound makeSentence(Sound[] soundArray, int pauseLength) { // Create constants for the number of words in the sentence // and the sampling rate of the sentence, and create variables // for the number of samples in each word and the total samples // in the finished sentence final int NUMBER_OF_WORDS = soundArray.length; final double SAMPLING_RATE = soundArray[0].getSamplingRate(); int[] numberOfSamples = new int[NUMBER_OF_WORDS]; int totalSamples = 0; // Loop through the words for(int i = 0; i < NUMBER_OF_WORDS; i++) { // Get the number of samples in each word and add // the number to the total number of samples numberOfSamples[i] = soundArray[i].getNumSamples(); totalSamples += numberOfSamples[i]; } // Add the samples for the pauses to the total totalSamples += pauseLength * 0.1 * SAMPLING_RATE; // Create an empty Sound object with the necessary length Sound sentence = new Sound(totalSamples); int j = 0; // Loop as many times as there are words for(int i = 0; i < NUMBER_OF_WORDS; i++) { // Create an array of SoundSample objects of the current word SoundSample[] wordSamples = soundArray[i].getSamples(); // Loop through the SoundSamples in the new array while(j < soundArray[i].getNumSamples()) { // Set the value in the sentence to the value in the word sentence.setSampleValueAt(j, soundArray[i].getSampleValueAt(j)); j++; } } return sentence; } }"Things are made of littler things that jiggle."
-
I have no idea since I'm not familiar with the Sound class. Question though, why do you make the wordSamples array but don't use it?
- 12-05-2008, 04:58 AM #3
Ah! I think I found the error! You're right, I'm not using wordSamples. I think I need to put it in the inside loop. I'll test around and post back soon. Thanks!
"Things are made of littler things that jiggle."
- 12-05-2008, 05:15 AM #4
Yes! I got it! Thanks for your help!
"Things are made of littler things that jiggle."
-
Similar Threads
-
Wave Sounds
By Doctor Cactus in forum New To JavaReplies: 2Last Post: 10-22-2008, 01:44 PM -
Turn off sounds in Eclipse
By gio.fou in forum EclipseReplies: 2Last Post: 09-06-2008, 08:31 PM -
Help combining loops into 1 program.
By kewlgeye in forum New To JavaReplies: 5Last Post: 04-22-2008, 09:58 AM -
How to cancel an individual timer in spite of canceling whole timer
By Java Tip in forum java.utilReplies: 0Last Post: 04-04-2008, 02:46 PM -
Sounds don't play when running applet
By leonard in forum Java AppletsReplies: 1Last Post: 08-06-2007, 08:08 PM


LinkBack URL
About LinkBacks

Bookmarks