Go Down

Topic: Recording Audio Signal (Read 247 times) previous topic - next topic

harry_lang

Hi guys,


So I am aiming to record, and loop a guitar signal using the Arduino software. I have setup the input signal on analogue pin 0 (A0) of the Arduino board and have tested to check there is a signal going into the Arduino. Now I want to view the level of the audio signal on the serial monitor or plotter (before thinking about how to record and loop it). Can anyone help me on this topic? Has anyone been able to record or loop an audio signal? Any help would be appreciated.


Here is the code I used taken from an Instructables tutorial "Arduino Audio Input":


#include <Boards.h>

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
*/

//variable to store incoming audio sample
byte incomingAudio;

//clipping indicator variables
boolean clipping = 0;

void setup(){
 
  Serial.begin(9600); // Start serial port
  pinMode(13,OUTPUT);//led indicator pin

 
  cli();//disable interrupts
 
  //set up continuous sampling of analog pin 0
 
  //clear ADCSRA and ADCSRB registers
  ADCSRA = 0;
  ADCSRB = 0;
 
  ADMUX |= (1 << REFS0); //set reference voltage
  ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only
 
  ADCSRA |= (1 << ADPS2) | (1 << ADPS0); //set ADC clock with 32 prescaler- 16mHz/32=500kHz
  ADCSRA |= (1 << ADATE); //enable auto trigger
  ADCSRA |= (1 << ADIE); //enable interrupts when measurement complete
  ADCSRA |= (1 << ADEN); //enable ADC
  ADCSRA |= (1 << ADSC); //start ADC measurements
 
  sei();//enable interrupts

  //if you want to add other things to setup(), do it here

}

ISR(ADC_vect) {//when new ADC value ready
  incomingAudio = ADCH;//store 8 bit value from analog pin 0
  if (incomingAudio == 0 || incomingAudio == 255){//if clipping
    digitalWrite(13,HIGH);//set pin 13 high
    clipping = 1;//currently clipping
  }
}

void loop(){

  if (clipping){//if currently clipping
    clipping = 0;//
    digitalWrite(13,LOW);//turn off clipping led indicator (pin 13)
   
 
 


  }

  delay(100);
}


DVDdoug

#1
Apr 25, 2016, 04:32 pm Last Edit: Apr 25, 2016, 04:34 pm by DVDdoug
Your sample code is only 8-bits (the Arduino's ADC on only 10 bits which is "bad enough") and I don't get the 100 millisecond delay... 


Quote
Now I want to view the level of the audio signal on the serial monitor or plotter (before thinking about how to record and loop it). Can anyone help me on this topic?
Just run the Analog Read Serial Example (with the guitar instead of the pot).   You'll see a lot of random-looking values because you are reading at "random" places along the waveform, including the zero-crossing, so just make note of the peaks.


Quote
I have setup the input signal on analogue pin 0 (A0) of the Arduino board...
Did you bias the input?   The Arduino cannot read the negative half of an AC audio waveform.   It can actually be damaged by negative voltages, but a guitar pickup doesn't put-out much current so you probably don't have to worry about damage...  just "damage" (distortion) to the signal.   Since the guitar has high impedance, I'd recommend changing the bias resistors to 1M.

Quote
...(before thinking about how to record and loop it). Can anyone help me on this topic? Has anyone been able to record or loop an audio signal?
Now, the BAD NEWS...    How long is your loop and have you thought about how much memory you need?    As you may know, there are 8 bits in a byte, so you calculate the required memory as:

Sample Rate x (Bit Depth/8) x Playing time.   For example, "CD quality" audio is 44,100 samples per second x (16 bits / 8 ) = 88,200 bytes for one second of audio.    (And audio CD is stereo, so it's double that.)   

...You're probably going to run out of RAM. 

And, the regular Arduino doesn't have a digital-to-analog converter built-in, so you'd have to add one in order to get analog out.




Grumpy_Mike

#2
Apr 26, 2016, 12:18 am Last Edit: Apr 26, 2016, 12:19 am by Grumpy_Mike
You can only have about a quarter of a second of sound recorded in the 2K of read write memory there is in a Uno. If you want to start adding external memory then you can extend that to several seconds.
Instructables are crap, that code will not compile it is crap.

You can find out how to do this on a Uno from my book, but it does involve building your own hardware.

http://www.apress.com/9781484217207

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