Author: fejj
Date: 2007-08-23 11:49:44 -0400 (Thu, 23 Aug 2007)
New Revision: 84708
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/mplayer.cpp
Log:
2007-08-23 Jeffrey Stedfast <[EMAIL PROTECTED]>
* mplayer.cpp: Implemented volume/balance
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-08-23 15:40:03 UTC (rev 84707)
+++ trunk/moon/src/ChangeLog 2007-08-23 15:49:44 UTC (rev 84708)
@@ -1,3 +1,7 @@
+2007-08-23 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
+ * mplayer.cpp: Implemented volume/balance
+
2007-08-23 Sebastien Pouliot <[EMAIL PROTECTED]>
* shape.cpp: Remove unneeded (cairo_close_path) and dead (break) code
@@ -17,6 +21,10 @@
2007-08-22 Jeffrey Stedfast <[EMAIL PROTECTED]>
+ * mplayer.cpp (MediaPlayer): Init mixer variables.
+
+2007-08-22 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
* media.cpp (advance_frame): Don't bother invalidating here, we'll
do that in OnPropertyChanged() for the PositionProperty.
(OnPropertyChanged): Invalidate if Position has changed and
Modified: trunk/moon/src/mplayer.cpp
===================================================================
--- trunk/moon/src/mplayer.cpp 2007-08-23 15:40:03 UTC (rev 84707)
+++ trunk/moon/src/mplayer.cpp 2007-08-23 15:49:44 UTC (rev 84708)
@@ -80,6 +80,11 @@
snd_pcm_t *pcm;
snd_pcm_uframes_t sample_size;
+ // mixer
+ snd_mixer_t *mixer;
+ snd_mixer_elem_t *volctl;
+ long vol_min, vol_max;
+
// sync
uint64_t initial_pts;
uint64_t pts_per_frame;
@@ -113,6 +118,8 @@
static Packet *pkt_new (AVPacket *avpkt);
#define pkt_free(x) g_free (x)
+static void audio_set_channel_volumes (Audio *audio);
+
// threads
static void *audio_loop (void *data);
static void *io_loop (void *data);
@@ -145,7 +152,7 @@
audio->inleft = 0;
audio->inptr = NULL;
audio->balance = 0.0f;
- audio->volume = 0.0f;
+ audio->volume = 1.0f;
audio->muted = false;
audio->stream_count = 0;
audio->stream_id = -1;
@@ -156,6 +163,10 @@
audio->outptr = audio->outbuf;
audio->pcm = NULL;
audio->sample_size = 0;
+ audio->mixer = NULL;
+ audio->volctl = NULL;
+ audio->vol_min = 0;
+ audio->vol_max = 0;
audio->initial_pts = 0;
audio->pts_per_frame = 0;
@@ -196,6 +207,9 @@
if (audio->pcm != NULL)
snd_pcm_close (audio->pcm);
+ if (audio->mixer != NULL)
+ snd_mixer_close (audio->mixer);
+
g_async_queue_unref (audio->queue);
g_async_queue_unref (video->queue);
@@ -308,6 +322,7 @@
if (audio->pcm != NULL && audio->stream_id != -1) {
snd_pcm_uframes_t buf_size;
+ snd_mixer_elem_t *elem;
encoding = audio->stream->codec;
@@ -323,6 +338,25 @@
audio->pts_per_frame = (buf_size * 2 * 2) /
(encoding->sample_rate / 100);
target_pts = audio->initial_pts;
+
+ // open the mixer
+ snd_mixer_open (&audio->mixer, 0);
+ snd_mixer_attach (audio->mixer, "default");
+ snd_mixer_selem_register (audio->mixer, NULL, NULL);
+ snd_mixer_load (audio->mixer);
+
+ for (elem = snd_mixer_first_elem (audio->mixer); elem != NULL;
elem = snd_mixer_elem_next (elem)) {
+ if (!snd_mixer_selem_is_active (elem))
+ continue;
+
+ if (snd_mixer_selem_has_playback_volume (elem)) {
+ snd_mixer_selem_get_playback_volume_range
(elem, &audio->vol_min, &audio->vol_max);
+ audio->volctl = elem;
+ break;
+ }
+ }
+
+ audio_set_channel_volumes (audio);
}
return true;
@@ -736,32 +770,95 @@
return audio->stream_id;
}
+static void
+audio_set_channel_volume (Audio *audio, int channel, double volume)
+{
+ long vol = (long) ((audio->vol_max - audio->vol_min) * volume) +
audio->vol_min;
+
+ snd_mixer_selem_set_playback_volume (audio->volctl,
(snd_mixer_selem_channel_id_t) channel, vol);
+}
+
+static void
+audio_set_channel_volumes (Audio *audio)
+{
+ double left, right;
+ int channel;
+
+ if (!audio->mixer || !audio->volctl)
+ return;
+
+ printf ("balance = %f, volume = %f\n", audio->balance, audio->volume);
+
+ if (audio->balance < 0.0) {
+ right = (1.0 + audio->balance) * audio->volume;
+ left = audio->volume;
+ } else if (audio->balance > 0.0) {
+ left = (1.0 - audio->balance) * audio->volume;
+ right = audio->volume;
+ } else {
+ left = right = audio->volume;
+ }
+
+ for (channel = 0; channel < (int) SND_MIXER_SCHN_LAST; channel++) {
+ if (!snd_mixer_selem_has_playback_channel (audio->volctl,
(snd_mixer_selem_channel_id_t) channel))
+ continue;
+
+ switch ((snd_mixer_selem_channel_id_t) channel) {
+ case SND_MIXER_SCHN_FRONT_LEFT:
+ case SND_MIXER_SCHN_REAR_LEFT:
+ case SND_MIXER_SCHN_SIDE_LEFT:
+ printf ("setting a left channel volume\n");
+ audio_set_channel_volume (audio, channel, left);
+ break;
+ case SND_MIXER_SCHN_FRONT_RIGHT:
+ case SND_MIXER_SCHN_REAR_RIGHT:
+ case SND_MIXER_SCHN_SIDE_RIGHT:
+ printf ("setting a right channel volume\n");
+ audio_set_channel_volume (audio, channel, right);
+ break;
+ default:
+ audio_set_channel_volume (audio, channel,
audio->volume);
+ break;
+ }
+ }
+}
+
double
MediaPlayer::GetBalance ()
{
- // FIXME: implement
return audio->balance;
}
void
MediaPlayer::SetBalance (double balance)
{
- // FIXME: implement
+ if (balance < -1.0)
+ balance = -1.0;
+ else if (balance > 1.0)
+ balance = 1.0;
+
audio->balance = balance;
+
+ audio_set_channel_volumes (audio);
}
double
MediaPlayer::GetVolume ()
{
- // FIXME: implement
return audio->volume;
}
void
MediaPlayer::SetVolume (double volume)
{
- // FIXME: implement
+ if (volume < -1.0)
+ volume = -1.0;
+ else if (volume > 1.0)
+ volume = 1.0;
+
audio->volume = volume;
+
+ audio_set_channel_volumes (audio);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches