コード例 #1
0
ファイル: MozziGuts.cpp プロジェクト: thomasfredericks/Mozard
static void pwmAudioOutput()
{
#if (USE_AUDIO_INPUT==true)
	adc_count = 0;
	startSecondAudioADC();
#endif

#if (AUDIO_MODE == HIFI)
	int out = output_buffer.read();
	pwmWrite(AUDIO_CHANNEL_1_PIN, out & ((1 << AUDIO_BITS_PER_CHANNEL) - 1));
	pwmWrite(AUDIO_CHANNEL_1_PIN_HIGH, out >> AUDIO_BITS_PER_CHANNEL);
#else
	pwmWrite(AUDIO_CHANNEL_1_PIN, (int)output_buffer.read());
#endif
}
コード例 #2
0
ファイル: usart.cpp プロジェクト: SirIndubitable/mech
void USART::read(uint8_t *buf, uint32_t readLength)
{
  for(uint32_t m = 0; m < readLength; ++m)
  {
    *buf++ = usart3_buffer.read();
  }
}
コード例 #3
0
ファイル: LpfDelayPatch.hpp プロジェクト: mazbox/OwlPatches
  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 printBuffer(CircularBuffer<BufferType> cb)
{
		unsigned int i;
		for(i=0; i< cb.getSize(); i++)
			cout << cb.read(i) << ", ";
		cout << "\n\n";
}
コード例 #6
0
ファイル: CircularBuffer.cpp プロジェクト: mpab/tutoring
void DumpBuffer(CircularBuffer &cb)
{
	cout << "reading from buffer" << endl;
	for (int i = 0; i != 100; ++i)
    {
        cout << cb.read() << endl;
    }
}
コード例 #7
0
 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;
 }
コード例 #8
0
static void teensyAudioOutput()
{
	
#if (USE_AUDIO_INPUT==true)
	adc_count = 0;
	startSecondAudioADC();
#endif

	analogWrite(AUDIO_CHANNEL_1_PIN, (int)output_buffer.read());
}
コード例 #9
0
ISR(TIMER1_OVF_vect, ISR_BLOCK)
{

#if (AUDIO_MODE == STANDARD_PLUS) && (AUDIO_RATE == 16384) // only update every second ISR, if lower audio rate
	static boolean alternate;
	alternate = !alternate;
	if(alternate)
	{
#endif

#if (USE_AUDIO_INPUT==true)
		adc_count = 0;
		startSecondAudioADC();
#endif

//if (!output_buffer.isEmpty()) {
/*
output =  output_buffer.read();
AUDIO_CHANNEL_1_OUTPUT_REGISTER = output;
AUDIO_CHANNEL_2_OUTPUT_REGISTER = 0;
*/

	AUDIO_CHANNEL_1_OUTPUT_REGISTER = output_buffer.read();
#if (STEREO_HACK == true)
		AUDIO_CHANNEL_2_OUTPUT_REGISTER = output_buffer2.read();
#endif

//}

	// flip signal polarity - instead of signal going to 0 (both pins 0), it goes to pseudo-negative of its current value.
	// this would set non-inverted when setting sample value, and then inverted when top is reached (in an interrupt)
	// non-invert
	//TCCR1A |= _BV(COM1A1);
	// invert
	//TCCR1A |= ~_BV(COM1A1)
	
	
#if (AUDIO_MODE == STANDARD_PLUS) && (AUDIO_RATE==16384) // all this conditional compilation is so clutsy!
	}
#endif

}
コード例 #10
0
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);
  
}
コード例 #11
0
ファイル: MozziGuts.cpp プロジェクト: SatoshiSann/Aruduino
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();
}
コード例 #12
0
  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;
  }
