아두이노 > Arduino Realtime Audio Processing

TODAY985 TOTAL605,614
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 아두이노 | 아두이노 | Arduino Realtime Audio Processing

페이지 정보

작성자 키트 작성일2017-09-13 13:15 조회768회 댓글0건

본문

logoLab3






Arduino Realtime Audio Processing



3660040649_B6ZcPowM_arduinoaudio.jpg" width="320" height="264" style="margin: 0px; padding: 0px; border: 0px;">

 

 

This is an experiment to show how some realtime audio processing can be done with the Arduino. The first set of examples alter an incoming audio signal and put it back to an audio output. We achieve effects like Reverb, Phasor, Flanger or Ringmodulator. The second set of examples are outputting computed waveforms like Sinewave, Bell and Xylophone sounds.

 

Building and testing the Audio Circuit around the Arduino

The audio input signal is connected via a 10uF capacitor to the the analog input 1 of the Arduino Board. Two resistors and a trimmpot are adding an DC offset to the audiosignal . A potentiometer connected to analog input 0 will be used to control the audio effects. Pin 11 is used as PWM audio output connected via a RLC Filter to the audio output jack. The output can be connected to a active PC Speakers.
A good way to generate a test Signal is using a PC and a audio software like Audacity. A clip of music or speech is recorded and then filtered with a 3KHz. lowpass function. The Signal has to be filtered to avoid the aliasing effect when the signal gets sampled which would lead to a distorted sound. Now you can connect the PC headphone output to our setup and playback the clip in an endless loop . You might have to use full volume since Arduinos ADC needs a level of 2.5 Volt peak for best quality. When you want to use a microphone or an other input source you have to build an extra preamplifier with an appropriate steep lowpassfilter.

 

 

3660040649_bXHroJ6n_arduinoaudiofig1.gif" width="617" height="279" style="margin: 0px; padding: 0px; border: none;">

 

 

 

Software Concept

The Software is divided into an interrupt function where the analog sampling an timing takes place and a main loop where the samples are processed an written back to the PWM as audio output. At first the Setup function changes the Timer 2 and ADC parameters. The ADC is set to a fast sampling mode and to 8-Bit precision. Timer2 is used as PWM to convert the digital sample back into an analog value . The prescaler is changed and the interrupt is enabled so that the interrupt service is invoked all 16 uSec or with a rate of 62.5 KHz controlled by the timer hardware. When an interrupt takes place the analog input of channel 0 and 1 is alternately sampled so that the audiosignal is sampled with an effective rate of 15.250 Khz. When a new sample is valid a flag is set which is used in the main loop to synchronize the process. Timer1 is disabled so the Adruino delayfunctions are not available anymore.

 

 

3660040649_JEO78Yfl_arduinoaudiofig2_1.png" width="354" height="338" style="margin: 0px; padding: 0px; border: 0px;">

 

 

 

The main loop waits for the sample flag to be set by the interrupt. When the flag is true the new sample value can be taken beeing processed and written back as output to the PWM. In this section you can program all the audio effects . Care must be taken that all calculation must be done in a timeslot of about 65 uSec otherwise you are not synchronous anymore with the sampling process and a distortion in the output signal would appear. If you have a oscilloscope available you can monitor a testsignal on pin 7 which shows a squarewave with a dutycycle corresponding to the remaining processing time.

 

 

3660040649_6FZ4lwXj_arduinoaudiofig2_2.png" width="357" height="422" style="margin: 0px; padding: 0px; border: 0px;">

 

 

 

DC Offset

A natural audiosignal consists of positive and negative waveparts which is leading to an electrical AC audiosignal. Since the Analog to digitalconverter on the Arduino can measure only positive voltages a constant offset has to be added to the signal. This is done with a resistor divider we see in our schematic. With the trimmpot the DC offset has to be adjusted to a value of 127. When doing the audio calculations this offset has to be subtracted first and when the result is calculated to be added again.

 

Ringbuffer

For effects like reverb or phasor you need to delay the audio signal which is done in an memory array of 512 bytes. For longer delays there is not enough memory in the ATMEGA168 available. In a ringbuffer this memoryarray is organized in a loop where write a pointer is used to access a memory location for writing data and a second pointer to address a read location. After a one step is done both pointers are directed to the next location. If a pointer reaches the end of the array (511) the pointer is set to 0 again and old data will be overwritten. The distance between read and write pointers determine the length of the time delay.

 

 

3660040649_dGg7ZMQD_arduinoaudiofig3.png" width="229" height="227" style="margin: 0px; padding: 0px; border: 0px;">

 

 

 

Wave Table

Sounds like a sinewave, a bell or xylophone are generated by filling the ringbuffer once with one wavecycle of the desired sound and playback the buffer contens repeatedly in an endless loop.

 

void fill_sinewave(){  dx=2 * pi / 512;                    // fill the 512 byte bufferarry  for (iw = 0; iw <= 511; iw++){      // with  1 period sinewawe    fd= 127*sin(fcnt);                // fundamental tone    fcnt=fcnt+dx;                     // in the range of 0 to 2xpi  and 1/512 increments    bb=127+fd;                        // add dc offset to sinewawe    dd[iw]=bb;                        // write value into array  }}

 

The sound of a percussive instrument is done by adding a decayfunction in the main loop and adding some overtones to the fundametal sinewave in the waveform function.

 

void load_waveform(){  float pi = 3.141592;  float dx ;  float fd ;  float fcnt=0;  dx=2 * pi / 512;                    // fill the 512 byte bufferarry  for (iw = 0; iw <= 511; iw++){      // with  50 periods sinewawe    fd= 100*sin(fcnt);                // fundamental tone    fd = fd + ( 10*sin(4*fcnt+fcnt));  // plus some overtone    fcnt=fcnt+dx;                     // in the range of 0 to 2xpi  and 1/512 increments    bb=127+fd;                        // add dc offset to sinewawe    dd[iw]=bb;                        // write value into array  }}

 

Source Codes

› arduino_audio_loopback.zip (64 KB)

› arduino_audio_loopback_t1.zip (64 KB)

› arduino_audio_phasor.zip (76 KB)

› arduino_audio_reverb.zip (76 KB)

› arduino_audio_ringmodulator.zip (76 KB)

› arduino_audio_sine_1.zip (76 KB)

› arduino_audio_sine_variable.zip (76 KB)

› arduino_audio_xylo_ping_1.zip (76 KB)

› arduino_audio_xylo_ping_var.zip (76 KB)

 

Documents

› arduino_realtime_audio_eng.pdf (1,8 MB)

 

 

Forum

further questions to this topic can be discussed here:

http://arduino.cc/forum/index.php/topic,64471.0.html

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?board=dev

 

Contact

Martin Nawrath, nawrath@khm.de

Lab3, Academy of Media Arts Cologne, Peter-Welter-Platz 2 50676 Cologne, Imprint


http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-realtime-audio-processing/ 

댓글 0

조회수 768

등록된 댓글이 없습니다.

아두이노HOME > 아두이노 > 전체 목록

아두이노 목록
제목 작성자 작성일 조회
61 아두이노 Adafruit Motor/Stepper/Servo Shield for Arduino kit - v1.2 이미지 키트 17-09-13 1073
60 아두이노 가스센서 이미지 키트 17-09-13 1031
59 아두이노 Arduino Waveform Generator 이미지 키트 17-09-13 822
58 아두이노 Arduino Waveform Generator 키트 17-09-13 811
57 아두이노 Arduino Waveform Generator 이미지 키트 17-09-13 1020
56 아두이노 Exclusive 2.5 GHz Frequency Counter 이미지 키트 17-09-13 2169
55 아두이노 AVR SIMULATOR IDE 이미지 키트 17-09-13 698
54 아두이노 Marlin 이미지 키트 17-09-13 773
53 아두이노 opencircuits.com - Oscilloscope 이미지 키트 17-09-13 792
52 아두이노 Zorkduino 키트 17-09-13 774
51 아두이노 Single Chip AVR BASIC Computer V0.1 키트 17-09-13 834
50 아두이노 Single Chip AVR BASIC Computer V0.3 키트 17-09-13 842
49 아두이노 Single Chip AVR BASIC Computer 키트 17-09-13 754
48 아두이노 Single Chip Computer: Easy to produce AVR BASIC Computer 이미지 키트 17-09-13 828
현재글 아두이노 Arduino Realtime Audio Processing 이미지 키트 17-09-13 769
게시물 검색

2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2017
모바일버전으로보기