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

Thread: Audio Tutorial and gain/clipping

  1. #1
    Junior Member
    Join Date
    Jul 2016
    Posts
    19

    Audio Tutorial and gain/clipping

    I'm going through the audio tutorial for the teensy 3.2 + Audio board I'm up to part 2-2 'Mixers & Playing Multiple Sounds' and I notice the use of gain and mention of clipping but it doesn't really make sense to me, I understand clipping to be when the audio signal goes above 0db generally but with the examples so far I'm not seeing any mention of levels at all just advice to make sure that you don't set the gain above 1.0, what am I missing?

    The info summary for mixers makes sense but contradicts the gain/clipping advice and says it amplifies above 1.0, obviously the wave files could already be mixed down to 0db which would make the advice in the tutorial make sense.

  2. #2
    Some of this takes careful reading, as the tutorial is using similar notation (IE: "1.0") to express both signal levels and mixer gain factors.

    If a signal is already at maximum, a mixer won't add clipping if:
    1. The channel gain is 1.0 or less.
    2. There are no other channels being added to cause the resulting sum to clip.


    I think the overall point is that if mixer channel gain is above 1.0, then it's possible to clip. Whether it clips or not is dependent on the signal. If a signal is below the maximum, you can amplify it without clipping. Similarly, gain below 1.0 can't clip, as there's no factor that's less than 1.0, but causes the output to be larger than the input.

    Gain factors can happily exceed the 1.0 ceiling, but signals shouldn't, in general*.

    *There are situations where you might want to clip the signal, so this is more of a guideline than a rule.

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,948
    If I recall doing the tutorial as the video played. In the video it was noted that this would happen only briefly - and either the resultant distortion would add emphasis, or likely not happen with the short duration sounds events involved as noted in p#2.

  4. #4
    Junior Member
    Join Date
    Jul 2016
    Posts
    19
    B.Jacquot, that's how I expect it to be, I wasn't trying to pick holes in the tutorials, I wanted to make sure I hadn't misunderstood something fundamental. So the distinction needs to be made that it's not the sum of the levels being > 1.0 that causes clipping, it's the sum of the levels of mixed objects exceeding 0db.

    defragster, it depends on the content you're trying to mix, in the tutorials I'd expect the examples to not clip, unless they're implicitly trying to show you what clipped signals sound/look like. In real world examples I'd expect every sample to be different and treated accordingly.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,684
    Quote Originally Posted by Reggie View Post
    So the distinction needs to be made that it's not the sum of the levels being > 1.0 that causes clipping, it's the sum of the levels of mixed objects exceeding 0db.
    Signal level of -1.0 to 1.0 peak-to-peak is effectively 0 dB, in traditional audio lingo.

    The Teensy Audio Library tries to use a consistent API where signals and gains are represented with linear scale numbers, not log scale decibels.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,948
    Quote Originally Posted by Reggie View Post
    ... defragster, it depends on the content you're trying to mix, in the tutorials I'd expect the examples to not clip, unless they're implicitly trying to show you what clipped signals sound/look like. In real world examples I'd expect every sample to be different and treated accordingly.
    Indeed - I do not have expert knowledge or even 'traditional' understanding, of this - just general and the tutorial presentation got across to me just that/this:: these samples may clip if you hit the buttons right and combine peak values - but generally will not - based on the samples and timing. If the samples were all full scale and played together there would be clipping - because the net gain would be over 1 as configured.

    It seems it has been 2 months since I got the Tutorial hardware and went through it once, then I focused on video display of the FFT data on two displays - and the last month on beta PJRC hardware. I do intend to go through it again on the Beta Teensy.

  7. #7
    Junior Member
    Join Date
    Jul 2016
    Posts
    19
    Quote Originally Posted by PaulStoffregen View Post
    Signal level of -1.0 to 1.0 peak-to-peak is effectively 0 dB, in traditional audio lingo.

    The Teensy Audio Library tries to use a consistent API where signals and gains are represented with linear scale numbers, not log scale decibels.
    Hi Paul, that's sort of how I understood it but with nothing to reference to, 1+1 =?? if you haven't actually measured the output signal(s). I hope it doesn't sound like I'm trying to be pedantic, log scale is well used in audio production, as I'm sure you're aware.

  8. #8
    Senior Member Ben's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    401
    0dB is referenced to the full scale digital representation of the signal, which is represented by a value of 1.0 in the Audio Library.
    Thus:
    dB = 20*log10(amplitude/1.0)

    So if you mix (add) two signals of 1.0 amplitude you get 1+1=2, plug it into the formula:
    dB = 20*log10(2.0/1.0) = 20 * 0.3 = 6dB
    As this is a positive number it will clip.

    I'm not sure that's what you were asking for though?

  9. #9
    Junior Member
    Join Date
    Jul 2016
    Posts
    19
    Thanks Ben, that's useful, a quick method to output a db value pretty much solves my next problem, my original post was just questioning the information that was given, that's been cleared up now too. I'm no expert either, it's just that all of my audio kit apart from synths tends to mostly use a +/- db scale when it's talking about clipping.

Posting Permissions

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