Help to resolve 24-Bit, 192 kHz Stereo D/A Converter - Page 1
Forum section: electronics / general

author: alizare368
author_rank: Regular Contributor
timestamp: July 05, 2019, 09:54:50 am
content: HiI used CS4344 sound codec for making the wave player,and it works well,but it has a problem,I have to disconnect and then connect one of the output to start reading,Or activating the output.Shematic is in the attachment.this is my code:Code:int main(void){MX_GPIO_Init();MX_DMA_Init();MX_I2S2_Init();MX_SDIO_SD_Init();MX_FATFS_Init();res=f_mount(&SDFatFs, (TCHAR const*)SDPath, 0);if(res==FR_OK){res=f_open(&MyFile, "2.wav",FA_READ);if(res==FR_OK){f_read(&MyFile,&sai_buf,sample_no*2,&br);f_read(&MyFile,&sai_buf,sample_no*2,&br);}}index_buf++;HAL_I2S_Transmit_DMA(&hi2s2,sai_buf,sample_no);while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */if(refill){refill=0;HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_SET);res=f_read(&MyFile,&sai_buf[index_buf%2],sample_no*2,&br);HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_RESET);}}}void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s){HAL_I2S_Transmit_DMA(&hi2s2,sai_buf[index_buf%2],sample_no);index_buf++;refill=1;}someone know what the problem is??

author: GromBeestje
author_rank: Frequent Contributor
timestamp: July 05, 2019, 12:15:44 pm
content: QuoteDo you mean, the wires between the microcontroller and the dac have to be disconnected?Can you show how they're connected? When you disconnect and reconnect, does this include the power?Furthermore, looking at the code, the filename "2.wav" suggests the file is a RIFF WAVE file, but you're parsing it like it contains RAW PCM data. I would generate some giberish digital noise at the beginning of the playback, (assuming the WAVE file contains PCM data, of course)Is CS4644 your DAC. I can't find it on Google. If this DAC is "smart" and detects a RIFF header, it might silent itself to prevent non-audio data being played.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 05, 2019, 01:01:43 pm
content: I don't know what the CS4644 is either. It's unknown on the Cirrus Logic web site. Are you sure about this reference? Can you check or give more info?That said, I don't know of any simple audio DAC that can parse a WAV file. That wouldn't make much sense either, as a WAV file can be of any format, so the DAC would additionally have to be able to support AND set the correct sample rate (or convert it on the fly, ouch!) and use the correct sample width. It's not going to happen unless maybe you were using some kind of complex audio SOC.So as GromBeestje said, you need to correctly parse the WAV file first, and make sure it contains 24-bit, 192kHz audio data. As is, it's probably just going to send garbage to the DAC, even after the header (there is no reason to think that the data would be correctly aligned once the header has been passed...)I don't know what exactly you mean by "disconnect" either, but that may just appear to "work" because of the above (when reconnecting the DAC on the fly, you may be lucky to get the audio samples properly aligned, or at least get something audible (which is still likely not to sound very good unless you're extremely lucky.)

author: linux-works
author_rank: Super Contributor
timestamp: July 05, 2019, 02:31:53 pm
content: if you are using i2s, i2s has 3 clocks and 1 data. the word clock keeps the left and right samples separate, even if you 'tune in later' at not an exact sample point. the dac will drop any sample that does not have the right framing and will 'resume' at the next proper start point.yes, wave file is not pure pcm; you need to send pure samples to the dac, not literal file values.

author: MT
author_rank: Super Contributor
timestamp: July 05, 2019, 11:45:11 pm
content: Quote from: alizare368 on July 05, 2019, 09:54:50 amCS4344?

author: hamster_nz
author_rank: Super Contributor
timestamp: July 06, 2019, 12:28:12 am
content: Quote from: MT on July 05, 2019, 11:45:11 pmif it is a CS4344, they are exceptionally dumb (or is that simple?) DAC. As long as valid I2S stream is presented they will convert it.Just expect to get a burst of noise when you "play" the WAV header file. It is more than likely that in the WAV file the the L/R samples will be aligned on a boundary that just makes it all work, as long as you set the same rate and sample size appropriately.A simple hack would be to trim 64 bytes off the beginning of the file, which should be more than enough to skip the header (and most likely a few samples too).