In Turbo C++ we have a header file called dos.h which exposes three functions sound, nosound and delay. Using these three functions it was possible to write a rudimentary piano program in C++.
I wanted to achieve the same result using Java. My options were either to use the library provided by jfugue or javax.sound.sampled. The problem is that I don't know the duration each note is played beforehand.
I want to start playing a certain frequency when the user presses a certain key and stop only when the user releases it. How may I tackle this problem?
The Java tutorials have an example where a boolean is consulted in the innermost while loop where one is packaging the bytes and handing them off to the SourceDataLine for playback.
Thus, your event, perhaps a key-off event, can be written to change this boolean. Since the sound playback is in its own thread, it is good to make the boolean "volatile", and to use this method of messaging rather than trying to directly control the playback.
Let's see if I can find the tutorial example...
http://docs.oracle.com/javase/tutorial/sound/playing.html
Notice in the example in the section "Using a Source Data Line" there is a while loop with the expression "!stopped" as one of the conditions. The base class for the playback in this example most certainly has a boolean "stopped", and probably has it marked "volatile".
Related
I want to generate chords from a midi file, but I can't find any source code written in java yet. So I want to write it by myself. What I want to do first is to gather the notes in the same position, but this is the problem, I don't know if there is a way to get the midi note position using JMusic. If not, are there any way to get this information? Thank you all~
Like slim mentioned, Midi files are basically a collection of Midi Events, which are basically hex bytes of code that correspond to a Midi action. EVERYTHING in Midi (including very in-depth things like tempo, setting the instrument bank to typical things such as note on/off events and note volume [called velocity in MIDI]) is controlled by those Midi Events. Unfortunately, you're going to need ALL of that information in order to do what you want.
My advice? There is this odd notion (that I once held before working with Midi as well) that Midi should be simple to work with because it's been around for so long and it's so easy to use in DAW's like FL Studio. Well let me be the person to crush this notion for you; MIDI is complex, hard, and idiosyncratic. As a beginner, it will force you to take caffeine (to keep the gears rolling and for headaches), tylenol (also for the headaches) and alcohol when you realize you just worked 6 hours for one thing and you're getting the fatigue. Turn back now, pay Dave Smith to help you, or hit the books, cause it's going to get nasty.
HOWEVER: You will never feel greater success than when your baby starts playing music.
I am working on a personal project. Basically I have a collection of small sound clips, like a clap or a beep noise. I want to create a program that listens for the sounds via a mic or some form of audio input, and when I play sound clip it should identify that clip.
I have tried looking into this myself and have found this article.
http://www.redcode.nl/blog/2010/06/creating-shazam-in-java/
I tried replicating it, but I have found that it doesn't work as expected. I am guessing the sound clips I am using to create my hash from are too small to create enough values to compare.
Wondering if there any well know programs or algorithms that are capable of doing this.
Dan Ellis' slides are probably a good start. They explain the principal task of audio fingerprinting and the two best known approaches:
The Shazam algorithm by A. Wang (paper)
The Philips (now Gracenote) algorithm by Haitsma/Kalker (paper)
As you have already tried the landmark (Shazam) approach, perhaps it's worth your time to fiddle around with the stream-based approach. Since your queries are very short, you might also want to tweak the analysis frame length and overlap. Shorter frames and greater overlap may improve your results for very short samples. If you want to delve even deeper into the Haitsma/Kalker algorithm, you might also be interested in this unfortunately paywalled paper (by me).
I have an ogg file loaded with the Sound class. I set it to loop and it runs ok but I hear a click when it starts to play all over again. The sound in barely 7 seconds long.
Is there a way to fix this because it is quite annoying?
There is undoubtedly a big discontinuity in the signal between the starting moment and the ending moment. With the Java Clip as it is constructed, there is no way to counteract this that I know of.
I recommend editing the sound in something like Audacity to try and make the two ends more similar. Easiest dodge is to have both ends taper to silence--but then that leaves a gap.
The other possibility is writing your own Clip and adding a provision that allows a degree of overlap of the two edges. Then, you can add tapers in Audacity and have the tapered parts overlap. This is similar to how audio editing ("splicing") is done in a DAW.
That is a bit of work though! I have done this and it does work well, but am a month or three away, still, from releasing my audio library. To program it yourself, read the bytes into an array, converting to PCM. Then, you can use the TargetDataLine as an example of an interface that allows reading progressive data (it is overkill, but the read() method is the key). In your read, you make a provision for starting a LERP (linear interpolation) of the PCM data at the overlap point.
If another means of dealing with this issue comes up, I will be happy to learn about it!
I'm trying to create an Android app which will get the lyrics of an mp3 from the ID3V2 tag of it. My question is, is it possible to get the lyrics automatically highlighted as the song plays? Like using speech processing or things like that. I've looked into the previous similar questions but all of them requires manual input. Need an ASAP feedback. Thank you.
This kind of thing is possible on Hollywood movie sets, using technology similar to those image enhancements that reconstruct a face using a 4-pixel square as input.
Okay, so your request is theoretically more feasible, but no current phone technology I know of could do this on the fly. You might need a Delorean, flux capacitor and some plutonium.
Also, detecting vocals over music is a much harder problem than speaking a text message into your phone:
Sung lyrics do not usually follow natural speech rhythm;
The frequency spectrum of music tends to conflict with the frequency spectrum of voice;
The voice varies in pitch, making it much harder to isolate and detect phonetic features;
The vocals are often mixed at a level equal to all other musical instruments;
IwannahuhIwannahuhIwannahuhIwannahuhIwannaReallireallirealliwannaZigaZiggUHH.
You might take a look at this paper LyricSynchronizer: Automatic Synchronization System Between Musical Audio Signals and Lyrics for a possible solution. Nothing implemented in Java for Android, but with the NDK you might take any C code and finagle it to work. ;-)
This paper describes a system that can automatically synchronize polyphonic musical audio signals with their corresponding lyrics. Although methods for synchronizing monophonic speech signals and corresponding text transcriptions by using Viterbi alignment techniques have been proposed, these methods cannot be applied to vocals in CD recordings because vocals are often overlapped by accompaniment sounds. In addition to a conventional method for reducing the influence of the accompaniment sounds, we therefore developed four methods to overcome this problem: a method for detecting vocal sections, a method for constructing robust phoneme networks, a method for detecting fricative sounds, and a method for adapting a speech-recognizer phone model to segregated vocal signals. We then report experimental results for each of these methods and also describe our music playback interface that utilizes our system for synchronizing music and lyrics.
Best of luck in your implementation!
I've been researching this off-and-on for a few months.
I'm looking for a library or working example code to detect the frequency in sound card audio input, or detect presence of a given set of frequencies. I'm leaning towards Java, but the real requirement is that it should be something higher-level/simpler than C, and preferably cross-platform. Linux will be the target platform but I want to leave options open for Mac or possibly even Windows. Python would be acceptable too, and if anyone knows of a language that would make this easier/has better pre-written libraries, I'd be willing to consider it.
Essentially I have a defined set of frequency pairs that will appear in the soundcard audio input and I need to be able to detect this pair and then... do something, such as for example record the following audio up to a maximum duration, and then perform some action. A potential run could feature say 5-10 pairs, defined at runtime, can't be compiled in: something like frequency 1 for ~ 1 second, a maximum delay of ~1 second, frequency 2 for ~1 second.
I found suggestions of either doing an FFT or Goertzel algorithm, but was unable to find any more than the simplest example code that seemed to give no useful results. I also found some limitations with Java audio and not being able to sample at a high enough rate to get the resolution I need.
Any suggestions for libraries to use or maybe working code? I'll admit that I'm not the most mathematically inclined, so I've been lost in some of the more technical descriptions of how the algorithms actually work.
If you are aiming at detecting frequency pairs then your job is very similar to a DTMF detector.
Try searching for DTMF in places like sourgeforge, you'll find detectors in many programming languages. The frequency pairs placing along the spectrum seems to be even more stringent than your specs so you should be fine adapting a DTMF detector to your input.
Check out SNDPeek, its a cross-platform C++ application that extracts all kinds of information from live audio; https://github.com/RobQuistNL/sndpeek