Converting voltages to PCM audio
- From: "vesse" <vessep@xxxxxxxxx>
- Date: 24 Nov 2005 08:33:16 -0800
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 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 with the
following code:
std::ofstream fd;
fd.open(fName, std::ios::out | std::ios::trunc | std::ios::binary);
short tmp = 0;
char byteConvert[2];
for (int i = 0; i < sampleCount; i++)
{
// "scale" to range from -32768 - 32767
tmp = (adData[i] - reduce);
byteConvert[0] = tmp >> 8;
byteConvert[1] = tmp;
// little-endian -format
fd << byteConvert[1] << byteConvert[0];
}
fd.close();
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 is 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?
And last, but not least, please forgive me if this was an inappropriate
choice for a newsgroup to ask about this matter.
Best regards,
vesse
.
- Follow-Ups:
- Re: Converting voltages to PCM audio
- From: Willem
- Re: Converting voltages to PCM audio
- Prev by Date: Re: New
- Next by Date: Re: New
- Previous by thread: Getting Involved with Open-Source Projects
- Next by thread: Re: Converting voltages to PCM audio
- Index(es):
Relevant Pages
|