... restricted to 44.2K and 16bit DATA. ...
You wrote 44.2K before so I thought it pertinent to point out that it is much closer to 44.1K
Thanks for the quick reply. I was aware that the sample frequency was "awfully close to CD quality". Thus as a slave device, it would be driven by the DAC in master mode with an accurate sample rate. The DAC I am interested in using will have a local clock of 45.1584MHz and the DAC can generate a bitclock of /16 which is 2.8224MHz. The frame clock is fixed as /64.
Regarding treating everything 32bit I2S, I think this will have wider appeal as it seems universally accepted by all DACs. Actually, it is the frame rate at 64*fs that is supported (and some requires it) by all DACs, the data can be 16 bit, 20 bit, 24 bit or 32 bit.
Can you hint me as to where to look for the 64*fs support?
Thanks.
Even if you specify which audio codec you intend to use the answer to where you could look for 64*fs support may just have to be "elsewhere"; to use a codec at all means having specific controlling code for that codec. Paul has put the SGTL5000 on PJRC's Audio Adapter so that one is clearly to be supported. Others may become supported but equally they may not.
@Paul: I spent a lot of yesterday poring over
https://www.pjrc.com/teensy/K20P64M72SF1RM and I am going to spend a lot hours reading (more of) it and pondering the less well defined items they have in there.
I read enough to become fairly confident that the 'split buffer' idea may be more work (for both author(s) and processor) than really ideal - I cannot currently see a way to do it other than to collect the data from the codec in an array of int32_t and then split each of those blocks into the two int16_t buffers currently in use, which gives rise to a question of sign in the LSB set too. Maybe that won't be as intensive an operation in the processor as I think but as the sampling rate increases it probably is.
I think conditional compiling where the data member of audio_block_struct is made int32_t when AUDIO_LIBRARY_BIT_DEPTH > 16 might be a better way to go - 24 bit samples can be processed by the same code that processes 32 bits and I think that it will be less work ultimately to write/modify objects which conditionally compile regarding bit depth as well instead of what would be necessary to deal with the split buffer method.
Where I think the bit depth should be library wide, even though the ADC is 16 bit (just shift << by (AUDIO_LIBRARY_BIT_DEPTH-16)) and the DAC is only 12 bit (similar shift, opposite direction), I've an idea that supporting multiple simultaneous sample rates could be cool enough to (perhaps, at least) be worth dealing with the trickier aspects of doing so - I can see reasons tho that I am probably wrong about this and perhaps a library wide AUDIO_LIBRARY_SAMPLE_RATE is called for too.
If audio_block_struct was re-written like this;
Code:
typedef struct audio_block_struct {
unsigned char ref_count;
unsigned char memory_pool_index;
#if AUDIO_LIBRARY_BIT_DEPTH>16
int32_t data[AUDIO_BLOCK_SAMPLES];
#else
int16_t data[AUDIO_BLOCK_SAMPLES];
#endif
uint32_t sample_rate;
} audio_block_t;
Source objects fill the sample_rate field, manipulation and destination objects check that field and act appropriately. Then, for example, the end user could run ADC->[manipulation]->DAC at 44.117'K and codec_in->[manipulation]->codec_out at another rate if for whatever reason they wanted to. I see problems with trying to modify sample rates using an 'object in the middle' approach so perhaps the sample_rate member I suggest isn't a workable approach and source objects would have to up/down sample to the destination object's rate as they go - maybe that isn't economically feasible, in terms of having enough compute-power/time to manipulate as much as desired, either.
On the other hand making the sample rate fixed library wide setting PDB_PERIOD to 1000 or 500 (or even 250) can be used to match 48K and 96K (I wonder if it would manage 192K ?) for ADC & DAC, better still if we could get them to operate from BCLK(in or out) using LRCLK as enable or trigger perhaps) to align more precisely with less effort but I haven't found the part of the manual for MK20DX256VLH7 which shows me how to make it so yet - if it is possible.
For others reading and thinking how brilliant it would be to do 96K at 24-32 bits it should probably be pointed out that the time available to process and manipulate samples is decreased by the raised sample rate and the time required to process or manipulate the samples is increased by the larger bit depth - all leaving less processor time for other activities. IMHO 44.1-48K @ 16 bits is pretty good audio and leaves plenty of time to apply more processing/manipulation to samples and other activities.