×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    1

    char array to qint24 array

    I'm doing music processing on 24bit samples. The raw samples are stored in a char array. I want to convert this array to a qint24 array.

    Now since there is no qint24 type, I decided to use qint32. A char has a size of 1 byte, so I will have to convert 3 chars to a 24bit sample at a time and store it in a qint32. This is what I'm currently doing:

    Code:
    char temp[3];
    int bufferCurrent;
    for(int i = 0; i < size; ++i)
    {
    	bufferCurrent = i * 3;
    	temp[0] = buffer[bufferCurrent];
    	temp[1] = buffer[bufferCurrent + 1];
    	temp[2] = buffer[bufferCurrent + 2];
    	result[i] = reinterpret_cast<qint32>(temp);
    }
    buffer is the char array and result my new array for the 24bit samples. g++ complaints that it can't convert char* to qint32 (loses precision).

    So I basically need some way to convert 3 chars to a qint32. Any ideas of how to accomplish this?

  2. #2
    Regular Contributor
    Join Date
    May 2010
    Posts
    362

    Re: char array to qint24 array

    I believe you could do this (didn't test it, but should work)

    Code:
    int a,b,c;
    for(int i = 0; i < size; i+= 3)
    {	
    	a = (buffer[i]);
    	if (i + 1 < size)
    		b =  (buffer[i+1]);
    	else
    		b = 0;
    	if (i + 2 < size)
    		c =  (buffer[i+2]);	
    	else
    		c = 0;
    	
    	result[i] = (qint32)((a << 16) | (b << 8) | c); 
    }
    This also takes in account situations where amount of original samples is not dividable by 3.

Similar Threads

  1. Replies: 6
    Last Post: 2011-01-19, 18:44
  2. Compilation array in Double Pointer Array.
    By SymbianTH in forum Open C/C++
    Replies: 3
    Last Post: 2009-09-29, 10:23
  3. Equivalent of a char* Array in symbian
    By ravi_sarma in forum Symbian
    Replies: 4
    Last Post: 2009-01-16, 10:09
  4. unsigned char array length
    By bharatuppal in forum Symbian
    Replies: 1
    Last Post: 2007-02-15, 18:01
  5. char array to TBuf
    By jetsetgo in forum Symbian
    Replies: 1
    Last Post: 2006-06-09, 04:06

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •