Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-05-2008, 04:40 AM
JDCAce's Avatar
Member
 
Join Date: Oct 2008
Location: Columbus, GA, US
Posts: 29
Rep Power: 0
JDCAce is on a distinguished road
Send a message via AIM to JDCAce Send a message via MSN to JDCAce Send a message via Yahoo to JDCAce Send a message via Skype™ to JDCAce
Default 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.

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."
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-05-2008, 04:48 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,189
Rep Power: 5
Fubarable is on a distinguished road
Default
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?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-05-2008, 04:58 AM
JDCAce's Avatar
Member
 
Join Date: Oct 2008
Location: Columbus, GA, US
Posts: 29
Rep Power: 0
JDCAce is on a distinguished road
Send a message via AIM to JDCAce Send a message via MSN to JDCAce Send a message via Yahoo to JDCAce Send a message via Skype™ to JDCAce
Default
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."
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-05-2008, 05:15 AM
JDCAce's Avatar
Member
 
Join Date: Oct 2008
Location: Columbus, GA, US
Posts: 29
Rep Power: 0
JDCAce is on a distinguished road
Send a message via AIM to JDCAce Send a message via MSN to JDCAce Send a message via Yahoo to JDCAce Send a message via Skype™ to JDCAce
Default
Yes! I got it! Thanks for your help!
__________________
"Things are made of littler things that jiggle."
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-05-2008, 05:17 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,189
Rep Power: 5
Fubarable is on a distinguished road
Default
I'm not sure what I did, but I'm glad to help.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wave Sounds Doctor Cactus New To Java 2 10-22-2008 01:44 PM
Turn off sounds in Eclipse gio.fou Eclipse 2 09-06-2008 08:31 PM
Help combining loops into 1 program. kewlgeye New To Java 5 04-22-2008 09:58 AM
How to cancel an individual timer in spite of canceling whole timer Java Tip java.util 0 04-04-2008 02:46 PM
Sounds don't play when running applet leonard Java Applets 1 08-06-2007 08:08 PM


All times are GMT +2. The time now is 06:09 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org