+38
-6
main.cpp
+38
-6
main.cpp
···
104
104
void StartStaticNoise();
105
105
void StopStaticNoise();
106
106
void UpdateStaticVolume(float signalStrength);
107
+
void UpdateStreamVolume();
107
108
108
109
// VU meter functions
109
110
void UpdateVULevels();
···
304
305
if (g_radio.signalStrength > 100) g_radio.signalStrength = 100;
305
306
306
307
UpdateStaticVolume(g_radio.signalStrength);
308
+
UpdateStreamVolume();
307
309
InvalidateRect(hwnd, NULL, TRUE);
308
310
break;
309
311
}
···
330
332
if (g_radio.signalStrength > 100) g_radio.signalStrength = 100;
331
333
332
334
UpdateStaticVolume(g_radio.signalStrength);
335
+
UpdateStreamVolume();
333
336
InvalidateRect(hwnd, NULL, TRUE);
334
337
break;
335
338
}
···
356
359
if (g_radio.signalStrength > 100) g_radio.signalStrength = 100;
357
360
358
361
UpdateStaticVolume(g_radio.signalStrength);
362
+
UpdateStreamVolume();
359
363
InvalidateRect(hwnd, NULL, TRUE);
360
364
break;
361
365
}
···
382
386
if (g_radio.signalStrength > 100) g_radio.signalStrength = 100;
383
387
384
388
UpdateStaticVolume(g_radio.signalStrength);
389
+
UpdateStreamVolume();
385
390
InvalidateRect(hwnd, NULL, TRUE);
386
391
break;
387
392
}
···
1052
1057
if (g_radio.signalStrength > 100) g_radio.signalStrength = 100;
1053
1058
1054
1059
UpdateStaticVolume(g_radio.signalStrength);
1060
+
UpdateStreamVolume();
1055
1061
}
1056
1062
1057
1063
void UpdateVolumeFromMouse(int mouseX, int mouseY) {
···
1067
1073
if (g_radio.volume < 0.0f) g_radio.volume = 0.0f;
1068
1074
if (g_radio.volume > 1.0f) g_radio.volume = 1.0f;
1069
1075
1070
-
// Update static volume when main volume changes
1076
+
// Update volumes when main volume changes
1071
1077
UpdateStaticVolume(g_radio.signalStrength);
1078
+
UpdateStreamVolume();
1072
1079
}
1073
1080
1074
1081
int InitializeAudio() {
···
1322
1329
}
1323
1330
}
1324
1331
1332
+
void UpdateStreamVolume() {
1333
+
if (g_audio.currentStream) {
1334
+
// Stream volume based on signal strength and radio volume
1335
+
float volume = g_radio.volume * (g_radio.signalStrength / 100.0f);
1336
+
BASS_ChannelSetAttribute(g_audio.currentStream, BASS_ATTRIB_VOL, volume);
1337
+
if (g_consoleVisible) {
1338
+
printf("Updated stream volume to: %.2f\n", volume);
1339
+
}
1340
+
}
1341
+
}
1342
+
1325
1343
void UpdateVULevels() {
1326
1344
// Initialize levels to zero
1327
1345
g_audio.vuLevelLeft = 0.0f;
···
1331
1349
if (g_audio.currentStream && BASS_ChannelIsActive(g_audio.currentStream) == BASS_ACTIVE_PLAYING) {
1332
1350
DWORD level = BASS_ChannelGetLevel(g_audio.currentStream);
1333
1351
if (level != -1) {
1334
-
// Extract left and right channel levels
1335
-
g_audio.vuLevelLeft = (float)LOWORD(level) / 32768.0f;
1336
-
g_audio.vuLevelRight = (float)HIWORD(level) / 32768.0f;
1352
+
// Extract left and right channel levels and apply volume scaling
1353
+
float rawLeft = (float)LOWORD(level) / 32768.0f;
1354
+
float rawRight = (float)HIWORD(level) / 32768.0f;
1355
+
1356
+
// Apply the same volume scaling as the actual audio output
1357
+
float streamVolume = g_radio.volume * (g_radio.signalStrength / 100.0f);
1358
+
g_audio.vuLevelLeft = rawLeft * streamVolume;
1359
+
g_audio.vuLevelRight = rawRight * streamVolume;
1337
1360
}
1338
1361
}
1339
1362
···
1344
1367
float staticLeft = (float)LOWORD(staticLevel) / 32768.0f;
1345
1368
float staticRight = (float)HIWORD(staticLevel) / 32768.0f;
1346
1369
1370
+
// Apply static volume scaling
1371
+
float staticVolume = (100.0f - g_radio.signalStrength) / 100.0f;
1372
+
float scaledStaticVolume = g_radio.volume * staticVolume * g_audio.staticVolume;
1373
+
1374
+
// Ensure minimum static when radio is on but no strong signal
1375
+
if (g_radio.power && g_radio.signalStrength < 50.0f) {
1376
+
scaledStaticVolume = fmax(scaledStaticVolume, g_radio.volume * 0.1f);
1377
+
}
1378
+
1347
1379
// Combine with existing levels (simulate mixing)
1348
-
g_audio.vuLevelLeft = fmin(1.0f, g_audio.vuLevelLeft + staticLeft * 0.3f);
1349
-
g_audio.vuLevelRight = fmin(1.0f, g_audio.vuLevelRight + staticRight * 0.3f);
1380
+
g_audio.vuLevelLeft = fmin(1.0f, g_audio.vuLevelLeft + staticLeft * scaledStaticVolume * 0.3f);
1381
+
g_audio.vuLevelRight = fmin(1.0f, g_audio.vuLevelRight + staticRight * scaledStaticVolume * 0.3f);
1350
1382
}
1351
1383
}
1352
1384