~ubuntu-branches/ubuntu/breezy/gtick/breezy

« back to all changes in this revision

Viewing changes to mixer.c

  • Committer: Bazaar Package Importer
  • Author(s): Roland Stigge
  • Date: 2005-02-20 13:24:57 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050220132457-akn7xjaplb1ev1cd
Tags: 0.3.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Gtick  -  A Gtk+ Metronome
2
 
 *
3
 
 *   mixer.c: Sound mixer code, for volume type stuff..
4
 
 *
5
 
 * Copyright (c) 1999, Alex Roberts
6
 
 *
7
 
 * This library is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Library General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2 of the License, or (at your option) any later version.
11
 
 *
12
 
 * This library is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Library General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Library General Public
18
 
 * License along with this library; if not, write to the
19
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
 * Boston, MA 02111-1307, USA.
21
 
 */
22
 
 
23
 
#include <unistd.h>
24
 
#include <sys/stat.h>
25
 
#include <sys/ioctl.h>
26
 
#include <fcntl.h>
27
 
#include <stdio.h>
28
 
#include <stdlib.h>
29
 
#ifdef FREEBSD
30
 
#include <machine/soundcard.h>
31
 
#else
32
 
#include <linux/soundcard.h>
33
 
#endif
34
 
#include <glib.h>
35
 
 
36
 
#include "gtick.h"
37
 
 
38
 
static gint mix;
39
 
static gchar devName[] = "/dev/mixer";
40
 
 
41
 
void gtInitMixer()
42
 
{
43
 
#ifdef DEBUG
44
 
        g_print ("gtInitMixer: Initialising %s..\n", devName);
45
 
#endif
46
 
        
47
 
        if ((mix = open (devName, O_RDWR, 0)) == -1)
48
 
          {
49
 
            g_error ("Couldnt open mixer device /dev/mixer\n");
50
 
            exit (1);
51
 
          }
52
 
         
53
 
}
54
 
 
55
 
void gtCloseMixer()
56
 
{
57
 
#ifdef DEBUG
58
 
        g_print ("gtCloseMixer: Closing /dev/mixer..\n");
59
 
#endif
60
 
        close (mix);
61
 
}
62
 
 
63
 
 
64
 
gint gtGetMixer()
65
 
{
66
 
        gint vol, r, l;
67
 
        
68
 
        ioctl (mix, MIXER_READ(SOUND_MIXER_PCM), &vol);
69
 
        
70
 
        l = vol & 0xff;
71
 
        r = (vol & 0xff00) >> 8;
72
 
 
73
 
#ifdef DEBUG    
74
 
        g_print ("gtGetMixer: vol=%d, l=%d, r=%d\n", vol, l, r);
75
 
#endif
76
 
        
77
 
        return (r+l)/2;
78
 
}
79
 
 
80
 
void gtSetMixer (gint vol)
81
 
{
82
 
        gint tvol;
83
 
        
84
 
        tvol = (vol << 8) + vol;
85
 
 
86
 
#ifdef DEBUG    
87
 
        g_print ("gtSetMixer: Setting mixer value: %d\n", tvol);
88
 
#endif
89
 
 
90
 
        ioctl (mix, MIXER_WRITE(SOUND_MIXER_PCM), &tvol);
91
 
}