happy 发表于 2006-10-20 10:21

采用bic准则的音频流分割程序

采用bic准则的音频流分割程序,能够准确找出不同音频种类的分界点位置,如音乐和语音。

给程序有两个函数组成,详细如下:

audioSeg.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function = 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
         
= 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 = ;%read signal   
    %when read frame is clipLen's integer times,nClip increase 1
    segLen = segLen + 1;
    if segLen == 3*clipLen
      clipMat = y(,:);%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 = ;
            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 = ;
t = / fs;
plot(t,y,'k');
hold on
for l = 1:length(position)
    line(, , 'Color', 'r');
end   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

happy 发表于 2006-10-20 10:22

BeyasInfoCrit.m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function segN = BeyasInfoCrit(c,framelen,framemov,labeta)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This function use BIC to find the change point of c
%input:
%   c = frame feature matrix;
%   framelen = frame length
%   framemov = frame move
%output:
%   segN = segment change point
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Written by Qian Yong Gao                   %%
%% Data:October 25,2005                     %%
%% Update:May 30,2006 by Qian Yong Gao      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin < 4
    labeta = 0.8;
end   
= size(c);
u0 = mean(c);
sigma0 = sum((c-u0(ones(1,N),:)).^2)/N;
det0 = max(prod(max(sigma0,eps)),realmin);%行列式的值
detBIC = zeros(1,N-1);
for m = 1:N-1%计算假定断点在m(1~N-1)处的BIC值
    %计算前一部分的参数
    c1 = c(1:m,:);
    u1 = mean(c1);
    sigma1 = sum((c1-u1(ones(1,m),:)).^2)/m;;
    %以对角线乘积代替行列式的值,避免数据不够带来的估计不正确
    det1 = max(prod(max(sigma1,eps)),realmin);
   
    c2 = c(m+1:N,:);
    u2 = mean(c2);
    sigma2 = sum((c2-u2(ones(1,N-m),:)).^2)/(N-m);
    det2 = max(prod(max(sigma2,eps)),realmin);
    %计算两种假设带来的差值
    detBIC(m) = 0.5*(N*log(det0)-m*log(det1)-(N-m)*log(det2))...
      - labeta*0.25*fd*(fd+3)*log(N);
end
= max(detBIC);
if DB > 0
    %segN = framemov*(index-1) + framelen;
    segN = index;
else
    segN = N;%framemov*(N-1) + framelen;
end

890516k 发表于 2008-4-20 18:24

请问mfc = melfc(f,30,30);中的melfc是什么函数,如有源程序能否发给我890516k@163.com

jingxinshulin 发表于 2009-3-17 22:03

求melfc函数代码

我也想要一份melfc 函数的代码,能否发给我:jingxinshulin@163.com
谢谢!

MISKERY 发表于 2011-5-11 23:18

我也想要一份melfc 函数的代码,能否发给我:z.heng@foxmail.com,谢谢了
页: [1]
查看完整版本: 采用bic准则的音频流分割程序