예제 #1
0
static void receiveSecondAudioADC()
{
	if (!input_buffer.isFull()) 
#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(TEENSYDUINO)  || defined(TEENSYDUINO) // teensy 3, 3.1
		input_buffer.write(adc->readSingle());
#else
		input_buffer.write(ADC);
#endif
}
예제 #2
0
static void receiveSecondAudioADC()
{
	if (!input_buffer.isFull()) 
#if IS_TEENSY3()
		input_buffer.write(adc->readSingle());
#elif IS_STM32()
	input_buffer.write(adc.getData());
#else
		input_buffer.write(ADC);
#endif
}
예제 #3
0
  void processAudio(AudioBuffer &buffer){
    float y[getBlockSize()];
    setCoeffs(getLpFreq(), 0.8f);
    float delayTime = getParameterValue(PARAMETER_A); // get delay time value    
    float feedback  = getParameterValue(PARAMETER_B); // get feedback value
    float wetDry    = getParameterValue(PARAMETER_D); // get gain value

    if(abs(time - delayTime) < 0.01)
      delayTime = time;
    else
      time = delayTime;
        
    float delaySamples = delayTime * (delayBuffer.getSize()-1);        
    int size = buffer.getSize();
    float* x = buffer.getSamples(0);
    process(size, x, y);     // low pass filter for delay buffer
    for(int n = 0; n < size; n++){
        
      //linear interpolation for delayBuffer index
      dSamples = olddelaySamples + (delaySamples - olddelaySamples) * n / size;
        
      y[n] = y[n] + feedback * delayBuffer.read(dSamples);
      x[n] = (1.f - wetDry) * x[n] + wetDry * y[n];  //crossfade for wet/dry balance
      delayBuffer.write(x[n]);
    }
    olddelaySamples = delaySamples;
  }
예제 #4
0
  void processAudio(AudioBuffer &buffer) {
    float delayTime, feedback, wetDry;
    delayTime = getParameterValue(PARAMETER_A);
    feedback  = getParameterValue(PARAMETER_B);
    wetDry    = getParameterValue(PARAMETER_D);
    int size = buffer.getSize();
    int32_t newDelay;
    if(abs(time - delayTime) > 0.01){
      newDelay = delayTime * (delayBuffer.getSize()-1);
      time = delayTime;
    }else{
      newDelay = delay;
    }
    float* x = buffer.getSamples(0);
    float y;
    for (int n = 0; n < size; n++){
//       y = buf[i] + feedback * delayBuffer.read(delay);
//       buf[i] = wetDry * y + (1.f - wetDry) * buf[i];
//       delayBuffer.write(buf[i]);
      if(newDelay - delay > 4){
	y = getDelayAverage(delay-5, 5);
	delay -= 5;
      }else if(delay - newDelay > 4){
	y = getDelayAverage(delay+5, 5);
	delay += 5;
      }else{
	y = delayBuffer.read(delay);
      }
      x[n] = wetDry * y + (1.f - wetDry) * x[n];  // crossfade for wet/dry balance
      delayBuffer.write(feedback * x[n]);
    }
  }
예제 #5
0
void FillBuffer(CircularBuffer &cb)
{
	cout << "filling buffer" << endl;
    for (int i = 0; i != 100; ++i)
    {
        cb.write(i);
    }
}
예제 #6
0
 void processAudio(AudioBuffer &buffer) {
   float* x = buffer.getSamples(0);
   float feedback = getParameterValue(PARAMETER_A);
   float mix = getParameterValue(PARAMETER_B);
   for(int n = 0; n < buffer.getSize(); n++){
     x[n] = delayBuffer.tail()*mix + x[n]*(1.0f-mix);
     delayBuffer.write(feedback * x[n]);
   }
 }
예제 #7
0
void audioHook() // 2us excluding updateAudio()
{
//setPin13High();
#if (USE_AUDIO_INPUT==true)
		if (!input_buffer.isEmpty()) 
			audio_input = input_buffer.read();
#endif

	if (!output_buffer.isFull()) {
		#if (STEREO_HACK == true)
		updateAudio(); // in hacked version, this returns void
		output_buffer.write((unsigned int) (audio_out_1 + AUDIO_BIAS));
		output_buffer2.write((unsigned int) (audio_out_2 + AUDIO_BIAS));
		#else
		output_buffer.write((unsigned int) (updateAudio() + AUDIO_BIAS));
		#endif

	}
//setPin13Low();
}
void AccelMaths::tick( void )
{
  //********Update to the Buffers********//
  //Start by filling a circular buffer
  upDataBuffer.write(readFloatAccelY());
  rightDataBuffer.write(readFloatAccelZ());
  //outDataBuffer.write(readFloatAccelX());
  
  //Now average the circular buffer into another
  float floatTemp = 0;
  for( int i = 0; i < 30; i++)
  {
    floatTemp += upDataBuffer.read(i);
  }
  upAverageBuffer.write(floatTemp / 30);
  
  floatTemp = 0;
  for( int i = 0; i < 30; i++)
  {
    floatTemp += rightDataBuffer.read(i);
  }
  rightAverageBuffer.write(floatTemp / 30);
  
  // floatTemp = 0;
  // for( int i = 0; i < 30; i++)
  // {
    // floatTemp += outDataBuffer.read(i);
  // }
  // outAverageBuffer.write(floatTemp / 30);
  
  //********Do Buffer Specific Calculation********//
  //Newer minus older
    // Serial.print("\n");
	// Serial.print(upAverageBuffer.read(0), 4);
	// Serial.print(",");
	// Serial.print(upAverageBuffer.read(1), 4);
  verticalDerivativeBuffer.write( (upAverageBuffer.read(0) - upAverageBuffer.read(1) ) * 1000);
  
}
예제 #9
0
void audioHook() // 2us excluding updateAudio()
{
//setPin13High();
#if (USE_AUDIO_INPUT==true)
		if (!input_buffer.isEmpty()) 
			audio_input = input_buffer.read();
#endif

	if (!output_buffer.isFull()) {
		output_buffer.write((unsigned int) (updateAudio() + AUDIO_BIAS));

	}
//setPin13Low();
}
예제 #10
0
 void processAudio(AudioBuffer &buffer){
   int size = buffer.getSize();
   unsigned int delaySamples;
     
   rate     = getParameterValue(PARAMETER_A) * 0.000005f; // flanger needs slow rate
   depth    = getParameterValue(PARAMETER_B);
   feedback = getParameterValue(PARAMETER_C)* 0.707; // so we keep a -3dB summation of the delayed signal
     
   for (int ch = 0; ch<buffer.getChannels(); ++ch) {
       for (int i = 0 ; i < size; i++) {
           float* buf = buffer.getSamples(ch);
           delaySamples = (depth * modulate(rate)) * (delayBuffer.getSize()-1); // compute delay according to rate and depth
           buf[i] += feedback * delayBuffer.read(delaySamples); // add scaled delayed signal to dry signal
           delayBuffer.write(buf[i]); // update delay buffer
       }
   }
 }
예제 #11
0
 void processAudio(AudioInputBuffer &input, AudioOutputBuffer &output) {        
   const int size = input.getSize();           // samples in block
   float* x = input.getSamples();              // arrays to hold sample data
   std::vector<float> y(size);
       
   delayTime = getParameterValue(PARAMETER_A); // delay time
   feedback  = getParameterValue(PARAMETER_B); // delay feedback
   wetDry    = getParameterValue(PARAMETER_D); // wet/dry balance
       
   float delaySamples = delayTime * (DELAY_BUFFER_LENGTH-1);        
   for (int n = 0; n < size; n++){             // for each sample            
     y[n] = x[n] + feedback * delayBuffer.read(delaySamples);
     x[n] = wetDry * y[n] + (1.f - wetDry) * x[n];  // crossfade for wet/dry balance
     delayBuffer.write(x[n]);
   }
       
   output.setSamples(x);
 }    
 void processAudio(AudioBuffer &buffer)
 {
   float delayTime, feedback, dly;
   delayTime = 0.05+0.95*getParameterValue(PARAMETER_A);
   feedback  = getParameterValue(PARAMETER_B);
   int32_t newDelay;
   newDelay = alpha*delayTime*(delayBuffer.getSize()-1) + (1-alpha)*delay; // Smoothing
   dryWet = alpha*getParameterValue(PARAMETER_D) + (1-alpha)*dryWet;       // Smoothing
     
   float* x = buffer.getSamples(0);
   int size = buffer.getSize();
   for (int n = 0; n < size; n++)
   {
     dly = (delayBuffer.read(delay)*(size-1-n) + delayBuffer.read(newDelay)*n)/size;
     delayBuffer.write(feedback * dly + x[n]);
     x[n] = dly*dryWet + (1.f - dryWet) * x[n];  // dry/wet
   }
   delay=newDelay;
 }
