Is there something wrong with Audio rectify1

rcarr

Well-known member
I am making a SDR radio, but this example shows the problem.

Teensy 3.2 at 72mhz compiled faster. Not sure how to find my version of Teensyduino. I haven't downloaded recently.

The idea is to listen to the undistorted audio path, but if you change one patchcord the audio is distorted. It is almost like the rectifiy object gets patched between the output of mixer1 and the input of the biquad1

Code:
#include <Audio.h>
//#include <Wire.h>
//#include <SPI.h>
//#include <SD.h>
//#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=280.0000114440918,121.42857360839844
AudioSynthWaveformDc     dc1;            //xy=280.0000305175781,218.5714168548584
AudioMixer4              mixer1;         //xy=464.28570556640625,164.28571891784668
AudioEffectRectifier     rectify1;       //xy=562.8571624755859,265.7142677307129
AudioFilterBiquad        biquad1;        //xy=658.5713386535645,132.85714149475098
AudioFilterBiquad        biquad2;        //xy=711.4284896850586,265.7142810821533
AudioMixer4              mixer2;         //xy=854.2857208251953,174.28573036193848
AudioOutputAnalog        dac1;           //xy=1005.7142791748047,174.28570461273193
AudioConnection          patchCord1(sine1, 0, mixer1, 1);
AudioConnection          patchCord2(dc1, 0, mixer1, 2);
AudioConnection          patchCord3(mixer1, biquad1);

AudioConnection          patchCord4(mixer1, rectify1);  // this connection sounds distorted
//AudioConnection          patchCord4(biquad1, rectify1);   // this connection sounds ok

AudioConnection          patchCord5(rectify1, biquad2);
AudioConnection          patchCord6(biquad1, 0, mixer2, 0);
AudioConnection          patchCord7(biquad2, 0, mixer2, 1);
AudioConnection          patchCord8(mixer2, dac1);
// GUItool: end automatically generated code






void setup() {
  // put your setup code here, to run once:

  AudioNoInterrupts();
  AudioMemory(40);

  sine1.amplitude(0.25);
  sine1.frequency(600);
  dc1.amplitude(-0.1);

  mixer1.gain( 0, 0.0 );
  mixer1.gain( 1, 1.0 );
  mixer1.gain( 2, 1.0 );
  mixer1.gain( 3, 0.0 );

  biquad1.setLowpass( 0,3000,0.707);

  biquad2.setLowpass( 0,3000,0.707);

  mixer2.gain(0,0.5);      // listen to undistorted tone
  mixer2.gain(1,0.0);      // OR listen to rectified tone
  mixer2.gain(2,0.0);
  mixer2.gain(3,0.0);  

  AudioInterrupts();

}

void loop() {
  // put your main code here, to run repeatedly:

}
 

Attachments

  • SoundsOK.png
    SoundsOK.png
    12.1 KB · Views: 53
  • SoundsNotOK.png
    SoundsNotOK.png
    11.2 KB · Views: 56
Looks like it updates a receive only buffer at least in the version of the library that I have.

Code:
void AudioEffectRectifier::update(void)
{
	[B]audio_block_t *block = receiveReadOnly();[/B]
	if (!block) return;

	int16_t *p = block->data;
	int16_t *end = block->data + AUDIO_BLOCK_SAMPLES;
	while (p < end) {
		int b = *p;
		int t = *(p + 1);
		if (b < 0) b = -b;
		if (t < 0) t = -t;
		b = signed_saturate_rshift(b, 16, 0);
		t = signed_saturate_rshift(t, 16, 0);
		*(uint32_t *)p = pack_16b_16b(t, b);
		p += 2;
	}
	transmit(block);
	release(block);
}
 
Thanks. I guess I should update my install. I was reluctant to because of some edits I made so I could use non-blocking I2C_t3 functions instead of Wire.
 
Back
Top