Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 22 of 22

Thread: Amplitude Modulation with offset

  1. #1
    Junior Member
    Join Date
    Jan 2016
    Posts
    13

    Amplitude Modulation with offset

    I am really scatching my head, but I don't have an Idea how to add an offset to an Audio modulation.
    The goal ist to have an WaveForm object with an amplitude of e.g 0.7 which is modulated +/- 0.1. by an very slow LFO.
    I assume it is pretty simple, but I don't know how. In german i would say "ich steh auf dem Schlauch"

    Cheers
    Marcus

  2. #2
    I would have the waveform object have an amplitude of 1. Have the lfo have an amplitude of 0.1 and an offset of 0.7. Use the multiply object (in the effects section) to multiply the 2 together. https://imgur.com/a/PPDJKv3
    Ich hoffe das hilft dir

  3. #3
    Junior Member
    Join Date
    Jan 2016
    Posts
    13
    This works very well
    der knoten ist geplatzt

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,943
    You can also use the DC object to create a constant signal and then feed it and a normal waveform into a mixer to add them together. So if the waveform is a low frequency sine wave with amplitude of 0.1, meaning it oscillates between -0.1 to +0.1, and the create a DC signal with level 0.7 and feed them into the same mixer (with inputs having gain of 1.0), the resulting output will be the sum of the signals. It will be a sine wave riding on top of DC, so it will oscillate from 0.6 to 0.8.

    Of course the normal waveform has an offset() function, so you can get the DC offset directly without the DC object and mixer. But not everything has an offset() function built in. If you need to add an offset to some signal that doesn't already have that capability, you can use the DC and mixer to do it.

    To actually amplitude modulate a live signal, of course you need the multiply effect.

  5. #5
    Hey, i was playing with offset and i wonder if it's possible to change the poles other way around, when going positive, the positive poles to remain an the negative to fade to dc and vice-versa, i guess here is the part for waveformMod:
    Code:
    if (tone_offset) {
    		bp = block->data;
    		end = bp + AUDIO_BLOCK_SAMPLES;
    		do {
    			val1 = *bp;
    			*bp++ = signed_saturate_rshift(val1 + tone_offset, 16, 0);
    		} while (bp < end);
    	}
    	if (shapedata) release(shapedata);
    	transmit(block, 0);
    	release(block);

    any tips?

  6. #6
    anyone?

  7. #7
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,850
    Not sure what you are asking.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,943
    I do not understand your question. In particular, these words seem rather confusing.

    if it's possible to change the poles other way around, when going positive, the positive poles to remain an the negative to fade to dc and vice-versa
    The original question of this thread asked about amplitude modulation. Is that what you're trying to accomplish?


    anyone?
    What do you expect? Your question is confusing, you haven't given much context about what you're really trying to do, and you showed a small code fragment rather than complete code so anyone can reproduce the problem.

    Look, I want to help you. That's why I'm taking the time to write this message. But you need to understand the reason nobody replies is because you've not asked a clear question, nor have you followed the Forum Rule to show a complete program so people can see & reproduce the problem. We solve a lot of problems on this forum using blind guesswork when we can understand the need, and we fix a lot of tech errors without knowing much of the larger picture... but when neither of those are possible, usually nobody replies.

  9. #9
    this is the normal library offset 1.00 on a sinewave with PT8211 Dac through an opamp bipolar 10 VPP

    Click image for larger version. 

Name:	DS1Z_QuickPrint2.png 
Views:	78 
Size:	37.4 KB 
ID:	21998

    and i am trying to switch the offset wave for the same 1.00 value, to be:
    Click image for larger version. 

Name:	DS1Z_QuickPrint3.png 
Views:	77 
Size:	37.7 KB 
ID:	21999

  10. #10
    Quote Originally Posted by PaulStoffregen View Post
    Look, I want to help you. That's why I'm taking the time to write this message. But you need to understand the reason nobody replies is because you've not asked a clear question, nor have you followed the Forum Rule to show a complete program so people can see & reproduce the problem. We solve a lot of problems on this forum using blind guesswork when we can understand the need, and we fix a lot of tech errors without knowing much of the larger picture... but when neither of those are possible, usually nobody replies.
    Thanks Paul, of course the code is from the library it self and it's good for a lot of purposes, something was described here about offset, this is why i was thinking it's a good place to start.
    I am following the code but i can't figure it how to switch this as described in the pics above
    Code:
    if (tone_offset) {
    		bp = block->data;
    		end = bp + AUDIO_BLOCK_SAMPLES;
    		do {
    			val1 = *bp;
    			*bp++ = signed_saturate_rshift(val1 + tone_offset, 16, 0);
    		} while (bp < end);
    	}
    	if (shapedata) release(shapedata);
    	transmit(block, 0);
    	release(block);

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,943
    Before answering, can I talk you into posting the complete code which created that top waveform in msg #9?

    That code will give us a starting point for helping you, and save a lot of time for everyone.

  12. #12
    Quote Originally Posted by PaulStoffregen View Post
    Before answering, can I talk you into posting the complete code which created that top waveform in msg #9?

    That code will give us a starting point for helping you, and save a lot of time for everyone.
    Sure!

    Here is it, the output it's made for the internal DAC

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <Encoder.h>
    
    // GUItool: begin automatically generated code
    AudioSynthWaveform       waveform1;      //xy=110,75
    AudioOutputAnalog        dac1;
    AudioConnection          patchCord3(waveform1, dac1);
    // GUItool: end automatically generated code
    Encoder modA(2, 3);
    
    void setup() {
      AudioMemory(16);
      waveform1.begin(WAVEFORM_SINE);
      waveform1.frequency(110);
      waveform1.amplitude(1.00);
    }
    
    void loop() {
    int16_t fLfo1 = modA.read(); 
    if(fLfo1 <= -100) { 
    modA.write(-100); // constrain the encoder object
    }
    else if(fLfo1 >= 100){
    modA.write(100); 
    }
    float Offset = fLfo1*0.01;
    waveform1.offset(Offset);
    }

  13. #13
    Senior Member
    Join Date
    Apr 2020
    Location
    Tucson
    Posts
    187
    Part of what is being asked for seems to be a single wave rectifier. Maybe adding a variable to AudioEffectRectifier.half() or AudioEffectRectifier.full()

  14. #14
    Yes, in principle half rectifier.. but this will work as the offset function, controlled or small amounts?

  15. #15
    Senior Member
    Join Date
    Apr 2020
    Location
    Tucson
    Posts
    187
    koerby, I think Dave from Notes-n-Volts might help you.

    https://www.youtube.com/watch?v=zphkBTkOIyQ

  16. #16
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,943
    I'm running your code from msg #12. It seems to work fine, producing either of those waveforms when the offset is +1.0 or -1.0.

    But I *still* do not understand what you want to make this program do. Can you explain clearly what you want it to do that it is not yet doing?

  17. #17
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,943
    As a quick guess, maybe your intention was for a LFO to take the place of that encoder?

    You could accomplish that by just feeding the LFO and original signal into a mixer. The mixer just adds together the signals.

    Click image for larger version. 

Name:	sc.png 
Views:	65 
Size:	10.8 KB 
ID:	22006


    Here's is the code (very simple...)

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioSynthWaveform       waveform2;      //xy=198,202
    AudioSynthWaveform       waveform1;      //xy=203,130
    AudioMixer4              mixer1;         //xy=387,155
    AudioOutputAnalog        dac1;           //xy=555,127
    AudioConnection          patchCord1(waveform2, 0, mixer1, 1);
    AudioConnection          patchCord2(waveform1, 0, mixer1, 0);
    AudioConnection          patchCord3(mixer1, dac1);
    // GUItool: end automatically generated code
    
    void setup() {
      AudioMemory(16);
      waveform1.begin(WAVEFORM_SINE);
      waveform1.frequency(110);
      waveform1.amplitude(1.00);
      waveform2.frequency(0.1);
      waveform2.amplitude(1.00);
    }
    
    void loop() {
    }
    And this is the result on my oscilloscope. It's the same as if someone slowly turned the encoder.


  18. #18
    Quote Originally Posted by PaulStoffregen View Post
    I'm running your code from msg #12. It seems to work fine, producing either of those waveforms when the offset is +1.0 or -1.0.

    But I *still* do not understand what you want to make this program do. Can you explain clearly what you want it to do that it is not yet doing?
    Ok, let's see it bipolar, presuming -5V 0 +5V peak to peak for the sinewave then.

    Maybe half rectifier is the right term here.. I was think for an inverted offset function in my mind )

    i just want to control the amount of the offset as on the code on msg# 12 but when going for from 0.00 to 1.00 the positive (+5v) part to stay untouched (like it's half rectified) and the negative part (-5V) to shrink to 0 as the amount is given by the encoder (pic)

    0.00 for full bipolar waveform and going to 1.00 only +5v part of the waveform:

    Click image for larger version. 

