• Software
  • RE: Input and Biquad/QuadBiquad.h and Source...

Hello,

This source can be found here: examples/Audio/filterbanks/render.cpp

/*
 ____  _____ _        _
| __ )| ____| |      / \
|  _ \|  _| | |     / _ \
| |_) | |___| |___ / ___ \
|____/|_____|_____/_/   \_\
http://bela.io
*/
#include <Bela.h>
#include <vector>
#include <libraries/Biquad/QuadBiquad.h>
std::vector<QuadBiquad> bs(150);
bool setup(BelaContext *context, void *userData)
{
        BiquadCoeff::Settings s = {
                .fs = context->audioSampleRate,
                .q = 0.8,
                .peakGainDb = 0,
        };
        // Setting cutoff and type for all the filters
        for(unsigned int b = 0; b < bs.size(); ++b)
        {
                if(b < bs.size() / 2) {
                        // the first half of the filters are lowpass
                        s.type = BiquadCoeff::lowpass;
                        s.cutoff= 2000;
                } else {
                        // the other half are highpass
                        s.type = BiquadCoeff::highpass;
                        s.cutoff = 500;
                }
                for(unsigned int q = 0; q < 4; ++q)
                {
                        // Each QuadBiquad object contains four filters (in parallel), which
                        // are completely independent of each other and you could set each
                        // to a different type of filter, cutoff, Q, etc
                        // Here we give to each of these four an increasing cutoff.
                        // This will result, for instance, in the right channel being
                        // brighter than the left channel.
                        bs[b].filters[q].setup(s);
                        s.cutoff *= 1.3;
                }
                // after updating the filter coefficients of the individual
                // filters, tell the QuadBiquad object to refresh its internal
                // registers
                bs[b].update();
        }
        return true;
}
void render(BelaContext *context, void *userData)
{
        unsigned int len = bs.size() & (~3);
        for(unsigned int n = 0; n < context->audioFrames; ++n)
        {
                const unsigned int datasz = 4;
                float data[datasz];
                // the data array is used for input and output of the four parallel filters in each QuadBiquad
                // we fill it with however audio inputs we have
                for(unsigned int c = 0; c < context->audioInChannels && c < datasz; ++c)
                        data[c] = audioRead(context, n, c);
                // we then process it through all the filters in series
                for(unsigned int b = 0; b < len; ++b) {
                         bs[b].process(data);
                         // after each call to process(), data contains the output of the filter.
                         // by processing it over and over, we effectively place the filters in series.
                }
                // last, we output the results to however many audio channels we have
                for(unsigned int c = 0; c < context->audioOutChannels && c < datasz; ++c)
                        audioWrite(context, n, c, data[c]);
        }
}
void cleanup(BelaContext *context, void *userData)
{

}

I am using this source to promote a sound fluctuation on the violin to a speaker w/ BELA/BBB as the median.

Anyway, am I way off here or is this what this source is attempting to perform?

Seth

P.S. I will try some other ideas while I prepare for the answer. If you have time, jump on in. I can use any ideas you have available. So far, I am just getting a bypass of sound w/out distortion.

    silver2row , I am just getting a bypass of sound w/out distortion.

    that code - which seems to be exactly the one in examples/Audio/filterbanks/render.cpp - is processing the input signal through 75 low-pass at 2000 Hz filters and 75 high-pass filters at 500Hz, and the processed signal is then sent to the output. In practice, this is a very narrow band-pass filter. You are not going to get much "distortion" (in the sense of overdrive) from this, but the sound should definitely change between input and output.

      giuliomoro

      Hello,

      I think you are right. I tried some of the other source that was already published. I think this source, the examples/Audio/filterbanks/render.cpp file, changes the output a bit.

      I wonder still how one could change the source to function as a distortion of sounds from different string sounds from this violin.

      I will keep trying things and learning in time.

      Seth

      P.S. I was going to try each example and run them to see the output but I have one week from Sat, i.e. so I am kind of stuck. No issue. I will try some more Audio output examples and see how far I get. I just got an amplifier that is not a tweeter. So, the sound is bellowing out. It is nice. The picking of the violin brings me sounds of short in length but highly clunky. I have not rosined the bow yet. I want a child to perform this action or a pretty girl at the faire. I was sort of doing just background work, i.e. scratching the surface until later. Yes sir!

      in a relatively simple form, a distortion effect looks like this:

      # include <libraries/math_neon/math_neon.h> // this at the top
      
      //this in render, within the usual nested `for` loops:
      float in = audioRead(context, n, c);
      float out =  tanhf_neon(in * gain); // using tanh for distortion. Experiment with other functions here
      audioWrite(context, n, c, out);

      and then you adjust the gain parameter to taste. In many cases, there would be low-pass filters or more complex filterbanks following (and possibly preceding) the gain stage. There may be oversampling to reduce aliasing, compression, multiband distortion, whatever. But the core is up there in the middle of the three lines.

        giuliomoro

        Yes sir...I will test it and promptly. Thank you.

        Seth

        P.S. Who knows? Maybe a real violin player will tune it proper and play it well w/ the distortion and the amplifier...

        giuliomoro

        Hello Sir...is the source supposed to promote some type of gain or distortion? I am asking b/c I applied the source w/ some extra tidbits of source.

        It seems I am in the same spot. Anyway, do I need to make the bool class in .cpp file aware of my interactions/source within render?

        Seth

        P.S. I am asking b/c I will read more on math_neon.h soon but I seem to be lost in space. Ha. Anyway, please let me know if you know of a nice place to start for readin' about math_neon.h. I found a couple of posts in this forum about math_neon.h and I see what you are talking about in these posts...

        Also...

        am I allowed to use more than one boot setup class in the source?

          giuliomoro

          Sir,

          Sorry for all these posts. I looked up the math_neon.h file and there is nothing in it on the docs. Is that on purpose?

          Seth

          P.S. It just references another file, #inculde <math_neon.h>, and ends. Anyway, please let me know what you think...I am not sure exactly how to use this file yet.

            silver2row am I allowed to use more than one boot setup class in the source?

            you can only have one setup() function in a project.

            silver2row I looked up the math_neon.h file and there is nothing in it on the docs. Is that on purpose?

            there is not much to know about it. It contains fast implementations of some of the math functions available in the standard C library. See, e.g.: https://github.com/BelaPlatform/Bela/wiki/Fast-math-functions, or The Source https://github.com/giuliomoro/math-neon.

            silver2row Anyway, do I need to make the bool class in .cpp file aware of my interactions/source within render?

            I have no idea what this means.

            The full file would look like this:

            #include <Bela.h>
            #include <libraries/math_neon/math_neon.h>
            
            bool setup(BelaContext *context, void *userData)
            {
            	return true;
            }
            
            void render(BelaContext *context, void *userData)
            {
            	for(unsigned int n = 0; n < context->audioFrames; ++n)
            	{
            		for(unsigned int c = 0; c < context->audioInChannels && c < context->audioOutChannels; ++c)
            		{
            			float gain = 1;
            			float in = audioRead(context, n, c);
            			float out =  tanhf_neon(in * gain); // using tanh for distortion. Experiment with other functions here
            			audioWrite(context, n, c, out);
            		}
            	}
            }
            
            void cleanup(BelaContext *context, void *userData)
            {}

              giuliomoro

              Hello Sir,

              Okay...thank you for the links to math_neon.h and where it is derived. I will test the source you provided again.

              ...

              I tried some other source, I can show you if you are interested, that you can probably pick apart to make me understand exactly what I have done but...

              I think you are right. I should keep it simple until I get a greater grasp on the ideas and source.

              Oh! No issue on what you do not understand from what I typed. I need the bool setup to initialize the source and void render to use it.

              Seth

              P.S. I was adding in the QuadBiquad.h and vertex.h and math_neon.h all together to test the source. I got one script working but I usually produce first and learn what it is I have done. "Not easy on the brain!" Thank you, again!

              I'm curious if you want distortion or a filter sound? Or maybe some of both?

              To be clear on terms, "distortion" is usually taken to mean a mathematically nonlinear function that creates harmonics that aren't naturally in the source material.

              A filter can selectively make certain frequency components more or less audible (like filterbanks or audio EQ).

              Modulated filters can create a form of distortion (like frequency shifting) but we don't often call it distortion since this term is often reserved primarily for waveshaping functions.

              Maybe some more explanation for what type of effect you want to perform on the violin somebody can give some specific help. Perhaps the Biquad is the thing you want and you only need some ideas to make this change the sound of the violin in a way you can easily hear.

              Maybe you want some distortion like suggested by @giuliomoro where you clip the signal and make it sound more like electric guitar.

              For example, I have coded a variety of sound effects which can be implemented on Bela that somebody could use for many fun experiments with a violin. These aren't simple enough for me to recommend them as examples for learning how to use Bela. The examples provided by the Bela team are better for learning because they are short and focus on one thing at a time.

              https://github.com/transmogrifox/transmogriFX_bela

              Everything works as-is, but you need to have something connected to the Analog Inputs to adjust levels or you might get settings stuck in very strange positions...and you need switches on digital inputs.

                as far as i get it, you want to have this violin open to the public, or at least have it played by people who don't normally play the violin? nice. 🙂
                so i understand that you would prefer some sort of 'different', 'unexpected' or 'surprising' sound to come out of the speaker, instead of just a badly played violin. hah.

                and while trying out all the examples may be a good starting point, i have to agree with @[deleted] and @[deleted] that this conversation would become easier once you decide what you want to do with the sound to make it surprising.
                you could have distortion, but only on the lower notes. you could have the higher notes be chopped up with a tremolo and disappear into an echo. or maybe you want to trigger Winston Churchill speech samples and speed them up as the violin gets louder?

                people here are more than willing to help you get the results you want - but it's kind of hard to help you if you don't know what you want to achieve. 🙂

                (that said, i can only help you if you choose to go with Pd - my C++ is still at kindergarten level.)

                  Remork and ryjobil

                  Hello,

                  I guess anything outside of the regular sound would be nice. And yes, I am not a violin/fiddle player. I wanted people to use BELA, the BBB, and play this fiddle with their own adaptation of instrument playing.

                  ...

                  I will try the link soon. Thank you both for replying.

                  Seth

                  P.S. So, in hindsight, I would have been preparing for months for this Faire but they only gave me a short window of notification. So, w/out further ado, off to look over the link.

                    silver2row
                    Here's a vocoder I got working.

                    https://github.com/transmogrifox/Bela_Misc/tree/master/vocoder

                    That certainly does something out of the ordinary. It's plug 'n' play as-is, but the trick is you need a second audio source going into ADC channel 1, which requires a preamp and some circuit work. Coding it to take the second source from either the other audio channel or even synthesizing some sort of signals internally (like sampling random numbers) could be fun.

                    Here's another crazy sound, but probably takes some more coding to make it more hands-free. I'm getting the impression you don't have much time to put together applications with control surfaces, knobs or other interactive sensors so I'm trying to focus on things that are likely to work without needing anything more than an instrument input. Is this correct?

                    This,
                    https://github.com/transmogrifox/transmogriFX_bela/blob/master/src/sample_hold_modulator.cpp
                    Connected into this,
                    https://github.com/transmogrifox/transmogriFX_bela/blob/master/src/envelope_filter.cpp

                    Can get you sounds like this,

                    Here is a sample of the vocoder. You can see a box to the right, which is a microphone preamp that I built. It's cheap and easy to make, but if you have or can get a commercial mic preamp that will work fine.

                      ryjobil

                      Hello,

                      You are right. I have until 3:30 today. So, I am out of luck I guess. No issue. When I return and start to use BELA more, I can start to learn about it more. I only made it to the sixth rendition of lectures on BELA via YouTube.com.

                      So, although BELA will not be showing up w/ me this time, as I had to focus on some attention getters and other hardware-software related things, I will learn more about what exactly is offered via BELA, the BBB, and music.

                      Seth

                      P.S. I really thank you and the other two people for helping me along my short journey of reaching out. I think all the work that has been put in for the repositories is worth it and I will learn more about them in time. Please forgive me.

                      Oh and I watched the two videos. That vocoder thing is nice! The first video is nice too, i.e. esp. w/ the bouyant sounds of melodic wish-wash. Yea and yes sir, nice! I think the vocoder will be nice for the violin once I figure out how to play a little more. I can try on guitar soon but the violin is my new intermediary of time consumption.

                        ryjobil

                        Hello,

                        Well...I went and did not conquer. The violin was out of tune and my rosined bow was not rosined enough. Now, I can start on the circuit construction and ideas for the BELA platform/Cape.

                        Seth

                        P.S. Thank you...I did enjoy it. I will most likely try to finish the rest of the ideas on Youtube.com for the BELA lectures and then proceed to circuits, vocoder, and other ideas.

                        ryjobil

                        Hello...I looked over the source in the github repo.

                        It is fine and okay by me but...

                        I have not figured out how to make any of it work just yet. I have four strings on this violin and six strings on my guitar.

                        I am not getting any pause of sound or change in sounds. I made another post on this blog site to better suit the needs of quick viewers.

                        Seth

                        P.S. If there is a particular circuit to make that is specific, please let me know. I will make this circuit and proceed. Anyway, I am very excited to make this 'heavily rosined' bow make angelic sounds of beauty once and for all. Ha. So in hindsight, I will keep trying and learn more about different circuits while I stay patient for replies.

                          silver2row
                          The vocoder has the best instructions. If you make the connections as diagrammed on the github README.md then the vocoder will work. You will need a microphone preamp for the ADC CH1 connection
                          https://github.com/transmogrifox/Bela_Misc/tree/master/vocoder

                          The "klingon tone" will also work without external connections because the defaults are set to something that will change the sound, and quick review of the code shows it starts in an active state:
                          https://github.com/transmogrifox/Bela_Misc/tree/master/klingon_tone
                          You can do more with knobs connected, but it will do something audibly different without.

                          The sample/hold modulator, ADSR and state variable filter require more understanding of Bela and the code. The TransmogriFX repo ( https://github.com/transmogrifox/transmogriFX_bela/tree/master/src ) works as a complete system but it requires a combination of correct hardware connections and an understanding of what the hardware inputs do in the code -- neither of which are documented yet, so you have to study the code and experiment to figure out my particular way of doing things to make it work.

                            ryjobil

                            Yes sir,

                            I will keep attempting the source learning. Also, I will try to build the preamp for the ADC connection.

                            Seth

                            P.S. I should have something done in the next couple of months. I am slow on building but things come together in the end. Thank you for supporting this channel. I appreciate your time a neat videos, i.e. esp. the vocoder playing.

                            ryjobil quick review of the code shows it starts in an active state

                            i was under the impression that the default was 'bypass = true'.
                            i should think that it therefore starts in bypass?