473,325 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Java Audio Help Plz

9
3 methods needs doing;

wave1: This static method takes an AudioInputStream and gradually lowers and then raises the volume so that the new AudioInputStream appears to be constantly alerting in volume.

wave2: This static method takes an AudioInputStream and alters it so that it seems to move from left to right. The resultant new audio stream is then returned.
down: This static method takes a 16 bit AudioInputStream and returns an AudiInputStream converted to an 8 bit AudioInputStream.

====================================


import javax.sound.sampled.*;
import java.io.*;
public class AudioManipulation {


/**
* Creating an echo.
* Out of a given AudioInputSteam a new one is created with an additional echo effect.
*
* @param ais the original sound
* @param delay the delay of the echo in mili seconds.
* @param fading the strength of the echo
*/
public static AudioInputStream echo(AudioInputStream ais, int delay, double fading) {

byte[] a=null;
int[] data;
int max;

try{
delay=(int) (delay*ais.getFormat().getFrameSize()*
ais.getFormat().getFrameRate()/1000);

// reset the AudioInputStream
ais.reset();

// create a byte array of the right size
a=new byte[(int) ais.getFrameLength() *
ais.getFormat().getFrameSize()];

// fill the byte array with the data of the AudioInputStream
ais.read(a);

// Create an integer array of the right size
data=new int[a.length/2];

// fill the integer array by combining two bytes of the
// byteArray to one integer
for (int i=0;i<data.length;++i) {
data[i]=a[2*i]*256+a[2*i+1];
}


// Adding a faded copy of the signal to the later measurements
for (int i=0; i<data.length-delay;++i) {
data[i+delay] += (int) (data[i]*fading);
}


// get the maxium amplitute
max=0;
for (int i=0;i<data.length;++i) {
max=Math.max(max,Math.abs(data[i]));
}

// scale the maximum amplitude down to 256*128
if (max > 256*128)
for (int i=0; i<data.length;++i) {
data[i] = (int) (data[i]*(256.0*256.0/2-1)/max);
}

// convert the integer array to a byte array
for (int i=0;i<data.length;++i) {
a[2*i]=(byte) (Math.round(data[i]/256.0));
a[2*i+1]=(byte) (data[i]-(a[2*i]*256));
}

} catch(Exception e){
System.out.println("Something went wrong");
e.printStackTrace();

}

// create a new AudioInputStream out of the the byteArray
// and return it.
return new AudioInputStream(new ByteArrayInputStream(a),
ais.getFormat(),ais.getFrameLength());
}

/**
* Creates a wave pattern out of a given sound.
* A new AudioInputStream is created with an additional wave effect.
* In the new sound the volume goes up and down in fixes intervals.
* If i is the length of the interval, then the amplitude of a sound
* at position x will be modified by a factor
* abs( 2 * ((x % i) / i -0.5))
*
* @param ais the original sound
* @param interval the length of the interval
*/
public static AudioInputStream wave1(AudioInputStream ais, int interval) {

// add your code here and change the return statement

return ais;
}


/**
* Creates a wave pattern out of a given sound.
* A new AudioInputStream is created with an additional wave effect.
* In the new sound the volume of the two channels goes up and down,
* which creates the effect that sound moves from the left to right
* and back.
* If i is the length of the interval, then the amplitude for the left channel
* at position x will be modified by a factor
* abs(2*((x % i) / i-0.5))
* and for the right channel
* abs(2*(((x+i/2) % i)/ i -0.5))
*
* @param ais the original sound
* @param interval the length of the interval
*/
public static AudioInputStream wave2(AudioInputStream ais,
int interval) {

// add your code here and change the return statement

return ais;
}


/**
* Convert a given sound from 16 bit to 8bit.
* A new AudioInputStream is created representing the originial sound in 8 bit.
*
* @param ais the original sound
*/
public static AudioInputStream down(AudioInputStream ais) {

// add your code here and change the return statement

return ais;
}


}
Nov 14 '06 #1
1 2339
mmc
9
?

?

? no one?
Nov 15 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Josh | last post by:
I am having a problem with sound in my program, it takes information from a TargetDataLine, put's it in a temporary file, then takes it back out of the temporary file and plays it using a...
3
by: SOB-like MIDIs | last post by:
The applet for endlessly rising/falling scale (auditory illusion) on this page is fantastic! http://www.cs.ubc.ca/nest/imager/contributions/flinn/Illusions/ST/st.html How is this done?...
1
by: nemokid | last post by:
hi all, i need to write an application that listen for DTMF tones from standard audio input (from the mic) and execute an action depending on the digit extracted from the DTMF tone. Unfortunaly i...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
1
by: dlarsson | last post by:
Music CD experts: So, here's my problem. I burned (or tried to burn) my first audio or music CD on my computer using Windows Media Player. I "Rip-ed" the tracks from a source CD and...
1
by: VB.NET | last post by:
I've seen tons of image galleries in java, but has anyone seen a fancy way of showcasing audio files?
1
by: cyberbrain7 | last post by:
Please help me how to add audio application (not applet) using java. Thanks!!!
1
by: pankhudi | last post by:
Hi everyone... I have to do a project work related on online audio system in Java...I have done the server-client prog(socket prog) n playing audio files..But how to stream my audio file from one PC...
63
by: s0suk3 | last post by:
I've been programming Python for a couple of years now. Now I'm looking to move on to either C++ or Java, but I'm not sure which. Which one do you think will be a better transition for a Python...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.