我只是想知道是否有人可以帮助我设置/清除音频样本的 LSB
下面的代码遍历一个包含 24 个元素的数组,每个元素都添加到文件中,并在后面添加一个新行。
FILE *fp;
fp = fopen(EmbedFile, "w");
for (int i = 0; i < 24; i++){
fprintf(fp, "%d\n", Bits[i]);
}
fclose(fp);
当我打开文件时,所有内容都已按照我希望的方式写入。
我要做的是,读取该行并比较该值,如果为 0,则清除音频样本的 LSB,否则将其设置为 1,代码如下:
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++;
}
打印输出没有显示我认为的内容,而是我得到的:
1 bit inserted
1 bit inserted
4294967295 bit inserted
4294967295 bit inserted
1 bit inserted
3 bit inserted
1 bit inserted
.txt 文件以这些值开头,因此如果我正确执行条件,打印输出应该与它们匹配。
0
0
1
0
0
0
1
如果有人能指出我哪里出错了,我真的很感激,我只是不知道为什么输出不是我所期望的。
谢谢