Thread: 16bit samples stored in shorts how i can reduce bits ?

  1. #1
    Registered User
    Join Date
    Dec 2013
    Posts
    46

    16bit samples stored in shorts how i can reduce bits ?

    16bit samples stored in shorts how i can reduce bits ? i meann idea
    not sources. i try learn code itself (i not school but i still dont want premade solutions for this)... i mean way make 16bit sample sound for example 4bit/8bit... and these are are audiosamples.

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,795
    Divide the 16-bit number by 2 (for 8 bit)??

  3. #3
    Registered User
    Join Date
    Dec 2013
    Posts
    46
    but same algorithm i think works for pics....(what i means something i have book which have image processing algorithms)
    and i want flexible code this code what i have makes fixed amount steps which means is still better than nothing.

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,795
    Dividing by 2 is incorrect, dunno why I said that. Divide by 256.

    Edit: if you want something more accurate you'll have to convert the input to a double, get the number as a percentage of the entire range (for 16-bits) and multiply this percentage by the range of the 8-bit type. For results even more accurate you'll need some fancy mathematics.
    Last edited by Hodor; 12-08-2013 at 07:43 PM.

  5. #5
    Registered User
    Join Date
    Dec 2013
    Posts
    46
    hodor but when i want still use whole range which is main problem. fi sample data goes originally in 4bit for this way:
    0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
    after code i get (and i algorithm what i can adjust not fixed ones which are so easy do)
    0,0,0,0,4,4,4,4,8,8,8,8,12,12,12,12
    my idea diving for example for example 2 and after this multiplying 2 dont work i think...

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,208
    An 8 bit number
    10011100

    The same 8 bit number reduced to a 4-bit range
    00001001
    This you get by doing something like
    var = var >> 4;

    The same 8 bit number reduced to a 4 bit range, but still stored in an 8 bit range.
    10010000
    This you get by doing something like
    var = var & 0xf0;

    > i mean way make 16bit sample sound for example 4bit/8bit... and these are are audiosamples.
    You can't just chop off bits and preserve any sense of audio quality.
    If you want meaningful compression (which has only a minor effect on quality, but saves a lot of space), then you need to read up on the theory of audio compression, and look at how MP3, OGG etc achieve their results.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It's easy to reduce bits if you don't need to recover the original data, or can accept a non-zero error rate (i.e. loss of data).

    If you need to recover the original data, you need to look for patterns in the bits (or in sets of ints) and do some form of encoding. Compression algorithms do this all the time. There are trade-offs, naturally. No encoding scheme can compress all possible sets of input data - and in the worst case, may increase the size.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  8. #8
    Registered User
    Join Date
    Dec 2013
    Posts
    46
    I know reducing bits affect sound quality and is what i want. this effect is common and gives "oldschool" falvour. i maybe found solutiong based what different people wrote here...

  9. #9
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    If you're just trying to distort the sound a bit, try masking off (set to zero) the lower order bits, like x = x & ((short)0 - (short)16).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bison/Yacc shift/reduce reduce/reduce
    By AnthonyGould in forum Tech Board
    Replies: 0
    Last Post: 11-20-2009, 08:15 AM
  2. Return 16bit structure or 16bit word?
    By nenpa8lo in forum C Programming
    Replies: 7
    Last Post: 06-25-2009, 05:16 PM
  3. An on the other corner with red shorts...
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-16-2008, 10:16 PM
  4. adding together two shorts
    By Bleech in forum C Programming
    Replies: 6
    Last Post: 06-11-2007, 03:59 PM
  5. Yacc: reduce/reduce
    By alphaoide in forum Tech Board
    Replies: 2
    Last Post: 04-27-2005, 08:03 PM