Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKylotan

Posted 17 May 2013 - 11:47 AM

Question 1.
I notice that the numbers in the array go from -9999 to 9999 when I print them out. Why is this? Is this the range that each hert(z?) can be within? This seems to produce the sinewave sound very nicely.

 

It's because the volume is set to 10000. That's basically the maximum amplitude, and every sample is a fraction of that.

It looks like an arbitrary number in this case. Each sample is a short, which means a signed 16 bit value. This is the same as a compact disc or a typical WAV file. So you could increase volume as high as 32767, which is the largest value that will fit in a short.

This range won't have any effect on whether you can produce a sine wave 'nicely' or not, because it's all relative. If your samples were 24 bit then you might use values that were much larger, and if your values were floats you'd probably stick to -1 to +1.

 

Question 2.
When I load a wave file and try to print the resulting array, I get some weird results. Like, instead of a number from -9999 to 9999 as with my sinewave, I get the Spade (from clubs,diamonds.hearts etc) among many other weird symbols.

 

That's a programming issue completely unrelated to audio. Basically when you open a wave file it's a binary series of bytes, not human readable decimals. When you print them, some of those bytes are represented by letters, some by numbers, some by symbols, and some are not visible at all. To display the values from a wave file, you need to do something more sophisticated and parse the file according to its specific format. How to do that is a bit tricky but it can be done with a couple of pages of Windows API code.

 

Question 3. 
I looked around online, and at Audacity. The numbers seem to go from -1.0 to 1.0 in a lot of examples. Having been using values from -9999 to 9999(generated from the sine and square formulas), I've no idea what's going on here. Somehow the OpenAL functions are interpreting all these different things into sound. Also If I were to experiment with these values(-1.0 to 1.0), putting them into an array, would I get sound as a result?

 

Going back to my answer to question 1, these values are arbitrary, and relate to the sample format being used. Digital sound can be described along 2 axes: sample rate (measured in Hertz) and the sample format (eg. 16bit signed integer, 24bit signed integer, 32 bit float). It's the sample format that is of interest here. Basically that specifies how each sample is to be stored. A maximum amplitude sine wave stored in a 16bit format would vary between -32768 to +32767. One in 24bit would vary from -8388608 to 8388607. A 32 bit floating point is slightly different - it's conventional to vary the maximum from -1.0 to +1.0, but unlike the integer formats, you can go outside that range if you like. (With the result being distortion when the time comes to output the value.)

 

Question 4. 
Lastly - a bit of theory stuff I'm not sure on (and can't quite find good google resources on) - If I were to create my own sound where every hertz never goes below 0, would the sound be audible? why/why not?

 

Hertz is a measure of frequency, not a specific thing in the file. I think you're talking about individual samples. You could certainly make a series of samples that never went below zero and if it still followed the standard sine wave pattern then it would sound pretty much the same. Zero is just an arbitrary point that lies in the middle of the range and has no special meaning.

: crap editor


#1Kylotan

Posted 17 May 2013 - 11:46 AM

Question 1.
I notice that the numbers in the array go from -9999 to 9999 when I print them out. Why is this? Is this the range that each hert(z?) can be within? This seems to produce the sinewave sound very nicely.

It's because the volume is set to 10000. That's basically the maximum amplitude, and every sample is a fraction of that.

It looks like an arbitrary number in this case. Each sample is a short, which means a signed 16 bit value. This is the same as a compact disc or a typical WAV file. So you could increase volume as high as 32767, which is the largest value that will fit in a short.

This range won't have any effect on whether you can produce a sine wave 'nicely' or not, because it's all relative. If your samples were 24 bit then you might use values that were much larger, and if your values were floats you'd probably stick to -1 to +1.

Question 2.
When I load a wave file and try to print the resulting array, I get some weird results. Like, instead of a number from -9999 to 9999 as with my sinewave, I get the Spade (from clubs,diamonds.hearts etc) among many other weird symbols.

That's a programming issue completely unrelated to audio. Basically when you open a wave file it's a binary series of bytes, not human readable decimals. When you print them, some of those bytes are represented by letters, some by numbers, some by symbols, and some are not visible at all. To display the values from a wave file, you need to do something more sophisticated and parse the file according to its specific format. How to do that is a bit tricky but it can be done with a couple of pages of Windows API code.

Question 3. 
I looked around online, and at Audacity. The numbers seem to go from -1.0 to 1.0 in a lot of examples. Having been using values from -9999 to 9999(generated from the sine and square formulas), I've no idea what's going on here. Somehow the OpenAL functions are interpreting all these different things into sound. Also If I were to experiment with these values(-1.0 to 1.0), putting them into an array, would I get sound as a result?

Going back to question 1, these values are arbitrary, and relate to the sample format being used. Digital sound can be described along 2 axes: sample rate (measured in Hertz) and the sample format (eg. 16bit signed integer, 24bit signed integer, 32 bit float). It's the sample format that is of interest here. Basically that specifies how each sample is to be stored. A maximum amplitude sine wave stored in a 16bit format would vary between -32768 to +32767. One in 24bit would vary from -8388608 to 8388607. A 32 bit floating point is slightly different - it's conventional to vary the maximum from -1.0 to +1.0, but unlike the integer formats, you can go outside that range if you like. (With the result being distortion when the time comes to output the value.)

Question 4. 
Lastly - a bit of theory stuff I'm not sure on (and can't quite find good google resources on) - If I were to create my own sound where every hertz never goes below 0, would the sound be audible? why/why not?

Hertz is a measure of frequency, not a specific thing in the file. I think you're talking about individual samples. You could certainly make a series of samples that never went below zero and if it still followed the standard sine wave pattern then it would sound pretty much the same. Zero is just an arbitrary point that lies in the middle of the range and has no special meaning.

PARTNERS