Re: linear PCM
Re: linear PCM
- Subject: Re: linear PCM
- From: Roland Silver <email@hidden>
- Date: Sun, 13 Jan 2008 21:06:44 -0700
Some more questions:
* What is the "device" which outputs to the Mac speakers or to the
output audio jack?
* What is the bit depth of that device? OR
* How do I query that device for its bit depth?
* after scaling by A to avoid clipping, do I put the scaled (float)
values A*v(t) directly into the buffers?
--RS
-----------------------------------------------
On 2008Jan13, at 19:21, Brian Willoughby wrote:
Aha! Now we're getting somewhere.
sin() is a mathematic function which just happens to meet the
following constraints: -1.0 <= sin(x) <= +1.0
This is very, very close to meeting the limited range of two's-
complement fixed point (the format used by digital-to-analog
converters, even when the software is working with float).
Other functions have different ranges. The following is only
appropriate for sin() while you would need different solutions for
other functions.
You should not put the v(t) values directly into the buffers because
the +1.0 results from the sin() function will clip the output
device. You need to multiply the function by a scaling factor.
v(t) = A*sin(2*pi*f*t)
... where
double A = 32767./32768.;
The scaling value I've given above is probably the safest universal
value you could use without testing the specific bit depth of the
output device that is currently in use. I suppose you might run
into an 8-bit device, or some other device with less than 16 bits of
accuracy, in which case you would still clip unless you compute a
smaller scaling factor. But in those cases you're getting such
horrible signal-to-noise ratios that perhaps harmonic clipping
distortion could be the least of your worries.
If you want to write all the code necessary to query the current
output device for its bit depth, as well as register for all
notifications which might result if the user were to change the bit
depth while your program is running, then you could compute the
scaling factor as follows:
double A = (pow(2., N - 1) - 1. / pow(2., N - 1));
... where N is the bit depth, e.g. 16, 20, 24, etc.
What happens after this - in terms of voltage, current, and air
pressure - depends entirely upon the analog electronics and
mechanical speakers. But I'm guessing we're close enough to
affrighting the air to satisfy the question. :-)
Brian W.
On Jan 13, 2008, at 17:09, Roland Silver wrote:
Well, let me get specific: Suppose I generate a signal whose
instantaneous value is v(t) = sin(2*pi*f*t) (both channels), for t =
0, dt, 2*dt, 3*dt, etc, where dt = 1/44,100 sec, and f = 440 Hz. I
want to affright the air with that signal by outputting the
successive samples to Audio Queue buffers as described in Chapter 3
(Playing Audio) of the Audio Queue Services Programming Guide.
I propose to set the mFormatID field of AudioStreamBasicDescription
= kAudioFormatLinearPCM, with appropriate values for the other
fields, specifying (say) two channels, 32-bit floating-point data
format.
My question is: do I put the successive v(t)s directly into the
buffers, or do I need to transform them first, somehow?
--RS
On 2008Jan13, at 16:21, Brian Willoughby wrote:
On Jan 13, 2008, at 15:04, Roland Silver wrote:
Given a signal with amplitude A at time t, is the value of the
corresponding linear PCM signal at time t just A itself,
No. Amplitude is the maximum value over an entire period of a
waveform. There is only one time t per cycle where the value would
be the maximum. At all other time t, the value will be less than A.
Perhaps, when you said "amplitude," you really meant "instantaneous
value."
or is a conversion required?
A conversion is always either implied or explicit. Signals can
either be pure mathematical functions, software algorithms, or
sampled signals. Functions and algorithms may have an infinite
range, and need to be scaled (converted) to fit within the allowed
range. Sampled signals also need to be scaled before
digitization. Linear PCM signals can be float or fixed, and they
can have varying numbers of bits of precision. As such, an
equivalent value can have many different specific numerical
values. The most important difference is between linear float PCM
and fixed linear PCM.
Or, in short, you have neither defined "signal" nor "linear PCM
signal" enough for anyone to answer. Both terms are vague enough
that there is no way to say.
Brian Willoughby
Sound Consulting
Roland Silver
email@hidden
Roland Silver
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden