function write_event(ddir,event_nr,x,fs2,t1,t2,class);

x=x-mean(x) + randn*std(x)/100;
x=0.99*x/max(abs(x));

ddir = [ddir, '/events/', class, '/'];
[res,msg]=mkdir(ddir);
listfile = [ddir, 'event_list.txt'];
wavfile = [ddir, 'event', num2str(event_nr,'%04d'), '.wav'];
wavfile0 = [ 'event', num2str(event_nr,'%04d'), '.wav'];
fprintf('Event list %s, wavfile %s\n',listfile,wavfile0);
fp=fopen(listfile,'a');
% ev001.wav 0  32000    0.000    0.504
fprintf(fp,'%s 0 %f %f %f\n',wavfile0, fs2, t1, t2);
fclose(fp);
wavwrite(x,fs2,16, wavfile);


