This video provides a surgical breakdown of the Linux audio pipeline, elegantly connecting high-level APIs to the physical reality of DMA and hardware buffers. It is a masterclass in demystifying low-level system architecture through clear, structural analysis.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
How does sound work on linux?Added:
Yo, what's up? What's up? What's up, everybody? Welcome back. Today, I want to look at Linux audio.
Uh the context is I am working on a virtual phone so that I can answer my door because I ate [ __ ] on the concrete.
My phone broke. I mean, that's not why, but it's like a nice little convenient excuse where I was like, "I don't like that the doorbell to my apartment calls my cell phone. I want it to call my computer. My computer needs a phone on it."
Um and to be able to I need to play back audio, right? So the guy at the door can be like, "Hey, Mick, it's me." And then I can be like, "Oh, okay." And then I hit the button and he comes in, right?
Um and so one of the questions or one of the things we have to do there is we have to play the audio. And um we've kind of like looked at this a couple times in the past like but using libraries. Like, I think we used mini audio last time that kind of handled this for us. Um but I have a question of like, what even is Linux audio playback, right?
Like, if I had to imagine, like I guess like my computer sits here, right? Computer. I've got a desktop like a [ __ ] old person, right? I'm back from the before the days of everyone using their cell phones and laptops everything. I have a desktop and a desk.
It's hype. Um but in here, there's like a 3.5 mm jack, right? And then that goes like to my speakers or to my headphones, right?
And I believe that like the most simple implementation of a speaker is you have like a little coil on like a membrane, I think. So you have like, you know, you have like the little cone with like some like plastic in here or some [ __ ] And then I think there's like a magnet maybe here.
Maybe. And then there's like a coil somewhere. And by taking the analog signal that's coming on this cable and just like shoving that through the coil, you introduce like magnetic fields that push or pull to the magnet at the back, and then that will like wiggle the membrane, which will push air into your eardrums and wiggle your eardrums. I think, right? So, there there's some somewhere in the system, like we have some analog signal that comes out of this thing, right? That's at the very base level, like that's the piece of information we have, right? Um [snorts] this thing is probably connected to a PCI card. I don't know. I'm making I'm making a lot of this up. I'm making a lot of this up, right? But this is probably connected to some PCI card.
Maybe it's not like a physical PCI card in the system, but it's probably on the PCI bus, at least, right?
Um which probably goes to the CPU, and then this you know, the Linux kernel probably has some sort of driver that takes like some sort of stream of bits and puts them either like on the hardware, maybe maybe the hardware has like some like physical chunk of memory that you put the stream of bits on, and then it has like a a digital-to-analog converter that turns that into this signal. Maybe maybe it's like in RAM, RAM, and since like RAM is visible from the PCI bus, maybe it talks to each other like this. Not sure, right?
But somewhere we must be like putting audio data into a buffer, and presumably there's like a piece of hardware that's just like ripping through that buffer and putting the stuff on it into the audio, right? And and you can kind of like imagine this case from like I don't know if you guys on the next ever like swap out so bad that your computer becomes like completely unresponsive, but when when I like compile too much at once, I start to hear like a second of playback of my song over and over. It goes like bump bump bump bump, and then I start like right? So, like I can imagine that as like there is some audio buffer that hardware is like ripping through and if that thing is not updated, then it just plays back whatever is in the buffer, right?
So, that this is like again, I'm making everything up right now, but that's like my imagination about how that works, right? So, if I were to like design this interface, I would would imagine that there's probably some like kernel handle somewhere, dev sound or something, right? Sound out.
Right? And maybe you like mmap this thing in some way and then your your user space application can just like put audio in there.
That'd be my guess. I would guess, however, this might not be true. Um if I were to implement this, I would make it so that this is like an exclusive handle for the whole system, right? And so then if you want to do like audio muxing, I think that that's like a complicated problem, right? Because like the only way you can take two audio signals and like play them both at once is to just add them up. But then like you get into a point where you start like clipping, right? Where you can't add signals together anymore. So, I think like the idea of muxing gets like kind of difficult and you have to like prioritize things or like compress everything down so that like the peak ranges don't go out of like go crazy.
You probably want like applications to be able to route into each other and volume adjustment and all that. So, like all of that seems like very user spacey to me, right? Like I can imagine you might want to switch out your implementation of how you mux audio. And so, probably there's someone in user space that has like a daemon somewhere and everyone talks to this guy and he would populate this like device handle.
That's how I would do it. I don't know if that's true, right?
Because you can also imagine a world where like maybe hardware muxing exists, right? Where like you maybe the hardware itself has like the ability to take several channels and has an integrated muxer in there and then you don't have to actually do the servicing on the CPU and like that's faster for some reason.
So maybe there's something there where maybe you have like sound out 0 1 2 3 and then like the user space daemon would like pick which ones that it wants to use for which purposes, maybe, right?
I don't know.
Um but the the goal for today is to figure it out, right? So um what I have right now is yesterday I set up an Alpine virtual machine because I believe that on my system audio is more complicated from than like a simple case, right? So Alpine's like the dumb [ __ ] version of Linux that you can use that like does nothing for you, you know? It's like my go-to like I want nothing but like give me the bare bones.
And in here I've installed this program called speaker-test. And when I play it you guys hear you know? Um and so what I think our entry point is we can figure out what this we can like S trace this program, figure out what it does, um how it's putting audio in the audio buffers. Um I've got this virtual machine set up so that we can actually like run GDB on the kernel, which is going to be nice. It'll help us like step through and figure out where the data is going.
Um and then maybe we figure out like how to hand roll playback, maybe we look at what speaker-test is doing. I I know that like I'm pretty sure I did like a quick S trace to speaker-test on my host system and it was like talking to this thing called pipewire.
Oh yeah, words I've heard before.
Um in in the context of Linux audio, right? So I have I kind of just made up a bunch of stuff, right? Um but words I've heard in Linux in the past 20 years. OSS, also JACK, PulseAudio, pipewire. These are all like things related to sound. I don't know what any of them are, right?
>> [laughter] >> But if you look up also, which is the thing I've heard most, um oopsies, also sound, maybe.
He says in here on Linux sound servers like sound IO, pipewire, jack, and pipewire, and high level APIs work on top of also, right? So, at the very least, it makes sense that I've seen also in the kernel as well, I think. So, the idea that like also is kind of like the base layer audio thing, and that somebody else manages stuff on top, that kind of makes sense.
Um so, I'm kind of hoping that in this Alpine VM I have some like bare bones also set up. Speaker test hopefully is just doing whatever the base also thing is we can figure out what what it does.
That's the plan.
That's the plan.
Um so, let's do a little bit of uh initial speaker test.
Right? Let's just kind of see what this thing does. And let's um reduce the volume of this thing because it's like ruining my [ __ ] brain.
Okay.
Uh but let's run estrus on this thing.
Estrus not found.
That makes sense. What was I expecting?
Okay.
So, we are seeing at very least like while there's some spam happening, right? But the spam is we're seeing some sound drive sound driver maybe sound driver uh call PCM I believe that's like uh PCM I I I I think that that's like pulse mod No, that's PWM. I don't know what PCM is.
Um but this is IO control, and he's like syncing with the hardware every once in a while. So, I guess he's probably saying like, "Hey, there's stuff for you to do."
Um and maybe these pointers are pointers to audio.
Maybe, not sure. Right? He's reading this thing every once in a while, and he's kind of waiting on some file descriptor three, which is different than four.
Um who this must be like probably this is probably the signal for when there's more data that we have to push in. I don't know.
I don't know.
Uh but I'd also like to look maybe more at the beginning of this.
Uh right? Like let's see let's see like how this guy starts up.
Um so he opens this thing libasound.
Uh so there's that.
And he like maps some some this is probably mapping shared libraries into his process space. Eventually he's he's writing to standard out, right? He's saying, "Hey, this is some stuff that I'm doing."
Um he looks at a configuration file at user share also.
So there's some some some stuff in there.
Um and here it looks like he's basically taking the data that's in also.conf and printing its configuration so or reading its configuration, right?
So he's saying like, "What is in this thing?" and he's seeing some pieces of like overall config, right?
Eventually he's looking at libasound again.
All right. Uh some more also configuration stuff. So there is also user share also, var lib also, etc. also. These are all places where information about the sound system seem to live.
Um blah blah blah, right? A lot more also configuration snooping. I'm really more interested in where he starts actually like doing some audio IO, right?
Um So, we see a new file here. Oh, this is HDA Intel. Okay, so there's some sort of sound card that might be HDA Intel. I've heard those letters before. Probably high definition audio on Intel CPUs. That'd be my guess for what that is.
Um Okay.
Where do we see some actual Oh, yeah, here we go. Here we go. So, we have dev sound.
dev sound seems to be our entry point, right? And we see control and a load, maybe audio load.
He's also saying here that none of these things exist, right? These are all you know it. But eventually he's going to find something.
Maybe he tries all of these things and then falls back on some shared library otherwise.
I would love to take a peek to see if those exist.
Uh So, the VM I think is port mapped like this.
Okay, so control C0 should have worked.
Uh control C0.
Ah, okay. So, he did manage to open that at some point here.
Control C0. And then they have they also have a What was the other thing? A dev It was dev a something? A load, right?
A load. So, does that ever manage to open successfully?
No.
So, it looks like he like tries Looks like a load is maybe like an alias for that thing where you know, typically you have it under dev sound, but maybe this is like an equivalent file that was older for like older versions of the kernel. Who knows?
Who knows? Okay.
But, we do have control C0.
Who he does instantly close. You are correct about that. Am I going up or down right now? Control C0.
But, does he ever not instantly close him?
Here.
Here he's opened him and he's leaving him open forever. And he starts issuing some ioctls on this thing, right? He's asking for some information.
He's reading something.
He's getting a version. And then I think that we're in the spam now.
Yeah, easy. We're in We're in spam.
All right.
Cool.
Cool. Cool. Cool. Cool. Cool.
So, we have kind of two paths of investigation here. One is opening up the Linux kernel and trying to look at what the devsound interface is.
The other is looking at the speaker test source code.
Let's see if there's any like kernel docs on on devsound. I think that might be interesting.
Uh and then we can work our way up. I think starting at the bottom and then going up is easier in my brain than kind of going top-down.
So, we're going to do uh you know, kernel docs maybe {question mark} So, let's go to Linux. I have Linux 61826 cloned, which is the exact same version that's in the Alpine repos. And I have compiled this thing in a way where speaker test works when I swap this kernel in. And I've also set up some I'm jump to definition stuff. So, I have like nice navigation features ready to go.
Um but, let's just look for dev sound.
Maybe let's go to docs and look for dev sound first.
Uh looks like there's a sound folder in here.
Kernel API.
Also driver API. All right.
So, there is PCM API, where we have sound core PCM.
Okay.
Then, there's control stuff.
Uh let's maybe look at it was there a cards, codecs, designs, HD audio, kernel API.
Also driver API writing. Okay. So, maybe they're kind of just telling us to go look at like individual [ __ ] source files, right? That's what kind of what they're trying to tell us.
This is called for a system on a chip stuff.
Uh nothing super interesting in here that I'm seeing that's like automatic jumping out at me as like clear docs.
Uh it was saying Wait, what what was it?
It was like PCM core was in there. He told us to go look at a file.
I don't know.
I don't know. Where was that?
Um kernel API also driver. So, this Oh, kernel API might be like internal kernel API, not external kernel API.
So, maybe What does this say? Also configuration.
This is like about how you build the kernel for this thing to work.
Um all right.
Let's go back to trying to find PCM stuff. Sound core PCM.
All right.
>> [snorts] >> Um Who like PCM at? Who calls this?
PCM next.
Who calls this?
Ooh, wait, we have a bunch of ioctls that we called. Can we look at those?
Like when we're feeding audio data?
Let's look for uh sound PCM HW sync.
Wow, what the [ __ ] That doesn't exist.
Oh, PCM ioctl HW sync. My bad.
Let's see Okay, so we are in some sort of PCM native thing. I think it's time to Google what PCM is.
What does this mean?
Um pulse code modulation.
So it's very similar to pulse width modulation, which I've heard is PWM, I would assume.
Uh what does it mean?
What does it mean?
Is there like a picture?
Is this the picture? Sampling for 4-bit LPCM.
Oh, are we literally just like sampling at a time?
PCM is fancy speak for a bunch of equally spaced apple thing. Yeah, that does look like what this picture is saying.
Also about GitHub might also be interesting to look at. I agree. I agree. Okay, but we like like I do let's look at what this HW sync thing is. Like what does this mean?
What does it mean?
Uh is sub stream like the arguments?
Arg. So, when we saw some pointer come in with this thing, right?
I guess HW sync does not have an arg, but we saw the arg in the cons here a lot, right? We saw HW sync on some pointer.
Which is a little confusing.
Cuz here it looks like he's not using it.
Uh, but you know, whatever.
And then what's Okay, but this looks like What are we doing here? Do PCM HW sync check and update PCM state.
Okay.
Okay. Yeah, yeah, yeah, yeah, yeah, yeah. So, here we're seeing some sort of like I'm maybe currently running and I need to update my hardware pointer to whatever thing you passed in, maybe.
Right? Maybe something like that. So, so that makes sense. That does make sense as like this is the command that we're using to update the audio data.
I would imagine. Let's look at um I octal LM read as well.
Uh, was it I octal LM read, right?
Like what is this thing doing?
What is this thing doing?
Um, he is Um, maybe getting like audio input, but I don't know why speaker test would have to do that. Also, watch has a good topology page.
Fine.
Fine. We'll go to their [ __ ] website.
You're saying somewhere in here they have a topology?
Is there no search? Top search.
Nice.
Nice.
All right.
So, the kernel does what?
Uh load the topology binary file from user space. What the [ __ ] is a topology?
Uh load their mixers. Wow, this is too advanced. Too advanced. Too advanced. I don't even know what this means yet.
We'll come back here.
But this is like a way to upload like blobs that tell you how you're supposed to like route all of your [ __ ] it looks like.
Too fancy.
Too fancy. Too fancy. All right, we'll come back. We'll come back.
Um let's let's look at the speaker test source code.
Let's look at the speaker speaker test source code. I think it is time.
Cuz I am lost as [ __ ] looking at the kernel right now. And so maybe some uh some extra context will help us. This comes from also to utils here. Can we just clone this [ __ ] Can we just clone this [ __ ] Um speaker test.
Okay, so somewhere presumably he is trying to generate some white noise, right? By just like ripping dev random into some [ __ ] So where is his like main loop?
He opens this thing, he sets some hardware params.
And then this seems to be the main loop.
Okay, right loop here is probably the main thing and are we pink noise? Which which type of test are we?
Speaker test.
Um.
Speaker test pink.
So that makes that sounds like the white noise that we heard before. And if I do Yeah, okay. So pink pink is what we are initially testing.
But it doesn't really matter, right?
Like Uh wait, where were we?
Yeah.
Right, like if we're using a sine wave, it can be do this do this, whatever.
This is But like what's interesting here is we're like doing some sort of frame generation and writing buffer. Now, where is this right loop used? He just does this forever, right? He's just in main ripping this [ __ ] He's calling right buffer all time.
But it sound seems like maybe sound PCM drain or sound PCM prepare might be like a way for you to block on this thing.
No, cuz this This Hold on. Is Is this thing called in a loop externally?
Yes, four and loops. And then when we run speaker test we see time per period is the is the log that we're looking for for like every once in a while this thing happens. That's kind of like the outer loop.
Top Oopsies, wrong thing.
Time per period. Okay. So this is the outer loop that we're seeing and then he goes into right loop which is doing He's like populating the buffer for like 1 second at a time or something.
So I guess an a question to ask is is this running like fast and then this is slow?
Or it must be, right? Unless we're let's see the implementation of right buffer.
Right, it doesn't Oh, I guess this could block.
This could block.
Okay, let's look that thing up. Where Where is this? Sound PCM right I.
This seems to be some sort of library function probably coming from a sound lib would be my guess. I think drain and block Yeah, but it does You're right though, like 1 second sounds like a long time. So he's either populating 1 second of audio up front and then waiting or the sound right is blocking in some way.
Sounds like a lot of make buffer contents followed by flush. Yeah, I do agree. I do agree like this does sound likely.
But if buffer size is greater than n times period size is the only time he does this.
So, I'm not sure. I'm not sure.
Uh let's look at Let's see if we can find some docs for like this function.
Like who who even owns this?
Also project, the PCM interface.
All right.
Um write interleaved frames to PCM.
If the blocking behavior is such that it is running, then the routine waits until all frames are put to the playback ring buffer. Aha. Aha. Okay.
Okay.
So, I guess we have some sort of also library, right? I mean, we saw that in the S trace that there was some sort of like libasound thing. Um but I would be curious to know like what this does.
So, maybe we take a little peek-sees at the uh libasound source, right? Cuz I assume that's what it's going to be coming from? Like Can Is there like an example in here?
Like what What is this? Also lib.
Like what is this?
Let's take a Let's pull this thing. See what that guy's up to.
What does this guy up to?
Uh Does this guy have like examples?
Maybe not. Unlucky.
Unlucky. But maybe we can see where this like sound PCM write I is going.
You know, what's this guy up to?
Can we Okay, wait.
We're close.
None of these look like the definition, but maybe it's like some sort of like macro [ __ ] It's always some sort of macro [ __ ] Right? Like here they're defining the function.
But like Oh, it's in the include, of course. My bad.
Oh, here we go.
There isn't examples, but not on the doc site.
Examples yet here.
Test PCM, okay.
Okay.
Oh, here we go. Beautiful. This is like speed This is going to be like very similar to the speaker test thing, right?
He is initializing some hardware params, some software params.
He's choosing a bunch of options for these things.
>> [snorts] >> Uh I don't know what the [ __ ] this means.
Oh, probably he is outputting the thing he's hearing to standard out and you have to pipe it into something.
Maybe.
A bunch of like initialization stuff.
And then he has transfer loop here.
What the [ __ ] What is transfer method?
Oh, here.
Sure.
I see. So, it's giving us all sorts of ways that we can access this data, right? We can write write and poll. We might have some sort of like async like notifications that the buffer's run out. I don't know what the difference between direct and non-direct are. Looks like direct means mmap here.
Right? Anything Anything that has the word direct in it has the word mmap here. So, direct probably means I have the map the memory of the audio buffer mapped directly into my process space versus the other one is probably doing some sort of like write call somewhere, right? This sound PCM right I here versus in the direct version They They use mmap here, but it's like who cares, right?
Okay.
V map is nice because you don't have to worry about buffers. It just says how many samples are available to write.
Interesting.
Interesting.
Driver memory gets mapped as in Yeah, maybe. Okay. Well, it seems like the core of everything here is again like in the right and poll loop, we have sound PCM right I in a sync callback with sound PCM right I. I think let's not worry about the mmap case yet cuz I think that'll make things like more complicated. Let's just start with trying to figure out what the [ __ ] sound PCM right I does cuz I think I think that that seems to be the core of everything.
Which we saw in here somewhere.
All right.
So, this guy Is he doing anything? Hello?
Am I high? Right here if I'm wave frames to PCM Yeah, we read that already.
Oh, here. Sorry. This is the actually interesting part.
Is this defined here? Okay. Uh who is calling some sort of V table um based off of this interface?
Okay.
So, there's some sort of like indirection going on here. I presume I stands for integer. Yeah, I also would presume that, right? Like I16s buff like I16 or I8 samples probably 16.
Um okay.
So, who implements right eye?
Um okay. So, I would assume that the interesting thing here would either be PCM file or PCM hardware. Hardware sounds the most interesting, right?
If we were just to like look at the names of these files, right? Shared memory, metered, like M mapped, some sort of like shared plugin, D mix, some sort of like mixing.
Hardware's got to be.
Hardware's got to be the interesting one, right?
Who is calling right eye frames, which is not what we were seeing in speaker test, by the way.
Right?
So, that's kind of interesting. I guess we know from the S trace that we're getting lots of hardware six, which maybe is a result of him using the M mapped mode, right? Like if we were to look for HW sync in here, we have this function.
Who it gets access through some HW sync V table, right?
So, can we look at like are there docs for that? Sound PCM HW sync in PCM.c maybe?
Here. Okay, synchronize stream position with hardware.
Notice this function does not update the actual read write pointer for applications.
This function the function PCM available update have to be called for any M map begin commit operation.
Okay. Can we like force this thing to use a stupider mode? You know what I mean?
It sounds like this function is deprecated. I mean, I'm sure it does the same thing, right?
I'm sure this thing is going to HW sync under the hood eventually, right? Surely.
Oh, maybe not.
Well, yeah, it does look like it does something else, huh? Interesting.
Interesting.
Um okay, let's I would love to get this PCM test compiled.
And then we can force it into the simpler mode, and then we can S trace that and try to get more information that way, right?
Oh, oops, this is a lib a sound I think is what we're looking at right now. No, also lib?
I don't know.
That's what we're looking at right now.
Uh yeah, can we like how the [ __ ] do we compile this?
Uh like I I presume Nix built this at some point.
At some point, right?
Where they had uh probably in here there's like what? Also lib?
Cool.
Cool.
With import Nix packages, uh packages, make shell, and then there is like I think it's inputs from to copy the configuration for another guy.
Yeah.
So, we're like just literally copy everything. And then, while we're here, can we also do like uh give me some clang tools.
Maybe some GDB, maybe PCM min C seems a lot easier.
This does seem easier. I agree.
Sure. I think either are fine in terms of like what I'm trying to understand, but yeah, let's let's do that.
Um so, presumably, we need to do like a Looks like an auto tools project. No configure file generated yet. So, I think How do you do this? You do like Oh, [ __ ] AC local.
Oh my god.
Uh auto tools.
Uh AC local, automake.
I don't remember how to do this. It's been a minute.
./configure.sh make, but I don't think that there is a configure here yet.
Auto reconf is definitely the thing I'm I remember typing.
Which doesn't seem to exist.
autoconf God damn it, dude.
God damn it.
All right.
configure Well, [ __ ] me, I guess. AUTO RECONF ERROR.
OH, USUALLY, this thing is already done for you if you pull like an actual release package.
Awesome lib.
Uh usually the tarballs have the like configure stuff already Oh, wait, get compiled. You're right. That is worth looking at.
This bad interpreter, great, cuz I'm a [ __ ] NYX.
[ __ ] me. [ __ ] me, I guess.
All right. All right. All right. All right. All right.
Sometimes awesome lib releases.
You trying to rebuild the lib awesome go? I don't know. I'm just trying to like I've got a project. I want to compile some code in it. I [laughter] haven't really thought that far.
CD speaker doesn't make This speaker test isn't from here. I would like speaker test isn't the one I'm trying to work on, but like sure.
Like I'm looking at source. I wanted to look at pcmmin.c.
The extra small demo.
Um great.
Cool. Cool. Cool. Cool. Cool. Cool.
Cool. Cool. Cool. Cool. Cool.
Their website's down.
Um all right.
GCC No, I mean maybe.
But like I think that it would it's not unreasonable to try to like build their software with their build system, right?
I don't think that's like unreasonable.
Like cuz like if you just stop just like typing commands, right? Like if you look in here, like they're clearly like expecting that I am like part of this project, right? I don't think that it's like guaranteed that if I do this Right? Like you know?
Use he's not he he's not that simple, right?
It's not that simple. A sound wave isn't even in here.
Um so, I think that it's reasonable to like build the project. I don't think that's crazy.
I don't [snorts] think that's crazy.
Uh [ __ ] finally. Uh okay.
Also lib is the thing I'm trying to download, right?
Uh probably like up here.
And how maybe this thing has the already configured scripts thing done. I don't know. Let's see.
Hello?
There we go.
Nice.
He's already got the stuff that we need.
Perfect.
Configure.
Much better.
Much better. There, see? Now he generated that thing.
Uh so, then can we like make help?
Make file. Does he have like tests?
Or what was the folder? Test.
Oh, test has no make file. Beautiful.
Uh do we have PCM in in here somewhere?
Uh yeah, it does look like it. Make PCM in.
Uh looks like we might have to build this guy first.
Give him a sec. He's thinking. Thinking hard. Perfect.
Tests.
Are we happy? Beautiful.
Perfect.
Um unfortunately, this is not the environment that I want to be in. I want to be in my VM.
But maybe we can do a little Like is this thing like dynamic link?
No, so we should be able to do like an SCP PCM in uh into root at localhost.
Maybe?
[ __ ] I guess we maybe need to build it in the VM.
I'll get Uh I guess I copy the tarball over.
[ __ ] my life.
[ __ ] my life. Uh SCP also lib into uh root at localhost.
Colon is root. Colon is the home directory of whoever you were talking to, which is {slash} root on this system, I think.
Uh tar xf also lib.
Beautiful.
Can I build this?
I [laughter] don't know.
Uh APK add GCC G++ I think you need like lib C dev.
I don't know, man.
Probably need make.
>> [laughter] >> I don't know what's happening.
I don't know what's happening.
I just remember Alpine being a little bit of a pain in the ass here.
Uh hi future me. Hello.
>> [laughter] >> See happy now? Configure.
Uh something went wrong.
Uh make. Yeah, uh APK add make.
All right, let's try that again.
Configure.
Beautiful.
Uh he's missing this thing. Oh, I remember seeing this as well. You need to like add Linux headers maybe.
Okay, closer. Closer.
Closer.
Closer.
It's building in the VM. Pipe test make PCM test make PCM in.
P- PCM in.
Oh, let's [ __ ] go.
We [ __ ] got it. We Okay, so now we can actually trace this.
And take a look at that thing.
Okay.
So, what is this guy doing in his spam lib? It's the same thing.
It's the same thing. He is doing the same HW sync spam.
So, can we make PCM What was the other one? The like more configurable one? Make PCM.
Right, we should be able to see in uh here we should be able to configure this thing to run in like a different mode, right? Like I want to see the [ __ ] right and poll loop or something.
Like one of the ones that's using like a different mode of doing this [ __ ] Uh so, how do we do that? Is it transfer method?
Yes.
PCM {dash} M right.
Okay, cool.
Then can we actually trace this?
Okay.
Hold on, let's let it run for a little longer. One Mississippi, two Mississippi, three Mississippi, four Mississippi.
It's a lot of the same, right? A lot of the same underlying spam of HW sync, which just doesn't line up with the code that we've seen, right?
Cuz the code that we were looking at was calling I can't remember. I can't remember.
Hold on. Hold.
Uh Bum bum.
I guess here.
Wait, where's the implementation of the function? Here.
Right, he was calling right I.
Which we were assuming was going to PCM hardware, but I guess that might not be true.
Right? Might not be true.
And now that we have this thing compiling, we can actually just edit this [ __ ] Um Drive him.
Uh this is going to be a little annoying in the VM, but whatever. C source source hardware Wait, what is it? Was source PCM?
And then PCM hardware.
Can we confirm if our right like this right I potentially is being called?
Hi, I'm writing PCM hardware. Right, it might be the case that this is not happening.
Might be the case.
Um, so can we just do a little make and test and make PCM and run this thing again?
Yeah.
Okay.
So that's a cool that's a good clue.
That's a good clue. Then who do we think that it might be?
Who else could it be?
I guess there was a bunch of like opening of that config file that we were seeing at the beginning. Maybe let's look at it look at that thing. ETC also conf nothing.
User share also also conf, right? Like can we Maybe there's something here.
Or maybe that that prints of debug info.
We didn't actually read anything.
Okay.
Using transfer method right playback device is plug HW, okay? Plug HW.
Uh Okay.
So maybe in like the default configuration plug HW sounds like we saw like a PCM plug, right? Plugin?
Right, we did see plug PCM plugin was a thing we saw. So maybe that's where this is going.
Maybe.
>> Uh print f Hi Mick, I'm writing plugin.
Plug plugin backslash n, perfect.
>> [laughter] [snorts] >> Okay.
So, CD test make PCM.
And then can we do PCM?
Aha!
Aha!
I see, I see.
So, this is going to some plugin. So, so the even in like the brain dead simple case, it gets way more complicated.
Right? So, also the like also user space library is dispatching to some plugin, but the plugin is a hardware plugin.
Right? Is that what I'm seeing? Is that what I'm seeing? How the [ __ ] does this thing get initialized? That's the next question.
So, like PCM plugins.
Plugins extend functionality and features of PCM devices. The plugins take care of various sample conversions, sample copy among blah blah blah. Ah, okay. So, we we saw something about like We saw plug HW, right?
This looks like like a This looks like a definition for what the plug HW can be, right? It's saying like, "Hey, you can be a card, a dev, a sub dev. You can be a PCM card or a card." It doesn't look like this is like an instantiation of that thing, you know what I mean?
You know what I mean?
So we keep I'm interested to know like where this is get coming from. Can we look at the S trace again? Oopsies. Uh So like where does he determine that plug HW is the thing that he wants to do?
I think that is a piece of information. And then also like does that does that involve some form of like shared object that's hooked in or or it does it not? I don't know.
Here he's doing a bunch of like looking at file descriptor three here. What is file descriptor three?
We're looking for like an equals three on the right here. So he's looking at this. User share also also.conf, which is just the thing that we just opened, right?
Oh, then there's also Well, here he's already decided that he's plug HW.
Okay.
Um let's just do some grepping for like or like scan this top of the file.
PCM plugin extends functionality. Slave plugin P specified directly with a string or the definition can be entered inside a compound configuration node.
Okay.
So just double checking, there's no A sound. There's no also.conf in ETC, so it's got to be looking at user share.
What else is in here? Also Okay.
There's a lot of configurations in here as well.
Maybe we got confused and we should have been looking at the defaults a little bit more closely.
Uh plug HW, right? So, maybe these defaults are the important thing to look at.
Maybe.
I'm so confused about where these where these variables are coming from.
I'm so confused about this.
Oopsies. Uh user share also.
So, like is this thing getting defined somewhere? Like or is it in my environment?
Is it like passed in? Who knows?
Who knows?
Env grep also.
Env grep card. No, okay.
Um why not pipewire 2007 card? Because we're try we need to start at the bottom before building our way up.
Right? Like pipewire, according to the also Wikipedia page, is built above also. So, if we're trying to understand the full stack, we got to we got to scope the problem first.
Um interesting.
Interesting.
Maybe the trick here is to look at PCM in and maybe try to figure out how he is constructing his V table in these guys, right?
Right? Yeah.
Sound PCM open. Let's look in there.
Um Looks like he's looking over some UCM device. I don't know what that means.
And trying to match like config names.
Okay, so the name is coming in as device.
Where he's using default, right? So he is iterating all Oh, if is device, sound is UCM device. What does this do?
Oh, okay. This will just be false.
So here, they're like config update ref.
What's this do?
What the [ __ ] does this thing do?
Oh, he's just he's just incrementing the the reference count.
To this pointer.
And then once the reference count is opened, then he's populating the stuff with this thing.
Gotcha.
So the name here is default. So he's searching for the config definition through like the list of all config of all configs.
And presumably he then starts like I don't know.
I don't know.
Okay. Uh let's go up a level. Maybe we're looking in the wrong spot.
Opens a piece of hardware. I mean, he's got like at this point he's got all resolved stuff, right? So I guess what is the return here?
He is returning PCMP. This is what he's trying to do, right?
So, who initializes this guy?
Open no update or open conf. Okay, sure.
So, we go to open conf.
We got this pointer that's the uplet.
Jesus [ __ ] Oh my lord.
So, he's like got some dynamically linked libraries that he might that he loads these things from.
Okay, which presumably are like in like user lib.
No.
Uh well, we can probably look at the S trace again to see who he's opening.
Maybe.
No deal open.
Okay, interesting.
Interesting.
Do we see anything like.so in here?
Just lib a sound.
Okay.
So, that's confusing.
Maybe maybe we're in the other path.
Open no update, maybe.
Uh wait, no. This is already the function we were in.
So, it has to this is where it initially end ends up going eventually.
Um I guess we could just start like adding logs.
That's not crazy. Sound config for each.
Oh my god.
Is he sound PCM blank open?
And oh, okay, then there's built-in PCMs. Here we go. Here we go.
And so this thing might not be an actual PCM module. It might be built-in.
Maybe. There's also lib asound module things in here.
lib asound star We don't see any modules.
So it's probably all built-in somewhere.
So where what are these built-in PCMs? AHA!
AHA! OKAY.
Now plug HW is not a thing in here. It's not. But but maybe we can get some extra information.
Okay. We're we're we're chipping away at it.
Um uh okay.
Lots of defaults in here.
I don't understand how the plug HW thing is going. Hey, what's up, guys? Thanks for the raid. What's up? What's up?
What's up?
We are slowly chipping away at trying to understand when I try to play sound on Linux what happen? What happen?
We are poking and prodding the also library to figure out like there's some mapping somewhere of like I have some bits and bytes and I want to put them on my card and we're trying to figure out where where does that go? How does it get to the driver?
And from there, where does it go? That's what we're trying to figure out.
We have found some examples where we have some you know some test that basically just rips right PCM data in a loop and then we're trying to figure out where the [ __ ] does that go under the hood. It goes into some V table. The V table has initialized with some plug HW interface and we're trying to understand like why and how and where does that go etc. etc. Um so hope you guys had fun over at S17N stream.
Um hope you had a good time over there.
And we're just going to keep going.
Um okay.
So we are presuming that in sound PCM open he is somehow determining that he wants to open the plug HW interface. That's what we're deciding in sound PCM open cough.
So I guess we can just start like ripping some logs in here and see what happens, right? Like at least we can look for the open name.
Let's do that. Let's just print the open name. Do we do we do GCC? Is it right?
Have we compiled in debug mode? I don't even know.
Uh maybe like verbose equals one make Uh can I like touch a file and see how it's getting compiled?
Uh maybe V equals one.
Oh, there we go. I saw a compile command somewhere.
I see dash G dash O two. So, we're building with optimizations, but it should be GDP-able.
It should.
You're not interested in kernel interface? I am eventually. I want to see how it gets the kernel interface so we can figure out what [ __ ] like what do we expect what what do we even think is supposed to happen from a user space side? Because when I was looking at the kernel space side, I was lost, right? So, I'm hoping to gain some context here.
So, if we're just like uh what like function are we in that we're like that is of interest to us?
This is sound PCM open conf.
All right.
Uh make PCM man.
And then we want to do like a GCC PCM man and we want to Oh.
GCC PCM man GDB, sorry, PCM man. I'm an idiot.
And can we break at B PCM.c line 2612?
Unlucky.
Are they stripped? They're probably [ __ ] stripped, right? Can we Probably there's like some config flag that we're supposed to do to like end up in debug?
Enable debug symbols.
I [ __ ] don't know how auto tools works, man.
Like GDB PCM man, can I break on a function here?
B sound open PCM Wait. Not in executable format? What the [ __ ] are we talking about?
What do you mean?
Does GDB need like some sort of like extra [ __ ] to work properly?
Hold on.
Uh touch test C uh vim test C it main What?
Return zero.
Uh GCC test test GG GDB I don't know dash 00 test.c or something. Like can I run B main? Yeah, I mean that's fine.
file test file not found. Of course not.
PA add file file test. This is a 64-bit executable. We go back to also live test.
Uh file PCM in What is this thing?
Oh.
The [ __ ] What?
Hello?
>> [laughter] >> Okay.
What [ __ ] [ __ ] auto tools?
[ __ ] auto tools. Who knows what the [ __ ] is going on here?
Where are we going to break? Sound PCM.
Open cough.
Maybe on shared library. Let's just see.
[ __ ] run it. Kill me. [ __ ] me.
Backtrace. We do Oh, I mean this is a static.
[ __ ] Can we like BPCM.seed?
Like what if we do this?
What line were we looking for? Open name.
2612 No, yeah. Okay. Well, [ __ ] me, I guess.
Maybe in here like RMPCM in and can we do like a make PCM min v equals one verbose equals one?
We do see some dash Gs in there.
He is using a sound.so.
So, what if we like force GDB to load that?
How do you do like a GDB load shared object?
Did enable debug not work? I thought that it was on.
We double double check.
We can double check.
On recognize options.
Yeah, I mean that's I don't even On recognize options, but also this isn't what we want, right? He's like I want some of [ __ ] asserts.
Can we like Dude, auto tools [ __ ] debug symbols GDB. Like can somebody just [ __ ] tell me what I'm supposed to do?
Oh my god.
C flags {dash} G GDB. Are you [ __ ] kidding me? Is that really what I'm supposed to do? Like, how do I set the optimization level?
Cuz he's like shoving in an O2 in there, right?
C flags. I see. Okay. Well, [ __ ] me.
Uh {dash} G GDB O zero.
Well, [ __ ] me.
[ __ ] me, man.
Why is everything so [ __ ] hard?
Do I do it Do I do C flags on configure here?
Okay, what a [ __ ] sick interface.
Yeah, just [ __ ] re- throw some random [ __ ] environment variables in there.
[ __ ] it. [ __ ] it.
Kill me.
>> [laughter] >> I'm not mad. I'm not mad.
Make PCM, man. What is it?
V equals one verbose equals one. Do we see some like We see some GGB O zero.
Okay.
And then we run this and maybe now we can break point at the [ __ ] function we want, which is PCM.c 2612.
And then we're going to get a future library to load it. [ __ ] B PCM.c 2612. Of course not because probably the shared object is stripped, right?
Right? Probably.
So, how can we [ __ ] build with like a static library to make my life easier?
>> Shared. Enable shared. No.
This is a fun a fun way to spend my time. Make clean.
Make. Try again.
You type PCM. I'll say [ __ ] Fine.
I'm a [ __ ] idiot, okay? I'm a [ __ ] idiot.
No, I didn't. Don't [clears throat] Don't [ __ ] Oh, PCM.OC was the file I'm looking for, by the way.
So, I think that's right.
Oh, okay. Now PCM in is not a not a script, by the way. So, I don't know.
Oh, let's [ __ ] go.
Okay, that function just never That function just never We're just never get here. We just never [ __ ] get here.
Bsound PCM open conf.
Run. Yes. Okay.
Let's just [ __ ] spam steps. Go.
Okay. What the [ __ ] happened?
We got to open funk.
Can we break there 2615?
Sound PCM empty open. Great.
Okay, so he's going through a lot of these, I guess.
And I guess Is this in a big ass loop?
Is this in a big ass [ __ ] loop? Are we recursing? What the [ __ ] is going on?
We're in sound PCM empty open, which I feel like I don't want to be.
Huh.
Interesting.
This is not what Okay, I just want to know how the [ __ ] he decides that he's in plug HW, right? That's That's how This is all we're looking for is like how does he decide where he is? Oh, wait, okay.
So, what we're going through some sort of chain here, right? We're like we start at empty, then we end back in A sim, and then we end back in plug, and we end up in PCM.
That's kind of funny.
And then we end up in soft ball?
And we end up in D mix?
What is this?
WHAT [laughter] THE [ __ ] IS HAPPENING?
WHY?
All right, well, this is not helpful.
Uh let's maybe try to after we do all this [ __ ] uh can we like just look at maybe PCM in?
Can we just break point at here? Like just right [ __ ] here.
Sound PCM open. Run. Finish.
P handle.
P star handle.
Um okay.
Does this give us any information?
Name equals default.
Name equals default. Right, so somewhere the default config has told us this is what we want. But how? But why?
But why?
Oh my lord.
Oh my [ __ ] god.
Can I So is he Here he is going What does our [ __ ] backtrace look like?
What are we looking at? Right, so he's in like each of these open functions is calling open named slave for some reason, right?
But all of these have the name default.
Is there like default configuration like something [ __ ] insane?
Okay, let's let's try to figure out where is this Why Why Where is this open funk coming from, right? That's probably the question.
Right, like this is coming from here somewhere open name.
Where he is iterating each configuration.
And is I like Where is I coming from? I is just an iterator type.
Like why isn't it just recursing over and over again into the same [ __ ] thing?
I would like to look at this. This is 2555.
Uh Hold on.
That never gets hit.
Hold on.
Hold on.
Oh, which means that we're probably here, right? 2589 Aha, okay. So, what is buff here?
Sterling stir, what is stir?
Config get string.
Okay.
Uh so, Uh okay, so he's looking for PCM type somewhere.
And then the open funk is sound PCM PCM PCM type. So, if we go back to our A sound conf, maybe?
Also conf?
Uh he is iterating over something.
Uh Mhm.
Yeah, okay.
Okay, we're going back. We're going back.
User share A also also conf.
Empty. Empty doesn't live in here at all.
Dude, I'm going to [ __ ] lose my mind.
I'm going to lose it. Like, what is happening? Sound config search.
I guess he's looking What is comp here?
PCM comp. So, this is coming We're we're kind of like down a couple layers, right?
Like, he is looking for definitions of PCM.
And then, within PCM configurations, he's looking for type.
I think.
Oh, wait. Wait. Wait. Wait. Wait. Wait.
Wait. Wait. Wait. Wait. Wait. Wait.
Wait. Wait. Wait.
In PCM, ah, maybe?
Wait. Is this it?
Aha!
I think we found it. So, in this user share also PCM, he has a default configuration where he's like, I am the empty type, and I below me have a plug type. And then, we look at plug.
Uh, maybe his type is hardware.
Slave PCM.
This is probably where plug HW is coming from.
And then I don't really understand what any of this means yet, but this seems to be where this is coming from.
Okay.
Plug type hardware below.
We found it. We found it. Now, what the [ __ ] does it mean?
>> [laughter] >> Right, what the [ __ ] does it mean?
So, we are expecting this guy I guess based off that configuration to have some sort of slave in here.
Okay, and so when we do like righty here or like sound was it plug HW?
Where am I?
High mic We had a log for high mic in here somewhere, but it's it was not in here. [ __ ] Plug.c PCM plug.c This feels like where we were. And then he's got like a V table somewhere, right?
Right, cuz we had like right eye somewhere.
But does PCM plug not have right eye?
That's interesting.
Right? There's IO plug, but I don't know if that's the same thing.
>> Okay.
We're getting We're getting closer.
We're getting closer.
Plug is plug in. It does That's seems likely.
Cuz I think we did see PCM plug in with that right function, right? Is that where we were before?
I don't remember.
I don't remember.
Um CD source uh PCM PCM plug in right I. Yeah, okay.
This is where we were. So, then presumably Like [snorts] this guy has to flush down to his children, right?
Somehow?
So, in the like example he does a bunch of right eyes.
For I 0 to 16.
He [snorts] Can we run the thing again and look at the output?
A lot He's just doing 16 rights, right?
Okay.
So then are we missing the piece where he does a flush underneath? No, right? He's just He's literally just calling right eye.
And that's it.
Oopsies.
Which calls areas from buffer and right here. So maybe this is the interesting part. Sound PCM right areas. Must be.
Which is sound one PCM right areas.
Hello.
Where is this defined?
Oh, here.
Maybe.
Maybe.
So what if this guy?
Like Oh, he's calling maybe hardware sync.
And maybe that in the plugin version ends up like pushing down to the underlying guy.
Maybe. We're really guessing here.
Yes. So he hardware syncs the slave after.
I see.
I see.
Which means that these buffers must be like pulled from somewhere.
I would Can we like just not do the plugin part?
Can we just like change our configuration to not do this?
What if we did that?
Right? What if we did um Vim user Okay, let's go to user share.
Also PCM.
And copy defaults like default back.
And can we change this guy to like [ __ ] like just take this part out?
You know what I mean? Is that a thing we can do? Just take it out?
And then does that make make us use the right the the more obvious right function?
No.
But maybe this is not using the right uh uh configuration.
Here it is.
I think.
Huh.
Can you please explain what you're trying to achieve? Not really, cuz I don't really know. I'm just trying to understand how the [ __ ] audio works, man.
How the [ __ ] does the audio work? That's about the extent of it.
But we don't understand. We don't know anything.
We don't know anything yet.
Um, okay. So, there's also like some sort of chaining to like a mix or something.
Oy, oy, oy.
Like, I'm assuming that somewhere in this chain we have like somehow mapped the memory from the audio buffer on hardware in the kernel driver somewhere, right? Like, we have to.
We have to have.
But, it's hard to find where that is.
You know what I mean?
This is freaking hard.
Like, maybe in here?
There's like prepare, start, hardware refined, software params.
Like, this mmap, probably, right?
He's asking on file descriptor four, where file descriptor four is this PCM handle.
Right? It looks like he's got a PCM handle. He's mmapping that thing.
And then, presumably, dumping [ __ ] Okay, can we like Uh great.
Cool. Love that.
Who calls mmap?
And know, like a server in here.
Oh, okay. Wait. This looks I guess we can look for like M map null, right? Cuz that's the thing that we saw.
This looks promising.
Uh We see 40 on the M map.
Sound dirt.
Sound RV [ __ ] Can I paste?
God damn it. Please. Please. Okay, copy.
Paste.
Data is zero.
That's not used anywhere.
Why?
Why?
Hmm.
Hmm.
Oh, wait.
How did I end up in A sound? Oh, yeah, we're good. Okay, M map null.
Like Yeah, seems wrong here.
Right, like searching for this string gives us nothing.
So, maybe we're looking at the wrong M map call.
I guess we could just log them all.
I guess we could.
Since we're so [ __ ] lost.
Where is this? This is in PCM M map.
Uh print f hi Mick, I'm area M mapping.
Uh we're looking for maybe this one in PCM hardware.
Print f hi Mick status data. I don't know, man. We're just trying to get some feel for anything.
Hi Mick control data.
Uh then can we do a little make and test and make PC make PCM in Do any of these?
Hi Mick status data. Hi Mick control data. Hi Mick I'm area mapping. It's actually hitting all of them.
>> [laughter] >> All of them.
Okay.
And And we can actually S trace this, which should give us a little bit more of a clue of um Yeah, like here we're saying hi Mick, I'm area mapping, followed by the thing that we were saying.
And then presumably, like this is where the actual data is being written. That's what I would assume, right? Cuz we're in plug hardware or in the hardware thing, we're mapping the area.
Okay.
Wait, wait, wait, wait, wait, wait, wait.
Where did I write I'm area mapping?
It's got to be here, right? Uh M map null.
PCM M map.
Great.
So, this guy is like he's he another [ __ ] V table?
Like like who is this? What is this function What is this file?
Maybe this is used everywhere?
Like >> [laughter] >> sound PCM M map. Like who uses this?
Plug-in.
Direct params local.
A server.
Jeez, Christ.
I guess we could break point there and backtrace and see.
Let's do that.
Let's do that.
B sound PCM M map. Run.
Continue.
Okay, so it was that one. Run.
Backtrace. Who's call Jesus [ __ ] Holy [ __ ] [ __ ] Holy [ __ ] And map is just for mapping PCM to a buffer at the place where I assume that's true, right?
I agree. I think that's what's happening, but it's like we have to prove it, right? We're trying to We are trying to understand the like entire audio pipeline, right?
And so if we can't even find where he's mapping the audio data, like how are we supposed to know what is happening, right? And like here we're seeing that like as part of like opening, we're seeing like a nesting of like six different plugins here, right? So we're going from like Like I don't even know.
I would love to write a more concise ALSA config so that we can like have less [ __ ] between us and the hardware, right? I think that this is where some of the confusion is coming from is that there is just so much stuff happening and I'm just trying to get like to the smallest thing so I can understand like at the very base level, what is it doing?
Because like already here, like Like how do I say this?
Uh like when we come down into the part where he does the M map, wherever the [ __ ] that is. I guess we should slap next level. I think we could like hit the we could uh break at 3:44.
Like I you M map.
Like you know what I mean? Like that's Where is this is like we're at so much like levels of indirection.
You know what I mean?
And I it's so hard to track down like what the hell is it?
>> [laughter] >> Simply ALSA app is just set up the PCM format and you read I read I. That's it.
BUT LIKE >> [laughter] >> IT'S BUT LIKE WHAT IS IT DOING? YOU KNOW? Like I understand. I understand, right? Obviously I can read I can read I can read this.
Right? This is a simple function This is a simple program, right? But this is not what I'm I'm not trying to ask like how do I run a program that writes some noise? I'm trying to ask like what the [ __ ] is this doing?
Right? Like I'm not sure if I CAN HAVE YOU TRIED PIPEWIRE. WE NEED TO BUILD OUR WAY UP THERE. We have to build our way up I like I'm so How do I say this?
>> [laughter] >> I don't even understand what problem ALSA solves versus PipeWire versus JACK versus like I don't understand what any of things that these things are doing.
Like why do I need all of this complexity for put pack put bytes in audio buffer? Right?
I'm missing something and that's why I want to like look under the hood and see what it's doing. Cuz once we understand like what also provides and what these things are doing, then maybe we'll get a better feel for like why are we building PipeWire on top of these things? And like why like what is also what is PipeWire? And if like also has all these plugins and stuff, why don't I just write an also application instead of a PipeWire application? Like what is the difference between those two things? Why should I choose one over the other? Like I think that just understanding Cuz like how do I say it? LIKE THE CONCEPT IS SIMPLE, RIGHT? Take bytes, put on wire.
But like there's a reason that all of these things are in the middle.
And so I'm trying to understand that.
And to understand that we have to understand what they're doing.
And maybe there is like a much simpler way.
But like I like doing it this way.
>> [laughter] >> I don't know. We'll see.
Um okay.
Yeah, I think I think the easiest form the the the easiest thing to do here is like cut out all of the middle men.
Right? So I wonder if there's like like also also conf simplest also conf.
Like you know what I mean?
Is there is there a thing that we can Can we take Ooh, is there a man page?
M- maybe.
This is not No, also conf is a is a program. Great.
Great.
Um Hmm.
Hum hum hum hum hum hum.
You need to figure out what PCM versus what ADC to DAC is. I mean, I know what those are, I think. Right? There's like some like sampling of waveforms. You've got to take the thing and turn it into analog, take the thing or sample from analog, turn it into Usually, you take the digital thing, turn it into analog.
You know, there's like complex ways of doing that and simple ways of doing that, right? You can do your little like resistor ladders for ADC.
Whatever, right? It's like I don't really care that much about that part.
I'm like assuming that there's like a piece of hardware at the bottom where there's like a you know, somehow the bytes on them on the piece of hardware are getting onto the wire and I'm like just trusting that they do that part right.
I'm more interested in like the mechanism for how the bytes get into that hardware buffer.
Anyways.
Uh yeah.
Maybe this is an ask the idiot angle.
Maybe it's an ask the idiot angle. Um can you help me write an ALSA conf file that will make lib a sound like skip all the layers of indirection and just talk directly to the hardware.
Uh I mean, well, look, that's looking right. That's looking pretty That's looking pretty in in the order of things that we're looking at that we want, right?
That looks That's looking pretty like I mean, it the it mirrors what we've been seeing a little bit.
He's saying slap that [ __ ] in etc sound.com.
Or I mean, what is it like we can also check the S trace for what this guy has been looking for?
Um so can we look at like A sound? That is one of the first things he checks.
So it's not crazy.
Let's see how likely it is that he's right.
Uh okay.
Sample format not available for playback. Oh, okay.
Okay.
So probably we are there's a layer in here that is trying to make it so that we like resample our inputs into the format that he's expecting.
That's what I would assume.
Right? So probably here there is like a specific uh there's a specific format that the hardware itself supports.
And PCM min, the the little test app that we're using is saying I want U8 interleaved.
I presume, right? Is this in Can we look at the G the back trace here?
Uh [ __ ] Like I assume that we're getting past open, right?
So we're like B PCM in 20 run.
Uh-huh, yep, okay, then we're trying to set parameters and somewhere in here he's going to be pissed off because it doesn't work. That makes sense.
Uh, so what is the log receiving?
Sample format.
So we want to break point in here somewhere, right?
What is it? Sound piece of hardware param set.
Got it.
Uh, and we're probably looking for hardware, nice.
Maybe not.
Can we look for like maybe white space followed by this thing?
I guess it's in here.
And then he calls this guy.
And I guess var is the interesting piece.
I'm not sure. Maybe we just break point there and then step in.
4389 And is this the one? Yes, okay, run.
Continue, step.
Step.
Go in.
Uh Okay, understood, understood, we go again. Continue.
So, we want to break at uh wherever the [ __ ] that was. PCM params.c675.
Uh Okay, we're going into sound mask set refine.
Wait.
Sound mask refine set.
Like, what the [ __ ] is happening here?
He is looking All right, so he's returning E and val, which I believe is the return code we're getting.
Um if this is not supported. Great. This is helpful.
This is helpful.
What the [ __ ] is a sound mask D? Okay, maybe this is the interesting piece here.
Maybe right here.
For a set Wait, is this not the one that's broken?
Sample format not available. Okay, hold on. Hold on. Hold on. Hold on. Hold on.
So, what goes in here?
What goes in here? Sound PCM hardware param set.
Oh my god.
I forget already. It was in PCM params.c?
Uh set format. Jesus Christ, my brain is like melting. Melting, melting, melting.
What's the log? What's the log?
Sample format not available for playback. Sample format not available for playback.
Okay.
Uh, actually that's not what it says.
For It says playback in all caps.
So, it's more of this one.
So, we're in here. Okay. Thank you.
Thank God. Thank God.
Just you Okay, I I don't think I don't think it's unreasonable.
Like I get that you're trying to help, but like I want to find the source of truth in the code. I don't want to just do random [ __ ] You know what I mean?
So, if you're saying 48k PCM 16 will be supported, you're probably right. I believe you, but I'm not going to like just randomly try that because like if I want to know I want to practice the uh, the action of like finding a thing in like looking at the problem and chipping away at it until I find a solution, right? Like I just like calling a friend and saying, "Hey, what's the answer?" is not like finding the answer. You know what I mean?
The goal is like not even to get the answer, right? The goal is to like do the process.
>> [laughter] >> If that makes sense.
Okay, so there is some We have some format that we are trying to set here.
This is some handle to some like PCM device.
And are these the parameters that the system like that the system has given us.
Right? So, we have like params here.
We are sampling the parameters here probably.
Right? Can we look at params? That might be interesting.
So, params here is probably like an array of things.
What is this? Sound hot PCM hardware params t.
What is this thing?
Okay, that's interesting. Where does that come from?
Why I see.
Is this a struct here?
Aha.
Here we are.
Jesus Christ, everything's so difficult, man. Everything's so freaking hard.
Um so, masks is probably what we're looking at, right? I think we saw something with the masks in there.
Here we are saying that we want to look at this format.
Sound PCM hardware Well, let's see where this is getting called. Right, I think we saw something with the masks, but let's let's double-check.
>> Um Yeah, yeah, yeah. Right. So, so we had a thing where he's looking at the mask for this thing where presumably there is a like list of formats where each bit in the format mask defines like one specified format. And the hardware like gives that thing to us and we don't like it, right? So, probably if we looked at like um How do I say this? We want to look at M who has M bits 40000, right? And then we can also look at the the the value that we were trying to set in pcmtest.c wherever the uh pcmmin.c, sorry.
So, we're trying to set format U8.
So, like this thing is probably defined somewhere.
Right? And so, if we think that this is bit 0 1 2 3 4 that or sorry, we we see four which is bit two.
So, signed 16 big Indian or signed 16 little Indian, right? 0 1 2. That lines up with the two to the power of two is four. So, presumably the hardware has set this thing somewhere. So, can we then update our test to use that.
Right? so it's this one.
And we would hope that we get further now.
Channels count not available for playback, right? So so that's really huge for us. Really huge. Um we found like we were correct about that.
We were we were correct about that.
Um so now can we look for PCM in.
So presumably we just have to pick this right set of actions here.
Right?
So uh Hello, here we go. So like presumably two channels, right? What is this? Sound PCM set params?
Channels like two? Probably.
Make PCM in PCM in.
Let's [ __ ] go.
Let's [ __ ] go.
Um so he made it past initialization now and he's like I don't know how to [ __ ] write to that address. A a bad address.
Uh where is that?
So I wonder if um I wonder if how do I say this?
I wonder if a if speaker test works.
Right? Like maybe maybe this PCM in thing is like too stupid.
No speak Okay, speaker test.
Okay.
So when I run speaker test, I am hearing stuff now, which is good. And I think that speaker test is using the stupid version of this thing. So if we S trace this again, uh can we like do we get like a more sane Oh, let's [ __ ] go, baby.
Let's [ __ ] go. So now now we have an actual more sane version of this thing that we can work with. We have the stupidest thing, right? No more of this like HW sync spam, but now we're seeing like an actual I octal that just puts frames on the device, which is all I was looking for this entire time, right? The past [ __ ] 2 hours, this is all I wanted was to find the code path that made us do just a simple [ __ ] write to [ __ ] driver. Write to [ __ ] driver. So thank [ __ ] god. So now we can look for this I octal in the kernel.
Am I in the kernel right now? Where am I? Yes.
Uh like is this compat maybe, right?
[ __ ] [ __ ] it. Oh, it doesn't [ __ ] matter. As I said, use correct PCM format. I WAS NEVER SAYING YOU WERE WRONG.
I DON'T THINK IT'S LIKE I DON'T THINK it's like, "Wow, good job. You were right." Like you Oh god, I'm going to lose my mind. I'm going to lose my mind.
Like I think it's I thought you were right.
NO, [laughter] LIKE WE DON'T HAVE TO DO a I told you so. We are trying again.
The goal is to find the answer ourselves. Right? It's like playing a puzzle game and you're like, I [ __ ] told you to put the put the block over here. It's like It's not the point.
IT'S NOT THE POINT.
OKAY.
Um can we GDB the kernel now?
Maybe.
Maybe.
Um let's kill the VM.
Let's kill the VM. And uh try to run it with our custom kernels that we can GDB it.
Uh so, what do we have here? Uh display GTK probably. Does this thing have our {dash} S {dash} S I believe is like a please turn on GDB and wait for me to connect before you do anything.
And then I think we call run with kernel.
Uh where are my arguments here?
Run with kernel. We have a kernel compiled over here somewhere.
We have a initramfs and we have a disk image.
Okay. So, if I go in here now and I say like GDB VM Linux and GDB Oh, [ __ ] me.
[ __ ] you.
[ __ ] you. I need you to be installed.
And target localhost 1234 I believe. Target remote localhost 1234 maybe.
Perfect. And now we're hoping to look for It's either going to be in PCM native or PCM octal, right? So, can we just breakpoint in both these places?
Uh [ __ ] Right I frame. So, it's going to be one of these.
Wait. I octal right I frames. Am I crazy?
Oh, this is only 32 version. Okay, then it's this one probably.
Okay, click continue.
Oh, I think uh I [ __ ] up.
I need to disable KVM for this to work.
No hardware accelerated virtualization, please. Only the stupid version of virtualization so that I can uh breakpoint.
Uh so, what's the other one? It was over here somewhere.
Boom.
Run. Continue.
Target remote localhost 1234. Continue.
There we go. This guy's running.
Eventually, we can SSH into him probably.
I don't like that it looks like nothing is happening.
This is not how this was working yesterday.
Oh, I see. We just have serial set up.
Can I SSH in?
Can I SSH?
No.
Oh, because uh probably networking is down because my kernel is broken.
But, can I do this? Oh, let's [ __ ] go, baby. Let's [ __ ] go. Okay.
So, now we can just kind of start poking and prodding and seeing where this goes.
Perfect.
Okay, so where do we think this should go?
This goes into this I octal sound PCM lib right probably is what we're looking for, which is owned by this guy who does sound PCM lib transfer.
Who up these?
Probably here is where he's defined.
Yep.
Who then presumably gets into some driver somewhere, right? Like what the [ __ ] is all this stuff?
Uh also, am I in the environment that has like everything uh how do I say this? Like clang and stuff? Like why am I struggling to jump to definition?
Yeah, I don't know why it's not a LSP info?
Do I not have clang in here?
Oh my god, I don't.
All right, hold on. We need We need a proper setup. We got to be able to jump to def, man. And then maybe I didn't generate this the clang script as well.
Uh scripts clang gen compile commands. All right, let's try this again.
And I think my thing expects the compile commands to be in build because of how I used to structure my C++ projects.
Sound X lib PCM lib Xfer. Okay, does it work now?
Kind of.
Yeah, okay. Close, but un- unfortunate.
Still got to grep like [ __ ] plebs.
Okay, but here we go. We got a bunch of colors now and we can jump around.
So, what is this guy doing?
We probably actually want to break point in here.
And just see where he looks like he's going.
So, where does it look like he is going?
Where's the part where he actually jumps into some V table of like a hardware implementation?
Uh, this looked promising maybe? Error equals writer?
Yeah, I suspect that function called writer was the one, huh?
So, there's going to be one of interleave copy or non-interleave copy.
Which one did we get?
Unknown.
Okay, but let's let's uh break point there and run again.
Okay, so we step into this.
Interleave copy.
All right, what does this do? Do transfer.
Do transfer.
Holy [ __ ] Transfer takes in some PCM transfer function. Okay.
Can we look for that?
What is the transfer function?
Default write copy.
Okay.
What does that do?
Get DMA pointer? Ah.
So he's interesting.
So like we actually don't end up in any driver specific code here at all. Right?
Like presumably we end up in this like transfer function?
Uh [ __ ] I got I got hit by an interrupt and that [ __ ] everything up.
>> [laughter] >> But like presumably we end up here.
Oh, wait. Why?
Maybe it's in line so it doesn't get a nice little thing.
What does get DMA pointer do though?
Can we break here maybe? Yep.
Uh well doesn't seem to be doing what I thought it would.
D O B R break here.
Where is the part step into the transfer?
Why does stepping into this cause like a hardware interrupt?
Every time like reliably.
You know what I mean? Like Yeah, interesting.
That's confusing.
So there's something something strange happening there.
But I think it seems like based off what I'm seeing here that it just has this stuff like DMA mapped already. Do I have like a P upstream runtime and then what does like get DMA pointer even do? He just calls like DMA area, right?
Yeah.
Interesting.
Interesting.
So like presumably somewhere uh somewhere like on initialization we've like set up some sort of like DMA memory area.
Like there's got to be some sort of like assignment here somewhere.
Somewhere. DMA area is equal to this.
Yeah, yeah. So like in hardware params they allocate some areas and presumably somehow this makes it into the driver for this specific audio device, probably.
Do you ever use layout source in GDB?
How does it help you debug things easier? I'm like too stupid.
>> [laughter] >> I just do it the dumb way.
I do everything the dumb way.
Yeah, yeah, yeah. So here yeah, you like have some sound card associated with this thing and then presumably you allocate in here according to the card somehow.
Yeah, like send DMA Alec der pages.
Yeah, interesting.
Interesting. Okay, but like from like the kernel perspective though?
Like I think that I've kind of poked it enough to feel like I have like a basic understanding here, right?
So like to play noise in like the simplest case, simplest case, you have some like hardware specific driver who does a bunch of stuff, but like one of the things he does is exposes a way to like get direct memory to the hardware, maybe.
Unclear, right? Maybe it's I mean it wouldn't be called DMA if it wasn't to some sort of physical buffer, right? So we can probably imagine there's some sort of like PCI mapped buffer somewhere.
Then there's like kind of like the dev sound stuff.
And in here, one of the ways that you can communicate with this guy is you can you can feed data into this thing with like some write I command, right? Who doesn't do anything hardware specific. He doesn't talk to the hardware at all, really. He just like puts data in this memory map buffer.
Right? Then on like the the user space side, you've got lib a sound who like configures some sort of like complex ALSA pipeline based off of whatever is in like a sound.conf and friends, right?
He like creates some pipeline, but that pipeline will eventually So, you you on him you call like right I here as well, right?
Who I guess is like functionally supposed to be like a one-to-one mapping of this, but then this goes through some like pipeline of [ __ ] right?
And then eventually gets into the hardware.
Who will call this is call.
Right?
And so, I guess you would pro I would I would imagine that some of these plugins are meant to like work around the fact that like not all hardware is the same, right? We saw things like D mix that sounds really familiar in terms as like a way to like mix different streams together in user space, right? So, it sounds we also saw something about like a a sound server, right? So, it sounds like the initial guess of like how this thing is laid out is not entirely wrong, right? There is some sort of like user space plugin system that can do who knows what. We don't know yet.
There is a piece of hardware that has some memory mapped buffer that you can shove stuff into.
We don't know yet if there are multiple buffers or if the hardware supports multiple streams. We're probably going to have to look at the also documentation to try to figure out like there's got to be some way to query information about this thing, right? We must be able to ask it, "Hey, do you support X XYZ? What sample formats do you support? What What like how many streams do you have?
How many channels do you have?" I imagine that that's in there somewhere.
Um we have absolutely no idea yet how these like higher level sound servers tie into this thing, right? And why they exist.
Does also have some limitation that doesn't let that like that they need to build on top of? Maybe? Maybe like writing these things is all like writing all the features that they want to do as also plugins doesn't work? Who [ __ ] knows?
Who [ __ ] knows, right? So we will come back and we will look more tomorrow or the next day. Not sure.
Um there is a lot more to dig into here.
But at the very least we have some model of like the lowest level here.
There's a [laughter] lot more to learn.
Um thanks for watching. If you like what you saw, this is a bit of an odd stream, but you know, we do stuff like this all the time. Some sort of like low level you know, investigation or writing of things, right? We we could have just said, I need sound, let's use insert sound library, but instead we do this and that's like a common theme here. So if you like that, uh swing back by. We stream many days. I think sometimes we say most days. Sometimes it feels like we're doing like every other day right now, but we see we stream some amount of days consistently um at around 12:30 Pacific time to 4:00 you know, 3:00 or 4:00 Pacific time. It's around 3:00 now. So if you're watching live, you know, 2 and 1/2 hours ago to now or to like an hour from now is when you just got to see this. There's a YouTube where this will go up. If you're watching on YouTube, there's a Twitch, and then there's a Patreon, YouTube member, and Twitch. If you sub in any of those places, there are some more VODs that don't necessarily make it here.
We're working on this like long-term project of a SIP or VoIP client. Um so some of the like clean up and testing and stuff is going up like that you know, some of that's going up there uh right now.
I think that's it. YouTube, peace out.
Twitch let's find someone to raid.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