예제 #13
0
    void processAudio(AudioBuffer &buffer) {

        float feedback, wet, _delayTime, _tone, delaySamples;

        _delayTime = getParameterValue(PARAMETER_A);
        feedback = 2*getParameterValue(PARAMETER_B)+0.01;
        _tone = getParameterValue(PARAMETER_C);
        wet = getParameterValue(PARAMETER_D);

        tone = 0.05*_tone + 0.95*tone;
        tf.setTone(tone);

        float* buf = buffer.getSamples(0);
        for (int i = 0 ; i < buffer.getSize(); i++) {
            delayTime = 0.01*_delayTime + 0.99*delayTime;
            delaySamples = delayTime * (delayBuffer.getSize()-1);
            buf[i] = dist(tf.processSample(buf[i] + (wet * delayBuffer.read(delaySamples))));
//            delayBuffer.write(dist(tf.processSample(feedback * buf[i],0)));
            delayBuffer.write(feedback * buf[i]);
        }
    }
  void processAudio(AudioBuffer &buffer)
  {
    float delayTime, feedback, wetDry,drive;
    delayTime = getParameterValue(PARAMETER_A);
    feedback  = getParameterValue(PARAMETER_B);
    drive     = getParameterValue(PARAMETER_C);
    wetDry    = getParameterValue(PARAMETER_D);
     
     
       drive += 0.03;
        drive *= 40;

      
    int newDelay;
    newDelay = delayTime * (delayBuffer.getSize()-1);
      
    float* x = buffer.getSamples(0);
    float y = 0;
      
    int size = buffer.getSize();
    for (int n = 0; n < size; n++)     {
        y = (delayBuffer.read(delay)*(size-1-n) + delayBuffer.read(newDelay)*n)/size + x[n];
   
        y = nonLinear(y * 1.5);
        
        delayBuffer.write(feedback * y);
        
        y = (nonLinear(y * drive)) * 0.25;
      
        
        x[n] = (y *  (1 - wetDry)) +  (x[n] * wetDry);

      
    }
    delay=newDelay;
  }
예제 #15
0
int main ( int argc, char ** argv )
{
    size_t  buffsize = DEFAULT_CIRBUFFER_SIZE;
    size_t  maxsize  = MAX_CIRBUFFER_SIZE;

    if ( argc == 2 )
        buffsize = StringUtils::FromString<size_t>(argv[1]);

    CircularBuffer * buff  = new CircularBuffer(buffsize);
    std::string      bstr  = "0123456789";
    int              count = buffsize / bstr.length();

    std::cout << " buffer capacity = " << buff->size() 
        << ", max is " << maxsize
        << ", string '" << bstr << std::endl
        << "', count is " << count << std::endl << std::endl;

    while ( buff->writeAvailable() >= bstr.length() )
        buff->write(bstr.c_str(), bstr.length());

    char * out = (char*) calloc(bstr.length(), sizeof(char));

    std::cout << " dataAvail in buffer = " << buff->readAvailable()
              << std::endl;

    for ( int i = 0; i < (count / 2); ++i ) {
        buff->read(out, bstr.length());
    }
    std::cout << " read: '" << out << "'" << std::endl;

    buffsize = buffsize - (count / 2);
    std::cout << " resizing to " << buffsize << std::endl;

    if ( ! buff->resize(buffsize) )
        std::cout << "RESIZE FAILED" << std::endl;

    std::cout << " buffer capacity = " << buff->size() << std::endl 
        << " fullDataAvail = " << buff->readAvailable()
        << " dataAvail = " << buff->readPtrAvailable() << std::endl
        << " fullSpaceAvail = " << buff->writeAvailable()
        << " spaceAvail = " << buff->writePtrAvailable()
              << std::endl << std::endl;

    int c = 0;
    while ( buff->writePtrAvailable() >= bstr.length() ) {
        buff->write(bstr.c_str(), bstr.length());
        c++;
    }
    std::cout << " write count = " << c << std::endl << std::endl;

    std::cout << " buffer capacity = " << buff->size() << std::endl 
              << " fullDataAvail = "   << buff->readAvailable()
              << " dataAvail = "       << buff->readPtrAvailable() << std::endl
              << " fullSpaceAvail = "  << buff->writeAvailable()
              << " spaceAvail = "      << buff->writePtrAvailable()
              << std::endl << std::endl;

    buffsize = buff->size() + bstr.length();
    std::cout << " resizing to " << buffsize << std::endl;
    
    if ( ! buff->resize(buffsize) )
        std::cout << " RESIZE FAILED " << std::endl;

    std::cout << " buffer capacity = " << buff->size() << std::endl 
              << " fullDataAvail = "   << buff->readAvailable()
              << " dataAvail = "       << buff->readPtrAvailable() << std::endl
              << " fullSpaceAvail = "  << buff->writeAvailable()
              << " spaceAvail = "      << buff->writePtrAvailable()
              << std::endl << std::endl;

    ::free(out);
    delete buff;

    return 0;
}