Ejemplo n.º 1
0
void Session::bounce_region(RegionPtr region, std::string filename, Session::FileType type){
  
	//use the bounce session to create file
	//e.g Session temp;
	//add the region 
	//temp->add_region(region)
	//bounce down
	//temp->bounce_session(filename)
	//change original region to the new soundfile.
	SamplePosition storedPosition = region->get_start_pos();
	Session temp;
	temp.set_playback_duration(region->get_duration() + region->get_extension());
	region->set_start_pos(0);
	temp.add_region(region);
	temp.bounce_session(filename,type);
	region->set_start_pos(storedPosition);
}
Ejemplo n.º 2
0
std::string Session::timestretch_region(RegionPtr region, double speed, std::string folderpath, std::string name, int fftSize, int numOverlaps){
  //got here
  //need to take region,
  //call internal process on the region passing the output into a table,
  //run through the table with phasor set up accordingly 
  //render out the new region using sndfile
  
  //initially use the table lookup functionality
  
  
  fsom::DebugStream << "Entering Timestretch"<<std::endl;
  ///////////////////////////////////////////////////////
  ////////Create new session with the region/////////////
  SamplePosition storedPosition = region->get_start_pos();
  Session temp;
  temp.set_playback_duration(region->get_duration() + region->get_extension());
  region->set_start_pos(0);
  temp.add_region(region);
  std::string filepath = folderpath + name+"bounce.wav";
  temp.bounce_session(filepath);
  region->set_start_pos(storedPosition);
  fsom::DebugStream << "Region Bounced"<<std::endl;
  ///////////////////////////////////////////////////////
  ///////

   std::stringstream ssPath;
   char number[24]; // dummy size, you should take care of the size!
//    sprintf(number, "%.2f", stretchAmount);
   
  ssPath<<  folderpath<<  "TS"  << name<< (1.0f/speed)*100<<"%.wav";
  
  TimeStretcher timeStretcher(speed,fftSize,numOverlaps,filepath,ssPath.str() );
  timeStretcher.run();
  /*
  MultiTableBuffer t_tables=load_file_to_table(filepath);
  fsom::DebugStream << "File loaded into table"<<std::endl;
  std::stringstream ssPath;
  ssPath<<  folderpath<< name<<stretchAmount*100<< "%TStretch.wav";
  SNDFILE* outfile;
  SF_INFO m_info;
  m_info.channels = 2;
  m_info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 | SF_ENDIAN_LITTLE;
  m_info.samplerate = 44100;
  outfile = sf_open(ssPath.str().c_str(),SFM_WRITE,&m_info);
  
  fsom::DebugStream << "Table size =  "<< t_tables.at(0)->get_size()+1  ;
  
  
  //FIXME mixing logic here!!!!!!
  
  /*
  Phasor t_phasor(44100,stretchAmount/2.0f);
  float* tempBuf = new float[2];
  for(int n = 0; n < float(region->get_duration()/2)*stretchAmount ;++n){
	      tempBuf[0]= t_tables.at(0)->linear_lookup(t_phasor.get_phase()*(t_tables.at(0)->get_size()+1));
	      tempBuf[1]= t_tables.at(1)->linear_lookup(t_phasor.get_phase()*(t_tables.at(1)->get_size()+1));
	      sf_writef_float(outfile,tempBuf,2);//write to disk
	      t_phasor.tick();
  }
  delete []tempBuf;
  
  
 
  const int HEADCOUNT = 16;
  const int WINDOWSIZE = 1024;
  const float FREQ = 44100.0f/float(WINDOWSIZE);
  Phasor tapeHead(44100,FREQ);
  Table<double> t_han(WINDOWSIZE);
  t_han.fill_hann();
  
  float pos = 0.0;
  
  float rate = 1.0f/stretchAmount;
  
  float headPos[HEADCOUNT];
  for(int n = 0; n < HEADCOUNT; ++n){
    headPos[n] = 0;
  }
  
  int size = region->get_duration()/rate;
  for(int samp = 0; samp < size;++samp){
  
	float s[2];
	s[0] = s[1] = 0.0f;
	
	
	
	for(int n = 0; n < HEADCOUNT; ++n){
	    float phase = phase_wrap(  tapeHead.get_phase() + float(n)/float(HEADCOUNT)    );      
	    float gain = t_han.linear_lookup(phase*float(WINDOWSIZE))      ;
	    
	    
	    if( phase < 0.001 ){
	      headPos[n] = pos;
	    }
	      
	    s[0] += ( t_tables.at(0)->linear_lookup( phase*float(WINDOWSIZE) + headPos[n]   ) * gain) * (1.0f/float(HEADCOUNT));
	    s[1] += ( t_tables.at(1)->linear_lookup( phase*float(WINDOWSIZE) + headPos[n]   ) * gain )* (1.0f/float(HEADCOUNT));
	}
	
	tapeHead.tick();
	
	sf_writef_float(outfile,s,1);//write to disk
	
	pos += rate;
  }
  
  */
  
  
  
  return ssPath.str();
  //////////////////////////////////////////////////////
  ///////
  
  
}