static bool validateSample(const database::Sample& sample)
{
    if(sample.isImageSample() && video::Image::isPathAnImageFile(sample.path()))
    {
        video::Image image(sample.path());

        try
        {
            image.loadHeader();

            if(!image.headerLoaded())
            {
                return false;
            }
        }
        catch(const std::exception& e)
        {
            return false;
        }

        return true;
    }
    else if(sample.isAudioSample())
    {
        audio::Audio waveform(sample.path());

        try
        {
            waveform.cache();
        }
        catch(const std::exception& e)
        {
            return false;
        }

        return true;
    }

    return false;
}
示例#2
0
void acquire_scans (void)
{
	int color;
	int Nleft=0;
	char file [ FILENAME_MAX ];
	char filename[FILENAME_MAX];
	int data_file;

	SetCtrlAttribute (ERG_panel, ERG_panel_acquire, ATTR_DIMMED, 1);
	SetCtrlAttribute (ERG_panel, ERG_panel_abortscan, ATTR_DIMMED, 1);
	GetCtrlVal (ERG_panel, ERG_panel_nscans, &Nscans);

	DirSelectPopup ("d:\\data\\test", "Select Directory", 1, 1, pathname);

//acquire preambule
	strcpy(filename, pathname);
	sprintf(file, "\\scope_info.txt");
	strcat(filename, file);
	IO_output = fopen (filename, "w");
	wavepreamble();
	fclose(IO_output);

//acquire scaling coefficients
	strcpy(filename, pathname);
	sprintf(file, "\\scope_xinterval.txt");
	strcat(filename, file);
	IO_output = fopen (filename, "w");
	wavexinterval();
	fclose(IO_output);

	strcpy(filename, pathname);
	sprintf(file, "\\scope_yscaling.txt");
	strcat(filename, file);
	IO_output = fopen (filename, "w");
	waveyscaling();
	fclose(IO_output);

	strcpy(filename, pathname);
	sprintf(file, "\\scope_x0.txt");
	strcat(filename, file);
	IO_output = fopen (filename, "w");
	wavex0();
	fclose(IO_output);

	i=0;
	SetCtrlAttribute (ERG_panel, ERG_panel_pause, ATTR_DIMMED, 0);
	SetCtrlAttribute (ERG_panel, ERG_panel_abortscan, ATTR_DIMMED, 0);
	
// start trigger 
	SRS_flag=2;
	SRS_onoff();

// prepare file for intensity values, mask type and scan ref
	strcpy(filename, pathname);
	sprintf(file, "\\intensity.txt");
	strcat(filename, file);
	IO_intensity = fopen (filename, "w"); 
	
	 
	
//prepare file name for acquiring data
	while ( i < Nscans )
	{
		strcpy(filename, pathname);
		sprintf(file, "\\scope_data%d.txt", i);
		strcat(filename, file);

		data_file=OpenFile (filename, VAL_WRITE_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);

		color=floor(256/Nscans)*i;
		waveform(color, data_file);
		
//the increment is done within the waveform function
		i++;

		Nleft=Nscans-i+1;
		SetCtrlVal (ERG_panel, ERG_panel_nremain, Nleft);
		ProcessSystemEvents();
		if (pause_flag)
		{
			while (pause_flag)
				ProcessSystemEvents();
		}
	}
	SetCtrlVal (ERG_panel, ERG_panel_nremain, 0);
	SetCtrlAttribute (ERG_panel, ERG_panel_pause, ATTR_DIMMED, 1);
	SetCtrlAttribute (ERG_panel, ERG_panel_abortscan, ATTR_DIMMED, 1);
	SetCtrlAttribute (ERG_panel, ERG_panel_acquire, ATTR_DIMMED, 0);
	
// stop trigger 	
	SRS_flag=0;
	SRS_onoff();

//clean buffer
	strcpy(filename, pathname);
	sprintf(file, "\\junk.txt");
	strcat(filename, file);
	IO_output = fopen (filename, "w");
	cleanbuffer();
	fclose(IO_output);

//close file 
	if (Nscans==0)
	{
	fclose(IO_intensity);
	}
	
	return;
}
示例#3
0
int drumsynth::generate(short * buffer,int len)
{
  //MessageBox(NULL, dsfile, "DrumSynth", MB_OK); //////////////////

  //input file

  int i=0;
  //output file 
  wavemode=1;
  wavewords=0;

  for (i=0;i<len;i++)
    buffer[i]=0;
  
  if (tpos>=Length)
    return -1;


  //sloppy programming? wait if DLL in use
  //while(busy==1) Sleep(0); busy=1;
  //while(busy==1) sleep(0); busy=1;

  prepare=1;
  if (prepare==0)
    {
      return -2;
    }

  for (i=0;i<len;i++)
    buffer[i]=0;


  //generate
  //tpos = 0;
  //while(tpos<Length)
  //{
    tplus = tpos + len-1;

    if(NON==1) //noise
    {
      for(t=tpos; t<=tplus; t++)
      {
        if(t < envData[2][NEXTT]) envData[2][ENV] = envData[2][ENV] + envData[2][dENV];
        else UpdateEnv(2, t);
        x[2] = x[1];
        x[1] = x[0];
        x[0] = (randmax2 * (float)rand()) - 1.f; 
        TT = a * x[0] + b * x[1] + c * x[2] + d * TT;
        DF[t - tpos] = TT * g * envData[2][ENV];
      }
      if(t>=envData[2][MDA_MAX]) NON=0;
    }
    else for(j=0; j<len; j++) DF[j]=0.f;
    
    if(TON==1) //tone
    {
      TphiStart = Tphi;
      if(TDroop==1)
      {
        for(t=tpos; t<=tplus; t++)
          phi[t - tpos] = F2 + (ddF * (float)exp(t * TDroopRate));
      }          
      else
      {
        for(t=tpos; t<=tplus; t++)
          phi[t - tpos] = F1 + (t / envData[1][MDA_MAX]) * ddF;
      }  
      for(t=tpos; t<=tplus; t++)
      {
        totmp = t - tpos;
        if(t < envData[1][NEXTT]) 
          envData[1][ENV] = envData[1][ENV] + envData[1][dENV];
        else UpdateEnv(1, t);
        Tphi = Tphi + phi[totmp];
        DF[totmp] += TL * envData[1][ENV] * (float)sin(fmod(Tphi,TwoPi));//overflow?
      }
      if(t>=envData[1][MDA_MAX]) TON=0;
    }
    else for(j=0; j<len; j++) phi[j]=F2; //for overtone sync
    
    if(BON==1) //noise band 1
    {
      for(t=tpos; t<=tplus; t++)
      {
        if(t < envData[5][NEXTT])
          envData[5][ENV] = envData[5][ENV] + envData[5][dENV];
        else UpdateEnv(5, t);
        if((t % BFStep) == 0) BdF = randmax * (float)rand() - 0.5f;
        BPhi = BPhi + BF + BQ * BdF;
        botmp = t - tpos;
        DF[botmp] = DF[botmp] + (float)cos(fmod(BPhi,TwoPi)) * envData[5][ENV] * BL;
      }
      if(t>=envData[5][MDA_MAX]) BON=0;
    }

    if(BON2==1) //noise band 2
    {
      for(t=tpos; t<=tplus; t++)
      {
        if(t < envData[6][NEXTT])
          envData[6][ENV] = envData[6][ENV] + envData[6][dENV];
        else UpdateEnv(6, t);
        if((t % BFStep2) == 0) BdF2 = randmax * (float)rand() - 0.5f;
        BPhi2 = BPhi2 + BF2 + BQ2 * BdF2;
        botmp = t - tpos;
        DF[botmp] = DF[botmp] + (float)cos(fmod(BPhi2,TwoPi)) * envData[6][ENV] * BL2;
      }
      if(t>=envData[6][MDA_MAX]) BON2=0;
    }

    for (t=tpos; t<=tplus; t++)
    {
      if(OON==1) //overtones
      {
        if(t<envData[3][NEXTT])
          envData[3][ENV] = envData[3][ENV] + envData[3][dENV];
        else
        {
          if(t>=envData[3][MDA_MAX]) //wait for OT2
          {
            envData[3][ENV] = 0; 
            envData[3][dENV] = 0; 
            envData[3][NEXTT] = 999999;
          }
          else UpdateEnv(3, t);
        }
        //
        if(t<envData[4][NEXTT])
          envData[4][ENV] = envData[4][ENV] + envData[4][dENV];
        else
        {
          if(t>=envData[4][MDA_MAX]) //wait for OT1
          {
            envData[4][ENV] = 0;
            envData[4][dENV] = 0;
            envData[4][NEXTT] = 999999;
          }
          else UpdateEnv(4, t);
        }
        //
        TphiStart = TphiStart + phi[t - tpos];
        if(OF1Sync==1) Ophi1 = TphiStart * OF1; else Ophi1 = Ophi1 + OF1;
        if(OF2Sync==1) Ophi2 = TphiStart * OF2; else Ophi2 = Ophi2 + OF2;
        Ot=0.0f;
        switch (OMode)
        {
          case 0: //add
            Ot = OBal1 * envData[3][ENV] * waveform(Ophi1, OW1);
            Ot = OL * (Ot + OBal2 * envData[4][ENV] * waveform(Ophi2, OW2));
            break;
        
          case 1: //FM
            Ot = ODrive * envData[4][ENV] * waveform(Ophi2, OW2);
            Ot = OL * envData[3][ENV] * waveform(Ophi1 + Ot, OW1);
            break;
        
          case 2: //RM
            Ot = (1 - ODrive / 8) + (((ODrive / 8) * envData[4][ENV]) * waveform(Ophi2, OW2));
            Ot = OL * envData[3][ENV] * waveform(Ophi1, OW1) * Ot;
            break;

          case 3: //808 Cymbal
            for(j=0; j<6; j++)
            {
              Oc[j][0] += 1.0f;
              
              if(Oc[j][0]>Oc[j][1])
              { 
                Oc[j][0] -= Oc[j][1]; 
                Ot = OL * envData[3][ENV];
              }
            }
            Ocf1 = envData[4][ENV] * OcF;  //filter freq
            Oc0 += Ocf1 * Oc1;
            Oc1 += Ocf1 * (Ot + Oc2 - OcQ * Oc1 - Oc0);  //bpf
            Oc2 = Ot;
            Ot = Oc1;
            break;
        }
      } 
          
      if(MainFilter==1) //filter overtones
      {
        if(t<envData[7][NEXTT])
          envData[7][ENV] = envData[7][ENV] + envData[7][dENV];
        else UpdateEnv(7, t);

        MFtmp = envData[7][ENV];
        if(MFtmp >0.2f)
          MFfb = 1.001f - (float)pow(10.0f, MFtmp - 1);
        else
          MFfb = 0.999f - 0.7824f * MFtmp; 
        
        MFtmp = Ot + MFres * (1.f + (1.f/MFfb)) * (MFin - MFout); 
        MFin = MFfb * (MFin - MFtmp) + MFtmp;
        MFout = MFfb * (MFout - MFin) + MFin;

        DF[t - tpos] = DF[t - tpos] + (MFout - (HighPass * Ot));
      }
      else if(MainFilter==2) //filter all
      {
        if(t<envData[7][NEXTT])
          envData[7][ENV] = envData[7][ENV] + envData[7][dENV];
        else UpdateEnv(7, t);

        MFtmp = envData[7][ENV];
        if(MFtmp >0.2f)
          MFfb = 1.001f - (float)pow(10.0f, MFtmp - 1);
        else
          MFfb = 0.999f - 0.7824f * MFtmp; 
        
        MFtmp = DF[t - tpos] + Ot + MFres * (1.f + (1.f/MFfb)) * (MFin - MFout); 
        MFin = MFfb * (MFin - MFtmp) + MFtmp;
        MFout = MFfb * (MFout - MFin) + MFin;
        
        DF[t - tpos] = MFout - (HighPass * (DF[t - tpos] + Ot));
      }
      else DF[t - tpos] = DF[t - tpos] + Ot; //no filter
    }
    
    if(DiON==1) //bit resolution
    {
      for(j=0; j<len; j++)
        DF[j] = DGain * (int)(DF[j] / DAtten);
      
      for(j=0; j<len; j+=DStep) //downsampling
      {
        DownAve = 0;
        DownStart = j;
        DownEnd = j + DStep - 1;
        for(jj = DownStart; jj<=DownEnd; jj++) 
          DownAve = DownAve + DF[jj];
        DownAve = DownAve / DStep;
        for(jj = DownStart; jj<=DownEnd; jj++) 
          DF[jj] = DownAve;
      }  
    }
    else for(j=0; j<len; j++) DF[j] *= DGain;
    
    for(j = 0; j<len; j++) //clipping + output
    {
      if(DF[j] > clippoint) 
        buffer[wavewords++] = clippoint;
      else
        if(DF[j] < -clippoint)
          buffer[wavewords++] = -clippoint;
        else 
          buffer[wavewords++] = (short)DF[j];
    } 

    if(((100*tpos) / Length) > (progress + 4))
    {
      progress = (100*tpos) / Length;
      sprintf(percent,"%i%%", progress);
      //if(hWnd>0) SetWindowText(hWnd, percent);
      
    }
    tpos = tpos + len;
    //}

  /* if(wavemode==0) */
  /* { */
  /*   fwrite(wave, 2, Length, fp);  //write data */
  /*   fwrite(&WI,  1, 44, fp); //write INFO chunk */
  /*   fwrite(&comment, 1, commentLen, fp); */
  /*   fclose(fp); */
  /* } */
  /* wavemode = 0; //force compatibility!! */
  /* busy = 0; //success!!  */

  return wavewords;
}
示例#4
0
void acquire_scans (void)
{
	int color;
	int Nleft=0;
	char file [ FILENAME_MAX ];

	SetCtrlAttribute (Main_pnl_handle, ERG_panel_acquire, ATTR_DIMMED, 1);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_abortscan, ATTR_DIMMED, 1);
	if (experiment==1){
		GetCtrlVal (Sequence_pnl_handle, Seq_panel_seq_number, &seq_num);
		Nscans=	seq_num*m;
	}
	else {
		GetCtrlVal (Main_pnl_handle, ERG_panel_nscans, &Nscans);
	}

	DirSelectPopup ("d:\\data\\test", "Select Directory", 1, 1, pathname);

	i=0;
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_pause, ATTR_DIMMED, 0);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_abortscan, ATTR_DIMMED, 0);
	
