summaryrefslogtreecommitdiffstats
path: root/mixer.c
blob: 3b7a21934c8d8ab13682929ec469405d644f6edc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

#include <string.h>
#ifndef __MINGW32__
#include <sys/ioctl.h>
#endif
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#include "config.h"
#include "mixer.h"
#include "libao2/audio_out.h"

extern ao_functions_t *audio_out;

char * mixer_device=NULL;

int muted = 0;
float mute_l = 0.0f;
float mute_r = 0.0f;

void mixer_getvolume( float *l,float *r )
{
  ao_control_vol_t vol;
  *l=0; *r=0;
  if(audio_out){
    if(CONTROL_OK != audio_out->control(AOCONTROL_GET_VOLUME,&vol))
      return;
    *r=vol.right;
    *l=vol.left;
  }
}

void mixer_setvolume( float l,float r )
{
  ao_control_vol_t vol;
  vol.right=r; vol.left=l;
  if(audio_out){
    if(CONTROL_OK != audio_out->control(AOCONTROL_SET_VOLUME,&vol))
      return;
  }
 muted=0;
}

#define MIXER_CHANGE 3

void mixer_incvolume( void )
{
 float mixer_l, mixer_r;
 mixer_getvolume( &mixer_l,&mixer_r );
 mixer_l += MIXER_CHANGE;
 if ( mixer_l > 100 ) mixer_l = 100;
 mixer_r += MIXER_CHANGE;
 if ( mixer_r > 100 ) mixer_r = 100;
 mixer_setvolume( mixer_l,mixer_r );
}

void mixer_decvolume( void )
{
 float mixer_l, mixer_r;
 mixer_getvolume( &mixer_l,&mixer_r );
 mixer_l -= MIXER_CHANGE;
 if ( mixer_l < 0 ) mixer_l = 0;
 mixer_r -= MIXER_CHANGE;
 if ( mixer_r < 0 ) mixer_r = 0;
 mixer_setvolume( mixer_l,mixer_r );
}

float mixer_getbothvolume( void )
{
 float mixer_l, mixer_r;
 mixer_getvolume( &mixer_l,&mixer_r );
 return ( mixer_l + mixer_r ) / 2;
}

void mixer_mute( void )
{
 if ( muted ) mixer_setvolume( mute_l,mute_r );
  else
   { 
    mixer_getvolume( &mute_l,&mute_r );
    mixer_setvolume( 0,0 );
    muted=1;
   }
}