sync
This commit is contained in:
@@ -38,7 +38,7 @@ K_SEM_DEFINE(audio_ready_sem, 0, 1);
|
||||
static const struct device *const i2s_dev = DEVICE_DT_GET(I2S_NODE);
|
||||
static const struct gpio_dt_spec amp_en_dev = GPIO_DT_SPEC_GET(AUDIO_AMP_ENABLE_NODE, gpios);
|
||||
|
||||
|
||||
static volatile int current_volume = 8;
|
||||
static volatile bool abort_playback = false;
|
||||
static char next_random_filename[64] = {0};
|
||||
|
||||
@@ -219,6 +219,8 @@ void audio_thread(void *arg1, void *arg2, void *arg3)
|
||||
|
||||
bool trigger_started = false;
|
||||
int queued_blocks = 0;
|
||||
uint8_t factor = MIN(255, current_volume * 0xFF / 100);
|
||||
LOG_INF("Volume factor: %u (for volume %d%%)", factor, current_volume);
|
||||
|
||||
while (!abort_playback)
|
||||
{
|
||||
@@ -234,7 +236,7 @@ void audio_thread(void *arg1, void *arg2, void *arg3)
|
||||
|
||||
if (abort_playback)
|
||||
{
|
||||
k_mem_slab_free(&audio_slab, &block);
|
||||
k_mem_slab_free(&audio_slab, block);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -242,7 +244,7 @@ void audio_thread(void *arg1, void *arg2, void *arg3)
|
||||
|
||||
if (bytes_read <= 0)
|
||||
{
|
||||
k_mem_slab_free(&audio_slab, &block);
|
||||
k_mem_slab_free(&audio_slab, block);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -252,7 +254,7 @@ void audio_thread(void *arg1, void *arg2, void *arg3)
|
||||
|
||||
for (int i = samples_read - 1; i >= 0; i--)
|
||||
{
|
||||
int16_t sample = samples[i];
|
||||
int16_t sample = (samples[i] * factor) >> 8; // Lautstärkeanpassung
|
||||
samples[i * 2] = sample;
|
||||
samples[i * 2 + 1] = sample;
|
||||
}
|
||||
@@ -267,7 +269,7 @@ void audio_thread(void *arg1, void *arg2, void *arg3)
|
||||
/* Block in die DMA-Queue schieben */
|
||||
if (i2s_write(i2s_dev, block, AUDIO_BLOCK_SIZE) < 0)
|
||||
{
|
||||
k_mem_slab_free(&audio_slab, &block);
|
||||
k_mem_slab_free(&audio_slab, block);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user