summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2009-08-20 20:46:48 +0200
committerGravatar waker <wakeroid@gmail.com>2009-08-20 20:46:48 +0200
commit429f0b3d8b051fd992166fcfcd4a38e9aa763833 (patch)
tree8fbb96fdcf91c0c698149d1b11d27025a5d9ab58
parent158b462b06d4e39d4e126a09e5404ec24d496f24 (diff)
fixed volume control
-rw-r--r--.vimrc2
-rw-r--r--Jamfile11
-rw-r--r--Makefile.am1
-rw-r--r--callbacks.c39
-rw-r--r--main.c22
-rw-r--r--palsa.c14
-rw-r--r--palsa.h6
-rw-r--r--playback.h3
-rw-r--r--sid/sidplay-libs-2.1.0/Jamfile17
-rw-r--r--volume.c57
-rw-r--r--volume.h40
11 files changed, 150 insertions, 62 deletions
diff --git a/.vimrc b/.vimrc
index 357bbfbd..fab5ba93 100644
--- a/.vimrc
+++ b/.vimrc
@@ -1,2 +1,2 @@
-"set makeprg=jam
+set makeprg=jam
diff --git a/Jamfile b/Jamfile
index ae17488a..5a2e9a1c 100644
--- a/Jamfile
+++ b/Jamfile
@@ -1,13 +1,12 @@
SubDir ROOT ;
SubInclude ROOT gme Game_Music_Emu-0.5.2 gme ;
SubInclude ROOT dumb ;
-SubInclude ROOT libsidplay2 sidplay-libs-2.1.0 ;
+SubInclude ROOT sid sidplay-libs-2.1.0 ;
SubDir ROOT ;
+CCFLAGS += -DPREFIX=\\\"/usr\\\" ;
CCFLAGS += -DVERSION=\\\"0.1.0\\\" ;
CCFLAGS += -D_GNU_SOURCE ;
CCFLAGS += -std=c99 ;
-#CCFLAGS += -DUSE_SDL ;
-# CCFLAGS += -D_REENTRANT ;
OPTIM += -O2 ;
OPTIM += -g ;
@@ -18,12 +17,12 @@ HDRS += /usr/lib/glib-2.0/include ;
HDRS += /usr/include/atk-1.0 ;
HDRS += /usr/include/pango-1.0 ;
HDRS += /usr/include/cairo ;
-HDRS += $(ROOT)/libsidplay2/sidplay-libs-2.1.0/libsidplay/include ;
-HDRS += $(ROOT)/libsidplay2/sidplay-libs-2.1.0/builders/resid-builder/include ;
+HDRS += $(ROOT)/sid/sidplay-libs-2.1.0/libsidplay/include ;
+HDRS += $(ROOT)/sid/sidplay-libs-2.1.0/builders/resid-builder/include ;
HDRS += $(ROOT)/gme/Game_Music_Emu-0.5.2 ;
Main deadbeef :
- codec.c cvorbis.c cmp3.c cgme.c cdumb.c cflac.c csid.cpp playlist.c palsa.c streamer.c md5/md5.c main.c support.c interface.c callbacks.c threading_pthread.c messagepump.c gtkplaylist.c search.c progress.c conf.c ;
+ codec.c cvorbis.c cmp3.c cgme.c cdumb.c cflac.c csid.cpp playlist.c palsa.c streamer.c md5/md5.c main.c support.c interface.c callbacks.c threading_pthread.c messagepump.c gtkplaylist.c search.c progress.c conf.c volume.c ;
LINKLIBS on deadbeef = -lm -lvorbis -logg -lvorbisfile -lmad -lFLAC -lsamplerate -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lgthread-2.0 -lstdc++ -lasound ;
diff --git a/Makefile.am b/Makefile.am
index 1eefbbdc..7dd067fb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,7 @@ deadbeef_SOURCES = callbacks.c csid.cpp interface.c playlist.c streamer.c\
cdumb.h cmp3.h gtkplaylist.h palsa.h threading.h\
cflac.h codec.h csid.h interface.h playback.h search.h\
cgme.h common.h cvorbis.h messagepump.h playlist.h streamer.h\
+ volume.c volume.h\
md5/md5.h md5/md5_loc.h
diff --git a/callbacks.c b/callbacks.c
index cc88b0cb..62efd595 100644
--- a/callbacks.c
+++ b/callbacks.c
@@ -41,6 +41,7 @@
#include "search.h"
#include "streamer.h"
#include "progress.h"
+#include "volume.h"
#include "cvorbis.h"
#include "cdumb.h"
@@ -993,7 +994,7 @@ volumebar_draw (GtkWidget *widget) {
}
int n = widget->allocation.width / 4;
- float vol = p_get_volume () * n;
+ float vol = (60.f + volume_get_db ()) / 60.f * n;
float h = 16;
for (int i = 0; i < n; i++) {
float iy = (float)i + 3;
@@ -1045,14 +1046,14 @@ on_volumebar_motion_notify_event (GtkWidget *widget,
gpointer user_data)
{
if (event->state & GDK_BUTTON1_MASK) {
- float volume = event->x / widget->allocation.width;
- if (volume < 0) {
+ float volume = event->x / widget->allocation.width * 60.f - 60.f;
+ if (volume > 0) {
volume = 0;
}
- if (volume > 1) {
- volume = 1;
+ if (volume < -60) {
+ volume = -60;
}
- p_set_volume (volume);
+ volume_set_db (volume);
volumebar_draw (widget);
volumebar_expose (widget, 0, 0, widget->allocation.width, widget->allocation.height);
}
@@ -1064,14 +1065,14 @@ on_volumebar_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
- float volume = event->x / widget->allocation.width;
- if (volume < 0) {
- volume = 0;
+ float volume = event->x / widget->allocation.width * 60.f - 60.f;
+ if (volume < -60) {
+ volume = -60;
}
- if (volume > 1) {
- volume = 1;
+ if (volume > 0) {
+ volume = 0;
}
- p_set_volume (volume);
+ volume_set_db (volume);
volumebar_draw (widget);
volumebar_expose (widget, 0, 0, widget->allocation.width, widget->allocation.height);
return FALSE;
@@ -1107,20 +1108,20 @@ on_volumebar_scroll_event (GtkWidget *widget,
GdkEventScroll *event,
gpointer user_data)
{
- float vol = p_get_volume ();
+ float vol = volume_get_db ();
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT) {
- vol += 0.1f;
+ vol += 1;
}
else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT) {
- vol -= 0.1f;
+ vol -= 1;
}
- if (vol < 0) {
+ if (vol > 0) {
vol = 0;
}
- else if (vol > 1) {
- vol = 1;
+ else if (vol < -60) {
+ vol = -60;
}
- p_set_volume (vol);
+ volume_set_db (vol);
GtkWidget *volumebar = lookup_widget (mainwin, "volumebar");
volumebar_draw (volumebar);
volumebar_expose (volumebar, 0, 0, volumebar->allocation.width, volumebar->allocation.height);
diff --git a/main.c b/main.c
index f7d3494e..73ef8ff1 100644
--- a/main.c
+++ b/main.c
@@ -27,6 +27,9 @@
#include <sys/un.h>
#include <sys/fcntl.h>
#include <sys/errno.h>
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
#include "interface.h"
#include "callbacks.h"
#include "support.h"
@@ -42,6 +45,11 @@
#include "search.h"
#include "progress.h"
#include "conf.h"
+#include "volume.h"
+
+#ifndef PREFIX
+#error PREFIX must be defined
+#endif
// some common global variables
char confdir[1024]; // $HOME/.config
@@ -385,20 +393,20 @@ on_trayicon_scroll_event (GtkWidget *widget,
GdkEventScroll *event,
gpointer user_data)
{
- float vol = p_get_volume ();
+ float vol = volume_get_db ();
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT) {
- vol += 0.1f;
+ vol += 1;
}
else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT) {
- vol -= 0.1f;
+ vol -= 1;
}
- if (vol < 0) {
+ if (vol > 0) {
vol = 0;
}
- else if (vol > 1) {
- vol = 1;
+ else if (vol < -60) {
+ vol = -60;
}
- p_set_volume (vol);
+ volume_set_db (vol);
GtkWidget *volumebar = lookup_widget (mainwin, "volumebar");
volumebar_draw (volumebar);
volumebar_expose (volumebar, 0, 0, volumebar->allocation.width, volumebar->allocation.height);
diff --git a/palsa.c b/palsa.c
index 1ebc81fd..02acfadd 100644
--- a/palsa.c
+++ b/palsa.c
@@ -23,6 +23,7 @@
#include "threading.h"
#include "streamer.h"
#include "conf.h"
+#include "volume.h"
static inline void
le_int16 (int16_t in, char *out) {
@@ -39,7 +40,6 @@ le_int16 (int16_t in, char *out) {
static snd_pcm_t *audio;
static int16_t *samplebuffer;
static int bufsize = 4096*4;
-static float volume = 1;
static int alsa_terminate;
static int alsa_rate = 48000;
static int state; // 0 = stopped, 1 = playing, 2 = pause
@@ -269,16 +269,6 @@ palsa_unpause (void) {
return 0;
}
-void
-palsa_set_volume (float vol) {
- volume = vol;
-}
-
-float
-palsa_get_volume (void) {
- return volume;
-}
-
int
palsa_get_rate (void) {
return alsa_rate;
@@ -347,7 +337,7 @@ palsa_callback (char *stream, int len) {
return;
}
int bytesread = streamer_read (stream, len);
- int ivolume = volume * 1000;
+ int ivolume = volume_get_amp () * 1000;
for (int i = 0; i < bytesread/2; i++) {
int16_t sample = (int16_t)(((int32_t)(((int16_t*)stream)[i])) * ivolume / 1000);
le_int16 (sample, (char*)&(((int16_t*)stream)[i]));
diff --git a/palsa.h b/palsa.h
index 61a9af2d..a544790c 100644
--- a/palsa.h
+++ b/palsa.h
@@ -42,12 +42,6 @@ palsa_pause (void);
int
palsa_unpause (void);
-void
-palsa_set_volume (float vol);
-
-float
-palsa_get_volume (void);
-
int
palsa_get_rate (void);
diff --git a/playback.h b/playback.h
index c14c6de0..2a4ce722 100644
--- a/playback.h
+++ b/playback.h
@@ -27,7 +27,6 @@
#define p_ispaused psdl_ispaused
#define p_pause psdl_pause
#define p_unpause psdl_unpause
-#define p_set_volume psdl_set_volume
#define p_get_rate psdl_get_rate
#else
#include "palsa.h"
@@ -38,8 +37,6 @@
#define p_ispaused palsa_ispaused
#define p_pause palsa_pause
#define p_unpause palsa_unpause
-#define p_set_volume palsa_set_volume
-#define p_get_volume palsa_get_volume
#define p_get_rate palsa_get_rate
#define p_isstopped palsa_isstopped
#endif
diff --git a/sid/sidplay-libs-2.1.0/Jamfile b/sid/sidplay-libs-2.1.0/Jamfile
index 2244829d..1f270819 100644
--- a/sid/sidplay-libs-2.1.0/Jamfile
+++ b/sid/sidplay-libs-2.1.0/Jamfile
@@ -1,13 +1,14 @@
-SubDir ROOT libsidplay2 sidplay-libs-2.1.0 ;
+SubDir ROOT sid sidplay-libs-2.1.0 ;
C++FLAGS += -DHAVE_UNIX ;
C++FLAGS += -DVERSION=\\\"2.1.0\\\" ;
-SubDirHdrs $(ROOT)/libsidplay2/sidplay-libs-2.1.0 ;
-SubDirHdrs $(ROOT)/libsidplay2/sidplay-libs-2.1.0/libsidplay ;
-SubDirHdrs $(ROOT)/libsidplay2/sidplay-libs-2.1.0/libsidplay/include ;
-SubDirHdrs $(ROOT)/libsidplay2/sidplay-libs-2.1.0/libsidplay/include/sidplay ;
-SubDirHdrs $(ROOT)/libsidplay2/sidplay-libs-2.1.0/libsidutils/include/sidplay/utils ;
-SubDirHdrs $(ROOT)/libsidplay2/sidplay-libs-2.1.0/builders/resid-builder/include/sidplay/builders ;
-SubDirHdrs $(ROOT)/libsidplay2/sidplay-libs-2.1.0/builders/resid-builder/include/ ;
+C++FLAGS += -Wno-deprecated ;
+SubDirHdrs $(ROOT)/sid/sidplay-libs-2.1.0 ;
+SubDirHdrs $(ROOT)/sid/sidplay-libs-2.1.0/libsidplay ;
+SubDirHdrs $(ROOT)/sid/sidplay-libs-2.1.0/libsidplay/include ;
+SubDirHdrs $(ROOT)/sid/sidplay-libs-2.1.0/libsidplay/include/sidplay ;
+SubDirHdrs $(ROOT)/sid/sidplay-libs-2.1.0/libsidutils/include/sidplay/utils ;
+SubDirHdrs $(ROOT)/sid/sidplay-libs-2.1.0/builders/resid-builder/include/sidplay/builders ;
+SubDirHdrs $(ROOT)/sid/sidplay-libs-2.1.0/builders/resid-builder/include/ ;
Library libsidplay :
libsidutils/src/SidDatabase.cpp
diff --git a/volume.c b/volume.c
new file mode 100644
index 00000000..85a9a125
--- /dev/null
+++ b/volume.c
@@ -0,0 +1,57 @@
+/*
+ DeaDBeeF - ultimate music player for GNU/Linux systems with X11
+ Copyright (C) 2009 Alexey Yakovenko
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+#include <math.h>
+#include <stdio.h>
+#include "volume.h"
+
+static float volume_db = 0; // in dB
+static float volume_amp = 1; // amplitude [0..1]
+
+void
+volume_set_db (float dB) {
+ volume_db = dB;
+ volume_amp = dB > -60 ? db_to_amp (dB) : 0;
+}
+
+float
+volume_get_db (void) {
+ return volume_db;
+}
+
+void
+volume_set_amp (float amp) {
+ volume_amp = amp;
+ volume_db = amp > 0 ? amp_to_db (amp) : -60.f;
+}
+
+float
+volume_get_amp (void) {
+ return volume_amp;
+}
+
+float
+db_to_amp (float dB) {
+ return pow (10, dB/20.f);
+}
+
+float
+amp_to_db (float amp) {
+ return 20*log10 (amp);
+}
+
diff --git a/volume.h b/volume.h
new file mode 100644
index 00000000..b6c2868d
--- /dev/null
+++ b/volume.h
@@ -0,0 +1,40 @@
+/*
+ DeaDBeeF - ultimate music player for GNU/Linux systems with X11
+ Copyright (C) 2009 Alexey Yakovenko
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+#ifndef __VOLUME_H
+#define __VOLUME_H
+
+void
+volume_set_db (float dB);
+
+float
+volume_get_db (void);
+
+void
+volume_set_amp (float amp);
+
+float
+volume_get_amp (void);
+
+float
+db_to_amp (float dB);
+
+float
+amp_to_db (float amp);
+
+#endif // __VOLUME_H