R
Robert Dow
Thanks for the comments on my last post, they were very useful. Here is another
question that it would be useful to get some comments on. I deal a lot with
sound data which comes in a fixed format of either signed 16 or 24 bit
integers. What is the best way of defining these types to allow some level
of portability? Is it simply a matter of using conditional preprocessor
inclusions to create a type suitable for a particular machine? Such as:
#ifdef SUN
typedef word16_t short;
#else
.... define for other platforms.
Also, for converting 24 bit integers to 32 bit (so I can use them) I have
written this:
#define WORD24_LEN 3
typedef long s32word_t; /* OK for Max OS X/G5 but not nesc. other platforms */
union word32 {
s32word_t lword;
unsigned char byte[4];
};
s32word_t word24toword32(const char *pWord24) {
union word32 outputword;
register unsigned int i;
for(i=0;i<WORD24_LEN;i++) outputword.byte[i+1] = pWord24;
if (outputword.byte[1] >= 0x80) outputword.byte[0] = 0xff;
else outputword.byte[0] = 0x00;
return(outputword.lword);
}
void word32toword24(s32word_t inword, char *pWord24) {
union word32 inputword;
register unsigned int i;
inputword.lword = inword;
for(i=0;i<WORD24_LEN;i++) pWord24 = inputword.byte[i+1];
}
I am wondering if there is a nicer way to do this?
Robert
question that it would be useful to get some comments on. I deal a lot with
sound data which comes in a fixed format of either signed 16 or 24 bit
integers. What is the best way of defining these types to allow some level
of portability? Is it simply a matter of using conditional preprocessor
inclusions to create a type suitable for a particular machine? Such as:
#ifdef SUN
typedef word16_t short;
#else
.... define for other platforms.
Also, for converting 24 bit integers to 32 bit (so I can use them) I have
written this:
#define WORD24_LEN 3
typedef long s32word_t; /* OK for Max OS X/G5 but not nesc. other platforms */
union word32 {
s32word_t lword;
unsigned char byte[4];
};
s32word_t word24toword32(const char *pWord24) {
union word32 outputword;
register unsigned int i;
for(i=0;i<WORD24_LEN;i++) outputword.byte[i+1] = pWord24;
if (outputword.byte[1] >= 0x80) outputword.byte[0] = 0xff;
else outputword.byte[0] = 0x00;
return(outputword.lword);
}
void word32toword24(s32word_t inword, char *pWord24) {
union word32 inputword;
register unsigned int i;
inputword.lword = inword;
for(i=0;i<WORD24_LEN;i++) pWord24 = inputword.byte[i+1];
}
I am wondering if there is a nicer way to do this?
Robert