Go Down

Topic: Static burst sound effect (Read 1 time) previous topic - next topic

onesky

in my project i need to have a short static burst follow my speech through a small amplified speaker

any idea how to accomplish this with arduino+mini amp+microphone+mp3 player?

tack

If you can connect an SD Card reader up then you could use the SimpleSDAudio library to play sounds straight from a PWM pin(s).

You can have 8 bit Mono (1 pin), 8 bit stero (2 Pins), 16 bit mono (2 pins and a resistor network) or 16 bit stereo (4 pins and 2 resistor networks).

I use the 8 bit mono for sound effects and that's plenty good enough for my requirements.

xl97

For like a Storm trooper type effect?


Im not sure this is really going to help..seems to be more 'pitch' related..  (and I think uses the Waveshiled as a base)

but I have got this working before:

http://learn.adafruit.com/wave-shield-voice-changer/overview



Grumpy_Mike

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(){
   wobble(10);
   delay(1000);
   sweepUp(200);
   sweepDown(200);
   noise(1000);
   delay(1000);
   notes(30);
   delay(1000);
}

void wobble(int wobbles){
   TIMSK2 = _BV(OCIE2B); // sound
    for(int j=0; j<wobbles; j++){
  for(int i = 0x500; i< 0x1300; i+=0x4){
    increment = i;
   delayMicroseconds(100);
  }
  }
  TIMSK2 = 0; // hush
}

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
}

void sweepUp(int time){ // time controls how long it takes start with 200
  TIMSK2 = _BV(OCIE2B); // Output Compare Match B Interrupt Enable
  for(int i = 0x500; i< 0x1300; i+=0x1){
    increment = i;
   delayMicroseconds(time);
}
TIMSK2 = 0; // Output Compare Match B Interrupt Disabled
}

void sweepDown(int time){ // time controls how long it takes start with 200
  TIMSK2 = _BV(OCIE2B); // Output Compare Match B Interrupt Enable
  for(int i = 0x500; i< 0x1300; i+=0x1){
    increment = 0x1300 - i;
   delayMicroseconds(time);
}
TIMSK2 = 0; // Output Compare Match B Interrupt Disabled
}

void notes(int length){
  TIMSK2 = _BV(OCIE2B); // sound
  for(int i=0; i<length; i++){
    increment = random(300,0x1500);
    delay(100);
  }
  TIMSK2 = 0; // hush
}

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