Go Down

Topic: Static burst sound effect (Read 3289 times) previous topic - next topic

Grumpy_Mike

Quote
Didn't come here for that, I came for some tech advice.
Well go away again until you learn some manners and feel like actually doing us the courtesy of behaving properly and obeying the rules we have around here.

tbird3

Well go away again until you learn some manners and feel like actually doing us the courtesy of behaving properly and obeying the rules we have around here.
Maybe, sir,you should take your own advice. BEng, IEE, MCSE, 15 C&G (185, 224), zilog programmer back in the day, I think I know netiquette inside out. The idea is you learn from Sketches put up (or be a parasite, you decide the grammar used), then as you develop, post the code up for the community to use, and probably move forward- the beauty of open source. Linux- a thing of beauty, brought forward by the sharing of many minds toiling away to produce an OS that anyone could push forward through mutual collaboration. Your attitude will drive "n00bs" away, as they will feel they cannot ask a question without getting flamed. I can quite adequately write what I need to to do what I require, in fact, since the post about noise, I have decided to go on a different path with a waveshield and a visduino, instead of an all in one. But I'm buggered if I'll post it up, as you decided it was "being a parasite".
Sayanora.

wm8s

How would I make the noise part of this run on timer1, so I don't interfere with tone()? I tried it myself, but I've yet to master Arduino register bits ;)

Thanks!

...R

Just use the noise bit out of this program:-
Code: [Select]
volatile unsigned int sample = 0;
 volatile unsigned int increment = 0x800;

void setup(){
    setSampleTimer();
}

ISR(TIMER2_COMPB_vect){  // Interrupt service routine to output next sample to PWM
      sample += increment;
     if((sample & 0x8000) != 0)  // implement a triangle wave
     OCR2B = 127 - (sample >> 8) & 0x7f;
     else
      OCR2B = (sample >> 8) & 0x7f;
}

void setSampleTimer(){  // sets timer 2 going at the output sample rate
  pinMode(3, OUTPUT);
  TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); // Just enable output on Pin 3 and disable it on Pin 11
  TCCR2B = _BV(WGM22) | _BV(CS22);
  OCR2A = 129; // defines the frequency 120 = 16.13 KHz or 62uS, 124 = 15.63 KHz or 64uS, 248 = 8 KHz or 125uS
  OCR2B = 64;  // deines the duty cycle - Half the OCR2A value for 50%
  TCCR2B = TCCR2B & 0b00111000 | 0x2; // select a prescale value of 8:1 of the system clock
}

void loop(){
[SNIP]
   noise(1000);
[SNIP]
}

[SNIP]

void noise(int length){ // length about 1000
     TIMSK2 = _BV(OCIE2B); // sound
  for(int i=0; i<length; i++){ // noise
   increment = random(30, 0x1500);
   delayMicroseconds(100);
 }
   TIMSK2 = 0; // hush
}

[SNIP]

charliesixpack

Well go away again until you learn some manners and feel like actually doing us the courtesy of behaving properly and obeying the rules we have around here.
Have you considered taking your own advice?

Grumpy_Mike

@charliesixpack
I notice that you are not rushing to help these thread hijackers. Go on tell them the answer I dare you.

Paul Stoffregen

Well, at the risk of shamelessly self-promoting my own software library, here's one way you might build this:


Paul Stoffregen



The microphone sound enters at the "i2s1" input.  There it goes to a 2nd order low pass filter.  You can reprogram the filter corner frequency at any time, so if you want the audio quality to improve at times you could raise the corner frequency to allow all the sound through, or at times you could reduce it to wipe out the high frequencies for a muffled sound.

The filter output goes to a bitcrusher effect, which will massively distort the sound.  Like all these objects, you can reprogram it from your Arduino code while it's processing the sound.

The "pink1" object is a pink noise generator.  You could also use a white noise object (similar to the idea above to use the random number function), but pink noise generally sounds a lot better because it has equal energy per octave rather than linearly scaled.

All of these go to a mixer.  Your code can program the gain on each mixer input, so you can create bursts of noise by just turning the noise input up.  The amount noise can vary, just change the gain for more or less.  Likewise, you'll probably get a more compelling "distorted voice" effect if you mix some of the bitcrusher output with the original that's only been filtered.  That way, the original words can be heard well, while you also hear the huge distortion from the bitcrusher effect.

The catch is you need a 32 bit Teensy board you run this.  There's no way normal 8 bit Arduino can do it... this whole thing runs at 44 kHz 16 bit and uses DMA and interrupts and the ARM Cortex-M4 DSP extensions to efficiently process audio while your Arduino sketch can run and control everything.  To see how this system works, I recommend you watch this tutorial video.

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

While I drew this with the i2s objects, which give the highest quality, they do require a shield.  The library also has ADC and DAC objects, so you can bring audio into a normal analog pin, and you can play audio out of the DAC pin.  These don't give the full 16 bit quality, but for this application 12 bits is probably fine (maybe even 8, as the code above suggested might sound ok...)  But the shield might be more convenient anyway, since it has a microphone input where you can solder a $1 condensor mic.  Otherwise, you'd need to build or buy a mic preamp circuit to get the tiny mic voltage amplified to the range the ADC pins can use.

Many options.  Hopefully this long-winded message at least gives you an alternative... one that requires a more capable board, but if you watch the video, I believe you'll see how easy and powerful it can be.  :)

Paul Stoffregen

Of course, if you go this route, you can very easily try a *lot* of different effects, just by graphically composing your audio processing system in the design tool, and then exporting into your Arduino sketch to try it.

For example, you might also try adding the delay object and feed that to another mixer input.  Probably keep the gain low... but if you're going for a distorted radio sound, a slightly delayed copy of the sound mixed in at a low level might really improve the overall effect.  Audio is funny like that, where subtle details (delays in the 30 to 80ms range) are heard and processed subconsciously.

Paul Stoffregen

One other quick point, which is actually mentioned a couple times in the tutorial video, is clipping distortion.  Normally you'd want to program the mixer gains so the signals can't add up to more than 1.0.  In fact, there's a part in the video which talks about when you might bend this rule a bit to risk a little distortion, but generally you want to avoid it.

But for this application, the clipping and a low pass filter might give you pretty good results.  Maybe no need for the bitcrusher distortion?  You might try doing the clipping before low pass filtering, versus afterwards.  The two will sound different.  Since those are generally the 2 things that go wrong in regular analogue radio communication (and also multi-path delay/echo), odds are good you'll get a pretty good result when you find the right combination of gains & bandwidth.

It's super easy to try different ways.  Just draw in the design tool, export to Arduino, and maybe add a few lines of code to configure gains and settings.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy