0
votes

This post is more about clarification than it is about implementing some sort of audio waveform algorithm. I've read a myriad of posts concerning the subject (both on SO and out on the web), and here's what I've gathered:

  • In the context of 16-bit WAV, I want to read every two bytes as a short, which will result in a value between -32768 to 32767.
  • With a sample rate of 44.1kHz, I'll have 44 thousand samples for every one second of audio.

This is pretty straight-forward, however I have the following questions:

  • A WAV rendered in mono only has one channel, which is two bytes of information per frame. In stereo, this becomes four bytes of information. In my situation, I'm not required to display both channels, so would I simply skip the right channel and read only the left? Some solutions I've read mentioned combining both the left and right channels, though I'm not sure if this is required.
  • Say I had an audio file that is two seconds long, and another that is thirty seconds long. If I need to grab a minimum of 800 samples to represent the waveform, would grabbing 800 samples along the length of the file introduce accuracy issues, e.g. (44,000 * 2) / 800 for the two second audio file, and (44,000 * 30) / 800 for the thirty second audio file.

An explanation would really be appreciated!

1
We cant answer your first question, ask the one who gave you the task. I don't understand your second question. Which "particular region" are you talking about? You need 2*44k samples to represent a two sec audio. That is what sampling rate means by definition. You cannot record a 44k audio using 22k samples.Tamas Hegedus
@TamasHegedus I updated my second question. I tried to re-phrase it the best I could. In a nutshell, I simply trying to determine if the samples within a region of 44,000 samples vary wildly, and if I need to do some sort of averaging.Raggeth
yeah both questions need clarification - by gathering a bunch of information doesnt make a question - you are not up to the stuff it seems and you are trying to explain something that you dont understand - tell me how that can be donegpasch
you say the audio may vary wildly ... you have not stated your goal concerning sampling however this vary wildly can mean a few things including changes to amplitude of the wave as well as frequency content ... update your question stating what information do you desire from performing your samplingsScott Stensland

1 Answers

1
votes

This is outside my area of expertise, but I'll give it a go.

As far as I can tell, you could probably skip some of the samples and retain reasonable accuracy - if you skip every other sample in a 43 kHz file, it would be like if you recorded the original at 22.05 kHz. However, according to Wikipedia, you run into accuracy issues when your sampling frequency is less than double the frequency of one of the components of the sound you are sampling. Unless you have high-pitched bells and cymbals in your audio, that's probably not much of an issue at 22.05 kHz. But if you're sampling only 800 times per 30 seconds, that wouldn't be enough to handle much more than the very lowest note on an organ.

Imagine you're sampling 800 times per second, and there's a sound at 800 Hz (which is near G or G# above treble C.) Every time you sample, you're going to get that wave at the exact same point. That place in the wave you are sampling could be the peak point, or it could be a low point. It's impossible for you to know without sampling more often.

As far as whether you can sample just one channel, that depends on whether it's OK for you to ignore the other channel. Imagine a stereo file with a voice on the right and music on the left. They're going to have different wavepatterns. If it's OK for you to just ignore the music, then you can sample the right and ignore the left. If you need both, then you obviously need to sample both.