1

I'm developing software that receives PCM audio data and converts it to a WAVE file. The audio stream has the following characteristics:

  1. 16 bit signed integers
  2. 6000 frames sent every 1/8th seconds, ie 48000 samples per second
  3. Mono-channel

I can save to the file just fine, but the audio sounds distorted upon playback.

After doing some experimentation, I've determined that the audio is symmetric across the frequency domain, causing the strange distortions.

Audacity Frequency enter image description here

My question is: what would cause this?

Could it be reading the data using an incorrect sampling rate? Or some strange normalization? I don't have enough experience with FFT to understand the relationship between time and frequency domains.

If I move the audio file into Audacity and use the "change pitch" tool with +100% (effectively doubling the pitch), it sounds roughly normal. It seems like the entire frequency spectrum has been squished into 12kHz and the mirrored across the other 12kHz range.

Any help is appreciated, and more info can be provided if necessary!

  • It seems that your input and output sample rates doesn't match or something else is messed up in wave headers. Double check your WAVE structures (BTW what audio interface are you using?) when getting and ouputing/writing your data. See if you find can anything. – vapid May 30 at 19:42
1

According to this spectral output you are not dealing with 48kHz sampled audio. For some reason the audio has been decimated and the actual sampling rate is 24kHz. Consequently the 'nyquist' frequency is 12kHz.

One of the key things to remember about digital audio, is that during the process of sampling analogue audio the spectral content is mirrored around the nyquist frequency (Fs/2). For 48kHz sampled audio, this is 24kHz, and for 24kHz sampled audio this is 12kHz. So basically the mirroring you are seeing here is typical of this. Were you to be able to analyse this to much higher frequencies, you would see mirroring around multiples of the Nyquist frequency all the way up (theoretically) to infinity.

Now, having said all this, you're still going to be pretty sure that your audio is 48kHz, and consequently, no further forward.

You should further note, that this effect can be simulated by 'nulling' every alternate sample (i.e. taking every odd sample and simply making the value zero). If you were to do this with an existing WAV file, this is exactly the sort of spectrum you would see.

Consequently, if you take all of this into account, and you are still positive your audio is 48kHz sampled, it points to an error in your software which is probably to do with the way you are exporting the signed integers in your PCM file. If I was you, I wouldn't try to reinvent the wheel here. There are any number of usable libraries out there that will write rock solid WAV files for you, without having to start from scratch.

Be careful of the WAV/RIFF header, and also be aware of 'endianness' when dealing with this data.

  • Thanks for the insight. Do you know how I could correct this (assuming I'm getting 48000 samples per second of "decimated" data)? The WAV files are correct as I've tried with several WAVE libraries, so the error must be in the raw data. Unfortunately, I don't have a lot of visibility since it's derived from a Simulink model, so I have to take the data at face value – Noraboutme May 31 at 14:17
  • I reckon your problem is the matrix multiply block in the simulink graph. – Mark Jun 1 at 2:53
  • try converting the raw data before and after the matrix multiply block. – Mark Jun 1 at 3:07
  • Looks like the matrix multiply is only zeroing the right channel, but it's not turning the [Nx2] matrix into a [N] matrix. – audionuma Jun 1 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.