c - Setting/clearing LSB of an audio sample -
i'm wondering if me out setting/clearing lsb of audio sample
the code below goes through array of 24 elements , each element added file new line follows.
file *fp; fp = fopen(embedfile, "w"); (int = 0; < 24; i++){ fprintf(fp, "%d\n", bits[i]); } fclose(fp);
when open file has been written way want them to.
what i'm trying is, read line , compare value, if it's 0 clear lsb of audio sample, else set 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 key sample prior lsb modification outputframes[frame] = inputframes[frame]; //sets lsb of audio sample match current line being read text file. if (strcmp(input, zero) == 0) { //clear lsb outputframes[frame] &= ~1; printf("%u bit inserted\n", outputframes[frame] &= ~1); } else { //set lsb outputframes[frame] |= 1; printf("%u bit inserted\n", outputframes[frame] |= 1); } //next frame frame++; }
the print outs aren't showing thought would, instead 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 start print out should match them if did conditions correctly.
0 0 1 0 0 0 1
if point out going wrong appreciate that, i'm @ loss why outputs aren't expected them.
thanks
after little more looking found issue code.
file *fp; fp = fopen(embedfile, "w"); (int = 0; < 24; i++){ fprintf(fp, "%d\n", bits[i]); } fclose(fp);
i mentioned in original post new line follows each insertion.
however my, chars compare don't take account these new lines.
char *zero = "0"; char *one = "1";
after changing them code below, outputs correct.
char *zero = "0\n"; char *one = "1\n";
@undwind thank suggestion, after looking @ it, way makes more sense.
thank you.
Comments
Post a Comment