add arrow-down arrow-left arrow-right arrow-up authorcheckmark clipboard combo comment delete discord dots drag-handle dropdown-arrow errorfacebook history inbox instagram issuelink lock markup-bbcode markup-html markup-pcpp markup-cyclingbuilder markup-plain-text markup-reddit menu pin radio-button save search settings share star-empty star-full star-half switch successtag twitch twitter user warningwattage weight youtube

Help me understanding audio codec functions (ak4953a and pic32mz)

mkioi

39 months ago

Hello,

I have the MEB II with the audio codec AK4953A and the PIC32MZ on it. I managed to alter the audio_speaker example so that I can record in addition to playback function. But if I record without using playback function I get sound distortions every few seconds. Since these "faults" disappear when I start the audio playback I came to the conclusion, that this could be connected to the functions AdjustSampleRate and TuneSampleRate. With these functions (if I understood correctly), the reference clock REFO1CLK is tuned a little bit (should be 12,288MHz, tuned between approx 12,2959MHZ and 12,2752MHz) so that the sample rate (48kHz) is tuned 50Hz up and down. As I understood this is done to work against clock mismatches because of tolerances of the usb clock. ()

So when the samplerate is tuned the amount of available playback data changes as well, with help of the tuning it is hold between 60 and 84 (bytes?). Playback seems to work fine with this variable data buffering. But with the recording I get a size fixed data packet of (I'm not sure if this is right) 48 and now and then of another size (96?). Using the tuning with information from the recording buffers does not work, but if the sample rate is tuned by playback, I don't get the "faults" in my recording.

Is there any chance that I can get my recording without playback and without faults? Any hints what or where to modify things?

//playback tuning void AK4953AAdjustSampleRateTx(AK4953AState* pCodecHandle) { INT DMASourceStartAddress; DMASourceStartAddress = (volatile INT)(PLIB_DMA_ChannelXSourcePointerGet(DMA_ID_0, AK4953A_SPI_TX_DMA_CHANNEL)); DMASourceStartAddress = KVA_TO_PA(DMASourceStartAddress); data_available_count = (pCodecHandle->bufferSize - DMASourceStartAddress) + data_index_value_tx;

if (data_available_count > pCodecHandle->underrunLimit && data_available_count < pCodecHandle->overrunLimit)
{
    if (data_available_count < pCodecHandle->underrunCount)
    { 
        AK4953ATuneSampleRate(pCodecHandle, DEC_TUNE);
    }
    else if (data_available_count > pCodecHandle->overrunCount)
    { 
        AK4953ATuneSampleRate(pCodecHandle, INC_TUNE);
    }
}

}

INT AK4953ATuneSampleRate(AK4953AState* pCodecHandle, TUNE_STEP tune_step) { if ((pllkUpdate - pCodecHandle->pllkValue)<(-1 * pCodecHandle->pllkTuneLimit)) pllkUpdate = pCodecHandle->pllkValue - pCodecHandle->pllkTuneLimit + pCodecHandle->pllkTune; else if ((pllkUpdate - pCodecHandle->pllkValue) > pCodecHandle->pllkTuneLimit) pllkUpdate = pCodecHandle->pllkValue + pCodecHandle->pllkTuneLimit - pCodecHandle->pllkTune;

pllkUpdate = (tune_step == INC_TUNE) ? (pllkUpdate - pCodecHandle->pllkTune) : (pllkUpdate + pCodecHandle->pllkTune);

REFO1TRIM = (pllkUpdate << 23);
REFO1CONSET = 0x00000200;
return (1);

}

And another strange thing is, that the playback always starts with another "data_available_count", often even outside the the over- and underrunLimits, so that theses cases aren't fixed. so the "data_available_count" drifts to so point, then I can listen to a "scratch" in the music, and then the "data_available_count" oscillates between underrun- and overrunCount limits... Here is the pdf link : http://www.kynix.com/uploadfiles/pdf65976/PIC32MZ2048ECH064-I2fPT_752902.pdf

I would be happy about some explanations or advices.

Regards,

Comments

  • 39 months ago
  • 1 point

There are some mistakes. But I DON'T know how to fix it.

Sort

add arrow-down arrow-left arrow-right arrow-up authorcheckmark clipboard combo comment delete discord dots drag-handle dropdown-arrow errorfacebook history inbox instagram issuelink lock markup-bbcode markup-html markup-pcpp markup-cyclingbuilder markup-plain-text markup-reddit menu pin radio-button save search settings share star-empty star-full star-half switch successtag twitch twitter user warningwattage weight youtube