CppCon 2015: Timur Doumler “C++ in the Audio Industry”

Sdílet
Vložit
  • čas přidán 15. 05. 2024
  • www.Cppcon.org
    -
    Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/cppcon/cppcon2015
    -
    Sound is an essential medium for human-computer interaction and vital for applications such as games and music production software. In the audio industry, C++ is the dominating programming language. This talk provides an insight into the patterns and tools that C++ developers in the audio industry rely on. There are interesting lessons to be learned from this domain that can be useful to every C++ developer.
    Handling audio in real time presents interesting technical challenges. Techniques also used in other C++ domains have to be combined: real-time multithreading, lock-free programming, efficient DSP, SIMD, and low-latency hardware communication. C++ is the language of choice to tie all these requirements together. Clever leveraging of advanced C++ techniques, template metaprogramming, and the new C++11/14 standard makes these tasks more exciting than ever.
    -
    Timur Doumler is Senior Software Developer at London-based technology company ROLI. He is working with Julian Storer to further develop JUCE, the leading cross-platform framework for creating audio applications that is used by hundreds of companies in the audio industry.
    After five years of writing high-performance code in Fortran, C, and C++ for numerical simulations of the cosmic structure formation, Timur became committed to audio and music production software. Before joining ROLI, he worked on various projects at market-leading company Native Instruments, such as KONTAKT, the industry standard sampling platform used by the majority of music producers and composers for film score, games, and contemporary popular music.
    Timur holds a PhD in astrophysics and is passionate about well-written code, modern C++ techniques, science-fiction, learning languages, and progressive rock music.
    -
    Videos Filmed & Edited by Bash Films: www.BashFilms.com
    *-----*
    Register Now For CppCon 2022: cppcon.org/registration/
    *-----*

Komentáře • 70

  • @almazmusic
    @almazmusic Před 7 lety +123

    Pure gold for the beginners. Thanks you Timur, you are a good teacher.

  • @jankopiano577
    @jankopiano577 Před 8 lety +24

    A couple of points you didn't cover: 1. Never rely on calloc or C++ new zero initialized memory. The zeroing may be done via VM tricks that will cause a page fault upon first touching the memory. 2. Code can page fault. You should pre-warm any code you run before you run it on the audio thread.

  • @anthonyparks505
    @anthonyparks505 Před 8 měsíci

    Timur I want to thank you for this talk. In my synthesizer project I simply moved all my graph updating logic to the GUI thread and used atomic shared ptr to swap references. Simply moving all these locks, memory alloc, file io, out of the callback has made my program crash 100% less than it did before, which was totally random. I know I'm probably not doing everything totally correctly but I can feel an enormous difference when playing my synthesizer. It is so satisfying when apps 'just work'. These talks are invaluable for audio programmers.

  • @budabudimir1
    @budabudimir1 Před 6 lety +13

    This is good stuff, but a thing to note at 46:00 is that atomic free functions to manipulate shared_ptr are not lock-free. Moreover, on 48:00, the solution to delete in callback can be solved in a lock-free manner using either hazard pointers or epoch garbage collector.

  • @DimitrisVasil
    @DimitrisVasil Před 8 lety +9

    REALLY helpful video! Everything was explained in a nice way. I want more stuff like this!

  • @frydac
    @frydac Před 8 lety +2

    Great content, thx! Would love to see a follow up talk on this (maybe at JUCE Summit in november?). Would definitely make a nice tutorial and add significant value to the JUCE docs imo.
    Also Projucer seems like an interesting interactive IDE, don't think that talk has been posted yet though..

  • @azymohliad
    @azymohliad Před 4 lety +3

    This is a treasure! Thanks a lot! Being a beginner in the topic, it's one of the most useful conference talks I've ever watched. Hopefully, it won't be too difficult to apply these patterns in Rust.

  • @jbusa5dimvzgkiik
    @jbusa5dimvzgkiik Před 8 lety

    Great talk, thank you for sharing your experience!

  • @MrBl00m
    @MrBl00m Před 5 lety +5

    re 44:47 - Having looked on ccpreference and having tried atomic_is_lock_free( const std::shared_ptr* p) and with T = juce::String, I think the atomic access on shared pointers is not lock free. At least when T is not a basic type. From cpp reference : "These functions are typically implemented using mutexes, stored in a global hash table where the pointer value is used as the key."

  • @batner
    @batner Před rokem +1

    Thanks Timur, a good intro for me.

  • @annaoaulinovna
    @annaoaulinovna Před 5 lety

    awesome tech without audio AFEs and audio DACs. very great job of coding.

  • @siwenzhang
    @siwenzhang Před 8 lety +2

    Great talk, full of useful info!

  • @charlesparker6167
    @charlesparker6167 Před 6 lety

    Bravo! Great talk!

  • @lowearthsurfer
    @lowearthsurfer Před 10 měsíci +1

    im always perplexed as to how people can come with this. This is an insane amount of genius, a feel so dumb I wish i could come with everything he said. :(

  • @kjtov1
    @kjtov1 Před 4 lety +1

    Excellent talk. About the std::atomic, now it is implemented as std::shared_ptr in C++20.

  • @Embedonix
    @Embedonix Před 6 lety +1

    Perfect explanation! Thanks!

  • @jankopiano577
    @jankopiano577 Před 8 lety +2

    It was my understanding that mt19937 is O(1) *amorttized*. Most of the time it is just a few ops, but periodically it recomputes a large buffer.

  • @tim_arterbury
    @tim_arterbury Před 8 lety +2

    @Timur Doumler is there source code for this project anywhere? I'd love to see how the oscilloscope works. I checked thecppcon githib for this presentation but it was not there. I've been researching how to implement one but am confused. Thanks.

  • @eriknatanael
    @eriknatanael Před 5 lety

    Really excellent talk!

  • @MrRightThinker
    @MrRightThinker Před 4 lety

    He is a knowledgeable person.

  • @valetprivet2232
    @valetprivet2232 Před 8 lety

    great stuff, good job, thanx

  • @TheOnlyAndreySotnikov
    @TheOnlyAndreySotnikov Před 3 lety

    39:24 If you use load/save without extra arguments, sequentially-consistent ordering will be used, which is way too slow. You should always explicitly specify memory ordering for std::atomic, if you care about performance.

  • @volodymyrkorniichuk1164

    Great talk!

  • @pizzabeerengineering2488
    @pizzabeerengineering2488 Před 4 lety +12

    15:05 woah am I seeing a slider in the IDE setting a value?

    • @sophiacristina
      @sophiacristina Před 3 lety +2

      I got impressed, but JUCE does that indeed. They should add this on Visual Studio.

  • @lithium
    @lithium Před 7 lety

    @Taylor Holliday Probably to preserve the deleter.

  • @michal.gawron
    @michal.gawron Před 6 lety +7

    A note: it's perfectly okay to wait on a mutex in audio thread if you can predict for how long it will be blocked. Think of audio thread waiting for all RT synthesis threads to finish. Locking and waiting is NOT BAD at all, it's bad when you wait for unpredictable threads.

    • @DevinSamarin
      @DevinSamarin Před 6 lety

      Michał Gawron why would you have RT synthesis done in separate threads?

    • @michal.gawron
      @michal.gawron Před 6 lety +5

      Devin Samarin You know, CPUs nowadays have multiple cores. ;-)

  • @rachidajewher8649
    @rachidajewher8649 Před 3 lety

    please help : do i need to create a program with ASIO api to call the right data from the sound device to the DAW ? or selecting the asio driver inside protools is enough to record a 24bit bit perfect .

  • @alessandrolima4266
    @alessandrolima4266 Před rokem +1

    Great pack of useful info

    • @CppCon
      @CppCon  Před rokem

      Glad it was helpful!

  • @geraldhinson
    @geraldhinson Před 8 lety +9

    Interesting that 10ms is the number shown as the high threshold for acceptable latency. I can't speak for keyboards, but for guitar anything above 5ms starts to noticeably affect the feel of playing. 5ms or below is definitely preferable. Historically coming up with an affordable audio interface and computer pairing that could achieve this was quite the challenge, which of course was one of the strongest arguments for dedicated hardware (a la AxeFX, Kemper, etc.) vs. software based amps.

    • @geraldhinson
      @geraldhinson Před 8 lety +1

      +Gerald Hinson Oh, forgot to say the obvious: Great presentation!

    • @thesomething8467
      @thesomething8467 Před 8 lety +1

      +Gerald Hinson 10ms that's a joke. If I go above 7ms, I can't play the fast parts on guitar anymore (shredding), the delay is literally thowing me off track. I hate it when people say, you can't notice things under 16ms or some bullshit like that.

    • @jonaspeters85
      @jonaspeters85 Před 8 lety +14

      Remember the speed of sound (in Air) is ~2.994 ms per meter.
      So, if your distance to a your Guitarbox is more than 2.4 Meters. Your Latency is to big for playing fast?

    • @thesomething8467
      @thesomething8467 Před 8 lety

      Monitors are rarely further than 3 meters away from me. I sometimes go off the stage and if I go too far away I start noticing the delay. If you say 7ms round-trip, it's usually a bit more because the software is calculating the best case (not including all variables).

    • @0oTHEJACKo0
      @0oTHEJACKo0 Před 6 lety +1

      Well I can explain:
      When your playing live with an amp and cab you are playing loud and you don't hear you own e-guitar itself at all. You will only hear the signal from the amp/cab. You learn to get easily adjusted to the small latency by the distance you are in front of your amp. But if you are playing sitting in front of your DAW or a VST on your PC with your guitar in your hands, you will never turn up the volume as high like on a live gig or rehearsal. So you hear the sound of your e-guitar alone (which can be remarkably loud by the way) but also the processed sound with latency
      ->
      and that is what will really throw you off the track if it is higher than let's say 10 ms in sum at least (better to have it around 5 ms).

  • @dlieu6597
    @dlieu6597 Před 8 lety

    nice talk

  • @francois9184
    @francois9184 Před 2 lety

    hello!
    how can i create a random between two values to control a parameter in Faust?

  • @jim0_o
    @jim0_o Před 8 lety +1

    14:50 I have heard so many times "I know XXXX isn't the correct way of doing random number" what should I google for the correct way ? C/C++ no lib. ??

    • @FanRRice
      @FanRRice Před 3 lety

      checkout cpp std library

  • @tayholliday
    @tayholliday Před 8 lety +1

    (49:00) Why doesn't ReleasePool::add just take a shared_ptr to void? The template seems unnecessary.

    • @nixiz1
      @nixiz1 Před 4 lety

      when checking if(object.empty()) you need to derefence to T type to check if the actual T object is nullptr or not. I think :)

  • @nksdp9776
    @nksdp9776 Před 8 lety

    It's nice to have a talk on that topic. I am really interested into making music programs and plugins, does any one knows if there are opportunities in that field ?

    • @tissuepaper9962
      @tissuepaper9962 Před 2 lety

      Hey friend, did you ever find a job? I'm interested in the same line of work, and I'm curious if you have any tips.

    • @oonmm
      @oonmm Před rokem

      @@tissuepaper9962 If you get no answer, generally it means that the people already working in the field doesn't want more people to enter. I.e. it's probably paradise for those few who have made the venture.

  • @moritzsur997
    @moritzsur997 Před 2 lety +1

    GOAT

  • @gmailaccountk406
    @gmailaccountk406 Před 7 lety

    smart man

  • @michal.gawron
    @michal.gawron Před 6 lety +9

    Instead of working on my own soft synth I'm watching a video which explains stuff I already know. :P

  • @climatechangedoesntbargain9140

    Repeat questions... you are presenting at CppCon

  • @fstopspictures8834
    @fstopspictures8834 Před 4 lety

    please someone answer ,asio4all can record audio and you can choose the buffer size what is the differance between asio4all and coding with c++??

  • @goeiecool9999
    @goeiecool9999 Před 3 lety +5

    57:50 "Nobody will notice if you drop like one of the 60 frames visually"
    And then you enter the world of video games.

    • @volodymyrkorniichuk1164
      @volodymyrkorniichuk1164 Před 3 lety +6

      Still not so important. Let's say you have recorded 1 min of game as video in 60 fps. Let's say in one of these 60 seconds there were actually 59 unique frames, not 60. Can you watch this video and tell where exactly there is second with 59 fps? No, you can't. Now let's say one of these 60 seconds has 16 ms of silence. Can you listen to this audio and tell where the silence occurred? Sure you can, from the first attempt. It means drop of audio is more important than drop of video.

  • @ABaumstumpf
    @ABaumstumpf Před 4 lety +1

    38:20
    Volatile IS the correct solution here - and it fixes several of the "problems" listed here.
    Also it only prevent the compiler from doing 2 things - optimising away any checks on that variable (We want the compiler to keep them) and reordering of volatile access (with read/write in the same function this is also what we want).
    So.... no, for the situation used as an example it is the best possible solution even - the least overhead, short and concise.

    • @DasAntiNaziBroetchen
      @DasAntiNaziBroetchen Před 3 lety

      Volatile also prevents the compiler from deferring the write to main memory.
      Also it seems like your assumptions about volatile are based on Microsoft's implementation of volatile, which apparently is redefined as a full memory barrier, unlike on other compilers.

  • @InXLsisDeo
    @InXLsisDeo Před 8 lety

    One way to reduce CPU usage significantly is to pre-render some tracks and run effects in real-time only on the tracks we are working at the moment.

  • @pfylim
    @pfylim Před 5 lety

    The buffer size should be 1 for the best audio performance. You need zero latency for the best performance.

    • @brandonkellner4053
      @brandonkellner4053 Před 5 lety +2

      Sending 1 frame at a time? That would be a lot of overhead. Regardless, it's more how many frames ahead you are that matter, not how many you send at a time, unless your resolution is less than like 200/sec or something. You're not going to be able to get audio to even work if you plan to be only 1 frame ahead.

    • @stpedro-ht9ng
      @stpedro-ht9ng Před rokem

      I can't go lower than 64 and I have a really powerful machine.

  • @olafurbjarki
    @olafurbjarki Před 8 lety +11

    14:36 - This is a terrible example of aliasing which everybody in the audio industry should be very well aware of. You might consider putting a comment in the video to point out that this is not the proper way to generate a square wave in the digital domain.
    This paper covers the basics of alias-free digital synthesis - ccrma.stanford.edu/~stilti/papers/blit.pdf

    • @CrazyHorse151
      @CrazyHorse151 Před 7 lety +2

      Have fun diving in to band limiting at CPPCon,.. maybe not the appropriate spot for that. :D

    • @michal.gawron
      @michal.gawron Před 7 lety +5

      A comment about aliasing would be nice, that's true, but it's just an overview, no need to go into details.

  • @valetprivet2232
    @valetprivet2232 Před 8 lety

    ... and unnecessary emplace_back, when plain push_back would do

    • @DasAntiNaziBroetchen
      @DasAntiNaziBroetchen Před 3 lety +1

      What's your problem with emplace_back? It's much more elegant and can be faster.