I'm just wondering if anyone could help me out with setting/clearing the LSB of an audio sample
The code below goes through an array of 24 elements and each element is added to the file with a new line that follows.
FILE *fp;
fp = fopen(EmbedFile, "w");
for (int i = 0; i < 24; i++){
fprintf(fp, "%d\n", Bits[i]);
}
fclose(fp);
When I open the file everything has been written the way I want them to.
What I'm trying to do is, read the line and compare the value, if it's 0 clear the LSB of the audio sample, else set it to 1, code below:
FILE *embedfile = fopen(EmbedFile, "r");
int line = 0;
char input[12];
char *zero = "0";
char *one = "1";
while (fgets(input, 12, embedfile))
{
//duplicates the key sample prior to lsb modification
outputFrames[frame] = inputFrames[frame];
//sets the lsb of the audio sample to match the current line being read from the text file.
if (strcmp(input, zero) == 0)
{
//clear the LSB
outputFrames[frame] &= ~1;
printf("%u bit inserted\n", outputFrames[frame] &= ~1);
}
else
{
//set the LSB
outputFrames[frame] |= 1;
printf("%u bit inserted\n", outputFrames[frame] |= 1);
}
//next frame
frame++;
}
The print outs aren't showing what I thought they would, instead this is what I get:
1 bit inserted
1 bit inserted
4294967295 bit inserted
4294967295 bit inserted
1 bit inserted
3 bit inserted
1 bit inserted
The .txt file has these values to start with so the print out should match them if I did the conditions correctly.
0
0
1
0
0
0
1
If anyone could point out where I am going wrong I would truly appreciate that, I'm just at a loss as to why the outputs aren't what I expected them.
Thanks