资源描述:
《源代码-MIDI信息隐藏技术研究.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、1、水印嵌入若(s[i]&0xf0)=0x90,则在第i+2个字节s[i+2]中嵌入1比特水印信息,表示修改声音开启的最低位。若(s[i]&0xf0)=0xc0,则在第i+1个字节s[i+1]中嵌入1比特水印信息,表示修改乐器编号的最低位比特。若在第i+1个字节s[i+1]中嵌入4比特水印信息,表示修改通道触动压力的低4比特位。源代码midihiding.m如下:clc;clear;wm=randsrc(1,3000,[01]);%产生长度为3000的随机水印信息save(‘watermark.mat’,’wm’);wm=uint8(wm);fid=fopen(‘love.mid’,’
2、r’);%读入音频文件wa=fread(fid,inf);[length,col]=size(wa);fclose(fid);modcount=1;watermarklen=3000;j=1;fori=1:lengthif(bitand(uint8(wa(i,1)),uint8(240))==144)&&(j<=watermarklen-1)wa((i+2),1)=bitand(wa(i+2),254);wa((i+2),1)=bitset(wa((i+2),1),1,wm(1,j));modcount=modcount+1;i=i+3;j=j+1;elseif(bitand(uint
3、8(wa(i,1)),uint8(240))==176)&&(j<=watermarklen-1)wa((i+1),1)=bitand(wa(i+1),254);wa((i+1),1)=bitset(wa((i+1),1),1,wm(1,j));modcount=modcount+1;i=i+2;j=j+1;elseif(bitand(uint8(wa(i,1)),uint8(240))==208)&&(j<=watermarklen-4)wa((i+1),1)=bitand(wa(i+1),254);wa((i+1),1)=bitset(wa((i+1),1),1,wm(1,j));
4、wa((i+1),1)=bitset(wa((i+1),1),2,wm(1,j+1));wa((i+1),1)=bitset(wa((i+1),1),3,wm(1,j+2));wa((i+1),1)=bitset(wa((i+1),1),4,wm(1,j+3));i=i+2;j=j+4;modcount=modcount+1;elsei=i+1;endendfid=fopen(‘watermarked.mid’,’wb’);fwrite(fid,wa);fclose(fid);2、水印提取源代码midiextract.m如下:clc;clear;fid=fopen(‘watermark
5、ed.mid’,’r’);%读入携密音频文件wa=fread(fid,inf);[length,col]=size(wa);fclose(fid);watermarklen=3000;forj=1:watermarklenwm1(j)=0;endj=1;fori=1:lengthif(bitand(uint8(wa(i,1)),uint8(240))==144)&&(j<=watermarklen)wm1(1,j)=bitget(wa(i+2),1);i=i+2;j=j+1;elseif(bitand(uint8(wa(i,1)),uint8(240))==176)&&(j<=wate
6、rmarklen-1)wm1(1,j)=bitget(wa(i+1),1);i=i+1;j=j+1;elseif(bitand(uint8(wa(i,1)),uint8(240))==208)&&(j<=watermarklen-4)wm1(1,j)=bitget(wa(i+2),1);wm1(1,j+1)=bitget(wa(i+2),2);wm1(j+2)=bitget(wa(i+2),3);wm1(j+3)=bitget(wa(i+2),4);i=i+2;j=j+4;endendload(‘watermark.mat’);diff=wm-wm1;通信0801班***