Forums

Converting voltages to PCM audio (programming related)

Started by Unknown November 29, 2005
Hello everyone,

I'm recording audio with a data acquisition card from the speaker
cables. When recording, I get an array of unsigned short integer
values. These I need to convert to PCM audio. Everything works quite
nicely, except the fact that a lot of noise occurs in the PCM file. I'm
using Measurement Computings PCI-DAS6036 -card, and I have tried this
also with a simulated National Instruments PCI-4462 -card (the
simulated card only gives a sine wave).

What I have done is that first I reduce the received unsigned short
values (1-65535) to scale them on the signed short value range (these
are from MCC card, NI card gives voltages which I multiply to match the
signed short value range). After that I write these values to a file as
16bit signed integers in little-endian format.

And when this so called audio is played, it has a _lot_ of noise in it
that can not be heard from the speakers or when recording from sound
card. Waveform and amplitude are correct and you can hear the actual
audio playing. So, is there something I'm missing? Can I convert the
received values directly to PCM format? I would not like to filter the
signal (nor could I since my knowledge of actual DSP is almost
non-existent).

And last, but not least, please forgive me if this was an inappropriate
choice for a newsgroup to ask about this matter. If any of you should
know a more appropriate newsgroup, I really would like to know.

Best regards,
vesse

vessep@gmail.com wrote:
> Hello everyone, > > I'm recording audio with a data acquisition card from the speaker > cables. When recording, I get an array of unsigned short integer > values. These I need to convert to PCM audio. Everything works quite > nicely, except the fact that a lot of noise occurs in the PCM file. I'm > using Measurement Computings PCI-DAS6036 -card, and I have tried this > also with a simulated National Instruments PCI-4462 -card (the > simulated card only gives a sine wave).
"These I get as a bunch of words that I need to convert to prose." The numbers you get are called PCM. Taking an audio signal from speaker cables is usually a poor choice. The noise and hum out of the power amplifier may be insignificant when fed to a loudspeaker, but the signal is substantially degraded by them. If you have "Line out" available, use that. "Tape out" is also good. Usually, "Tape out" is unaffected by tone controls, and neither is affected by the listening volume.
> What I have done is that first I reduce the received unsigned short > values (1-65535) to scale them on the signed short value range (these > are from MCC card, NI card gives voltages which I multiply to match the > signed short value range). After that I write these values to a file as > 16bit signed integers in little-endian format.
You lost me. You start and end with 16-bit numbers. Are you merely adjusting the volume?
> And when this so called audio is played, it has a _lot_ of noise in it > that can not be heard from the speakers or when recording from sound > card. Waveform and amplitude are correct and you can hear the actual > audio playing. So, is there something I'm missing? Can I convert the > received values directly to PCM format? I would not like to filter the > signal (nor could I since my knowledge of actual DSP is almost > non-existent).
Describe the noise. I would expect hum, but your math may be flawed.
> And last, but not least, please forgive me if this was an inappropriate > choice for a newsgroup to ask about this matter. If any of you should > know a more appropriate newsgroup, I really would like to know.
There are better choices. How about rec.audio? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
are there time stamps or some other data in the words that come out of
the data aq card along with the signal?


what is the sampling rate?

Mark

Jerry wrote:

> Taking an audio signal from speaker cables is usually a poor choice. The > noise and hum out of the power amplifier may be insignificant when fed > to a loudspeaker, but the signal is substantially degraded by them. If > you have "Line out" available, use that. "Tape out" is also good. > Usually, "Tape out" is unaffected by tone controls, and neither is > affected by the listening volume.
Hi Jerry, Yes, line out or such would most likely be the best alternative, but they do not exist as I'm using a portable music player and I have connected the headset wires to DA card (sorry I had written speaker cables). Connection is made so that the earpeace is still attached to the cable.
> You lost me. You start and end with 16-bit numbers. Are you merely > adjusting the volume?
No, just trying to store the audio that is played as PCM audio (I mean a WAV-file without the headers). Such file should consist of 16bit signed integers written in byte by byte. Bit order of each byte is little endian. I have done many tests and I seem to do it right (description at the end if you're interested).
> Describe the noise. I would expect hum, but your math may be flawed.
It's quite hard for me to describe it since my english vocabulary is not that good on this subject. It's like when your radio is not tuned to a station. I've looked practically every word that would describe the noise in my native language from a dictionary and translation to each of them is "noise"...
> There are better choices. How about rec.audio?
I'll take a look. Thank you very much. And then, a small example of what I have received from the DA card and written to a file Received unsigned value: 39001 Corresponding signed value: 6234 (= 39001 - 32767) 6234 in bits: 0001 1000 0101 1010 6234 written to a binary file, byte per byte, each byte in little-endian form: 0101 1010 0001 1000 (ie. the order of the bits is 7-6-5-4-3-2-1-0-15-14-13-12-11-10-9-8) Content of the file after writing this is 5A 18 (hex), which matches the binary presentation. BR, vesse
Mark wrote:

> are there time stamps or some other data in the words that come out of > the data aq card along with the signal?
Hi Mark, No, not that I know of. I have not found any evidence on such matter from the DA-cards manual.
> what is the sampling rate?
44100Hz. I have tried also with 88200Hz and 100kHz. When using higher sampling rate, the noise is not that bad, but still exists. Or at least that's what it sounds like, I have no fancy equipment nor software to analyze it very precisely. The noise is so loud that it can be verified aurally. Also, the amount and quality of the noise differs when using different players, e.g. my mobile phone makes a lot more noise than my iPod, and the noise in the mobile phone is quite different from iPod's. BR, vesse
Mark wrote:
> are there time stamps or some other data in the words that come out of > the data aq card along with the signal?
Not usually.
> what is the sampling rate?
Whatever you set it for. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
vessep@gmail.com wrote:
> Jerry wrote: > > >>Taking an audio signal from speaker cables is usually a poor choice. The >>noise and hum out of the power amplifier may be insignificant when fed >>to a loudspeaker, but the signal is substantially degraded by them. If >>you have "Line out" available, use that. "Tape out" is also good. >>Usually, "Tape out" is unaffected by tone controls, and neither is >>affected by the listening volume. > > > Hi Jerry, > > Yes, line out or such would most likely be the best alternative, but > they do not exist as I'm using a portable music player and I have > connected the headset wires to DA card (sorry I had written speaker > cables). Connection is made so that the earpeace is still attached to > the cable. > > >>You lost me. You start and end with 16-bit numbers. Are you merely >>adjusting the volume? > > > No, just trying to store the audio that is played as PCM audio (I mean > a WAV-file without the headers). Such file should consist of 16bit > signed integers written in byte by byte. Bit order of each byte is > little endian. I have done many tests and I seem to do it right > (description at the end if you're interested).
From your description below, your card gives you offset binary and you convert to two's-complement signed binary. When you wrote "reduced" in your first message, I took it to mean a shortening the word. Another way to do the conversion that is faster on some processors is inverting the most significant bit.
>>Describe the noise. I would expect hum, but your math may be flawed. > > > It's quite hard for me to describe it since my english vocabulary is > not that good on this subject. It's like when your radio is not tuned > to a station. I've looked practically every word that would describe > the noise in my native language from a dictionary and translation to > each of them is "noise"...
What you describe could well be distortion caused by overloading the ADC. As a test, turn down the volume and try again. If that works, put a level control in the line to the card and turn that down with the volume coming out of the player fairly high but not overloading. Some of the hum and noise coming out of the player is independent of volume, and by attenuating a loud signal, you attenuate the noise also. ... Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:

> What you describe could well be distortion caused by overloading the > ADC. As a test, turn down the volume and try again. If that works, put a > level control in the line to the card and turn that down with the volume > coming out of the player fairly high but not overloading. Some of the > hum and noise coming out of the player is independent of volume, and by > attenuating a loud signal, you attenuate the noise also.
Hi, That is not the cause, I've tried that like quazillion times. It seems now, that the cause of the noise is the card. I got a change to test a NI card that is especially meant for capturing audio, and result was like from a different planet. The card is quite expensive, so I think that it is out of the question.... BR, vesse
vessep@gmail.com wrote:
> Jerry Avins wrote: > > >>What you describe could well be distortion caused by overloading the >>ADC. As a test, turn down the volume and try again. If that works, put a >>level control in the line to the card and turn that down with the volume >>coming out of the player fairly high but not overloading. Some of the >>hum and noise coming out of the player is independent of volume, and by >>attenuating a loud signal, you attenuate the noise also. > > > Hi, > > That is not the cause, I've tried that like quazillion times. It seems > now, that the cause of the noise is the card. I got a change to test a > NI card that is especially meant for capturing audio, and result was > like from a different planet. The card is quite expensive, so I think > that it is out of the question....
Don't give up too soon. You may have a defective card, or you may be using an input with a microphone preamp. What is the difference between "capturing audio" and "recording audio"? Your card should -- in theory, at least -- be able to record. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������