Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Comments on Week of 31 Jan 2005


Comments? Questions?

Here's the last state of the code for insertAfter from this morning. Mark Guzdial
  /**
   * insert the input Sound after the nth sample (input integer).
   * Modifies the given sound
   * @param insound Sound to insert
   * @param start index where to start inserting the new sound
  **/
  public void insertAfter(Sound inSound, int start){

    SoundSample current=null;
    // Find how long insound is
    int amtToCopy = inSound.getLength();
    int endOfThis = this.getLength()-1;
    // If too long, copy only as much as will fit
    if (start + amtToCopy > endOfThis)
    {amtToCopy = endOfThis-start-1;}
    else {
      // ** First, clear out room.
      // Copy from start up to start+amtToCopy
      for (int i=start; i < start+amtToCopy-1 ; i++)
      {
        current = this.getSample(i+amtToCopy);
        current.setValue(this.getSampleValueAt(i));
      }}

    //** Second, copy in inSound up to amtToCopy
    for (int target=start,source=0;
         source < amtToCopy;
         target++, source++) {
      current = this.getSample(target);
      current.setValue(inSound.getSampleValueAt(source));
    }
  }



Okay, I think that this version works. The big insight that helped me understand this was the answer to this question: When you insert a smaller sound into a bigger sound and shift down samples, how many samples get lost off the end? Answer: amtToCopy – the amount that you shifted in! So, the sample that's at endOfThis-amtToCopy gets moved to endOfThis, and so on, up to start. Mark Guzdial

  /**
   * insert the input Sound after the nth sample (input integer).
   * Modifies the given sound
   * @param insound Sound to insert
   * @param start index where to start inserting the new sound
  **/
  public void insertAfter(Sound inSound, int start){

    SoundSample current=null;
    // Find how long insound is
    int amtToCopy = inSound.getLength();
    int endOfThis = this.getLength()-1;

    if (start + amtToCopy > endOfThis)
    {// If too long, copy only as much as will fit
      amtToCopy = endOfThis-start-1;}
    else {
      // If short enough, need to clear out room.
      // Copy from endOfThis-amtToCopy;, moving backwards
      // (toward front of list) to start,
      // moving UP (toward back) to endOfThis
      // KEY INSIGHT: How much gets lost off the end of the
      // array?  Same size as what we're inserting -- amtToCopy
      for (int source=endOfThis-amtToCopy; source > start ; source--)
      {
        // current is the TARGET -- where we're copying to
        current = this.getSample(source+amtToCopy);
        current.setValue(this.getSampleValueAt(source));
      }
    }

    // NOW, copy in inSound up to amtToCopy
    for (int target=start,source=0;
         source < amtToCopy;
         target++, source++) {
      current = this.getSample(target);
      current.setValue(inSound.getSampleValueAt(source));
    }
  }


re: hw3
is there a way to add jmusic notes to our audio collage method?

There is. Here are two different ways. (1) I'll show you Wed. that you can output a MIDI file from JMusic really easily. QuickTime Pro can read in MIDI and generate a WAV from from it. You could then include that WAV file in your collage. (2) JMusic can actually do all kinds of cool things with sampled sounds (WAV files) including generating WAV files–but I've never used those facilities. You're welcome to read through the documentation on JMusic and see if you can get it do that. If you use some JMusic sampled sound methods in your collage, I'll give you five extra points on HW3. Mark Guzdial


For the Midterm next week... will there be any study guides or practice things for us to review...? gracias!

Check your neighborhood Hotspots now! Mark Guzdial

another question about hw3. is there a method to speed up a sound? i noticed that after converting a midi to a wav it somehow slows down.
Yup – scale it. Mark Guzdial

if i were to write a method, how would it work?
Hmm, depends on what you want the method to do? Mark Guzdial

found a way to do it in window's wav recorder, but i am still curious as to how to write a method for it.

is there not a hw3 questions page?

there is not
Is now. Mark Guzdial




Link to this Page