473,785 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Audio Help Plz

9 New Member
3 methods needs doing;

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

wave2: This static method takes an AudioInputStrea m 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 AudioInputStrea m and returns an AudiInputStream converted to an 8 bit AudioInputStrea m.

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


import javax.sound.sam pled.*;
import java.io.*;
public class AudioManipulati on {


/**
* 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 AudioInputStrea m echo(AudioInput Stream ais, int delay, double fading) {

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

try{
delay=(int) (delay*ais.getF ormat().getFram eSize()*
ais.getFormat() .getFrameRate()/1000);

// reset the AudioInputStrea m
ais.reset();

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

// fill the byte array with the data of the AudioInputStrea m
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.leng th;++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.leng th;++i) {
max=Math.max(ma x,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.leng th;++i) {
a[2*i]=(byte) (Math.round(dat a[i]/256.0));
a[2*i+1]=(byte) (data[i]-(a[2*i]*256));
}

} catch(Exception e){
System.out.prin tln("Something went wrong");
e.printStackTra ce();

}

// create a new AudioInputStrea m out of the the byteArray
// and return it.
return new AudioInputStrea m(new ByteArrayInputS tream(a),
ais.getFormat() ,ais.getFrameLe ngth());
}

/**
* Creates a wave pattern out of a given sound.
* A new AudioInputStrea m 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 AudioInputStrea m wave1(AudioInpu tStream 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 AudioInputStrea m 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 AudioInputStrea m wave2(AudioInpu tStream 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 AudioInputStrea m is created representing the originial sound in 8 bit.
*
* @param ais the original sound
*/
public static AudioInputStrea m down(AudioInput Stream ais) {

// add your code here and change the return statement

return ais;
}


}
Nov 14 '06 #1
1 2362
mmc
9 New Member
?

?

? no one?
Nov 15 '06 #2

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

Similar topics

2
4127
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 SourceDataLine. currently, it does not play back. andrewjj20 the play method: class Player implements Runnable { public Player() {
3
6994
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? (I'm assuming it uses MIDI.)
1
4318
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 have short time to set up this application and i'm really new to this kind of problem (sound analisys). I take a look at JTAPI but i don't have any telephone in this context, i just have to analyze a normal sound signal from the sound card. I...
11
9271
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 C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
1
3430
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 then put
1
2755
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
1450
by: cyberbrain7 | last post by:
Please help me how to add audio application (not applet) using java. Thanks!!!
1
1813
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 to other using Java(using socket programming) So i wanted to know whether it's possible?How?We have not been taught JMf..So still any hope.. Please help i hav 2 submit this within 15 days..
63
4992
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 programmer? Which one will educate me the best?
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.