Hereby Certify That I Wrote My Diploma Thesis on My Own, Under the Guidance of the Thesis Supervisor
Total Page:16
File Type:pdf, Size:1020Kb
Institute of Informatics in the field of study Computer Science and specialisation Computer Systems and Networks FPGA based hardware accelerator for musical synthesis for Linux system Jakub Duchniewicz student record book number 277132 thesis supervisor dr hab. inz.˙ Wojciech M. Zabołotny WARSAW 2020 FPGA based hardware accelerator for musical synthesis for Linux system Abstract. Work focuses on realizing audio synthesizer in a System on Chip, utilizing FPGA hardware resources. The resulting sound can be polyphonic and can be played directly by an analog connection and is returned to the Hard Processor System running Linux OS. It covers aspects of sound synthesis in hardware and writing Linux Device Drivers for communicating with the FPGA utilizing DMA. An optimal approach to synthesis is researched and assessed and LUT-based interpolation is asserted as the best choice for this project. A novel State Variable IIR Filter is implemented in Verilog and utilized. Four waveforms are synthesized: sine, square, sawtooth and triangle, and their switching can be done instantaneously. A sample mixer capable of spreading the overflowing amplitudes in phase is implemented. Linux Device Driver conforming to the ALSA standard is written and utilized as a soundcard capable of generating the sound of 24 bits precision at 96kHz sampling speed in real time. The system is extended with a simple GPIO analog sound output through 1 pin Sigma-Delta DAC. Keywords: FPGA, Sound Synthesis, SoC, DMA, SVF 3 Sprz˛etowy syntezator muzyczny wykorzystuj ˛acy FPGA dla systemu Linux Streszczenie. Celem pracy jest realizacja syntezatora muzycznego na platformie SoC (System on Chip) z wykorzystaniem zasobów sprz˛etowych FPGA. Wymagana jest gener- acja polifonicznego d´zwi˛eku,który mozna˙ odtworzy´cw czasie rzeczywistym za pomoc ˛a przetwornika cyfrowo analogowego. Wygenerowany d´zwi˛ekjest takze˙ przekazywany do systemu Linux, pracuj ˛acego na procesorze systemu SoC. W pracy poruszone s ˛azagad- nienia dotycz ˛acesprz˛etowej syntezy muzycznej, tworzenia sterownika urz ˛adzenia dla systemu Linux oraz komunikacji z FPGA poprzez DMA. Po zbadaniu szeregu sposobów syn- tezy, zostaje wybrany system z interpolacj ˛aprzy uzyciu˙ LUT. Zaprojektowany został nowa- torski filtr zmiennych stanu o niesko´nczonej odpowiedzi impulsowej, który został zaimple- mentowany w j˛ezyku Verilog a nast˛epnie uzyty˙ jako filtr dolnoprzepustowy. Syntezowane s ˛acztery przebiegi akustyczne: sinusoidalny, kwadratowy, piłowy oraz trójk ˛atny. Dla wzbo- gacenia efektów muzycznych mozliwe˙ jest ich błyskawiczne przeł ˛aczanie. W celu zmini- malizowania zniekształcenia d´zwi˛ekuprzy chwilowym przekroczeniu zakresu podczas sumowania próbek, zrealizowano eksperymentalny akumulator próbek, który rozkłada w czasie próbki o warto´sciwykraczaj ˛acejpoza zakres reprezentacji wyj´sciowej. Dzi˛ekitemu sterownikowi urz ˛adzenie jest widoczne w systemie Linux jako karta d´zwi˛ekowa, która jest w pełni zgodna ze standardem ALSA, oraz generuje d´zwi˛eko rozdzielczo´sci24 bitów z cz˛estotliwo´sci˛apróbkowania 96kHz. System jest rozszerzony za pomoc ˛aprzetwornika cyfrowo-analogowego zaimplementowanego w układzie Sigma-Delta na jednym bicie GPIO. Słowa kluczowe: FPGA, Synteza d´zwi˛eku, SoC, DMA, SVF 4 załącznik nr 10 do zarządzenia nr 46 /2016 Rektora PW Politechnika Warszawska Warsaw University of Technology ………........................ miejscowość i data place and date …………………………….. imię i nazwisko studenta name and surname of the student …………………………….. numer albumu student record book number …………………….………. kierunek studiów field of study OŚWIADCZENIE DECLARATION Świadomy/-a odpowiedzialności karnej za składanie fałszywych zeznań oświadczam, że niniejsza praca dyplomowa została napisana przeze mnie samodzielnie, pod opieką kierującego pracą dyplomową. Under the penalty of perjury, I hereby certify that I wrote my diploma thesis on my own, under the guidance of the thesis supervisor. Jednocześnie oświadczam, że: I also declare that: niniejsza praca dyplomowa nie narusza praw autorskich w rozumieniu ustawy z dnia 4 lutego 1994 roku o prawie autorskim i prawach pokrewnych (Dz.U. z 2006 r. Nr 90, poz. 631 z późn. zm.) oraz dóbr osobistych chronionych prawem cywilnym, this diploma thesis does not constitute infringement of copyright following the act of 4 February 1994 on copyright and related rights (Journal of Acts of 2006 no. 90, item 631 with further amendments) or personal rights protected under the civil law, niniejsza praca dyplomowa nie zawiera danych i informacji, które uzyskałem/-am w sposób niedozwolony, the diploma thesis does not contain data or information acquired in an illegal way, niniejsza praca dyplomowa nie była wcześniej podstawą żadnej innej urzędowej procedury związanej z nadawaniem dyplomów lub tytułów zawodowych, the diploma thesis has never been the basis of any other official proceedings leading to the award of diplomas or professional degrees, wszystkie informacje umieszczone w niniejszej pracy, uzyskane ze źródeł pisanych i elektronicznych, zostały udokumentowane w wykazie literatury odpowiednimi odnośnikami, all information included in the diploma thesis, derived from printed and electronic sources, has been documented with relevant references in the literature section, znam regulacje prawne Politechniki Warszawskiej w sprawie zarządzania prawami autorskimi i prawami pokrewnymi, prawami własności przemysłowej oraz zasadami komercjalizacji. I am aware of the regulations at Warsaw University of Technology on management of copyright and related rights, industrial property rights and commercialisation. 1 / 2 5 załącznik nr 10 do zarządzenia Politechnika Warszawska nr /2016 Rektora PW Warsaw University of Technology Oświadczam, że treść pracy dyplomowej w wersji drukowanej, treść pracy dyplomowej zawartej na nośniku elektronicznym (płycie kompaktowej) oraz treść pracy dyplomowej w module APD systemu USOS są identyczne. I certify that the content of the printed version of the diploma thesis, the content of the electronic version of the diploma thesis (on a CD) and the content of the diploma thesis in the Archive of Diploma Theses (APD module) of the USOS system are identical. ............................................... czytelny podpis studenta legible signature of the student 6 Contents 1. Introduction ........................................ 9 1.1. Scope of Thesis.................................... 9 1.2. Thesis Layout..................................... 10 1.3. Overview of existing solutions........................... 10 1.3.1. Synthesis techniques............................ 10 1.3.2. DMA techniques .............................. 11 1.3.3. Writing ALSA driver............................. 11 2. Background ......................................... 12 2.1. Origins of synthesis ................................. 12 2.2. Synthesis approaches................................ 14 2.2.1. Subtractive synthesis............................ 14 2.2.2. Additive synthesis ............................. 15 2.2.3. Other approaches.............................. 16 2.3. MIDI protocol .................................... 16 3. Hardware overview and System Design ........................ 17 3.1. Hardware overview ................................. 17 3.2. Requirements Analysis ............................... 19 3.3. System Design .................................... 20 4. Hardware Design ...................................... 21 4.1. Sine wave generation ................................ 22 4.2. Square wave generation............................... 24 4.3. Sawtooth wave generation............................. 25 4.4. Triangle wave generation.............................. 25 4.5. State Variable Filter ................................. 25 4.6. Sample accumulator ................................ 26 5. Software Design ...................................... 28 5.1. Board Setup...................................... 29 5.2. MIDI receiving application............................. 30 5.3. DMA - ALSA synthesizer driver .......................... 30 5.4. Obtaining the data.................................. 31 6. Testing ............................................ 32 6.1. Verilog Testbenches................................. 32 6.2. Oscilloscope testing................................. 33 6.3. System Testing.................................... 36 6.3.1. Examples................................... 38 6.4. Debugging ...................................... 39 6.5. Timing and Delays.................................. 39 7 6.5.1. Software delays............................... 39 6.5.2. Hardware delays .............................. 39 7. Results ............................................ 41 7.1. Resource Utilization................................. 41 8. Conclusions ......................................... 42 8.1. Future Work...................................... 43 8.2. Alternative solutions ................................ 44 9. Acknowledgements .................................... 45 References ............................................ 47 List of Symbols and Abbreviations ............................. 49 List of Figures .......................................... 50 List of Appendices ....................................... 50 8 1. Introduction Since the popularization of a modular one by Robert Moog in the mid-60s, synthesizers have changed the way humans produce music tremendously. While at first analog, they soon became digital and dominated the music industry. Nevertheless, analog ones are still sought