Results 1 to 5 of 5
  1. #1
    sunshine64 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Unhappy Reversing half a sound and putting it at the front

    I will admit this is a class project and I don't want the answer. I just want a shove in the right direction. I need to take a sound and reverse the second half of it and then place that reversed half at the beginning of the sound. I simply do not know where to begin. Please help.
    This is what the reverseSnd looks like:

    public Sound reverseSnd() {

    Sound target = new Sound(getLength());
    int sampleValue;

    for (int srcIndex = 0, trgIndex = getLength() - 1; srcIndex < getLength(); srcIndex++, trgIndex--) {
    sampleValue = this.getSampleValueAt(srcIndex);
    target.setSampleValueAt(trgIndex, sampleValue);
    }

    return target;
    }

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    First off, Welcome! Second, please put your code in [code][/code] tags so its easy to read.

    So, you're off to a good start. You'll also need to copy the first half of the unaltered sound into the second half of the new array - right now I only see the reversed second half being copied. Second, you will need to take your sample size into account. If the sound file is 16bit, then you need to read pairs of bytes, and make sure not to reverse the order of the pair, rather the sequence of the pair in the sound. For example, if we had a series of sound samples: A, B, C, D, ... , N and it was a 16 bit song, every sample would be represented with two bytes: A1A2, B1B2, C1C2, D1D2, ..., N1N2. It is important when reversing the soundtrack not to alter the relationship between 1 and 2, just the order of the samples. So a correct example would be:
    N1N2, ..., D1D2, C1C2, B1B2, A1A2
    not
    N2N1, ..., D2D1, C2C1, B2B1, A2A1

    The reason for this is that 16bit samples use 2 bytes to store a large number in binary, i.e. 10110000 11110101 which is 45301 as an unsigned int. If you change the order of these two bytes to 11110101 10110000 you get 62896 which is a totally different sample value, not the same sample in reverse. This kind of transformation would produce garbage. However, reading the two bytes as 2byte chucks and keeping their order the same respective to each byte, but reversing them with respect to each sample will produce a 'backwards' sound.

    Sorry if thats complicated, but high bit-rate sounds are tricky to deal with. With any luck, you're using 8 bit samples which simplifies things greatly.

  3. #3
    sunshine64 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Well that just went way over my head...I am just using simple sounds (mono) 8 bits. As for the reverse, it is actually reversing the entire thing. I don't know how to get it to do just the second half. Then I have to take that and have it play first and then the first non-reversed half play second.

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    So.. Take the size of the whole thing... divide by 2... Start there!

  5. #5
    sunshine64 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Heh heh...believe me, I've tried. The result is a slowed down reversed sound. It sounds rather cool but not what I want. I will keep playing with it.

Similar Threads

  1. problem in the half of odd integer
    By matin1234 in forum New To Java
    Replies: 5
    Last Post: 06-03-2010, 04:03 AM
  2. loop in a half
    By Brain_Child in forum New To Java
    Replies: 4
    Last Post: 12-02-2009, 04:00 AM
  3. Reversing
    By whosadork in forum New To Java
    Replies: 14
    Last Post: 11-06-2008, 05:29 AM
  4. Telecommute only at half rate
    By Johnny Kewl in forum Jobs Wanted
    Replies: 0
    Last Post: 05-11-2008, 05:05 PM
  5. Half a semester into java
    By apfroggy0408 in forum New To Java
    Replies: 3
    Last Post: 12-17-2007, 11:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •