Synch 2 similar audio input (one by file and one by microphone) - java

i have 2 audio input of a concert.
The first is a wav file and the second is taken by microphone in real time.
I need play the first file in synch with the microphone input.
What library can i use?
Is there any tutorial, guide or example for do this?
thanks

Take a look here
This is entire sound api documentation
http://download.oracle.com/javase/1.5.0/docs/guide/sound/programmer_guide/
Also
Chapter 4: Synchronizing Playback on Multiple Lines
Chapter 6: Processing Audio with Controls
BUT
here is what i found in jsresource faq
How can I synchronize two or more playback lines ?
The synchronization functions in Mixer are not implemented. Nevertheless, playback typically stays in sync
How can I synchronize playback (SourceDataLines) with recording (TargetDataLines)?
As with multiple playback lines from the same Mixer object, playback and recording lines from the same Mixer object stay in sync once they are started. In practice, this means that you can achieve synchronization this easy way only by using the "Direct Audio Device" mixers. Since the "Java Sound Audio Engine" only provides playback lines, but no recording lines, playback/recording sync is not as easy with the "Java Sound Audio Engine".
If playback and recording lines originate from different Mixer objects, you need to synchronize the soundcards that are represented by the Mixer objects. So the situation is similar to external synchronization.
AND
The main problem is buffering and processing mic audio hits and timing realtime , a practical way is using external clock
And here is a bunch of java sound resources , i think u should look at monitoring sound section in api documentation and try to trigger timedelay based on hits and monitor outputs , it's little complicated i also interested in this question i will try to find out if i did i will let u know
Take a look at this links and it's going to be easy as i found and read description of this processing libraries
http://sonia.pitaru.com/
http://visualap.java.net/
http://www.softsynth.com/jsyn/ Check this out
http://jmetude.dihardja.de/
http://www.tree-axis.com/Ess/
http://www.abstract-codex.net/tactu5/index.html
http://code.google.com/p/echonestp5/

Related

adding sfx on Clip object in java

I'm working on a project where I will have one 24-hours long sound clip which has different phases based on local daytime (morning phase has one sound, transition phases, evening phase, etc.)
so here is what i got now, and it's ok
method that plays the clip (turns current local time in microseconds and sets starting point to match current time - if i start program 13:35 it will start playing mid-day phase of sound which is on that position, and it's ok
void playMusic(String musicLocation){
try{
File musicPath = new File(musicLocation);
if(musicPath.exists())
{
Calendar calendar = Calendar.getInstance();
//Returns current time in millis
long timeMilli2 = calendar.getTimeInMillis();
System.out.println("Time in milliseconds using Calendar: " + (timeMilli2 * 1000)) ;
AudioInputStream audioInput = AudioSystem.getAudioInputStream(musicPath);
Clip clip = AudioSystem.getClip();
clip.open(audioInput);
clip.setMicrosecondPosition(12345678);
clip.start();
clip.loop(Clip.LOOP_CONTINUOUSLY);
System.out.println(clip.getMicrosecondLength());
//setFramePosition
JOptionPane.showMessageDialog(null, "Press OK to stop playung");
}
else
{
System.out.println("no file");
}
}catch(Exception ex){
ex.printStackTrace();
}
}
main method that just calls this method
public static void main(String[] args) {
String filepath = "src/sounds/test_file.wav";
PyramidMethods pyra = new PyramidMethods();
pyra.playMusic(filepath);
}
now this is pretty simple and straightforward, and also what I need, but now what i wonder is the following -> can I and if can, how, add sound effects based on the temperature outside?
so what I was thinking is to open separate thread in main which would regularly check some wheather API and when temperature changes add sound effects like echo, distortion or something else based on temperature change (if it's colder then x it would put echo sound effect on running clip, etc.)
it this even possible in Java? it's my first time using sounds with Java so I am even inexperienced with the search terms here, would someone suggest some other programming language for it?
thanks for your answers in advance.
That must be a huge file!
Yes, Java works quite well for creating and managing soundscapes.
It is possible to play and hear different Clips at the same time. When you play them, Java automatically creates a Thread for that playback, and most operating systems will mix together all the playing threads. At one time there were Linux systems that only allowed a single output. IDK if that is still a limitation or if you are even targeting Linux systems. Also, there is going to be a ceiling on the total number of sound playbacks that an OS will be able to handle cleanly. (Usually what happens is you get dropouts if you overstress the system in this way.)
To manage the sounds, I'd consider using a util.Timer (not the Swing.Timer), and check the time and date (and weather if you have an API for that) with each iteration before deciding what to do with the constituent cues of your mix. Or maybe use an util.concurrent.ExecutorService. If your GUI is JavaFX, an AnimationTimer is also a reasonable choice.
If you do prefer to mix the sound files down to a single output line, this can most easily be done by using a library such as TinySound or AudioCue. With AudioCue (which I wrote) you can both mix down to a single output, and have guaranteed volume, panning and even playback speed management for each sound cue that is part of your "soundscape".
This could help with lowering the total amount of RAM needed to run program. As I show in a demo, one can take a single cue (e.g. a frog croak) and play it multiple times as different volumes, pans, and speeds to create the illusion of a whole pond of frogs croaking. Thus, a single .wav, only a second in length can be used to simulate a .wav that is hours in length.
I think if you want to add effects like echo or distortion, you will have to use a library or write your own. Java supports Processing Audio with Controls, but this is highly dependent upon the OS of the computer being used. Echo and Distortion are not terribly difficult to write though, and could be added to the AudioCue library code if you have incorporated that into your program. (Echo involves adding a time delay, usually using an array to hold sound data until it is time for it to play, and Distortion involves running the PCM sound data through a transform function, such as Math.tanh and a max and min to keep the results within the [-1, 1] range.)
For other possible libraries or languages, I believe both Unity (C#) and Unreal (C++) game engines/environments have extensive array of audio effects implemented, including 3D handling.

Encountered LineUnavailableException when capturing sound with Java Sound API

I am using Java Sound API to capture sound on a Windows machine by reading data from a TargetDataLine. It works fine if I open a line, read data from the line and then close it. However, If I reopen it once closed, I will get a LineUnavailableException. Can someone explain to me what is going on? If I want to record multiple sound clips, one after another, say repeating this: start -------> record ---------> stop several times, how can I do it?
Thanks
The API says:
Some lines, once closed, cannot be reopened. Attempts to reopen such
a line will always result in a LineUnavailableException.
I think the reason they say "some lines" is that it depends on external factors pertaining to the particular system.
You will need to create a line for each additional recording, it seems.

How to make volume up down animation in Java

I am developing a music player and I am almost done. But I need to try something because I have seen there are more commercial music applications use different types of animations for volume up and down while playing the music.
I need something like this,
.
How can I do this? Can anybody help me? Thank you in advance.
If you are outputting your audio via a SourceDataLine, it is possible to inspect the audio data as it is being processed. There is a useful code example of this presented in the Oracle Sound Trail tutorials, on the page Using Files and Format Converters, in the section "Reading Sound Files". The important point in the code is marked with a comment "// Here, do something useful"
At that point you would convert the bytes to audio values, and use the values as part of an RMS calculation. Details for the coversion and the RMS calculation should be searchable--I know I've seen explanations for both on stackoverflow.
Once you have an RMS value calculated, it can be sent to an independent thread that handles the graphics visualization. A loose-coupling pattern should be employed so that you minimize the amount of work being done on the audio thread, and so that you avoid any blocking that might hang up the audio.
For example, the visualization thread can have a setRMSValue method that simply updates an instance variable, without synchronization or blocking of any sort. The audio processing thread can call this method freely as it generates new RMS data points. The visualizer can simultaneously read the current instance variable at your animation rate. No synchronization needed. If the visualization thread skips a few RMS data points, it should not a problem.

Java - recording and capturing

I am developing a small real-time application to record sound waves. It has two modules: recording , listening.
here is how it should work :
The program starts listening.
A sound wave arrives.
The program recognizes that a signal has arrived, and starts
recording it.
When the signal is over (no more loud sounds), the program stops
recording and saves the result to a file.
So in order to recognize when the signal is over - we should listen to the wave (capture) along with recording, so we can detect when the sound is over.
In order to implement this, iv'e used the Java sound API, but i have one problem:
The target-data-line object is shared between the recording-thread and the capture-thread. In this case, two threads are working on the same target-data-line : The capture and the recorder threads.
which cases some real-time problems.
I have tried to open two target-data-lines, one for recording and one for capturing , but the program throws an exception when trying to open the second one.
How can i fix the problem ?
please help.
You need to use a single thread which has exclusive access to the TargetDataLine. This thread can then generate events which your recording and listening thread can subscribe to.

Need to "react" on any sound initiated

I need to be able to launch certain procedure only when there is some sound output initiated. This is like when some sound is "beeped" (having complete silence before). I image for this to handle is somehow to monitor the strength of the output channel (where usually all sound is outputted), and if it reaches the certain border, I will launch my "procedure". The sound can be initiated by any program in the system, I just need to monitor the output strength and react.
Is there a way to make such "monitor" in java?
Thanks.

Categories

Resources