Patch: soft mixer volume
Ralf Engels <[email protected]>
| Newsgroups | gmane.comp.audio.zinf.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
the following patch cleans up some issues with soft mixer volume.
Known (old) Bugs:
UI doesn't update the volume when started. It only does this when a song
is played (only then it has a valid pmo)
The soft mixer volume is not saved. I just didn't know the best place
for this.
diff -ur zinf-compiled/base/include/prefs.def zinf/base/include/prefs.def
--- zinf-compiled/base/include/prefs.def 2003-08-09 19:48:42.000000000 +0200
+++ zinf/base/include/prefs.def 2003-08-13 18:55:59.000000000 +0200
@@ -66,6 +66,8 @@
ZINF_PREF(ShowToolbarImages,true)
ZINF_PREF(ShowToolbarTextLabels,true)
ZINF_PREF(SoftMixer,false)
+ZINF_PREF(SoftMixerLeft,85)
+ZINF_PREF(SoftMixerRight,85)
ZINF_PREF(StayOnTop, false)
ZINF_PREF(StreamBufferInterval,3)
ZINF_PREF(TextUI, "zinfcmd.ui")
diff -ur zinf-compiled/base/src/player.cpp zinf/base/src/player.cpp
--- zinf-compiled/base/src/player.cpp 2003-08-11 19:35:33.000000000 +0200
+++ zinf/base/src/player.cpp 2003-08-13 18:56:11.000000000 +0200
@@ -1568,17 +1568,25 @@
Player::
GetVolume(Event *pEvent)
{
- int32_t left = -1, right = -1;
- bool bMixer;
delete pEvent;
+
+ bool bMixer = false;
m_context->prefs->GetPrefBoolean(kSoftMixerPref, &bMixer);
- if(bMixer){
- ZinfGetVolume(left, right);
+ int32_t right = 85;
+ m_context->prefs->GetPrefInt32(kSoftMixerRightPref, &right);
+ int32_t left = right;
+ m_context->prefs->GetPrefInt32(kSoftMixerLeftPref, &left);
+
+ if(bMixer)
+ {
+ ZinfGetVolume( &left, &right);
}
- else {
+ else
+ {
if(m_pmo)
m_pmo->GetVolume(left, right);
}
+
Event *e = new VolumeEvent(INFO_VolumeInfo, left, right);
SendToUI(e);
delete e;
@@ -1592,10 +1600,13 @@
int32_t right=((VolumeEvent *) pEvent)->GetRightVolume();
bool bMixer;
m_context->prefs->GetPrefBoolean(kSoftMixerPref, &bMixer);
- if(bMixer){
- ZinfSetVolume(left, right);
+
+ if(bMixer)
+ {
+ ZinfSetVolume( left, right);
}
- else {
+ else
+ {
if(m_pmo)
m_pmo->SetVolume(left, right);
}
diff -ur zinf-compiled/base/src/preferences.cpp
zinf/base/src/preferences.cpp
--- zinf-compiled/base/src/preferences.cpp 2003-08-09 19:48:42.000000000
+0200
+++ zinf/base/src/preferences.cpp 2003-08-13 17:57:42.000000000 +0200
@@ -73,6 +73,8 @@
const char* kTimeDisplayPref = "TimeDisplay";
const char* kVolumePref = "Volume";
const char* kSoftMixerPref = "SoftMixer";
+const char* kSoftMixerLeftPref = "SoftMixerLeft";
+const char* kSoftMixerRightPref = "SoftMixerRight";
const char* kUserNamePref = "UserName";
const char* kReclaimFiletypesPref = "ReclaimFiletypes";
const char* kAskToReclaimFiletypesPref = "AskToReclaimFiletypes";
diff -ur zinf-compiled/io/include/zinfvolume.h zinf/io/include/zinfvolume.h
--- zinf-compiled/io/include/zinfvolume.h 2003-08-09 19:48:43.000000000
+0200
+++ zinf/io/include/zinfvolume.h 2003-08-13 19:24:53.000000000 +0200
@@ -5,8 +5,21 @@
#include "utility.h"
-ZINF_EXPORT void ZinfGetVolume(int32_t&, int32_t&);
-ZINF_EXPORT void ZinfSetVolume(int32_t, int32_t);
-ZINF_EXPORT void ZinfVolumize(short*,int);
+/** Returns the volume for the internal soft mixer.
+ * This function returns the volume of the soft mixer.
+ * If not set before the default value 85 is delivered.
+ * Valid values for <var>left</var> and <var>right</var> are 0 till 100.
+ */
+ZINF_EXPORT void ZinfGetVolume(int32_t* left, int32_t* right);
+
+/** Sets the value for the internal mixer.
+ */
+ZINF_EXPORT void ZinfSetVolume(int32_t left, int32_t right);
+
+/** Modifies the buffer values.
+ * This function modifies the buffer values with the set volume.
+ * Note: The volume is logarithmic (sort of)
+ */
+ZINF_EXPORT void ZinfVolumize(short* buffer, int count);
#endif
diff -ur zinf-compiled/io/src/zinfvolume.cpp zinf/io/src/zinfvolume.cpp
--- zinf-compiled/io/src/zinfvolume.cpp 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/src/zinfvolume.cpp 2003-08-13 19:25:43.000000000 +0200
@@ -1,29 +1,56 @@
#include "zinfvolume.h"
-int Left=0;
-int Right=0;
-void ZinfGetVolume(int32_t &left, int32_t &right)
+#define ZINF_DEFAULT_VOLUME 85
+
+int left = ZINF_DEFAULT_VOLUME;
+int right = ZINF_DEFAULT_VOLUME;
+
+void ZinfGetVolume(int32_t* valLeft, int32_t* valRight)
{
- if(Left == 0 && Right == 0){
- left = Left;
- right = Right;
- }
+ if( left>=0 )
+ *valLeft = left;
+
+ if( right>=0 )
+ *valRight = right;
}
-void ZinfSetVolume(int32_t left, int32_t right)
+void ZinfSetVolume(int32_t valLeft, int32_t valRight)
{
- static int vol_scale[] = {0,1,2,4,7,12,18,26,35,45,56,69,75,87,100
};
- Right = vol_scale[(int)(14*((double)right/100))];
- Left = vol_scale[(int)(14*((double)left/100))];
+ if( valLeft>=0 && valLeft<=100 )
+ left = valLeft;
+
+ if( valRight>=0 && valRight<=100 )
+ right = valRight;
}
void ZinfVolumize(short *data, int DataSize)
{
- if(Right == -1) Right = Left;
- for (int i=0; i < DataSize << 1; i+=8) {
- int v=(int) ((*(data) * Left) / 100);
- *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
- v=(int) ((*(data) * Right) / 100);
- *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
+ static int vol_scale[] = {0,1,2,4,7,12,18,26,35,45,56,69,75,87,100 };
+
+ int realRight;
+
+ if( right<=0 )
+ realRight = 0;
+ else if( right>=100 )
+ realRight = 100;
+ else
+ realRight = vol_scale[(int)(14.0*((double)right/100))];
+
+
+ int realLeft;
+
+ if( left<=0 )
+ realLeft = 0;
+ else if( left>=100 )
+ realLeft = 100;
+ else
+ realLeft = vol_scale[(int)(14.0*((double)left/100))];
+
+ for (int i=0; i < DataSize << 1; i+=8) {
+ int v;
+ v=(int) ((*(data) * realLeft) / 100);
+ *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
+ v=(int) ((*(data) * realRight) / 100);
+ *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
}
}
zinf-volume1.diff
(text/plain, 5.9 KB)
diff -ur zinf-compiled/base/include/prefs.def zinf/base/include/prefs.def
--- zinf-compiled/base/include/prefs.def 2003-08-09 19:48:42.000000000 +0200
+++ zinf/base/include/prefs.def 2003-08-13 18:55:59.000000000 +0200
@@ -66,6 +66,8 @@
ZINF_PREF(ShowToolbarImages,true)
ZINF_PREF(ShowToolbarTextLabels,true)
ZINF_PREF(SoftMixer,false)
+ZINF_PREF(SoftMixerLeft,85)
+ZINF_PREF(SoftMixerRight,85)
ZINF_PREF(StayOnTop, false)
ZINF_PREF(StreamBufferInterval,3)
ZINF_PREF(TextUI, "zinfcmd.ui")
diff -ur zinf-compiled/base/src/player.cpp zinf/base/src/player.cpp
--- zinf-compiled/base/src/player.cpp 2003-08-11 19:35:33.000000000 +0200
+++ zinf/base/src/player.cpp 2003-08-13 18:56:11.000000000 +0200
@@ -1568,17 +1568,25 @@
Player::
GetVolume(Event *pEvent)
{
- int32_t left = -1, right = -1;
- bool bMixer;
delete pEvent;
+
+ bool bMixer = false;
m_context->prefs->GetPrefBoolean(kSoftMixerPref, &bMixer);
- if(bMixer){
- ZinfGetVolume(left, right);
+ int32_t right = 85;
+ m_context->prefs->GetPrefInt32(kSoftMixerRightPref, &right);
+ int32_t left = right;
+ m_context->prefs->GetPrefInt32(kSoftMixerLeftPref, &left);
+
+ if(bMixer)
+ {
+ ZinfGetVolume( &left, &right);
}
- else {
+ else
+ {
if(m_pmo)
m_pmo->GetVolume(left, right);
}
+
Event *e = new VolumeEvent(INFO_VolumeInfo, left, right);
SendToUI(e);
delete e;
@@ -1592,10 +1600,13 @@
int32_t right=((VolumeEvent *) pEvent)->GetRightVolume();
bool bMixer;
m_context->prefs->GetPrefBoolean(kSoftMixerPref, &bMixer);
- if(bMixer){
- ZinfSetVolume(left, right);
+
+ if(bMixer)
+ {
+ ZinfSetVolume( left, right);
}
- else {
+ else
+ {
if(m_pmo)
m_pmo->SetVolume(left, right);
}
diff -ur zinf-compiled/base/src/preferences.cpp zinf/base/src/preferences.cpp
--- zinf-compiled/base/src/preferences.cpp 2003-08-09 19:48:42.000000000 +0200
+++ zinf/base/src/preferences.cpp 2003-08-13 17:57:42.000000000 +0200
@@ -73,6 +73,8 @@
const char* kTimeDisplayPref = "TimeDisplay";
const char* kVolumePref = "Volume";
const char* kSoftMixerPref = "SoftMixer";
+const char* kSoftMixerLeftPref = "SoftMixerLeft";
+const char* kSoftMixerRightPref = "SoftMixerRight";
const char* kUserNamePref = "UserName";
const char* kReclaimFiletypesPref = "ReclaimFiletypes";
const char* kAskToReclaimFiletypesPref = "AskToReclaimFiletypes";
diff -ur zinf-compiled/io/include/zinfvolume.h zinf/io/include/zinfvolume.h
--- zinf-compiled/io/include/zinfvolume.h 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/include/zinfvolume.h 2003-08-13 19:24:53.000000000 +0200
@@ -5,8 +5,21 @@
#include "utility.h"
-ZINF_EXPORT void ZinfGetVolume(int32_t&, int32_t&);
-ZINF_EXPORT void ZinfSetVolume(int32_t, int32_t);
-ZINF_EXPORT void ZinfVolumize(short*,int);
+/** Returns the volume for the internal soft mixer.
+ * This function returns the volume of the soft mixer.
+ * If not set before the default value 85 is delivered.
+ * Valid values for <var>left</var> and <var>right</var> are 0 till 100.
+ */
+ZINF_EXPORT void ZinfGetVolume(int32_t* left, int32_t* right);
+
+/** Sets the value for the internal mixer.
+ */
+ZINF_EXPORT void ZinfSetVolume(int32_t left, int32_t right);
+
+/** Modifies the buffer values.
+ * This function modifies the buffer values with the set volume.
+ * Note: The volume is logarithmic (sort of)
+ */
+ZINF_EXPORT void ZinfVolumize(short* buffer, int count);
#endif
diff -ur zinf-compiled/io/src/zinfvolume.cpp zinf/io/src/zinfvolume.cpp
--- zinf-compiled/io/src/zinfvolume.cpp 2003-08-09 19:48:43.000000000 +0200
+++ zinf/io/src/zinfvolume.cpp 2003-08-13 19:25:43.000000000 +0200
@@ -1,29 +1,56 @@
#include "zinfvolume.h"
-int Left=0;
-int Right=0;
-void ZinfGetVolume(int32_t &left, int32_t &right)
+#define ZINF_DEFAULT_VOLUME 85
+
+int left = ZINF_DEFAULT_VOLUME;
+int right = ZINF_DEFAULT_VOLUME;
+
+void ZinfGetVolume(int32_t* valLeft, int32_t* valRight)
{
- if(Left == 0 && Right == 0){
- left = Left;
- right = Right;
- }
+ if( left>=0 )
+ *valLeft = left;
+
+ if( right>=0 )
+ *valRight = right;
}
-void ZinfSetVolume(int32_t left, int32_t right)
+void ZinfSetVolume(int32_t valLeft, int32_t valRight)
{
- static int vol_scale[] = {0,1,2,4,7,12,18,26,35,45,56,69,75,87,100 };
- Right = vol_scale[(int)(14*((double)right/100))];
- Left = vol_scale[(int)(14*((double)left/100))];
+ if( valLeft>=0 && valLeft<=100 )
+ left = valLeft;
+
+ if( valRight>=0 && valRight<=100 )
+ right = valRight;
}
void ZinfVolumize(short *data, int DataSize)
{
- if(Right == -1) Right = Left;
- for (int i=0; i < DataSize << 1; i+=8) {
- int v=(int) ((*(data) * Left) / 100);
- *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
- v=(int) ((*(data) * Right) / 100);
- *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
+ static int vol_scale[] = {0,1,2,4,7,12,18,26,35,45,56,69,75,87,100 };
+
+ int realRight;
+
+ if( right<=0 )
+ realRight = 0;
+ else if( right>=100 )
+ realRight = 100;
+ else
+ realRight = vol_scale[(int)(14.0*((double)right/100))];
+
+
+ int realLeft;
+
+ if( left<=0 )
+ realLeft = 0;
+ else if( left>=100 )
+ realLeft = 100;
+ else
+ realLeft = vol_scale[(int)(14.0*((double)left/100))];
+
+ for (int i=0; i < DataSize << 1; i+=8) {
+ int v;
+ v=(int) ((*(data) * realLeft) / 100);
+ *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
+ v=(int) ((*(data) * realRight) / 100);
+ *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
}
}