Results 1 to 5 of 5
- 01-31-2011, 11:08 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
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;
}
- 01-31-2011, 11:27 PM #2
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.
- 01-31-2011, 11:52 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
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.
- 01-31-2011, 11:54 PM #4
So.. Take the size of the whole thing... divide by 2... Start there!
- 02-01-2011, 12:23 AM #5
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
problem in the half of odd integer
By matin1234 in forum New To JavaReplies: 5Last Post: 06-03-2010, 03:03 AM -
loop in a half
By Brain_Child in forum New To JavaReplies: 4Last Post: 12-02-2009, 03:00 AM -
Reversing
By whosadork in forum New To JavaReplies: 14Last Post: 11-06-2008, 04:29 AM -
Telecommute only at half rate
By Johnny Kewl in forum Jobs WantedReplies: 0Last Post: 05-11-2008, 04:05 PM -
Half a semester into java
By apfroggy0408 in forum New To JavaReplies: 3Last Post: 12-17-2007, 10:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks