ESP32 Audio Processing with PCB Artists ES8388

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you've seen any of my pre previous videos on audio processing you'll have noticed that i've been using the digilent pmod i2s2 board as codec and here's a let me just zoom into that here you can see the board has line in and line out and then on the right hand side of the board are all the i2s inputs which i've described earlier and i'll provide a link to those videos down below now i'm a big fan of the pmod board but i've been looking for a while for a board that exposes the audio in and out as pins rather than as 3.5 millimeter jack and i recently came across this board that you can see over to the right hand side there let me just uh pan in that so you can get a close-up view of that board so this board here is the pcb artist's 88 es8388book and i thought i'd uh you know buy a couple give it a go and and share the results um now now i put just purchased these boards myself and i'll provide a link below if you're uh interested in getting a hold of some yourself so not only does this board um expose all the signals uh line in line out all the so all the digital signals are on the left hand side here and we'll go through a pin out in a little bit but uh not only does it expose all those signals as pins through a pin header but the es 8388 is the codex that's used by espressives t audio dev kit and so there is full support with a few bugs that'll go through below in the esp adf the audio development framework for it i'll include a link to the es 8388 data sheet below but another key difference to the pmod is there's an i squared c interface that allows control of the internal adc's the dax etc in fact pretty much everything you can see on the block diagram can be programmatically controlled so let's have a quick look at the block diagram and then we'll move on to the pin out here's the block diagram for for the board here it's all uh kind of conceptual but you've got line in line two uh both left and right channel you've got down the bottom here you've got the the serial audio data interfaces so this is the lr clock that we've covered before you've got uh i2s data out i2s data in here's the bit clock or s clock and then finally over the left hand side here we've got the master clock now i'm operating this in slave mode so all these signals come from the esp32 but you can see internally you have all these sub modules and you can control pretty much any of these sub modules through the i squared c interface so for example there is a part of the i squared c interface that allows you to control the gain of this amplifier component right here so signal comes in here you can programmatically control the gain right here before it passes on to other parts of the of the es 8388 okay so here's the pin out diagram of the board together with the default gpios and this comes from a link which i'll share on the pcb artists website now if you hook up your esp32 to these default pins you can pretty much use the lyra t 4.3 board out of the esp adf and i'll kind of show you how you select the board a little later on and then you're good to go from there note on the board here also there's multiple grounds here so we've got a ground here a couple of grounds here now these are all tied together so you just need to ground one of them uh and then you know you don't need to sort of have a ground line on each one of these grounds here just so i've i've chosen this one to to ground now there are two different voltage supplies though so we've got a digital voltage supply over here and an analog voltage supply over here and they are not connected together so um i i think the you know the idea is that you connect your two supplies separately and then you don't have sort of high frequency noise leaking into uh leaking into the audio circuitry um but i've got them simply hooked up together and that might explain some of the high frequency noise i'm actually getting the output here uh but the board does give you the option of hooking them up separately just a quick note there are actually three on the es 8388 there are actually three vdds there's a vdd dvd and there's also an hp vdd which is the um uh the headphone um uh vdd and they they're actually just connected together on the on the board here the final note here is uh these two um these two uh pins here are for a microphone a separately supplied microphone bias if you if you wish to do that i'm actually not using the microphone here i'm using rin2 lin2 and r out and l out but more to come on that later on so i chose to however not use the default esp32 pins um and and i've gone uh with this diagram right right here now the main reason for that is the board that i'm using does not have gpio0 which is used for the master clock exposed uh so i'm using gpo3 for that um and master clock is is one of the exceptional um uh interfaces in that you can't map master clock to unlike the other gpios you can't map master clock to whatever pin you want to you've basically got a selection of gpio01 or 3 and that's it and you do have to do some magic code which i will walk through uh later on so you can see the the pin outs uh right here that that i've got set up here so d out to gpo 19 lr clock to gpio18 data data in which is data out from the from the esp32 is 21. bit clocks on gpo5 now this is the master clock here and it's on my board it's called rx0 but it actually maps to gpio3 and then i've got uh scl and sda for the i squared c interface there on pins 23 and 22 respectively on the input and output side so here's the audio signal coming in and i've got that coming into rin2 and lind2 on the bull the board as i mentioned i've got my av dd here just connected to 3.3 volts and that's the same 3.3 volt source and then on the output side basically i've got it going through this simple low pass filter here that consists of a 220 ohm resistor and a 0.1 microfarad capacitor before it actually goes out and i've got it going to my oscilloscope so here's the actual board i've got set up here here's all those digital lines uh the data in data out lr clock master clock and so on and so forth going over to the right hand side of the pcb artist board and then here's the input lines coming in here to rin2 and lint2 and then here's that uh simple low pass filter here there's that 0.1 microfarad cap and there's a 220 m resistor before it goes out and then this is audio out so audio in down the bottom audio out at the top okay so let's start with a simple example here and i'm not in the first example i'm going to show you and i'll walk through the code i'm not using the esp adf i'm just kind of programming the es 8388 i squared c interface manually using a copy of the code from the esp8f but what i'm basically doing here is i'm just generating a tone and varying the amplitude so you can see on the oscilloscope there that that that amplitude is waxing and waning let's just hear that so you can hear that let me just change the frequency so i can uh i can kind of prove that i'm uh i'm not uh faking it here so let's go up to let's say a thousand hertz now one of the things i've noticed is uh as you're programming it you get a lot of noise on the output there so there's a thousand hertz tone uh amplitude varying as before okay so let's just uh quickly walk through some of the code here so as i mentioned um this piece of code isn't using the esp8df i'll provide a link below to the github repo for this so what i've basically done is take the es 8388 code out of the esp adf and just basically copy it into this file so pretty straightforward stuff let me just walk you through some of the highlights this code we've seen before this is just the es esp32 i2c setup which you need for the for the codec just moving down to the initialization so this is all through the i squared c interface and it's basically powering up the chip powering up the dac and the adc setting some volume just so so just some setup code there just moving quickly on this configures the i2s interface on the codec so this is different to the i2s interface on the esp32 uh and there's two sections here the first is the format and that's just simply really you've got a choice between i2s or or a standard pcm so this just sets i2s and then the second portion sets the sample bits length now the sample bits length uh we've covered that before in i2s i'm using 16-bit samples here the interesting thing is you have to set that both on the codec as well as in the i2s which we'll see below okay so just moving down to the es 8388 to initialization code and as i mentioned this is all over i squared c uh so you can see here um i pulled this initialization code directly from the esp adf this would be this would be tough to derive myself but basically involves powering up the chip uh setting the esp the i2s mode in this case this is in slave mode and what that means is the lr clock bit clock and master clock come from outside the codec it powers up the adc's and the dax moving on down next section of interest is configuring the i2s on the codec and that's different to i2s elsewhere and and what it basically does here is it sets the format and the format can be one of i2s i think there's a left justified right justified mode and a dsp pcm mode and then moving down a bit further we have the the sample bits length here and and as i mentioned the the sample bits length you have to set it on the codec and you have to set it separately in i2s and they have to match uh so you can see here i'm uh setting this up through the i squared c interface and as we go down a little bit further you can see i'm also setting that that sample bits in the i2s configuration so just moving back up after you've finished initialization you then uh run this start uh function here and that and that actually fires up the chip and starts uh processing inbound outbound uh audio and i2s signals just one quick note this is the magic code that i alluded to above to set the master clock pin on the esp32 as i mentioned you can't use any pin for master clock and in fact on the esp32 you are limited to gpi gpio num0 one and the final one is gpio pin 3 which i'm actually using uh and this magic piece of code i actually got out of the esp8df i probably would not have been able to work this out work this out myself so moving down a bit further we have the the actual esp i2s configuration here i'm in master mode i'm only transmitting data to the codec this is the sample rate the sample rate i'm using here is 44.1 kilohertz now you don't have to actually tell the codec what your sample rate rate is only the bits per sample which is here so this bits per sample here has to match the bits per sample that you set above when you are configuring the codec just moving on down here is the set of pins that i'll be using for the bit clock word select with all the left lr clock data in data out and they can be pretty much any pins uh on on the esp32 you're not fixed to a specific set uh you and then install the driver uh you tell it what pins that you're going to use from this this struct here uh you invoke the master clock gpio select which we went through above and then finally call set clock and what set clock does is for a given sample rate so that's 44.1 kilohertz a given bits per sample 16 bits in this case and then this number is how many channels so we've got left and right channel and then once you've got all the i2s set up in the codec setup it's a simple matter of this i2s write function basically takes what what is ever in the tx buff and in this case it just happens to be that simple sine wave and it uh sends that out through the through the i2s uh and really once you get to this point to interacting with i2s couldn't be simpler um there's no worrying about uh interrupts or or dna buffers that's all handled under the covers of course you can do all that yourself this is all part of the esp idf so you know you can interact directly with the i2s i2s registers yourself if if you so desire okay so uh finally let's do uh something a little more interesting with the i2s uh and here i demonstrated this software in an earlier video but this is uh using the esp adf together with the dsp library to do phase shifting so i've done this in quite a few videos before and i'll include a link to a few of the other videos that that has more details on this but what you're basically seeing here is i'm injecting a 700 hertz signal in phase to here and it's being ingested into the pcb artists board here it's then being sent over i2s to the esp32 right here and we're doing phase basically if there's a finite impulse response filter that's running in here that does phase shifting and it sends it back out to the board so the result of which is uh basically the left channels getting shifted back 45 degrees the right channels being being shifted forward 45 degrees and the result being you've got those two audio signals now 90 degrees out of phase so i've done this before just to confirm that i'll turn xy on you can see there's the the perfect circle as you would expect for two signals at uh 90 degrees out of phase with one another um and so what i'll do now is i'll just move on to a quick walkthrough i won't go into the details of the finite impulse response code uh like i said i'll i'll give a link to that this is the same code that i was running using the pmod board so um it's good to see it all working together but let me quickly walk through the changes that i have to do to get this working with the uh with the es 8388 board okay so let's uh just go through some of the changes that i made uh to the code and and starting with the es 8388 so this is the main driver file for the es 8388 codec and i noticed a couple of things uh at least they weren't working for me so the first ones this line here this was originally uh 0xbb uh and this is the mic channel uh sort of the input gain on the uh on the line in and i found bb to be too high in fact b the 0x bb wasn't even in the documentation so i turned that down a little bit the other change that i made is this uh function here set voice volume uh what i noticed is that these two both set the volume to zero uh so this is setting the output volume of the dax and this is uh route two and loud two or loud two and round two i'm not sure but these were both set to zero so it you would get nothing out of uh r out or l out two if uh you know in the original code okay so then moving on um back in the previous video i'll show how to add uh your own custom board so basically you create this board directory and it defines the pins and some startup code for whatever board you want to add to esp8df so i added this pcb artist underscore es3 8388 board uh and in that board there's a couple of files here a couple important ones board pins config contains the gpios for the i2c as well as the i2s and it also contains that bit of magic code that i showed i showed you before where it this one happens to hard code the master clock to to pin three uh just uh i took a copy of this from the lyra t 4.3 uh so this is pretty much a bare bones version of that the lara t has a whole pile of additional features that that the pcb artist board just doesn't have it's just the codec so that's the changes there and once you add that pcb artists directory you can then see that will appear now in sdk config as a board option so if we have a look in audio hell here so you can see that's uh defaulting to the lyra t now i can change that to there you go there's the pcp artist board there so uh so there you go there you have it um that is the um that's all i planned to do in this video um hope you enjoyed this video um i guess the upshot is the uh uh the pcb artists uh board worked for me um it was relatively uh straightforward to set up and um uh and consider it if you're in the market for a uh a codec that's all for now
Info
Channel: NA5Y
Views: 7,710
Rating: undefined out of 5
Keywords: codec, es8388, pcb artists, pcbartists, esp32, audio processing
Id: q5wghoIwrkg
Channel Id: undefined
Length: 20min 49sec (1249 seconds)
Published: Tue Aug 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.