コード例 #13
0
ファイル: MozziGuts.cpp プロジェクト: SatoshiSann/Aruduino
void dummy_function(void)
#endif
{
#if (USE_AUDIO_INPUT==true)
	adc_count = 0;
	startSecondAudioADC();
#endif

		// read about dual pwm at http://www.openmusiclabs.com/learning/digital/pwm-dac/dual-pwm-circuits/
		// sketches at http://wiki.openmusiclabs.com/wiki/PWMDAC,  http://wiki.openmusiclabs.com/wiki/MiniArDSP
		//if (!output_buffer.isEmpty()){
		unsigned int out = output_buffer.read();
		// 14 bit, 7 bits on each pin
		AUDIO_CHANNEL_1_HIGHUINT8_T_REGISTER = out >> 7; // B11111110000000 becomes B1111111
		AUDIO_CHANNEL_1_lowByte_REGISTER = out & 127; // B01111111
		//}
}
コード例 #14
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
       }
   }
 }
コード例 #15
0
ファイル: SimpleDelayPatch.hpp プロジェクト: simu/OwlSim
 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);
 }    
コード例 #16
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();
}
コード例 #17
0
void dummy_function(void)
#endif
{
#if (USE_AUDIO_INPUT==true)
	adc_count = 0;
	startSecondAudioADC();
#endif

		// read about dual pwm at http://www.openmusiclabs.com/learning/digital/pwm-dac/dual-pwm-circuits/
		// sketches at http://wiki.openmusiclabs.com/wiki/PWMDAC,  http://wiki.openmusiclabs.com/wiki/MiniArDSP
		//if (!output_buffer.isEmpty()){
		unsigned int out = output_buffer.read();
		// 14 bit, 7 bits on each pin
		//AUDIO_CHANNEL_1_highByte_REGISTER = out >> 7; // B00111111 10000000 becomes B1111111
		// try to avoid looping over 7 shifts - need to check timing or disassemble to see what really happens
		unsigned int out_high = out<<1; // B00111111 10000000 becomes B01111111 00000000
		AUDIO_CHANNEL_1_highByte_REGISTER = out_high >> 8; // B01111111 00000000 produces B01111111
		//
		AUDIO_CHANNEL_1_lowByte_REGISTER = out & 127; 
		//}
}
コード例 #18
0
ファイル: DubDelayPatch.hpp プロジェクト: UIKit0/OwlPatches-1
    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]);
        }
    }
コード例 #19
0
ファイル: MozziGuts.cpp プロジェクト: SatoshiSann/Aruduino
ISR(TIMER1_OVF_vect, ISR_BLOCK)
{

#if (AUDIO_MODE == STANDARD_PLUS) && (AUDIO_RATE == 16384) // only update every second ISR, if lower audio rate
	static boolean alternate;
	alternate = !alternate;
	if(alternate)
	{
#endif

#if (USE_AUDIO_INPUT==true)
		adc_count = 0;
		startSecondAudioADC();
#endif

//if (!output_buffer.isEmpty()) {
	AUDIO_CHANNEL_1_OUTPUT_REGISTER = output_buffer.read();
//}

#if (AUDIO_MODE == STANDARD_PLUS) && (AUDIO_RATE==16384) // all this conditional compilation is so clutsy!
	}
#endif

}
コード例 #20
0
ファイル: cirbuffer_test.cpp プロジェクト: tcarland/tcanetpp
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;
}
コード例 #21
0
float AccelMaths::milliDeltaDeltaAverageUp( void )
{
  float returnValue = (verticalDerivativeBuffer.read(0) - verticalDerivativeBuffer.read(1));
  return returnValue;
}
コード例 #22
0
float AccelMaths::rollingAverageUp( void )
{
  return upAverageBuffer.read(0);
}
コード例 #23
0
float AccelMaths::rollingAverageRight( void )
{
  return rightAverageBuffer.read(0);
}
コード例 #24
0
 float getDelayAverage(int index, int points){
   float result = delayBuffer.read(index);
   for(int i=1; i<points; ++i)
     result += delayBuffer.read(index+i);
   return result/points;
 }
コード例 #25
0
float AccelMaths::milliDeltaAverageUp( void )
{
  return verticalDerivativeBuffer.read(0);
}