Name:	DS1Z_QuickPrint3.png 
Views:	65 
Size:	19.0 KB 
ID:	22012

    AND the same behaviour for the -1.00 amount (-5v) waveform part to stay untouched and positive +5v part to shrink to 0

    My purpose is to modulate external gear FM, CV, Envelopes and i am thinking it's more usefull if we invert the function offset, but as i mentioned above, half rectified is the right term here, so this is why checked in the library code offset function in the first place
    Last edited by vincentiuș; 10-07-2020 at 06:31 AM.

  19. #19
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,943
    Quote Originally Posted by vincentiuș View Post
    i just want to control the amount of the offset as on the code on msg# 12 but when going for from 0.00 to 1.00 the positive (+5v) part to stay untouched (like it's half rectified) and the negative part (-5V) to shrink to 0 as the amount is given by the encoder (pic)
    You can use the waveshape effect to get the half wave rectified behavior. Create 2 of them, one for the positive half of the waveform and another for the negative half.

    Then add the 2 halves back together with a mixer, where you can control the gain on each channel. To get "from 0.00 to 1.00 the positive (+5v) part to stay untouched" set the gain to 1.0. For the encoder to control the amount of the negative part "the negative part (-5V) to shrink to 0 as the amount is given by the encoder (pic)", just write some code for the encoder to adjust the gain of the other mixer input.

    Click image for larger version. 

Name:	sc.png 
Views:	96 
Size:	16.4 KB 
ID:	22014

    Here is very simple code which sets the negative half gain to 0.33.

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioSynthWaveform       waveform1;      //xy=167,118
    AudioEffectWaveshaper    waveshape1;     //xy=389,77
    AudioEffectWaveshaper    waveshape2;     //xy=396,160
    AudioMixer4              mixer1;         //xy=628,112
    AudioOutputAnalog        dac1;           //xy=833,121
    AudioConnection          patchCord1(waveform1, waveshape1);
    AudioConnection          patchCord2(waveform1, waveshape2);
    AudioConnection          patchCord3(waveshape1, 0, mixer1, 0);
    AudioConnection          patchCord4(waveshape2, 0, mixer1, 1);
    AudioConnection          patchCord5(mixer1, dac1);
    // GUItool: end automatically generated code
    
    float positiveOnly[3] = {0.0, 0.0, 1.0};
    float negativeOnly[3] = {-1.0, 0.0, 0.0};
    
    void setup() {
      AudioMemory(16);
      waveform1.begin(WAVEFORM_SINE);
      waveform1.frequency(110);
      waveform1.amplitude(1.00);
      waveshape1.shape(positiveOnly, 3);
      waveshape2.shape(negativeOnly, 3);
      mixer1.gain(0, 1.0);
      mixer1.gain(1, 0.33);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    Here is the resulting waveform. You can see the positive half is unaltered, but the negative half is reduced in amplitude. Hopefully that is what you wanted?

    Click image for larger version. 

Name:	file.png 
Views:	60 
Size:	32.8 KB 
ID:	22015

  20. #20
    Senior Member
    Join Date
    Apr 2020
    Location
    Tucson
    Posts
    187

    here it is again

    That's an awful lot of memory to dedicate to a halfwave rectifier.
    Attached Files Attached Files

  21. #21
    Quote Originally Posted by PaulStoffregen View Post
    Here is the resulting waveform. You can see the positive half is unaltered, but the negative half is reduced in amplitude. Hopefully that is what you wanted?
    I did played with the code and it's nice to experiment by giving values from the encoder to the mixer gain.
    But i think more simple is to invert the offset poles in sort to speak, maybe Halfwave effect function will do the trick anyway

  22. #22
    Experimenting.. I did change the + sign from the library with a -

    Code:
    *bp++ = signed_saturate_rshift(val1 + tone_offset, 16, 0);
    and the thing is happening but i need to keep the half wave up for 1.00 and the lower part down for -1.00 seen as bipolar

    Code:
    if (tone_offset) {
    		bp = block->data;
    		end = bp + AUDIO_BLOCK_SAMPLES;
    		do {
    			val1 = *bp;
    			*bp++ = signed_saturate_rshift(val1 - tone_offset, 16, 0);
    		} while (bp < end);
    	}
    	if (shapedata) release(shapedata);
    	transmit(block, 0);
    	release(block);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •