Hi again people!!! ...I have gone into a far smaller scope here with my problem, but after hours of messing around have literally got nowhere!!!! here is a small compilable program to show the error!
Code:
/**********************************************************************/
/** file: test.c **/
/** description: to find out how to stuff two signed short ints into **/
/** an unsigned int and then ustuff them and print the result! **/
/** author: matt conway. **/
/**********************************************************************/
#include <stdio.h>
unsigned int audioEffect(short int inLeft, short int inRight){
unsigned int retVal; /* return value */
short int outLeft, outRight; /* output audio samples */
/* code to process stereo audio data here */
outLeft = inLeft; /* return input left channel audio data */
outRight = inRight; /* return input right channel audio data */
/* now return both left and right channel audio data */
retVal = 0;
retVal = outLeft << 16; /* stuff left audio data into int */
retVal |= outRight;
return retVal;
} /* audioEffect() */
int main(void){
/* example array of audio data for left and right channels */
short int leftAudio[15] = {-17,11,59,51,31,42,17,-1,9,-12,-12,20,16,6,27};
short int rightAudio[15] = {12,78,20,4,-43,5,43,-314,114,-49,-5,113,-98,-32,1};
unsigned int effectedAudio; /* stores result from audioEffect() function */
short int leftData; /* result of audio effect for left channel */
short int rightData; /* result of audio effect for right channel */
int i; /* loop counter */
printf("example program to show my bitwise problem!\n");
/* loop through audio data and apply effect */
for (i=0;i<15;i++){
effectedAudio = 0;
effectedAudio = audioEffect(leftAudio[i],rightAudio[i]);
/* now extract stereo data */
leftData = effectedAudio >> 16; /* left channel data */
rightData = effectedAudio & 0x0000FFFF; /* right channel data */
/* print audio sample before effect and after effect */
/* audio effect does nothing, so values should be same! */
printf("1.Left: %8d, Right: %8d\n", leftAudio[i], rightAudio[i]);
printf("2.Left: %8d, Right: %8d\n", leftData, rightData);
} /* loop */
return 0; /* finished */
} /* main() */
and for the output...
Code:
example program to show my bitwise problem!
1.Left: -17, Right: 12
2.Left: -17, Right: 12
1.Left: 11, Right: 78
2.Left: 11, Right: 78
1.Left: 59, Right: 20
2.Left: 59, Right: 20
1.Left: 51, Right: 4
2.Left: 51, Right: 4
1.Left: 31, Right: -43
2.Left: -1, Right: -43
1.Left: 42, Right: 5
2.Left: 42, Right: 5
1.Left: 17, Right: 43
2.Left: 17, Right: 43
1.Left: -1, Right: -314
2.Left: -1, Right: -314
1.Left: 9, Right: 114
2.Left: 9, Right: 114
1.Left: -12, Right: -49
2.Left: -1, Right: -49
1.Left: -12, Right: -5
2.Left: -1, Right: -5
1.Left: 20, Right: 113
2.Left: 20, Right: 113
1.Left: 16, Right: -98
2.Left: -1, Right: -98
1.Left: 6, Right: -32
2.Left: -1, Right: -32
1.Left: 27, Right: 1
2.Left: 27, Right: 1
Shows that everytime right goes negative, when left is put into the int and then pulled back out it just results to -1 - as pointed out in a previous post earlier today!!!
Thanks again!