@@ -53,6 +53,20 @@ static esp_err_t uac_device_output_cb(uint8_t *buf, size_t len, void *arg)
5353
5454 // Process the data in chunks
5555 while (s_data_in_head >= CHUNK_SIZE ) {
56+ // Get volume from config manager
57+ app_config_t * config = config_manager_get_config ();
58+ float volume = config -> volume ;
59+
60+ if (volume < 1.0f ) {
61+ // Apply volume scaling for 16-bit PCM audio
62+ int16_t * samples = (int16_t * )s_data_in ;
63+ int num_samples = CHUNK_SIZE / 2 ; // 2 bytes per sample for 16-bit audio
64+
65+ for (int i = 0 ; i < num_samples ; i ++ ) {
66+ samples [i ] = (int16_t )(samples [i ] * volume );
67+ }
68+ }
69+
5670 memcpy (s_data_out + HEADER_SIZE , s_data_in , CHUNK_SIZE );
5771
5872 // Send with retry logic
@@ -112,6 +126,16 @@ static void uac_device_set_volume_cb(uint32_t volume, void *arg)
112126 }
113127
114128 ESP_LOGI (TAG , "Mapped volume: %" PRIu32 "" , s_volume );
129+
130+ // Update config manager's volume (convert from 0-100 to 0.0-1.0 scale)
131+ float config_volume = (float )s_volume / 100.0f ;
132+ app_config_t * config = config_manager_get_config ();
133+ config -> volume = config_volume ;
134+
135+ // Save the new volume setting to NVS
136+ config_manager_save_setting ("volume" , & config_volume , sizeof (float ));
137+
138+ ESP_LOGI (TAG , "Config volume updated to %.2f" , config_volume );
115139}
116140
117141esp_err_t scream_sender_init (void )
0 commit comments