Noisy sound data when recording 16 bit. Anyone experience this?

I'm working on a program that displays a spectrogram and it works just fine with 8-bit audio, but not so well with 16-bit. In the 16-bit data there's an incredible amount of noise that isn't present in the 8-bit data. Oddly, the noise is present across the entire range of frequencies I'm reading. If it makes a difference, I've only tested this on Vista. Here is an abbreviated code snippet:
ArrayList<double[]> wave = new ArrayList<double[]>();
int sampSize = audioFormat.getSampleSizeInBits();
numBytesRead = targetDataLine.read(data, 0, data.length);
wave.add(new double[dataSize]);
if (sampSize == 16) {
      for (int i = 0; i < numBytesRead / 2; i++) {
            wave.get(wave.size()-1) = (double) ((data[2*i+1] << 8) | data[2*i]);
} else if (sampSize == 8) {
for (int i = 0; i < numBytesRead; i++) {
wave.get(wave.size()-1)[i] = (double) data[i];
//perform fft on wave data

Alright. I've created an "sscce" as suggested, and managed to keep it just under 20KB. It's pretty self explanatory but I will describe it briefly:
The program graphs the waveform of data read from a microphone. Two graphs are displayed. The top graph displays the data read in 8-bit form, and the bottom graph reads the data in 16-bit form. I wasn't sure if it was possible to read in 8-bit data and 16-bit data from the same source simultaneously, so you have to toggle between them. Clicking in the graph area will pause/unpause that graph, allowing the other graph to run. Pausing both graphs allows for the data to be compared side-by-side.
This image illustrates my problem: http://yfrog.com/3d8vs16graphj. The data was recorded during silence, so what you see is purely noise. The 16-bit data clearly has plateaus that aren't present in the 8-bit data. I believe these "plateaus" are the cause of the broad spectrum of noise in my fft results. If anyone is interested, please test my code by copying and pasting directly into a new project:
package sscce16bit;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.TargetDataLine;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
public class sscce extends JPanel {
    static MainThread mainThread;
    static final int gh = 100;
    static final int gw = 300;
    static final int ch = 40;
    static final int labw = 60;
    static final int cw = gw;
    static final Dimension graphSize = new Dimension(gw, gh);
    static final Dimension labelPSize = new Dimension(labw, gh);
    static final Dimension controlsSize = new Dimension(cw, ch);
    static final Dimension panelSize = new Dimension(gw + labelPSize.width + 20,
                                            2 * (labelPSize.height + ch));
    static GraphPanel graph8;
    static GraphPanel graph16;
    static ControlsPanel cPan;
    int procCounter = 0;
    int curArrayPos = 0;
    TargetDataLine targetDataLine8;
    TargetDataLine targetDataLine16;
    //double maxAmpShown = -1.0d;
    //double MAX_AMP = 0.0d;
    ArrayList<double[]> wave = new ArrayList<double[]>();
    boolean pauseProc = false;
    //graph display controls
    int tickMarkLen = 8;
    int numOfLabels = 5;
    //audio format
    AudioFormat audioFormat8;
    AudioFormat audioFormat16;
    int dataSize = 1024; //buffer size = 2^10 (line buffer size is 4000 typically);
    final int dataSampleSize = dataSize;
    final float sampleRate = 8000.0F; //8000,11025,16000,22050,44100
    final int sampleSizeInBits8 = 8; //8 or 16
    final int sampleSizeInBits16 = 16;
    final int numofchannels = 1; //1 or 2
    final boolean signed = true;
    final boolean bigEndian = false;
    public sscce () { //constructor
        audioFormat8 = new AudioFormat(sampleRate,
                sampleSizeInBits8, numofchannels, signed, bigEndian);
        audioFormat16 = new AudioFormat(sampleRate,
                sampleSizeInBits16, numofchannels, signed, bigEndian);
        this.setPreferredSize(panelSize);
        this.setMinimumSize(panelSize);
        this.setMaximumSize(panelSize);
        this.setBorder(BorderFactory.createLineBorder(Color.black));
        this.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(0, 0, 0, 0);
        gbc.anchor = GridBagConstraints.CENTER;
        graph8 = new GraphPanel(sampleSizeInBits8,
                audioFormat8, targetDataLine8, true);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 1;
        add(graph8.labP, gbc);
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.gridwidth = 1;
        add(graph8, gbc);
        cPan = new ControlsPanel();
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.gridwidth = 1;
        add(cPan, gbc);
        graph16 = new GraphPanel(sampleSizeInBits16,
                audioFormat16, targetDataLine16, false);
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = 1;
        add(graph16.labP, gbc);
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.gridwidth = 1;
        add(graph16, gbc);
        mainThread = new MainThread(this);
        mainThread.execute();
    } //end constructor
    class ControlsPanel extends JPanel {
        ControlsPanel() {
            this.setPreferredSize(controlsSize);
            this.setMinimumSize(controlsSize);
            this.setMaximumSize(controlsSize);
        @Override
        public void paint(Graphics g) {
            String pause8, pause16;
            String zoom8, zoom16;
            Rectangle2D textR[] = new Rectangle2D[6];
            if (graph8.pauseGraph) {
                pause8 = "paused";
            } else {
                pause8 = "running";
            if (graph16.pauseGraph) {
                pause16 = " paused,";
            } else {
                pause16 = " running,";
            zoom8 = " " + Double.toString(graph8.MAX_AMP / graph8.maxAmpShown) +
                    "x zoom";
            zoom16 = " " + Double.toString(graph16.MAX_AMP / graph16.maxAmpShown) +
                    "x zoom";
            String text[] = new String[] { "8bit: "+ pause8 + zoom8,
                                        "16bit: " + pause16 + zoom16 };
            for (int i = 0; i < text.length; i++) {
                textR[i] = g.getFontMetrics().getStringBounds(text[0], g);
            textR[0].setRect(0, textR[0].getHeight(),
                    textR[0].getWidth(), textR[0].getHeight());
            textR[1].setRect(cw / 2.0d, textR[1].getHeight(),
                    textR[1].getWidth(), textR[1].getHeight());
            for (int i = 0; i < text.length; i++) {
                g.drawString(text, (int) textR[i].getX(), (int) textR[i].getY());
class GraphPanel extends JPanel implements MouseListener{
double maxAmpShown = -1.0d;
double MAX_AMP = 0.0d;
boolean pauseGraph = false;
AudioFormat audioFormat;
CaptureThread capThread;
TargetDataLine targetDataLine;
LabelsPanel labP;
ArrayList<Integer> labels = null;
boolean setLabels = true;
boolean stopped = true;
Image bImage;
Graphics bg;

Similar Messages

  • My iPhone 5 dropped on the floor, then I heard a strange noisy sound inside when I hit it on it's back, any explanations ?

    My iPhone 5 dropped on the floor, then I heard a strange noisy sound inside when I hit it on it's back, any explanations ?

    Bring it to Apple and get it checked out.  How could anyone here possibly know what happened to your phone without seeing it?

  • HT1498 It took 2 hours to download my rental, then when i go to play the movie it flashes loading and then authorizing.  It stays stuck on authorizing. Anyone experience this?

    It took 2 hours to download my rental, then when i go to play the movie it flashes loading and then authorizing.  It stays stuck on authorizing. Anyone experience this?

    Welcome to the Apple Community.
    The first thing to check would be your internet download speed, you can do this at www.speedtest.net.
    1080p HD movies require a recommended speed of 8 Mbps, 720p HD movies require a recommended speed of 6 Mbps, while SD movies require a recommended speed of 2.5 Mbps.

  • CCX 8.0.2 Script prompt recording stopped working. Recording command stop after beep, "Error Unmarshaling return" Has anyone experience this error?

    Our Script prompt recording stopped working. After user authentication, the Recording command plays the prompt asking to record after the beep, but after the beep the application ends with error exception on screenshot below.
    Have anyone experience this error?
    Any thoughts will be appreciated
    Cisco Unified CCX Administration
    System version: 8.0.2.11004-12

    Hello Everyone,
    Just in case that someone experience this problem, this problem points to a permission issue with the owner of one of the directories via root. TAC needs to be involved in order to modify the following settings.
    Note:
    If you have two servers, you need to do it on both.
    I've seeing sometimes that it takes a couple of minutes to take action.
    Record prompt script failing with error message    "CMTRecordingDialogImpl"
    UCCX versions:   Linux versions and especially after upgrades to the system.
    Solution:   Problem is due to permissions,
    [root@DISDUCCXPUB ~]# cd /opt/cisco/uccx/
    [root@DISDUCCXPUB uccx]# ls -l | grep temp
    drwxr-xr-x   2 root       root         4096 Oct  6  2011 temp
    [root@DISDUCCXPUB uccx]# chown uccxuser:uccxservice temp
    [root@DISDUCCXPUB uccx]# chmod 775 temp
    [root@DISDUCCXPUB uccx]# ls -l | grep
    temp  drwxrwxr-x   2 uccxuser   uccxservice  4096 Oct  6  2011 temp
    [root@DISDUCCXPUB uccx]#   drwxrwxr-x   2 uccxuser   uccxservice  4096 Jan 17 15:07 temp
    This should take care of the problem. Again, Cisco TAC needs to be engage because of the root access.
    Regards,
    Daniel Amador
    Cisco TAC Support Engineer, IPCC Express Team

  • TS4079 I ask Siri a question, there is a very long pause and then when she does come back she appologises by saying she cannot help me now and I should check back later...anyone experience this??

    I ask Siri a question, there is a very long pause and then when she does come back she appologises by saying she cannot help me now and I should check back later...anyone experience this??

    Yes... a search of the forums would have prevented asking that question.

  • I have experience this last saturday...anyone experience this same as mine...

    I have experience this last saturday...anyone experience this same as mine...
    When im in the last fersion of ios its doing good as it is..
    And then when i updated into ios 7 a few hours after my ipad retina hungs up..it freeze and i dont know why..then when i try to push home button it won't function..
    Then when i push sleep button my ipad goe's asleep and then i try to push any button it wont wake up any more in a few mins..then i try to leave it with out pressing any button and back to it in a few mins..then it goes again...
    And sometimes i press apps or letters when i type its very late to respond...
    Is this a buspgs or im incoutering a problem with my ipad...
    Please could any one answer and help me...

    (A) Reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.
    (B) Reset all settings
    Settings>General>Reset>Reset all settings
    Note: Data will not be affected but settings will be reset.

  • I am having dark blurred light ghosting effect on my imac screen. Does anyone experience this?

    I am having dark blurred light ghosting effect on my imac screen. Does anyone experience this?

    When posting in Apple Communties/Forums/Message Boards.......It would help us to know which iMac model you have, which OS & version you're using, how much RAM, etc. You can have this info displayed on the bottom of every post by completing your system profile and filling in the information asked for.
    ***This will help in providing you with the proper and/or correct solutions.***
    Can you post a picture of your problem?  Sometimes, that helps.  You did not mention where this ghosting effect takes place?  Startup?  Finder?  Browser? 

  • Has anyone experience this! - default browser helper 537

    Hi,
    I use Firefox as my default browser, since the firefox plug-in "default browser helper 537" was installed (in November) my mac has slow down, especially when browsing using both firefox and safari. I un-installed firefox a week ago and my pc has gone back to it original state. I installed Firefox again after two days from the previous un-install and the browsing slow down again. I then un-installed again. Has anyone experience this! IS there a issue with Firefox???

    Just experienced same today. Firefox didn't even want to quit without a force quit. Removed Firefox and so far so good with other browsers - Safari and Chrome

  • I upgraded my cloud storage from 2G to 120G and today it went back to 2G and I cannot save my work. Anyone experience this? Unable to get any customer service.

    I upgraded my cloud storage from 2G to 120G and today it went back to 2G and I cannot save my work. Anyone experience this? Unable to get any customer service.

    Purplehiddledog wrote:
    I do backup with iCloud.  I can't wait until the new iMac is available so that I can once again have my files in more than 1 location without needing to rely solely on the cloud. 
    I also rely on iTunes and my MacBook and Time Machine as well as backing up to iCloud. I know many users know have gone totally PC free, but I chose to use iCloud merely as my third backup.
    I assume that the restore would result in my ability to open Pages and Numbers and fix the problem with deleting apps, but this would also mean that if my Numbers documents still exist solely within the app and are just not on iCloud for some reason that they would be gone forever.  Is that right?
    In a word, yes. In a little more detail.... When you restore from an iCloud backup, you must erase the device and start all over again. There is no other way to access the backup in iCloud without erasing the device. Consequently, you are starting all over again. Therefore, it would also be my assumption that Pages and Numbers will work again and that the deleting apps issues would be fixed as well.
    If the documents are not in the backup, and you do not have a backup elsewhere, the documents could be gone forever.

  • Help does anyone experience this too??

    Just bought the iPad and the apple case
    first I regret buying the apple case for iPad coz it easily get marks and stains. And I don't like the built. (can I change it?) I think belkin case is better just 10 dollars diff. Is anyone experiencing it too?
    Second my iPad screen! It easily gets finger print marks! I don't know if my fingers are dirty but the screen surely loves my finger prints it's all over!! Does anyone experience this too? The prints shows when the screen is turned off and when on a white bright page

    The iPad display is oleophobic, it resists oily marks. Just wipe the display across your pants leg and they are easily wiped away.
    There are about 20 or more 3rd party cases for the iPad. Everything from simple rayon silk slipcases, to denim or corduroy shoulder bags and backpacks, to wooden picture frame cabinets.
    http://www.ilounge.com/index.php/accessories/ipad
    And Zagg has an InvisibleShield ready for the iPad. They are military grade scratch protection.
    http://www.zagg.com/invisibleshield/apple-ipad-cases-screen-protectors-covers-sk ins-shields.php
    BTW, word on the street is that Apple has banned screen protectors from their stores and as soon as they sell out of their current stock you will have to get your 3rd party protectors, like Zann's InvisibleShield, strictly from 3rd party venders.
    http://www.ilounge.com/index.php/news/comments/apple-bans-protective-screen-film -from-apple-store/
    Dah•veed

  • Has anyone experience this ...

    Has anyone experience the IPOD FROZEN in the middle of the song? I recently bought the Ipod 30GB Video. It functioned fine for the first couple of weeks (last approx 12-15 hours of uncharge played song). Then comes the frozen. I fully charged the Ipod and played for half of an hour or so and suddenly, It froze and I could not do anything with it. I tried to reset several times and the problem still persisted. I also tried to restore to the manufacturing setting but it was not a successful restore. It hang in the middle of process. I took the Ipod to the Apple Store and one of the guy at the Genius Bar looked at it and said "it might caused by your song" ... ***? Anyhow, it turned out that it was the Ipod problem ... so he said. I got the replacement one.
    Well, brought the replacement home and I thought it was fine until today ... the Ipod froze AGAINNNN .... grzzzzzz ... WHAT's HAPPENING? This time even worst, I cannot even reset ... It display a small sliver of red color at the battery and even though I plugged it into the computet for an hour or so, it still not being able to charged. Well, I paid another visit to the Apple store. Murphy Law, it's not working at home but it worked at the store (although, one of the Genius Bar guy explain that the Ipod "somehow" got into the critical low battery and the the provided USB cable does not have sufficient power to boost the Ipod to its recovery mode.) In fact, this guy (Genius Bar Guy) had to plug the Ipod into the other connector (not the USB one ... I am not a fan of Apple therefore not knowing the exact term for this connector) from his laptop and waited for 10 minutes of so and voila ... I took it home an charge for a nother few hours or so before I can put all of my music back into the Ipod.
    Sorry for the long story but has anyone experience this ... if so, how do you comes into the fix ... I am not convince that the problem will go away and the the "boosting" thing ... or I just come with an unlucky Ipod ....

    Just experienced same today. Firefox didn't even want to quit without a force quit. Removed Firefox and so far so good with other browsers - Safari and Chrome

  • I cannot select radial filter points after I create them in Lightroom.  Anyone experience this issue before and what might be the solution?

    I cannot select radial filter points after I create them in Lightroom.  Anyone experience this issue before and what might be the solution?

    Press H to hide/show control points.

  • I can't get the camera to switch to video on the new iOS7.  Anyone experience this?

    I can't get the camera to switch to video on the new iOS7.  Tapping it, but it's not responding. 
    Anyone experience this?

    Thanks! I went to the new user guide.  Have to slide screen to choose function

  • Hi there - Every time I try to open an app, it seems to crash. Has anyone experience this problem? Suggestions are appreciated for getting this fixed. Thx!

    Hi there - Every time I try to open an app, it seems to crash. Has anyone experience this problem? Suggestions are appreciated for getting this fixed. Thx!

    - Reset the iPod. Nothng is lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Purchase/.install any new app.
    - The remaining items here:
    iOS: Troubleshooting applications purchased from the App Store
    - Last, restore the iPod

  • I upgraded my iMac to Mountain Lion and now my Canon Pixima MP500 will not open because PowerPC apps are no longer supported! Has anyone experience this problem?

    I upgraded my iMac to Mountain Lion and now my Canon Pixima MP500 will not open because PowerPC apps are no longer supported! Has anyone experience this problem?

    Correct. Applications designed to run on the old PPC Macs (which Apple stopped making in 2005) cannot run on Mountain Lion.
    You need to update your printer driver:
    Printer and Scanner software available for download:
    http://support.apple.com/kb/HT3669?viewlocale=en_US

Maybe you are looking for