mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 08:45:24 +03:00
[X10] mute audio when fifo buffer is empty (#5875)
* [X10] mute audio when fifo buffer is empty * do not push audio data if volume is muted.
This commit is contained in:
parent
f2d444e2d5
commit
54d430f3c5
2 changed files with 30 additions and 4 deletions
|
@ -792,13 +792,18 @@ void AudioQueue::wakeup()
|
|||
if (size > 0) {
|
||||
// TRACE("pushing buffer %p", buffer);
|
||||
buffer->size = size;
|
||||
|
||||
#if defined(SOFTWARE_VOLUME)
|
||||
for(uint32_t i=0; i<buffer->size; ++i) {
|
||||
int32_t tmpSample = (int32_t) ((uint32_t) (buffer->data[i]) - AUDIO_DATA_SILENCE); // conversion from uint16_t
|
||||
buffer->data[i] = (int16_t) (((tmpSample * currentSpeakerVolume) / VOLUME_LEVEL_MAX) + AUDIO_DATA_SILENCE);
|
||||
if (currentSpeakerVolume > 0) {
|
||||
for (uint32_t i=0; i<buffer->size; ++i) {
|
||||
int32_t tmpSample = (int32_t) ((uint32_t) (buffer->data[i]) - AUDIO_DATA_SILENCE); // conversion from uint16_t
|
||||
buffer->data[i] = (int16_t) (((tmpSample * currentSpeakerVolume) / VOLUME_LEVEL_MAX) + AUDIO_DATA_SILENCE);
|
||||
}
|
||||
buffersFifo.audioPushBuffer();
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
buffersFifo.audioPushBuffer();
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
// break the endless loop
|
||||
|
|
|
@ -51,6 +51,17 @@ void dacInit()
|
|||
dacTimerInit();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
GPIO_InitStructure.GPIO_Pin = AUDIO_MUTE_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(AUDIO_MUTE_GPIO, &GPIO_InitStructure);
|
||||
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#endif
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = AUDIO_OUTPUT_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
|
@ -83,6 +94,10 @@ void audioConsumeCurrentBuffer()
|
|||
|
||||
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
|
||||
if (nextBuffer) {
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
// un-mute
|
||||
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#endif
|
||||
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN ; // Disable DMA channel
|
||||
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits
|
||||
AUDIO_DMA_Stream->M0AR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
|
@ -91,6 +106,12 @@ void audioConsumeCurrentBuffer()
|
|||
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
|
||||
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC
|
||||
}
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
else {
|
||||
// mute
|
||||
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue