1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 01:35:21 +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:
Raphael Coeffic 2018-05-08 22:27:19 +02:00 committed by Bertrand Songis
parent f2d444e2d5
commit 54d430f3c5
2 changed files with 30 additions and 4 deletions

View file

@ -792,13 +792,18 @@ void AudioQueue::wakeup()
if (size > 0) { if (size > 0) {
// TRACE("pushing buffer %p", buffer); // TRACE("pushing buffer %p", buffer);
buffer->size = size; buffer->size = size;
#if defined(SOFTWARE_VOLUME) #if defined(SOFTWARE_VOLUME)
for(uint32_t i=0; i<buffer->size; ++i) { if (currentSpeakerVolume > 0) {
int32_t tmpSample = (int32_t) ((uint32_t) (buffer->data[i]) - AUDIO_DATA_SILENCE); // conversion from uint16_t for (uint32_t i=0; i<buffer->size; ++i) {
buffer->data[i] = (int16_t) (((tmpSample * currentSpeakerVolume) / VOLUME_LEVEL_MAX) + AUDIO_DATA_SILENCE); 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(); buffersFifo.audioPushBuffer();
#endif
} }
else { else {
// break the endless loop // break the endless loop

View file

@ -51,6 +51,17 @@ void dacInit()
dacTimerInit(); dacTimerInit();
GPIO_InitTypeDef GPIO_InitStructure; 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_Pin = AUDIO_OUTPUT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
@ -83,6 +94,10 @@ void audioConsumeCurrentBuffer()
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer(); nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
if (nextBuffer) { 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_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->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); 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->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC 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
} }
} }