Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-05-2008, 06:40 AM
JDCAce's Avatar
Member
 
Join Date: Oct 2008
Location: Columbus, GA, US
Posts: 29
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
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
Sponsored Links
  #2 (permalink)  
Old 12-05-2008, 06:48 AM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 1,289
Fubarable is on a distinguished road
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, 06:58 AM
JDCAce's Avatar
Member
 
Join Date: Oct 2008
Location: Columbus, GA, US
Posts: 29
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
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, 07:15 AM
JDCAce's Avatar
Member
 
Join Date: Oct 2008
Location: Columbus, GA, US
Posts: 29
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
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, 07:17 AM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 1,289
Fubarable is on a distinguished road
I'm not sure what I did, but I'm glad to help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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 03:44 PM
Turn off sounds in Eclipse gio.fou Eclipse 2 09-06-2008 10:31 PM
Help combining loops into 1 program. kewlgeye New To Java 5 04-22-2008 11:58 AM
How to cancel an individual timer in spite of canceling whole timer Java Tip java.util 0 04-04-2008 04:46 PM
Sounds don't play when running applet leonard Java Applets 1 08-06-2007 10:08 PM


All times are GMT +3. The time now is 09:23 AM.


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