马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
采用bic准则的音频流分割程序,能够准确找出不同音频种类的分界点位置,如音乐和语音。
给程序有两个函数组成,详细如下:
audioSeg.m
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [y,fs,position] = audioSeg(filenm,clipLen)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %This is main audio stream segment function,it can classfication the audio file to different segments.
- %
- %input:
- % filenm = the flie which need to be classification;
- % clipLen = segment clip length,unit is frame,default value is 100;
- %output:
- % y = the points vector of the file;
- % fs = sample rate;
- % position = type change points;
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% Written by Qian Yong Gao %%
- %% Data:June 23,2006 %%
- %% Update:June 23,2006 by Qian Yong Gao %%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- if nargin < 2
- clipLen = 100;
- end
-
- [fid,msg] = fopen(filenm,'rb');%open file
- error(msg);
- fseek(fid,8,-1);%file point rewind
- header = fread(fid,4,'uchar');
- % makesure '*wav' file format
- if header' ~= 'WAVE'
- error('This file is not a wavfile');
- else
- fseek(fid,8,0);
- iPCM = fread(fid,1,'ushort');%PCM code format
- iMono = fread(fid,1,'ushort');%Mono channel
- if (iPCM ~= 1) & (iMono ~= 1)
- error('This wavefile is not Mono PCM type');
- end
- end
- fs = fread(fid,1,'ushort');%sample rate
- fseek(fid,8,0);
- nBit = fread(fid,1,'ushort');%each sample bits
- nByte = nBit/8;%each sample bytes;
- header = fread(fid,4,'uchar');
- if header' ~= 'data'
- error('The file is corrupt');
- end
- if nByte == 1
- nData = fread(fid,1,'ulong'); %file samples number
- rid = 'uchar';
- else
- nData = fread(fid,1,'ulong') / 2;
- rid = 'short';
- end
- position = 0;%beginning position is '0'
- nRead = 0; %n samples read
- nFrame = 0; %n frame read
- segLen = 0; %n clip read
- y = [];%signal read
- frameLen = floor(0.02 * fs); %frame length
- frameMov = ceil(0.01 * fs); %frame step
- overlap = frameLen - frameMov;%frame overlap
- while nRead <= nData - frameLen
- y1 = fread(fid,frameLen,rid);%read a frame
- nRead = nRead + frameMov;%read samples number increase frameMov
- if fid == 'uchar'
- y1 = (y1 - 128) / 128 ;
- fseek(fid,-overlap,0);%8 bit,rewind file pointer overlap bites
- else
- y1 = y1 / 32768;
- fseek(fid,-2 * overlap,0);%16 bit,rewind file pointer 2*overlap bites
- end
- nFrame = nFrame + 1;%increase read frame number
- y = [y;y1'];%read signal
- %when read frame is clipLen's integer times,nClip increase 1
- segLen = segLen + 1;
- if segLen == 3*clipLen
- clipMat = y([nFrame-3*clipLen+1:nFrame],:);%clip matrix which wait for classifcation
- f = fft(clipMat'.*(hamming(frameLen)*ones(1,3*clipLen)),1024);
- f = abs(f);
- mfc = melfc(f,30,30);
- segN = BeyasInfoCrit(mfc,frameLen,frameMov,0.6);
- if (segN>=clipLen) & (segN<=2*clipLen)
- position = [position;nFrame-3*clipLen+segN];
- segLen = 3 * clipLen - segN;
- else
- segLen = 2 * clipLen;
- end
- end
- end
- fclose(fid);
- position(2:end) = ((position(2:end)-1)*frameMov+frameLen) / fs;
- y = y';
- y1 = y(:,end);
- y(:,end) = [];
- y(frameMov+1:end,:) = [];
- y = y(:);
- y = [y;y1];
- t = [1:length(y)] / fs;
- plot(t,y,'k');
- hold on
- for l = 1:length(position)
- line([position(l) position(l)], [min(y) max(y)], 'Color', 'r');
- end
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
复制代码 |