delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2014/03/29/15:41:14

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
Message-ID: <533721CC.9000408@buffalo.edu>
Date: Sat, 29 Mar 2014 15:41:00 -0400
From: "Stephen R. Besch" <sbesch AT buffalo DOT edu>
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version: 1.0
To: geda-user AT delorie DOT com
Subject: Re: [geda-user] Wav to C array ~ 16 bit to 12 bit
References: <CALSZ9gpoxnz9V-CbisKqmdwQyTtVf6G9nCe2Wt=4p4su-afFBQ AT mail DOT gmail DOT com> <5336E080 DOT 5080600 AT buffalo DOT edu>
In-Reply-To: <5336E080.5080600@buffalo.edu>
X-PM-EL-Spam-Prob: X: 10%
Reply-To: geda-user AT delorie DOT com

I don't know why I didn't think of this earlier (too much of a hurry) 
but after reading John's response and realizing that I had forgotten 
about the sign bit it became clear that you cannot just toss the high 
bits - you need to toss the low bits (essentially an integer divide by 
16). However, now I think that the best technique is to formally rescale 
the data to 12 bits. This is really quite simple. Convert each 16 bit 
sample into a float, divide by 16.0 and then convert the float back into 
an integer, which should now fit into your target 12 bit magnitude. It 
takes care of the signed nature of the data as well and should provide a 
better result than an integer divide.

Steve Besch

On 03/29/2014 11:02 AM, Stephen R. Besch wrote:
> On 03/29/2014 10:36 AM, Rob Butts wrote:
>> I have a short 8kHz 16 bit wav pcm file that I converted to an 8kHz 
>> 16 bit
>> unsigned C numerical array.  I'm using a 12 bit dac so I need to convert
>> the 16 bit numerical array to a 12 bit numerical array.
>>
>> Before I get started is this just a matter of shifting out the four most
>> significant bits of the binary 16 bit value?
>>
> That depends on the nature of the signal. Usually the noise is mostly 
> in the low order bits so you may want to dump at least one or 2 of 
> those. But first, you may also want to examine the high order bits. 
> Depending upon the initial gain settings when the data was sampled, 
> one or 2 of the high order bits may be all the same anyway. In either 
> case, I think I would do this in 2 stages. First, shift up to get rid 
> of unused dynamic range at the top end. Then throw away the rest at 
> the low end where the noise is. You may want to signal average the low 
> bits, say 3 bits into 1 or 4 bits into 2
>
> Steve Besch
>


-- 
fictio cedit veritati

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019