mirror of
https://github.com/Goldenkrew3000/OSSP_OpenSource.git
synced 2025-12-19 00:04:44 +10:00
Added frontend pitch and volume control
This commit is contained in:
@@ -23,7 +23,7 @@ bool bAudioSettingsShow = false;
|
|||||||
void showLikedSongs();
|
void showLikedSongs();
|
||||||
void showAudioSettings();
|
void showAudioSettings();
|
||||||
|
|
||||||
int qt_gui_entry(int argc, char** argv) {
|
int gui_entry() {
|
||||||
// Initialize SDL
|
// Initialize SDL
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
|
||||||
printf("SDL could not be initialized: %s\n", SDL_GetError());
|
printf("SDL could not be initialized: %s\n", SDL_GetError());
|
||||||
@@ -196,20 +196,38 @@ void showLikedSongs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float in_volume_val = 0;
|
float in_volume_val = 0;
|
||||||
|
float out_volume_val = 0;
|
||||||
|
float pitch_val = 0;
|
||||||
bool hasInVolumeFirstRun = false;
|
bool hasInVolumeFirstRun = false;
|
||||||
void showAudioSettings() {
|
void showAudioSettings() {
|
||||||
ImGui::Begin("Audio Settings");
|
ImGui::Begin("Audio Settings");
|
||||||
|
|
||||||
if (!hasInVolumeFirstRun) {
|
if (!hasInVolumeFirstRun) {
|
||||||
in_volume_val = OSSPlayer_GstECont_InVolume_Get();
|
in_volume_val = OSSPlayer_GstECont_InVolume_Get();
|
||||||
|
out_volume_val = OSSPlayer_GstECont_OutVolume_Get();
|
||||||
|
pitch_val = configObj->audio_pitch_cents / 100.0f; // Cents to semitones
|
||||||
hasInVolumeFirstRun = true;
|
hasInVolumeFirstRun = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::Text("In Vol / Out Vol");
|
||||||
|
|
||||||
// Idk what that field is, styling?, Size, Storage, Low, High
|
// Idk what that field is, styling?, Size, Storage, Low, High
|
||||||
if (ImGui::VSliderFloat("##v", ImVec2(35, 160), &in_volume_val, 0.0f, 1.0f)) {
|
if (ImGui::VSliderFloat("##invol", ImVec2(35, 160), &in_volume_val, 0.0f, 1.0f)) {
|
||||||
// Data has changed
|
// Data has changed
|
||||||
OSSPlayer_GstECont_InVolume_set(in_volume_val);
|
OSSPlayer_GstECont_InVolume_set(in_volume_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::VSliderFloat("##outvol", ImVec2(35, 160), &out_volume_val, 0.0f, 1.0f)) {
|
||||||
|
OSSPlayer_GstECont_OutVolume_set(out_volume_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::VSliderFloat("##pitch", ImVec2(35, 160), &pitch_val, -6.00f, 6.00f)) {
|
||||||
|
OSSPlayer_GstECont_Pitch_Set(pitch_val * 100.0f); // Convert semitones to cents
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
int qt_gui_entry(int argc, char** argv);
|
int gui_entry();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ int main(int argc, char** argv) {
|
|||||||
discordrpc_struct_deinit(&discordrpc);
|
discordrpc_struct_deinit(&discordrpc);
|
||||||
|
|
||||||
// Launch QT frontend
|
// Launch QT frontend
|
||||||
qt_gui_entry(argc, argv);
|
gui_entry();
|
||||||
|
|
||||||
// Cleanup and exit
|
// Cleanup and exit
|
||||||
configHandler_Free(&configObj);
|
configHandler_Free(&configObj);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
extern configHandler_config_t* configObj;
|
extern configHandler_config_t* configObj;
|
||||||
static int rc = 0;
|
static int rc = 0;
|
||||||
GstElement *pipeline, *playbin, *filter_bin, *conv_in, *conv_out, *in_volume, *equalizer, *pitch, *reverb;
|
GstElement *pipeline, *playbin, *filter_bin, *conv_in, *conv_out, *in_volume, *equalizer, *pitch, *reverb, *out_volume;
|
||||||
GstPad *sink_pad, *src_pad;
|
GstPad *sink_pad, *src_pad;
|
||||||
GstBus* bus;
|
GstBus* bus;
|
||||||
guint bus_watch_id;
|
guint bus_watch_id;
|
||||||
@@ -216,6 +216,7 @@ int OSSPlayer_GstInit() {
|
|||||||
// Calf Studio Plugins Reverb
|
// Calf Studio Plugins Reverb
|
||||||
reverb = gst_element_factory_make(configObj->lv2_reverb_filter_name, "reverb");
|
reverb = gst_element_factory_make(configObj->lv2_reverb_filter_name, "reverb");
|
||||||
}
|
}
|
||||||
|
out_volume = gst_element_factory_make("volume", "out-volume");
|
||||||
// TODO: Make better error messages for here, and exit out early
|
// TODO: Make better error messages for here, and exit out early
|
||||||
if (!equalizer) {
|
if (!equalizer) {
|
||||||
logger_log_error(__func__, "Could not initialize equalizer.");
|
logger_log_error(__func__, "Could not initialize equalizer.");
|
||||||
@@ -229,8 +230,8 @@ int OSSPlayer_GstInit() {
|
|||||||
|
|
||||||
// Add and link elements to the filter bin
|
// Add and link elements to the filter bin
|
||||||
// TODO: Check creation and dynamic as per config
|
// TODO: Check creation and dynamic as per config
|
||||||
gst_bin_add_many(GST_BIN(filter_bin), conv_in, in_volume, equalizer, conv_out, NULL);
|
gst_bin_add_many(GST_BIN(filter_bin), conv_in, in_volume, equalizer, pitch, out_volume, conv_out, NULL);
|
||||||
gst_element_link_many(conv_in, in_volume, equalizer, conv_out, NULL);
|
gst_element_link_many(conv_in, in_volume, equalizer, pitch, out_volume, conv_out, NULL);
|
||||||
sink_pad = gst_element_get_static_pad(conv_in, "sink");
|
sink_pad = gst_element_get_static_pad(conv_in, "sink");
|
||||||
src_pad = gst_element_get_static_pad(conv_out, "src");
|
src_pad = gst_element_get_static_pad(conv_out, "src");
|
||||||
gst_element_add_pad(filter_bin, gst_ghost_pad_new("sink", sink_pad));
|
gst_element_add_pad(filter_bin, gst_ghost_pad_new("sink", sink_pad));
|
||||||
@@ -240,7 +241,7 @@ int OSSPlayer_GstInit() {
|
|||||||
|
|
||||||
// Setup playbin3 (Configure audio plugins and set user agent)
|
// Setup playbin3 (Configure audio plugins and set user agent)
|
||||||
g_object_set(playbin, "audio-filter", filter_bin, NULL);
|
g_object_set(playbin, "audio-filter", filter_bin, NULL);
|
||||||
g_signal_connect (playbin, "source-setup", G_CALLBACK(gst_playbin3_sourcesetup_callback), NULL);
|
g_signal_connect(playbin, "source-setup", G_CALLBACK(gst_playbin3_sourcesetup_callback), NULL);
|
||||||
|
|
||||||
// Add playbin3 to the pipeline
|
// Add playbin3 to the pipeline
|
||||||
gst_bin_add(GST_BIN(pipeline), playbin);
|
gst_bin_add(GST_BIN(pipeline), playbin);
|
||||||
@@ -248,6 +249,9 @@ int OSSPlayer_GstInit() {
|
|||||||
// Initialize in-volume (Volume before the audio reaches the plugins)
|
// Initialize in-volume (Volume before the audio reaches the plugins)
|
||||||
g_object_set(in_volume, "volume", 0.175, NULL);
|
g_object_set(in_volume, "volume", 0.175, NULL);
|
||||||
|
|
||||||
|
// Initialize out-volume (Volume after the audio plugins)
|
||||||
|
g_object_set(out_volume, "volume", 1.00, NULL);
|
||||||
|
|
||||||
// Initialize equalizer
|
// Initialize equalizer
|
||||||
if (configObj->audio_equalizer_enable) {
|
if (configObj->audio_equalizer_enable) {
|
||||||
printf("Initializing %d equalizer bands...\n", configObj->audio_equalizer_graphCount);
|
printf("Initializing %d equalizer bands...\n", configObj->audio_equalizer_graphCount);
|
||||||
@@ -296,7 +300,7 @@ int OSSPlayer_GstInit() {
|
|||||||
g_object_set(equalizer, fl_name, freq, NULL);
|
g_object_set(equalizer, fl_name, freq, NULL);
|
||||||
g_object_set(equalizer, fr_name, freq, NULL);
|
g_object_set(equalizer, fr_name, freq, NULL);
|
||||||
} else {
|
} else {
|
||||||
printf("EQ band %d - F: %.2f / G: %.2f / Q: 4.36\n", i + 1, (float)configObj->audio_equalizer_graph[i].frequency, gain);
|
printf("EQ band %d - F: %.2f(Nfp) / G: %.2f / Q: 4.36\n", i + 1, (float)configObj->audio_equalizer_graph[i].frequency, gain);
|
||||||
g_object_set(equalizer, fl_name, (float)configObj->audio_equalizer_graph[i].frequency, NULL);
|
g_object_set(equalizer, fl_name, (float)configObj->audio_equalizer_graph[i].frequency, NULL);
|
||||||
g_object_set(equalizer, fr_name, (float)configObj->audio_equalizer_graph[i].frequency, NULL);
|
g_object_set(equalizer, fr_name, (float)configObj->audio_equalizer_graph[i].frequency, NULL);
|
||||||
}
|
}
|
||||||
@@ -315,9 +319,11 @@ int OSSPlayer_GstInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize pitch
|
// Initialize pitch
|
||||||
|
if (configObj->audio_pitch_enable) {
|
||||||
|
float scaleFactor = OSSPlayer_CentsToPSF(configObj->audio_pitch_cents);
|
||||||
|
printf("Pitch Cents: %.2f, Scale factor: %.6f\n", configObj->audio_pitch_cents, scaleFactor);
|
||||||
|
g_object_set(pitch, "pitch", scaleFactor, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize reverb
|
// Initialize reverb
|
||||||
}
|
}
|
||||||
@@ -348,6 +354,7 @@ char* OSSPlayer_QueuePopFront() {
|
|||||||
/*
|
/*
|
||||||
* Gstreamer Element Control Functions
|
* Gstreamer Element Control Functions
|
||||||
*/
|
*/
|
||||||
|
// TODO: Consolidate volume functions?
|
||||||
float OSSPlayer_GstECont_InVolume_Get() {
|
float OSSPlayer_GstECont_InVolume_Get() {
|
||||||
gdouble vol;
|
gdouble vol;
|
||||||
g_object_get(in_volume, "volume", &vol, NULL);
|
g_object_get(in_volume, "volume", &vol, NULL);
|
||||||
@@ -358,6 +365,25 @@ void OSSPlayer_GstECont_InVolume_set(float val) {
|
|||||||
g_object_set(in_volume, "volume", val, NULL);
|
g_object_set(in_volume, "volume", val, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float OSSPlayer_GstECont_OutVolume_Get() {
|
||||||
|
gdouble vol;
|
||||||
|
g_object_get(out_volume, "volume", &vol, NULL);
|
||||||
|
return (float)vol;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSSPlayer_GstECont_OutVolume_set(float val) {
|
||||||
|
g_object_set(out_volume, "volume", val, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
float OSSPlayer_GstECont_Pitch_Get() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSSPlayer_GstECont_Pitch_Set(float cents) {
|
||||||
|
float psf = OSSPlayer_CentsToPSF(cents);
|
||||||
|
g_object_set(pitch, "pitch", psf, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Utility Functions
|
* Utility Functions
|
||||||
*/
|
*/
|
||||||
@@ -370,3 +396,9 @@ float OSSPlayer_PitchFollow(float freq, float semitone) {
|
|||||||
// Calculate new EQ frequency from semitone adjustment
|
// Calculate new EQ frequency from semitone adjustment
|
||||||
return freq * pow(2.0, semitone / 12.0);
|
return freq * pow(2.0, semitone / 12.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float OSSPlayer_CentsToPSF(float cents) {
|
||||||
|
// Convert Cents to a Pitch Scale Factor
|
||||||
|
float semitone = cents / 100.0;
|
||||||
|
return pow(2, (semitone / 12.0f));
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,9 +19,14 @@ char* OSSPlayer_QueuePopFront();
|
|||||||
|
|
||||||
float OSSPlayer_GstECont_InVolume_Get();
|
float OSSPlayer_GstECont_InVolume_Get();
|
||||||
void OSSPlayer_GstECont_InVolume_set(float val);
|
void OSSPlayer_GstECont_InVolume_set(float val);
|
||||||
|
float OSSPlayer_GstECont_OutVolume_Get();
|
||||||
|
void OSSPlayer_GstECont_OutVolume_set(float val);
|
||||||
|
float OSSPlayer_GstECont_Pitch_Get();
|
||||||
|
void OSSPlayer_GstECont_Pitch_Set(float cents);
|
||||||
|
|
||||||
float OSSPlayer_DbLinMul(float db);
|
float OSSPlayer_DbLinMul(float db);
|
||||||
float OSSPlayer_PitchFollow(float freq, float semitone);
|
float OSSPlayer_PitchFollow(float freq, float semitone);
|
||||||
|
float OSSPlayer_CentsToPSF(float cents);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user