Ejemplo n.º 1
0
EmoVoiceVAD::EmoVoiceVAD () {
	
	int version = DSP_MK_VERSION(1,0);
	vad = dsp_vad_create (version, EMOVOICEVAD_FRAME_SIZE);
	voice = new dsp_sample_t[EMOVOICEVAD_FRAME_SIZE];
	steps = 0;
	no_va_counter = 0;
	in_va_segment = false;
}
Ejemplo n.º 2
0
int emo_afile_segment(char *file, asegmentation_method_t *method, asegmentation_type_t type, dsp_sample_t ***signal_segment, int **segment_length) {
	int size=SEGMENT_LENGTH, n_samples=0, n_segments, samples_read;
	FILE *fp;
	dsp_sample_t *signal=NULL;
	dsp_vad_t *Vad;

	signal = (dsp_sample_t *) rs_malloc(sizeof(dsp_sample_t) * size, "Signal data");
	if (!method)
		method = (asegmentation_method_t *) rs_malloc(sizeof(asegmentation_method_t),"Audio segmentation method");

	if (strcmp(file,"-")==0)
		fp = stdin;
	else 
		fp = fopen(file,"r");
	if (!fp) {
		rs_warning("Cannot open file %s!",file);
		return -1;
	}

	while ((samples_read =fread(signal+n_samples,sizeof(dsp_sample_t),BLOCKSIZE,fp)) && samples_read >0) {
		n_samples+=samples_read;
		if (size <= n_samples) {
			size +=SEGMENT_LENGTH;
			signal = (dsp_sample_t *) rs_realloc(signal,sizeof(dsp_sample_t) * size, "Signal data");
		}
		if (samples_read != BLOCKSIZE)
			break;
	}
	fclose(fp);


	if (type == vad && !method->vad) {
		Vad  = dsp_vad_create(DSP_MK_VERSION(1,0),VAD_FRAME_LEN);
		method->vad = Vad;
	}

	n_segments = emo_asegment(method,type,signal,n_samples,signal_segment,segment_length);
	if (n_segments == -1)
		rs_error("Aborting during procession of file %s!",file);

	rs_free(signal);

	return n_segments;
}
Ejemplo n.º 3
0
/*
    Segmentiert eine Liste von Dateien
  
    Argumente:
      filelist:   Name der Datei, die die Dateien enthaelt, die segmentiert 
                  werden sollen
      method: dsp_vad_t*    fuer voice activity detection, 
              int           fuer frames mit fester Laenge
	      char*         fuer Segmentierungsinfo 
      type:   vad, fixed oder info

    Rueckgabewert:
      Anzahl der Signalabschnitte in signal_segment; 
      -1, falls ein Fehler aufgetreten ist
 */
int emo_afilelist_segment(char *filelist, asegmentation_method_t *method, asegmentation_type_t type,int audio_output){
	FILE *fp;
	int n_segments=0;
	int *segment_length=NULL;
	dsp_sample_t **signal_segment=NULL;

	fp = fopen(filelist,"r");
	if (!fp) {
		rs_warning("Cannot open input file: %s!",filelist);
		return -1;
	}

	switch (type) {
		case vad: {
			int stat=0, x=0;
			char filename[STRING_LENGTH], outdir[STRING_LENGTH];
	    
			if (!method)
				method = (asegmentation_method_t *) rs_malloc(sizeof(asegmentation_method_t),"Audio segmentation method");
			if (!method->vad)
				method->vad = dsp_vad_create(DSP_MK_VERSION(1,0),VAD_FRAME_LEN);
	    //rest der zeile ueberspringen
			while(fscanf(fp,"%s\t%s",filename,outdir)==2 && stat >=0) {
				if (output)
					fprintf(stderr,"%s\t%s\t",filename,outdir);
				stat=emo_afile_segment(filename,method,vad,&signal_segment,&segment_length);
				if (stat == -1){
					rs_warning("Segmentation of file %s failed!",filename);
					return -1;
				}
				if (audio_output && stat != emo_afile_output(filename,outdir,stat,signal_segment,segment_length)) {
					rs_warning("Output of segments of file %s failed!",filename);
					return -1;
				}
				if (segment_length)
					rs_free(segment_length);
				if (signal_segment) {
					int i;
					for (i=0;i<stat;i++)
						if (signal_segment[i])
							rs_free(signal_segment[i]);
					rs_free(signal_segment);
				}
				n_segments+=stat;
				while (x != '\n' && x != EOF)
					x=fgetc(fp);
				x=0;
			}
			break;
		}
		case fixed: {
			int stat=0, x=0;
			char filename[STRING_LENGTH], outdir[STRING_LENGTH];
	    
			if (!method->segmentation_info) {
				rs_warning("No segment length or shift info available!");
				return -1;
			}
	    
			while(fscanf(fp,"%s\t%s",filename,outdir)==2 && stat >=0) {
				stat=emo_afile_segment(filename,method,fixed,&signal_segment,&segment_length);
				if (stat == -1){
					rs_warning("Segmentation of file %s failed!",filename);
					return -1;
				}
				if (audio_output) {
					stat = emo_afile_output(filename,outdir,stat,signal_segment,segment_length);
					if (stat == -1){
						rs_warning("Output of segments of file %s failed!",filename);
					}
		    
					return -1;
				}
				n_segments+=stat;
				while (x != '\n' && x != EOF)
					x=fgetc(fp);
				x=0;
			}
			break;
		}
		case info: {
			int stat=0;
			char filename[STRING_LENGTH], outdir[STRING_LENGTH], seg_info[10*STRING_LENGTH];

			if (!method->segmentation_info) {
				rs_warning("No segment length or shift info available!");
				return -1;
			}
	    
			while(fscanf(fp,"%s\t%s\t%[^\n]s",filename,outdir,seg_info)==3 && stat >=0) {
				method->segmentation_info=seg_info;
				stat=emo_afile_segment(filename,method,info,&signal_segment,&segment_length);
	    
				if (stat == -1){
					rs_warning("Segmentation of file %s failed!",filename);
					return -1;
				}

				if (audio_output && stat != emo_afile_output(filename,outdir,stat,signal_segment,segment_length)) {
					rs_warning("Output of segments of file %s failed!",filename);
					return -1;
				}
				n_segments+=stat;
			}
			break;
		}
		default: rs_warning("Unknown segmentation type: %d",type);
		return -1;
	}
    
	fclose(fp);
	return n_segments;
}