SlideShare una empresa de Scribd logo
1 de 43
Descargar para leer sin conexión
Real-time Audio on Embedded Linux


                                              April, 2011

                                           Remi Lorriaux
                                       Adeneo Embedded

                               Embedded Linux Conference 2011




Remi Lorriaux - ELC 2011   1
Agenda

●   Introduction to audio latency
●   Choosing a board for our project
●   Audio using a vanilla kernel
●   Audio using a real-time kernel
●   JACK on our embedded device
●   Conclusion

Remi Lorriaux - ELC 2011   2
Who am I?

●   Software engineer at Adeneo Embedded
    (Bellevue, WA)
     ●   Linux, Android
     ●   Main activities:
          –   Firmware development (BSP adaptation, driver
              development, system integration)
          –   Training delivery


●   Guitar player (at home)

Remi Lorriaux - ELC 2011            3
Context and objectives
●   Case study
     ●   Using a generic embedded device, see how we can
         create a Linux system
     ●   Does not necessarily apply to all types of devices
     ●   Not an in-depth study of real-time systems


●   Focus on software integration
     ●   Not an exhaustive review of all software solutions
     ●   We want to use open source components


Remi Lorriaux - ELC 2011        4
A typical audio chain


                           ADC




                                             DAC
                                 CPU / DSP




●   Digital processing made with a DSP or a
    general-purpose CPU
●   CPUs used in embedded devices generally
    have sufficient power to do the audio
    processing in software

Remi Lorriaux - ELC 2011            5
Typical audio chain on Linux
                 Application



     Server (e.g. JACK, PulseAudio)                                    Application



                                       alsa-lib
                                                read(), write(), poll(), select(), mmap()...


                                 ALSA kernel driver
              Capture buffer                                          Output buffer
                                      INT   DMA

                                      Hardware



Remi Lorriaux - ELC 2011                    6
Audio Latency

●   Delay between an action and its effect, e.g.
     ●   Pressing a key → Hearing a note
     ●   Record input → Processed output
●   Causes
     ●   Physical: 3ft away from loudspeakers ~ 3ms latency
     ●   Hardware: conversion can cause delays
         (magnitude: 40/Fs)
     ●   Software: various levels of buffering


Remi Lorriaux - ELC 2011        7
Audio Latency


●   Consequences on applications:
     ●   Music: critical issue
     ●   Communications: larger latencies can be tolerated
         but still have to be limited (Android specifies
         continuous output latency < 45 ms, continuous
         input latency < 50 ms)
     ●   Audio/Video playback: larger latencies can be
         tolerated as long as synchronization is maintained



Remi Lorriaux - ELC 2011         8
Measuring audio latency
●   Measuring total latency (including hardware):
     ●   Use an oscilloscope or a soundcard
     ●   Can measure the difference between 2
         measurements to assess software changes

●   Measuring software latency
     ●   ALSA: use latency test in alsa-lib (can automatically
         figure out the optimal latency through trial and error)
     ●   JACK: jdelay, qjacklam


Remi Lorriaux - ELC 2011          9
Buffering
 ●   ALSA uses periods: blocks of audio samples
 ●   Size and number is configurable on runtime by applications
 ●   At the end of each period, an interrupt is generated.
     → Shorter periods: more interrupts
     → Shorter periods + less periods: lower latency


          p1                p2              p3               p4

                                                                   INT




Application fills output buffer                     Samples sent to device


 Remi Lorriaux - ELC 2011            10
Reducing audio latency
●   Buffering creates latency
    → Solution: Reduce buffering

●   Reducing buffer size
    → Interrupts are generated more frequently
    → The system has less time to process the
    buffers: risk of over/underrun
    → The system must be designed to schedule
    the different tasks on time

Remi Lorriaux - ELC 2011   11
Tuning the latency


●   alsa-lib provides “latency”
     ●   Test tool used for measuring latency between
         capture and playback
     ●   Audio latency is measured from driver (difference
         when playback and capture was started)
     ●   Can choose a real-time priority (we changed the
         code to make it configurable at runtime)




Remi Lorriaux - ELC 2011       12
Tuning the latency
●   Trial and error:
     ●   Start with a low latency value
     ●   Load the system (CPU, IO stress, your
         application...)
     ●   If XRUN or bad sound quality → Increase the
         latency (periods number and size)
●   “latency” can do it for you automatically:
         > latency ­m [minimum latency in 
         frames] ­M [maximum latency in frames] 
         ­r [sample rate] ­S [priority] ­p


Remi Lorriaux - ELC 2011        13
Loading the system
●   Ideally:
     ●   Realistic load (i.e. your end applications)
     ●   Worst-case scenario

●   Our experiment:
     ●   Stress tests from the Linux Test Projet (LTP)
          –   CPU stress
          –   Memory allocation
     ●   Generate IO interrupts copying from block devices
     ●   cyclictest


Remi Lorriaux - ELC 2011          14
Choosing a board for our project
●   Deciding factors:
     ●   Pick a board that is supported in the latest mainline
         kernel with real-time patches (2.6.33)
     ●   Tested real-time features (Open Source Automation
         Development Lab)
     ●   Pick a board that was available at the time
     ●   Power and features did not matter (except for audio)


●   Other boards could have been chosen (e.g.
    BeagleBoard)


Remi Lorriaux - ELC 2011         15
Our project: Hardware
●   Zoom™ AM3517 EVM Development Kit (AM3517 EVM)
●   ARM™ Cortex™-A8 600 MHz
    → Powerful, but real-time issues still have to be taken into account
●   Ethernet, USB, SD, NAND, Wireless, CAN, LCD, Video capture...
    → Many ways to generate software interrupts
●   Audio in/out (obviously!)




Remi Lorriaux - ELC 2011                16
Our project: Software
●   Bootloader
     ●   U-Boot (Built by Arago)
●   Kernel
     ●   2.6.33
     ●   Patched to 2.6.33.7
     ●   Patched to 2.6.33.7.2-rt30 (RT version)
●   Root filesystem
     ●   Built by Arago
     ●   Customized recipe (arago-console-image.bb + JACK)
     ●   Test applications: alsa-lib tests, LTP, rt-tests

Remi Lorriaux - ELC 2011           17
Our project: Software challenges
●   Support for the AM3517 EVM in mainline 2.6.33
    is somewhat minimal (this has changed a lot)

●   Ported some of the board code/drivers from TI's
    PSP (2.6.32): audio, SD/MMC

●   Still, not many drivers are supported on our test
    system (not exactly a real-life example)


Remi Lorriaux - ELC 2011   18
Experiment #1: Vanilla kernel


●   Vanilla kernel: no RT patches
●   Kernel configuration (see files/kernel/am3517_std_defconfig)
         CONFIG_PREEMPT_DESKTOP=y
         CONFIG_PREEMPT=y
    (other preemption schemes not investigated)




Remi Lorriaux - ELC 2011         19
Experiment #1: First observation
●   The priority of latency has to be set to real-time
    otherwise, it over/underruns for low latency values
    (under 1024 samples @ 44.1 kHz)
●   Even using a non-RT kernel, once the application
    priority is increased, it runs fine when competing with
    other “stress” processes (can be different in the real
    world)
●   cyclictest also exhibits this behavior
    → Use sched_setscheduler() or chrt and set your
    audio thread priority to SCHED_RR or
    SCHED_FIFO


Remi Lorriaux - ELC 2011      20
Experiment #1: CPU usage vs latency
●   Measured with no load:
         > ./latency -m 64 -M 64 -r 44100 -p -S 60
    → Low-latencies can generate a large CPU load!
    Latency (samples)      Latency (@ 44.1kHz)   CPU Load (%)

    64                     1.5 ms                65%

    128                    2.90 ms               3%

    1024                   23 ms                 < 1%

    8192                   185 ms                < 1%




Remi Lorriaux - ELC 2011             21
Experiment #1: Loading the system
●   Creating CPU load:
     ●   LTP CPU stress test
         → Competition between processes (preemptible)
●   Creating IRQ pressure:
     ●   Transfers from SD Card

●   Result: Works fine with 1.5ms latencies
    → Vanilla + SCHED_FIFO did the trick


Remi Lorriaux - ELC 2011       22
Why use a real-time kernel?
●   Tuning the application priority and audio buffering
    requirements can be sufficient for “soft real-time”
    audio systems – where occasional errors do not
    cause unacceptable audio quality consequences
    BUT:
●   There is still a lot of non-preemptible code in the
    vanilla kernel
    ●   Interrupt handlers, tasklets...
    ●   Regions protected by spinlocks (depending on the number
        of processors on your system)



Remi Lorriaux - ELC 2011            23
CONFIG PREEMPT RT Patch

●   Using the CONFIG PREEMPT RT Patch gives
    you:
     ●   Almost full-preemption
     ●   Threaded interrupts: ability to prioritize interrupts
         like processes → your application can have a
         higher priority than hardware interrupts
         → Lower risk of over/underruns




Remi Lorriaux - ELC 2011          24
Making the system real-time
●   Apply the CONFIG PREEMPT RT Patch on
    vanilla kernels.
     ●   Latest available version: patch-2.6.33.7.2-rt30
     ●   Also set the configuration
●   Difficult task on non-mainline/recent kernels
     ●   Making non-mainline boards compatible can be
         difficult (check locks and interrupt management in
         drivers and platform code, make sure that the
         timers are appropriate)
     ●   Cannot apply the patch on proprietary drivers


Remi Lorriaux - ELC 2011        25
Checking the real-time behavior

●   Check that the patch has been correctly applied:
    ●   Running “ps” on the device will show that IRQs are
        threaded
    ●   Use cyclictest to check the scheduling latency under load
        → The non-RT kernel fails right away under high IRQ
        pressure
        → Latencies remain bounded with RT
    ●   Use ftrace to see advanced information (see kernel
        documentation for usage) – changes the timing behavior of
        the system!




Remi Lorriaux - ELC 2011          26
Tuning the real-time system
●   Set the priority of IRQs and processes
    (decreasing priority):
     ●   (High-resolution) Timers (especially since we are
         using a tickless system!)
     ●   Audio (e.g. DMA on our platform)
     ●   Your audio process
     ●   Other interrupts
     ●   Other processes

     ●   More information (FFADO project)


Remi Lorriaux - ELC 2011        27
Tuning audio parameters (RT edition)
●   Same process as the non-RT experiment: trial and error
●   Use the results provided by cyclictest to adjust the latency, e.g.
●   Does not solve the problem of using shared hardware resources
    (e.g. DMA, busses...)
    → Requires careful platform and driver design

root@am3517-evm:~# cyclictest -t5 -n -p 60
policy: fifo: loadavg: 10.89 9.99 6.83 12/76 1342
T: 0 ( 1338) P:60 I:1000 C: 42699 Min:      21 Act:   36 Avg:   37 Max:     96
T: 1 ( 1339) P:59 I:1500 C: 28463 Min:      25 Act:   41 Avg:   37 Max:    135
T: 2 ( 1340) P:58 I:2000 C: 21344 Min:      25 Act:   37 Avg:   39 Max:    111
T: 3 ( 1341) 41 Avg:   39 Max:     111    22 Act:   54 Avg:   38 Max:     91
T: 3 ( 1341) P:57 I:2500 C: 17140 Min:      22 Act:   41 Avg:   38 Max:     91
T: 4 ( 1342) P:56 I:3000 C: 14283 Min:      25 Act:   27 Avg:   38 Max:     86




Remi Lorriaux - ELC 2011                   28
Experiment #2: RT Audio

●   Dirty trick: Added udelay(1000) in the USB
    interrupt handler!
    → Simulate IRQ pressure since the kernel for
    our board did not support ethernet, display...
    → Not a perfect example

●   Result: Works flawlessly with 1ms latency



Remi Lorriaux - ELC 2011   29
Improving the experiment


●   Run typical applications (UI, gstreamer,
    LADSPA...)

●   More stress on the interrupts: Network, Display,
    Video Capture...




Remi Lorriaux - ELC 2011   30
High-end audio applications: JACK
●   System for handling real-time, low latency audio (and MIDI)
●   Cross-platform: GNU/Linux, Solaris, FreeBSD, OS X and
    Windows
●   Server/client model
●   Connectivity:
    ●   Different applications can access an audio device
    ●   Audio applications can share data between each other
    ●   Support for distributing audio processing across a network, both
        fast & reliable LANs as well as slower, less reliable WANs.
●   Designed for professional audio work



Remi Lorriaux - ELC 2011              31
JACK: latency and real-time
●   JACK does not add latency

●   An RT kernel is needed only if:
    ●   You want to run JACK with very low latency settings that
        require real-time performance that can only be achieved
        with an RT kernel
    ●   Your hardware configuration triggers poor latency
        behaviour which might be improved with an RT kernel
●   Most users do not need an RT kernel in order to use
    JACK, and most will be happy using settings that are
    effective without an RT kernel


Remi Lorriaux - ELC 2011         32
JACK on our platform

●   Built using OpenEmbedded (added the recipe
    to our image)
●   Used straight out of the box

●   Set priorities:
     ●   Make jackd have SCHED_FIFO priority (like your
         audio application seen before)
     ●   More information: FFADO wiki



Remi Lorriaux - ELC 2011      33
Experiment #3: JACK on our platform
root@am3517­evm:~#jackd ­R ­P 60 ­d alsa ­i 2 ­r 44100 ­o 2 ­ ­p 64 ­n 6 &
root@am3517­evm:~# jackd 0.118.0                                                
Copyright 2001­2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and ot.
jackd comes with ABSOLUTELY NO WARRANTY                                         
This is free software, and you are welcome to redistribute it                   
under certain conditions; see the file COPYING for details                      
                                                                                
JACK compiled with System V SHM support.                                        
loading driver ..                                                               
apparent rate = 44100                                                           
creating alsa driver ... hw:0|hw:0|64|3|44100|2|2|nomon|swmeter|­|32bit         
control device hw:0                                                             
configuring for 44100Hz, period = 64 frames (1.5 ms), buffer = 6 periods        
ALSA: final selected sample format for capture: 16bit little­endian             
ALSA: use 3 periods for capture                                                 
ALSA: final selected sample format for playback: 16bit little­endian            
ALSA: use 3 periods for playback                                                
                                                                                
root@am3517­evm:~# jack_simple_client                                           
engine sample rate: 44100  




Remi Lorriaux - ELC 2011                       34
Experiment #3: JACK on our platform


●   JACK works fine on our platform with
    < 10 ms latency


    (Note: simplest possible test, so this is a best-
    case value)




Remi Lorriaux - ELC 2011   35
Using multi-core systems
●   Embedded systems can have multi-core architectures:
    ●   Several CPUs
    ●   Mixed CPU/DSP
●   The audio processing can be assigned to a particular
    core
●   Example: TI Audio SoC example (Mixed DSP and ARM
    core)

●   Shared hardware resources is still important (bus
    contention, DMA access...)



Remi Lorriaux - ELC 2011      36
Conclusion
●   Trade-offs:
     ●   CPU/power consumption
     ●   Latency
     ●   Design complexity


●   Tune your priorities/audio parameters first and
    load your system
     ●   Procedure similar to desktop environments (well
         documented)


Remi Lorriaux - ELC 2011       37
Conclusion


●   Adding real-time support:
     ●   Not necessarily trivial or required
     ●   Depends on the implementation
     ●   Non-RT kernel can be surprisingly adequate for
         “soft real-time” audio




Remi Lorriaux - ELC 2011         38
Questions?




Remi Lorriaux - ELC 2011   39
Appendix: Files
●   The files used for this experiment should be
    attached with the presentation
●   Just run or have a look at the different scripts
●   Run (in order):
     ●   oe_prepare.sh: installs prerequisites for
         Arago/OpenEmbedded (some other changes might
         be needed)
     ●   oe_download.sh: downloads and installs custom
         recipes for OE
     ●   oe_build.sh: builds OE


Remi Lorriaux - ELC 2011          40
Appendix: Files
●   Run (continued):
     ●   uboot_build.sh: builds U-Boot (sources pulled from
         OE)
     ●   kernel_download.sh: downloads the kernel sources
         and applies relevant patches for our experiments
     ●   kernel_build.sh: builds the RT and non-RT kernel
     ●   apps_build.sh: builds extra test applications out of
         the OE tree
     ●   sd_flash.sh: flashes the bootloader + kernel + rootfs
         on an SD Card


Remi Lorriaux - ELC 2011        41
Appendix: References
●   Real-Time Linux wiki: Lots of information about
    the RT patch and testing procedures
●   The JACK Audio Connection Kit: General
    presentation. Also covers audio topics on Linux
●   FFADO wiki: How to tune audio parameters
●   ALSA wiki: General documentation and ALSA
    samples
●   JACK: Developer documentation, tuning...
●   AM3517 EVM: Board specification and tools


Remi Lorriaux - ELC 2011   42
Audio in linux embedded

Más contenido relacionado

La actualidad más candente

Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsLinaro
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia FrameworkPicker Weng
 
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)William Liang
 
Introduction 2 linux
Introduction 2 linuxIntroduction 2 linux
Introduction 2 linuxPapu Kumar
 
Linux a free and open source operating system
Linux a free and open source operating systemLinux a free and open source operating system
Linux a free and open source operating systembanwait
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
File System Hierarchy
File System HierarchyFile System Hierarchy
File System Hierarchysritolia
 
Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)fefe7270
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)fefe7270
 

La actualidad más candente (20)

Linux basics
Linux basicsLinux basics
Linux basics
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Android 10
Android 10Android 10
Android 10
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia Framework
 
Android
AndroidAndroid
Android
 
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
 
Introduction 2 linux
Introduction 2 linuxIntroduction 2 linux
Introduction 2 linux
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Linux a free and open source operating system
Linux a free and open source operating systemLinux a free and open source operating system
Linux a free and open source operating system
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
File System Hierarchy
File System HierarchyFile System Hierarchy
File System Hierarchy
 
Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
 

Destacado

Embedded Linux Multimedia
Embedded Linux MultimediaEmbedded Linux Multimedia
Embedded Linux MultimediaCaglar Dursun
 
오픈세미나 플러그인만들기(한번더)
오픈세미나 플러그인만들기(한번더)오픈세미나 플러그인만들기(한번더)
오픈세미나 플러그인만들기(한번더)승훈 오
 
學生學習歷程簡報
學生學習歷程簡報學生學習歷程簡報
學生學習歷程簡報Fang-fang
 
Tg discussion guide90
Tg discussion guide90Tg discussion guide90
Tg discussion guide90lschmidt1170
 
Geog 5 fa 2012 schmidt fri
Geog 5 fa 2012 schmidt friGeog 5 fa 2012 schmidt fri
Geog 5 fa 2012 schmidt frilschmidt1170
 
Pi3 Ef 7 Pe Revision Class
Pi3 Ef 7 Pe Revision ClassPi3 Ef 7 Pe Revision Class
Pi3 Ef 7 Pe Revision ClassAna Menezes
 
Tutorial para crear cuenta en slideshare
Tutorial para crear cuenta en slideshareTutorial para crear cuenta en slideshare
Tutorial para crear cuenta en slideshareAnnie Nitzschke Peña
 
Isabelle: Not Only a Proof Assistant
Isabelle: Not Only a Proof AssistantIsabelle: Not Only a Proof Assistant
Isabelle: Not Only a Proof AssistantAchim D. Brucker
 
UDPSRC GStreamer Plugin Session VIII
UDPSRC GStreamer Plugin Session VIIIUDPSRC GStreamer Plugin Session VIII
UDPSRC GStreamer Plugin Session VIIINEEVEE Technologies
 

Destacado (20)

Embedded Linux Multimedia
Embedded Linux MultimediaEmbedded Linux Multimedia
Embedded Linux Multimedia
 
오픈세미나 플러그인만들기(한번더)
오픈세미나 플러그인만들기(한번더)오픈세미나 플러그인만들기(한번더)
오픈세미나 플러그인만들기(한번더)
 
學生學習歷程簡報
學生學習歷程簡報學生學習歷程簡報
學生學習歷程簡報
 
Kpi publikovani 2
Kpi publikovani 2Kpi publikovani 2
Kpi publikovani 2
 
r3-4-2009f_xts5000_new
r3-4-2009f_xts5000_newr3-4-2009f_xts5000_new
r3-4-2009f_xts5000_new
 
Tg discussion guide90
Tg discussion guide90Tg discussion guide90
Tg discussion guide90
 
CV_Jeeshan CPE
CV_Jeeshan CPECV_Jeeshan CPE
CV_Jeeshan CPE
 
CV_SANJAY SOHIL
CV_SANJAY SOHILCV_SANJAY SOHIL
CV_SANJAY SOHIL
 
Geog 5 fa 2012 schmidt fri
Geog 5 fa 2012 schmidt friGeog 5 fa 2012 schmidt fri
Geog 5 fa 2012 schmidt fri
 
Grouping objects
Grouping objectsGrouping objects
Grouping objects
 
Brain maturation
Brain maturationBrain maturation
Brain maturation
 
Pi3 Ef 7 Pe Revision Class
Pi3 Ef 7 Pe Revision ClassPi3 Ef 7 Pe Revision Class
Pi3 Ef 7 Pe Revision Class
 
Tutorial para crear cuenta en slideshare
Tutorial para crear cuenta en slideshareTutorial para crear cuenta en slideshare
Tutorial para crear cuenta en slideshare
 
Rreflexion cuento
Rreflexion cuentoRreflexion cuento
Rreflexion cuento
 
Heap and Partners
Heap and PartnersHeap and Partners
Heap and Partners
 
Isabelle: Not Only a Proof Assistant
Isabelle: Not Only a Proof AssistantIsabelle: Not Only a Proof Assistant
Isabelle: Not Only a Proof Assistant
 
Device driver
Device driverDevice driver
Device driver
 
UDPSRC GStreamer Plugin Session VIII
UDPSRC GStreamer Plugin Session VIIIUDPSRC GStreamer Plugin Session VIII
UDPSRC GStreamer Plugin Session VIII
 
2014 April 17- Fox Valley Program
2014 April 17- Fox Valley Program2014 April 17- Fox Valley Program
2014 April 17- Fox Valley Program
 
Java Thread
Java ThreadJava Thread
Java Thread
 

Similar a Audio in linux embedded

A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. TanenbaumA Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaumeurobsdcon
 
Shak larry-jeder-perf-and-tuning-summit14-part1-final
Shak larry-jeder-perf-and-tuning-summit14-part1-finalShak larry-jeder-perf-and-tuning-summit14-part1-final
Shak larry-jeder-perf-and-tuning-summit14-part1-finalTommy Lee
 
UNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsUNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsButtaRajasekhar2
 
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be Slow
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be SlowELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be Slow
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be SlowBenjamin Zores
 
AMP Kynetics - ELC 2018 Portland
AMP  Kynetics - ELC 2018 PortlandAMP  Kynetics - ELC 2018 Portland
AMP Kynetics - ELC 2018 PortlandKynetics
 
Asymmetric Multiprocessing - Kynetics ELC 2018 portland
Asymmetric Multiprocessing - Kynetics ELC 2018 portlandAsymmetric Multiprocessing - Kynetics ELC 2018 portland
Asymmetric Multiprocessing - Kynetics ELC 2018 portlandNicola La Gloria
 
Linux Kernel Platform Development: Challenges and Insights
 Linux Kernel Platform Development: Challenges and Insights Linux Kernel Platform Development: Challenges and Insights
Linux Kernel Platform Development: Challenges and InsightsGlobalLogic Ukraine
 
DESIGN CHOICES FOR EMBEDDED REAL-TIME CONTROL SYSTEMS @ 4th FPGA Camp
DESIGN CHOICES FOR EMBEDDED REAL-TIME CONTROL SYSTEMS @ 4th FPGA CampDESIGN CHOICES FOR EMBEDDED REAL-TIME CONTROL SYSTEMS @ 4th FPGA Camp
DESIGN CHOICES FOR EMBEDDED REAL-TIME CONTROL SYSTEMS @ 4th FPGA CampFPGA Central
 
Considerations when implementing_ha_in_dmf
Considerations when implementing_ha_in_dmfConsiderations when implementing_ha_in_dmf
Considerations when implementing_ha_in_dmfhik_lhz
 
PowerDRC/LVS 2.2 released by POLYTEDA
PowerDRC/LVS 2.2 released by POLYTEDAPowerDRC/LVS 2.2 released by POLYTEDA
PowerDRC/LVS 2.2 released by POLYTEDAAlexander Grudanov
 
Porting_uClinux_CELF2008_Griffin
Porting_uClinux_CELF2008_GriffinPorting_uClinux_CELF2008_Griffin
Porting_uClinux_CELF2008_GriffinPeter Griffin
 
Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Four Ways to Improve Linux Performance IEEE Webinar, R2.0Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Four Ways to Improve Linux Performance IEEE Webinar, R2.0Michael Christofferson
 
01 Computer Basics (Ch1.1).pptx
01 Computer Basics (Ch1.1).pptx01 Computer Basics (Ch1.1).pptx
01 Computer Basics (Ch1.1).pptxsarah380333
 
Embedded platform choices
Embedded platform choicesEmbedded platform choices
Embedded platform choicesTavish Naruka
 
Current and Future of Non-Volatile Memory on Linux
Current and Future of Non-Volatile Memory on LinuxCurrent and Future of Non-Volatile Memory on Linux
Current and Future of Non-Volatile Memory on Linuxmountpoint.io
 
LAS16-209: Finished and Upcoming Projects in LMG
LAS16-209: Finished and Upcoming Projects in LMGLAS16-209: Finished and Upcoming Projects in LMG
LAS16-209: Finished and Upcoming Projects in LMGLinaro
 
Embedded Graphics Drivers in Mesa (ELCE 2019)
Embedded Graphics Drivers in Mesa (ELCE 2019)Embedded Graphics Drivers in Mesa (ELCE 2019)
Embedded Graphics Drivers in Mesa (ELCE 2019)Igalia
 
DPDK Summit - 08 Sept 2014 - NTT - High Performance vSwitch
DPDK Summit - 08 Sept 2014 - NTT - High Performance vSwitchDPDK Summit - 08 Sept 2014 - NTT - High Performance vSwitch
DPDK Summit - 08 Sept 2014 - NTT - High Performance vSwitchJim St. Leger
 

Similar a Audio in linux embedded (20)

A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. TanenbaumA Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
 
Lect17
Lect17Lect17
Lect17
 
Shak larry-jeder-perf-and-tuning-summit14-part1-final
Shak larry-jeder-perf-and-tuning-summit14-part1-finalShak larry-jeder-perf-and-tuning-summit14-part1-final
Shak larry-jeder-perf-and-tuning-summit14-part1-final
 
Optimizing Linux Servers
Optimizing Linux ServersOptimizing Linux Servers
Optimizing Linux Servers
 
UNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsUNIT 3 - General Purpose Processors
UNIT 3 - General Purpose Processors
 
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be Slow
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be SlowELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be Slow
ELCE 2011 - BZ - Embedded Linux Optimization Techniques - How Not To Be Slow
 
AMP Kynetics - ELC 2018 Portland
AMP  Kynetics - ELC 2018 PortlandAMP  Kynetics - ELC 2018 Portland
AMP Kynetics - ELC 2018 Portland
 
Asymmetric Multiprocessing - Kynetics ELC 2018 portland
Asymmetric Multiprocessing - Kynetics ELC 2018 portlandAsymmetric Multiprocessing - Kynetics ELC 2018 portland
Asymmetric Multiprocessing - Kynetics ELC 2018 portland
 
Linux Kernel Platform Development: Challenges and Insights
 Linux Kernel Platform Development: Challenges and Insights Linux Kernel Platform Development: Challenges and Insights
Linux Kernel Platform Development: Challenges and Insights
 
DESIGN CHOICES FOR EMBEDDED REAL-TIME CONTROL SYSTEMS @ 4th FPGA Camp
DESIGN CHOICES FOR EMBEDDED REAL-TIME CONTROL SYSTEMS @ 4th FPGA CampDESIGN CHOICES FOR EMBEDDED REAL-TIME CONTROL SYSTEMS @ 4th FPGA Camp
DESIGN CHOICES FOR EMBEDDED REAL-TIME CONTROL SYSTEMS @ 4th FPGA Camp
 
Considerations when implementing_ha_in_dmf
Considerations when implementing_ha_in_dmfConsiderations when implementing_ha_in_dmf
Considerations when implementing_ha_in_dmf
 
PowerDRC/LVS 2.2 released by POLYTEDA
PowerDRC/LVS 2.2 released by POLYTEDAPowerDRC/LVS 2.2 released by POLYTEDA
PowerDRC/LVS 2.2 released by POLYTEDA
 
Porting_uClinux_CELF2008_Griffin
Porting_uClinux_CELF2008_GriffinPorting_uClinux_CELF2008_Griffin
Porting_uClinux_CELF2008_Griffin
 
Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Four Ways to Improve Linux Performance IEEE Webinar, R2.0Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Four Ways to Improve Linux Performance IEEE Webinar, R2.0
 
01 Computer Basics (Ch1.1).pptx
01 Computer Basics (Ch1.1).pptx01 Computer Basics (Ch1.1).pptx
01 Computer Basics (Ch1.1).pptx
 
Embedded platform choices
Embedded platform choicesEmbedded platform choices
Embedded platform choices
 
Current and Future of Non-Volatile Memory on Linux
Current and Future of Non-Volatile Memory on LinuxCurrent and Future of Non-Volatile Memory on Linux
Current and Future of Non-Volatile Memory on Linux
 
LAS16-209: Finished and Upcoming Projects in LMG
LAS16-209: Finished and Upcoming Projects in LMGLAS16-209: Finished and Upcoming Projects in LMG
LAS16-209: Finished and Upcoming Projects in LMG
 
Embedded Graphics Drivers in Mesa (ELCE 2019)
Embedded Graphics Drivers in Mesa (ELCE 2019)Embedded Graphics Drivers in Mesa (ELCE 2019)
Embedded Graphics Drivers in Mesa (ELCE 2019)
 
DPDK Summit - 08 Sept 2014 - NTT - High Performance vSwitch
DPDK Summit - 08 Sept 2014 - NTT - High Performance vSwitchDPDK Summit - 08 Sept 2014 - NTT - High Performance vSwitch
DPDK Summit - 08 Sept 2014 - NTT - High Performance vSwitch
 

Último

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneUiPathCommunity
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 

Último (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyone
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 

Audio in linux embedded

  • 1. Real-time Audio on Embedded Linux April, 2011 Remi Lorriaux Adeneo Embedded Embedded Linux Conference 2011 Remi Lorriaux - ELC 2011 1
  • 2. Agenda ● Introduction to audio latency ● Choosing a board for our project ● Audio using a vanilla kernel ● Audio using a real-time kernel ● JACK on our embedded device ● Conclusion Remi Lorriaux - ELC 2011 2
  • 3. Who am I? ● Software engineer at Adeneo Embedded (Bellevue, WA) ● Linux, Android ● Main activities: – Firmware development (BSP adaptation, driver development, system integration) – Training delivery ● Guitar player (at home) Remi Lorriaux - ELC 2011 3
  • 4. Context and objectives ● Case study ● Using a generic embedded device, see how we can create a Linux system ● Does not necessarily apply to all types of devices ● Not an in-depth study of real-time systems ● Focus on software integration ● Not an exhaustive review of all software solutions ● We want to use open source components Remi Lorriaux - ELC 2011 4
  • 5. A typical audio chain ADC DAC CPU / DSP ● Digital processing made with a DSP or a general-purpose CPU ● CPUs used in embedded devices generally have sufficient power to do the audio processing in software Remi Lorriaux - ELC 2011 5
  • 6. Typical audio chain on Linux Application Server (e.g. JACK, PulseAudio) Application alsa-lib read(), write(), poll(), select(), mmap()... ALSA kernel driver Capture buffer Output buffer INT DMA Hardware Remi Lorriaux - ELC 2011 6
  • 7. Audio Latency ● Delay between an action and its effect, e.g. ● Pressing a key → Hearing a note ● Record input → Processed output ● Causes ● Physical: 3ft away from loudspeakers ~ 3ms latency ● Hardware: conversion can cause delays (magnitude: 40/Fs) ● Software: various levels of buffering Remi Lorriaux - ELC 2011 7
  • 8. Audio Latency ● Consequences on applications: ● Music: critical issue ● Communications: larger latencies can be tolerated but still have to be limited (Android specifies continuous output latency < 45 ms, continuous input latency < 50 ms) ● Audio/Video playback: larger latencies can be tolerated as long as synchronization is maintained Remi Lorriaux - ELC 2011 8
  • 9. Measuring audio latency ● Measuring total latency (including hardware): ● Use an oscilloscope or a soundcard ● Can measure the difference between 2 measurements to assess software changes ● Measuring software latency ● ALSA: use latency test in alsa-lib (can automatically figure out the optimal latency through trial and error) ● JACK: jdelay, qjacklam Remi Lorriaux - ELC 2011 9
  • 10. Buffering ● ALSA uses periods: blocks of audio samples ● Size and number is configurable on runtime by applications ● At the end of each period, an interrupt is generated. → Shorter periods: more interrupts → Shorter periods + less periods: lower latency p1 p2 p3 p4 INT Application fills output buffer Samples sent to device Remi Lorriaux - ELC 2011 10
  • 11. Reducing audio latency ● Buffering creates latency → Solution: Reduce buffering ● Reducing buffer size → Interrupts are generated more frequently → The system has less time to process the buffers: risk of over/underrun → The system must be designed to schedule the different tasks on time Remi Lorriaux - ELC 2011 11
  • 12. Tuning the latency ● alsa-lib provides “latency” ● Test tool used for measuring latency between capture and playback ● Audio latency is measured from driver (difference when playback and capture was started) ● Can choose a real-time priority (we changed the code to make it configurable at runtime) Remi Lorriaux - ELC 2011 12
  • 13. Tuning the latency ● Trial and error: ● Start with a low latency value ● Load the system (CPU, IO stress, your application...) ● If XRUN or bad sound quality → Increase the latency (periods number and size) ● “latency” can do it for you automatically: > latency ­m [minimum latency in  frames] ­M [maximum latency in frames]  ­r [sample rate] ­S [priority] ­p Remi Lorriaux - ELC 2011 13
  • 14. Loading the system ● Ideally: ● Realistic load (i.e. your end applications) ● Worst-case scenario ● Our experiment: ● Stress tests from the Linux Test Projet (LTP) – CPU stress – Memory allocation ● Generate IO interrupts copying from block devices ● cyclictest Remi Lorriaux - ELC 2011 14
  • 15. Choosing a board for our project ● Deciding factors: ● Pick a board that is supported in the latest mainline kernel with real-time patches (2.6.33) ● Tested real-time features (Open Source Automation Development Lab) ● Pick a board that was available at the time ● Power and features did not matter (except for audio) ● Other boards could have been chosen (e.g. BeagleBoard) Remi Lorriaux - ELC 2011 15
  • 16. Our project: Hardware ● Zoom™ AM3517 EVM Development Kit (AM3517 EVM) ● ARM™ Cortex™-A8 600 MHz → Powerful, but real-time issues still have to be taken into account ● Ethernet, USB, SD, NAND, Wireless, CAN, LCD, Video capture... → Many ways to generate software interrupts ● Audio in/out (obviously!) Remi Lorriaux - ELC 2011 16
  • 17. Our project: Software ● Bootloader ● U-Boot (Built by Arago) ● Kernel ● 2.6.33 ● Patched to 2.6.33.7 ● Patched to 2.6.33.7.2-rt30 (RT version) ● Root filesystem ● Built by Arago ● Customized recipe (arago-console-image.bb + JACK) ● Test applications: alsa-lib tests, LTP, rt-tests Remi Lorriaux - ELC 2011 17
  • 18. Our project: Software challenges ● Support for the AM3517 EVM in mainline 2.6.33 is somewhat minimal (this has changed a lot) ● Ported some of the board code/drivers from TI's PSP (2.6.32): audio, SD/MMC ● Still, not many drivers are supported on our test system (not exactly a real-life example) Remi Lorriaux - ELC 2011 18
  • 19. Experiment #1: Vanilla kernel ● Vanilla kernel: no RT patches ● Kernel configuration (see files/kernel/am3517_std_defconfig) CONFIG_PREEMPT_DESKTOP=y CONFIG_PREEMPT=y (other preemption schemes not investigated) Remi Lorriaux - ELC 2011 19
  • 20. Experiment #1: First observation ● The priority of latency has to be set to real-time otherwise, it over/underruns for low latency values (under 1024 samples @ 44.1 kHz) ● Even using a non-RT kernel, once the application priority is increased, it runs fine when competing with other “stress” processes (can be different in the real world) ● cyclictest also exhibits this behavior → Use sched_setscheduler() or chrt and set your audio thread priority to SCHED_RR or SCHED_FIFO Remi Lorriaux - ELC 2011 20
  • 21. Experiment #1: CPU usage vs latency ● Measured with no load: > ./latency -m 64 -M 64 -r 44100 -p -S 60 → Low-latencies can generate a large CPU load! Latency (samples) Latency (@ 44.1kHz) CPU Load (%) 64 1.5 ms 65% 128 2.90 ms 3% 1024 23 ms < 1% 8192 185 ms < 1% Remi Lorriaux - ELC 2011 21
  • 22. Experiment #1: Loading the system ● Creating CPU load: ● LTP CPU stress test → Competition between processes (preemptible) ● Creating IRQ pressure: ● Transfers from SD Card ● Result: Works fine with 1.5ms latencies → Vanilla + SCHED_FIFO did the trick Remi Lorriaux - ELC 2011 22
  • 23. Why use a real-time kernel? ● Tuning the application priority and audio buffering requirements can be sufficient for “soft real-time” audio systems – where occasional errors do not cause unacceptable audio quality consequences BUT: ● There is still a lot of non-preemptible code in the vanilla kernel ● Interrupt handlers, tasklets... ● Regions protected by spinlocks (depending on the number of processors on your system) Remi Lorriaux - ELC 2011 23
  • 24. CONFIG PREEMPT RT Patch ● Using the CONFIG PREEMPT RT Patch gives you: ● Almost full-preemption ● Threaded interrupts: ability to prioritize interrupts like processes → your application can have a higher priority than hardware interrupts → Lower risk of over/underruns Remi Lorriaux - ELC 2011 24
  • 25. Making the system real-time ● Apply the CONFIG PREEMPT RT Patch on vanilla kernels. ● Latest available version: patch-2.6.33.7.2-rt30 ● Also set the configuration ● Difficult task on non-mainline/recent kernels ● Making non-mainline boards compatible can be difficult (check locks and interrupt management in drivers and platform code, make sure that the timers are appropriate) ● Cannot apply the patch on proprietary drivers Remi Lorriaux - ELC 2011 25
  • 26. Checking the real-time behavior ● Check that the patch has been correctly applied: ● Running “ps” on the device will show that IRQs are threaded ● Use cyclictest to check the scheduling latency under load → The non-RT kernel fails right away under high IRQ pressure → Latencies remain bounded with RT ● Use ftrace to see advanced information (see kernel documentation for usage) – changes the timing behavior of the system! Remi Lorriaux - ELC 2011 26
  • 27. Tuning the real-time system ● Set the priority of IRQs and processes (decreasing priority): ● (High-resolution) Timers (especially since we are using a tickless system!) ● Audio (e.g. DMA on our platform) ● Your audio process ● Other interrupts ● Other processes ● More information (FFADO project) Remi Lorriaux - ELC 2011 27
  • 28. Tuning audio parameters (RT edition) ● Same process as the non-RT experiment: trial and error ● Use the results provided by cyclictest to adjust the latency, e.g. ● Does not solve the problem of using shared hardware resources (e.g. DMA, busses...) → Requires careful platform and driver design root@am3517-evm:~# cyclictest -t5 -n -p 60 policy: fifo: loadavg: 10.89 9.99 6.83 12/76 1342 T: 0 ( 1338) P:60 I:1000 C: 42699 Min: 21 Act: 36 Avg: 37 Max: 96 T: 1 ( 1339) P:59 I:1500 C: 28463 Min: 25 Act: 41 Avg: 37 Max: 135 T: 2 ( 1340) P:58 I:2000 C: 21344 Min: 25 Act: 37 Avg: 39 Max: 111 T: 3 ( 1341) 41 Avg: 39 Max: 111 22 Act: 54 Avg: 38 Max: 91 T: 3 ( 1341) P:57 I:2500 C: 17140 Min: 22 Act: 41 Avg: 38 Max: 91 T: 4 ( 1342) P:56 I:3000 C: 14283 Min: 25 Act: 27 Avg: 38 Max: 86 Remi Lorriaux - ELC 2011 28
  • 29. Experiment #2: RT Audio ● Dirty trick: Added udelay(1000) in the USB interrupt handler! → Simulate IRQ pressure since the kernel for our board did not support ethernet, display... → Not a perfect example ● Result: Works flawlessly with 1ms latency Remi Lorriaux - ELC 2011 29
  • 30. Improving the experiment ● Run typical applications (UI, gstreamer, LADSPA...) ● More stress on the interrupts: Network, Display, Video Capture... Remi Lorriaux - ELC 2011 30
  • 31. High-end audio applications: JACK ● System for handling real-time, low latency audio (and MIDI) ● Cross-platform: GNU/Linux, Solaris, FreeBSD, OS X and Windows ● Server/client model ● Connectivity: ● Different applications can access an audio device ● Audio applications can share data between each other ● Support for distributing audio processing across a network, both fast & reliable LANs as well as slower, less reliable WANs. ● Designed for professional audio work Remi Lorriaux - ELC 2011 31
  • 32. JACK: latency and real-time ● JACK does not add latency ● An RT kernel is needed only if: ● You want to run JACK with very low latency settings that require real-time performance that can only be achieved with an RT kernel ● Your hardware configuration triggers poor latency behaviour which might be improved with an RT kernel ● Most users do not need an RT kernel in order to use JACK, and most will be happy using settings that are effective without an RT kernel Remi Lorriaux - ELC 2011 32
  • 33. JACK on our platform ● Built using OpenEmbedded (added the recipe to our image) ● Used straight out of the box ● Set priorities: ● Make jackd have SCHED_FIFO priority (like your audio application seen before) ● More information: FFADO wiki Remi Lorriaux - ELC 2011 33
  • 34. Experiment #3: JACK on our platform root@am3517­evm:~#jackd ­R ­P 60 ­d alsa ­i 2 ­r 44100 ­o 2 ­ ­p 64 ­n 6 & root@am3517­evm:~# jackd 0.118.0                                                 Copyright 2001­2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and ot. jackd comes with ABSOLUTELY NO WARRANTY                                          This is free software, and you are welcome to redistribute it                    under certain conditions; see the file COPYING for details                                                                                                        JACK compiled with System V SHM support.                                         loading driver ..                                                                apparent rate = 44100                                                            creating alsa driver ... hw:0|hw:0|64|3|44100|2|2|nomon|swmeter|­|32bit          control device hw:0                                                              configuring for 44100Hz, period = 64 frames (1.5 ms), buffer = 6 periods         ALSA: final selected sample format for capture: 16bit little­endian              ALSA: use 3 periods for capture                                                  ALSA: final selected sample format for playback: 16bit little­endian             ALSA: use 3 periods for playback                                                                                                                                  root@am3517­evm:~# jack_simple_client                                            engine sample rate: 44100   Remi Lorriaux - ELC 2011 34
  • 35. Experiment #3: JACK on our platform ● JACK works fine on our platform with < 10 ms latency (Note: simplest possible test, so this is a best- case value) Remi Lorriaux - ELC 2011 35
  • 36. Using multi-core systems ● Embedded systems can have multi-core architectures: ● Several CPUs ● Mixed CPU/DSP ● The audio processing can be assigned to a particular core ● Example: TI Audio SoC example (Mixed DSP and ARM core) ● Shared hardware resources is still important (bus contention, DMA access...) Remi Lorriaux - ELC 2011 36
  • 37. Conclusion ● Trade-offs: ● CPU/power consumption ● Latency ● Design complexity ● Tune your priorities/audio parameters first and load your system ● Procedure similar to desktop environments (well documented) Remi Lorriaux - ELC 2011 37
  • 38. Conclusion ● Adding real-time support: ● Not necessarily trivial or required ● Depends on the implementation ● Non-RT kernel can be surprisingly adequate for “soft real-time” audio Remi Lorriaux - ELC 2011 38
  • 40. Appendix: Files ● The files used for this experiment should be attached with the presentation ● Just run or have a look at the different scripts ● Run (in order): ● oe_prepare.sh: installs prerequisites for Arago/OpenEmbedded (some other changes might be needed) ● oe_download.sh: downloads and installs custom recipes for OE ● oe_build.sh: builds OE Remi Lorriaux - ELC 2011 40
  • 41. Appendix: Files ● Run (continued): ● uboot_build.sh: builds U-Boot (sources pulled from OE) ● kernel_download.sh: downloads the kernel sources and applies relevant patches for our experiments ● kernel_build.sh: builds the RT and non-RT kernel ● apps_build.sh: builds extra test applications out of the OE tree ● sd_flash.sh: flashes the bootloader + kernel + rootfs on an SD Card Remi Lorriaux - ELC 2011 41
  • 42. Appendix: References ● Real-Time Linux wiki: Lots of information about the RT patch and testing procedures ● The JACK Audio Connection Kit: General presentation. Also covers audio topics on Linux ● FFADO wiki: How to tune audio parameters ● ALSA wiki: General documentation and ALSA samples ● JACK: Developer documentation, tuning... ● AM3517 EVM: Board specification and tools Remi Lorriaux - ELC 2011 42