// start trigger 
	SRS_flag=2;
	SRS_onoff();
	DeleteGraphPlot (Main_pnl_handle, ERG_panel_mask_display, -1, VAL_IMMEDIATE_DRAW);
	
	if (experiment==1){			 // mode sequence
		for (i=0;i<seq_num;i++) {
			for (h=0;h<m;h++){
				SetCtrlIndex (Sequence_pnl_handle, Seq_panel_mask_list, h);
				for (k=0;k<Npixel;k++){
					drive_level[k]=mask[h].voltages[k];
				}				
				display_masks();
				
				ProcessSystemEvents();
				GetLabelFromIndex (Sequence_pnl_handle, Seq_panel_mask_list, h, &mask_filename);
				strcpy(filename, pathname);
				
				//prepare file to write
				sprintf(file, "\\sequence%d_%s.txt", i, mask_filename);
				strcat(filename, file);
				data_file = OpenFile (filename, VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_ASCII);
				
				//enable oscillo then wait for trigger and get ERG trace
				color=floor(256/Nscans)*(i*m+h);
				waveform(color, data_file);	
				get_intensity();
				
				//write header file
				headerfile();
				
				//write ERG trace 
				ArrayToFile (filename, data2fit, VAL_DOUBLE, 10000, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_SEP_BY_TAB, 100, VAL_ASCII, VAL_APPEND);
				nmeasure[0]=i*m+h+1;
				displaychannel();
				
				Nleft=Nscans-(i*m+h);
				SetCtrlVal (Main_pnl_handle, ERG_panel_nremain, Nleft);
				ProcessSystemEvents();
				if (pause_flag)
				{
					while (pause_flag)
						ProcessSystemEvents();
				}
			}
		}
	}
	
	else{				  // mode normal
	//prepare file name for acquiring data
		while ( i < Nscans )
		{
			strcpy(filename, pathname);
			sprintf(file, "\\scope_data%d.txt", i);
			strcat(filename, file);
			data_file = OpenFile (filename, VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_ASCII);
			color=floor(256/Nscans)*i;
			waveform(color, data_file);
			get_intensity();
			
			headerfile();
			ArrayToFile (filename, data2fit, VAL_DOUBLE, 10000, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_SEP_BY_TAB, 100, VAL_ASCII, VAL_APPEND);
			
			i++;
			Nleft=Nscans-i+1;
			SetCtrlVal (Main_pnl_handle, ERG_panel_nremain, Nleft);
			ProcessSystemEvents();
			if (pause_flag)
			{
				while (pause_flag)
					ProcessSystemEvents();
			}
			CloseFile (data_file);
		}
	}
	
	SetCtrlVal (Main_pnl_handle, ERG_panel_nremain, 0);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_pause, ATTR_DIMMED, 1);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_abortscan, ATTR_DIMMED, 1);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_acquire, ATTR_DIMMED, 0);
	
// stop trigger 	
	SRS_flag=0;
	SRS_onoff();
	
	ibsic(device); 
	return;
}