Java Performance Tuning

Java(TM) - see bottom of page

|home |services |training |newsletter |tuning tips |tool reports |articles |resources |about us |site map |contact us |

Our valued sponsors who help make this site possible
New Relic: Try free w/ production profiling and get a free shirt! 

ManageEngine's Site24x7: End-to-End analysis on Java EE web transactions. Sign up for FREE! 

AppDynamics: Get complete browser to backend visibility. Monitor Now! 

Timers and audio performance: page 1 of 2

Chart Java Jitter with jHiccup
Monitor and identify pauses in your Java apps. Download now

Why is my application so slow?
Learn 3 ways to detect Java Application Performance Trends

JProfiler
Get rid of your performance problems and memory leaks!


Java Performance Training Courses
COURSES AVAILABLE NOW. We can provide training courses to handle all your Java performance needs

See Your Message Here
You could have your tool advertised here, to be seen by thousands of potential customers

Java Performance Tuning, 2nd ed
The classic and most comprehensive book on tuning Java

Java Performance Tuning Newsletter
Your source of Java performance news. Subscribe now!
Enter email:


New Relic
New Relic: Try free w/ production profiling and get a free shirt!

ManageEngine
ManageEngine's Site24x7: End-to-End analysis on Java EE web transactions. Sign up for FREE!

AppDynamics
AppDynamics: Get complete browser to backend visibility. Monitor Now!


Chart Java Jitter with jHiccup
Monitor and identify pauses in your Java apps. Download now

Why is my application so slow?
Learn 3 ways to detect Java Application Performance Trends

JProfiler
Get rid of your performance problems and memory leaks!


How do you synchronize audio and video frames? What is Java's current capability for recording audio samples? Why is clock skew important to audio recording? In this article Scot Mcphee describes what you need to know about timers for recording audio samples from Java.

Published September 2003, Author Scot Mcphee

Page 1 of 2
next page: Measuring elapsed time of an audio recording

I had been using computer audio and midi applications, as a musician and composer for many years before I became a professional computer programmer. As a computer programmer, I have been traditionally designing and writing systems that have very little do with audio, or music; the usual enterprise type systems. Ultimately, it was my love for music that motivated me to focus my more than 5 years of experiences with Java on a personal project, involving the automatic synchronisation of music provided by artists for free download, onto personal workstations or portable music players. It was this personal project that lead me to join the java sound mailing list.

The performance issue

During my first month on that list, an interesting discussion came up about the performance of the java sound API. ( http://swjscmail1.java.sun.com/cgi-bin/wa?A1=ind0307&L=javasound-interest#40). The discussion highlights an interesting area of Java performance, identifying what I think are glaring deficiencies in Java timers.

The original poster complained that his ‘sample length was inaccurate’. The poster was attempting to record x seconds of audio, but was actually measuring x+1/x (or some fraction difference) seconds recorded. The fractional amount was continually variable. The poster wanted to know if there were any techniques to speed or slow the audio (such as brute force dropping samples) to force the audio back ‘in sync’, all of which result in chipmunk’d or mogodon’d speech, and crackly, distorted audio, or both. This naturally lead to a discussion about the accuracy of the audio timing clocks in various consumer and semi-pro soundcards, and how to best measure the ‘clock skew’ of the audio card. It was felt that either the java sound API or the soundcard or its OS driver was at fault.

Digital audio and timing accuracy.

In professional digital audio, clock skew is very important, and let me explain why.

Digital audio is achieved by slicing up an analogue audio waveform into a series of many thousands of discrete instantaneous level measurements every second. On a CD, there are 44,100 of these measurements every second. This is referred to as the sample rate (44.1kHz). Additionally, there is the ‘bit depth’ to consider, the amount of data retained for each sample, which on CDs is 16 bits. In other words, on a CD, the level of the analogue input is measured with a 16 bit accuracy 44,100 times every second.

To achieve a correct and accurate playback, the timing of the 44,100 samples is absolutely critical, which is to say that each of the 44,100 samples must be evenly and regularly spaced over the whole second – and with the same timing on playback as record. Additionally, in a multi-device interconnected digital sound network, all the digital clocks of all the machines connected have to be perfectly in sync. This is usually achieved in professional circumstances by use of a centralised master ‘word clock’ which is connected via BNC cabling to all the machines in the studio or facility.

The quality of the word clock greatly affects the quality of the recorded and playback sound of the device. An accurate and stable word clock will noticeably improve the sound quality of existing audio equipment. (Also as an aside, it’s why those familiar with pro-audio are frequently sceptical of claims about “CD-quality” audio merely because it is specified as 16bit, 44.1kHz).

Timing precision

Now here’s a little calculation for you. What is the time interval between each sample at 44.1kHz? Well, you need 44.1 samples every millisecond that goes by, or about 22 microseconds between each sample. A sample rate of 1kHz (i.e. a sample every millisecond) would result in audio that is normally not intelligible. Telephone bandwidth, or a 3kHz sample rate, is about the lowest rate that still allows intelligible and individually distinguishable speech.

The problem, simply put, is that single frame accuracy for digital audio of any appreciable quality, cannot be achieved with only a millisecond accurate timer. Even a completely rubbish consumer soundcard with horrifically audible clock skew (measured in microseconds) is still going to be far, far, more accurate, than the finest resolution time available to us in Java – System.currentTimeMillis().

Continued on next page

Page 1 of 2
next page: Measuring elapsed time of an audio recording


Last Updated: 2014-04-01
Copyright © 2000-2014 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/articles/soundtimer.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us