OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [m68k/] [amiga/] [amisound.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1623 jcastillo
/*
2
 * linux/amiga/amisound.c
3
 *
4
 * amiga sound driver for 680x0 Linux
5
 *
6
 * This file is subject to the terms and conditions of the GNU General Public
7
 * License.  See the file COPYING in the main directory of this archive
8
 * for more details.
9
 */
10
 
11
#include <linux/sched.h>
12
#include <linux/timer.h>
13
 
14
#include <asm/system.h>
15
#include <asm/amigahw.h>
16
#include <asm/bootinfo.h>
17
 
18
static u_short *snd_data = NULL;
19
static const signed char sine_data[] = {
20
        0,  39,  75,  103,  121,  127,  121,  103,  75,  39,
21
        0, -39, -75, -103, -121, -127, -121, -103, -75, -39
22
};
23
#define DATA_SIZE       (sizeof(sine_data)/sizeof(sine_data[0]))
24
 
25
    /*
26
     * The minimum period for audio may be modified by the frame buffer
27
     * device since it depends on htotal (for OCS/ECS/AGA)
28
     */
29
 
30
volatile u_short amiga_audio_min_period = 124;  /* Default for pre-OCS */
31
 
32
#define MAX_PERIOD      (65535)
33
 
34
 
35
    /*
36
     *  Current period (set by dmasound.c)
37
     */
38
 
39
u_short amiga_audio_period = MAX_PERIOD;
40
 
41
static u_long clock_constant;
42
 
43
static void init_sound(void)
44
{
45
        snd_data = amiga_chip_alloc(sizeof(sine_data));
46
        if (!snd_data) {
47
                printk (KERN_CRIT "amiga init_sound: failed to allocate chipmem\n");
48
                return;
49
        }
50
        memcpy (snd_data, sine_data, sizeof(sine_data));
51
 
52
        /* setup divisor */
53
        clock_constant = (amiga_colorclock+DATA_SIZE/2)/DATA_SIZE;
54
}
55
 
56
static void nosound( unsigned long ignored );
57
static struct timer_list sound_timer = { NULL, NULL, 0, 0, nosound };
58
 
59
void amiga_mksound( unsigned int hz, unsigned int ticks )
60
{
61
        static int inited = 0;
62
        unsigned long flags;
63
 
64
        if (!inited) {
65
                init_sound();
66
                inited = 1;
67
        }
68
 
69
        if (!snd_data)
70
                return;
71
 
72
        save_flags(flags);
73
        cli();
74
        del_timer( &sound_timer );
75
 
76
        if (hz > 20 && hz < 32767) {
77
                u_long period = (clock_constant / hz);
78
 
79
                if (period < amiga_audio_min_period)
80
                        period = amiga_audio_min_period;
81
                if (period > MAX_PERIOD)
82
                        period = MAX_PERIOD;
83
 
84
                /* setup pointer to data, period, length and volume */
85
                custom.aud[2].audlc = snd_data;
86
                custom.aud[2].audlen = sizeof(sine_data)/2;
87
                custom.aud[2].audper = (u_short)period;
88
                custom.aud[2].audvol = 64; /* maxvol */
89
 
90
                if (ticks) {
91
                        sound_timer.expires = jiffies + ticks;
92
                        add_timer( &sound_timer );
93
                }
94
 
95
                /* turn on DMA for audio channel 2 */
96
                custom.dmacon = DMAF_SETCLR | DMAF_AUD2;
97
 
98
                restore_flags(flags);
99
                return;
100
        } else {
101
                nosound( 0 );
102
                restore_flags(flags);
103
                return;
104
        }
105
}
106
 
107
 
108
static void nosound( unsigned long ignored )
109
{
110
        /* turn off DMA for audio channel 2 */
111
        custom.dmacon = DMAF_AUD2;
112
        /* restore period to previous value after beeping */
113
        custom.aud[2].audper = amiga_audio_period;
114
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.