etrax should not select foxboard-utils by default as the package is now in the packag...
[openwrt/staging/chunkeey.git] / package / fonera-mp3 / src / lib / mp3_common.c
1 /*
2 * FOXMP3
3 * Copyright (c) 2006 acmesystems.it - john@acmesystems.it
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
18 *
19 * Feedback, Bugs... info@acmesystems.it
20 *
21 */
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <sys/ioctl.h>
27 #include <fcntl.h>
28
29 #include "mp3.h"
30
31 static int mp3_fd;
32 static int mp3_frequency_val = CRYSTAL12288;
33 unsigned int volume = 0x3030;
34
35 int mp3_open_port(unsigned char *port_name){
36 int fd;
37 if ((fd = open(port_name, O_RDWR)) < 0) {
38 printf("Error whilst opening %s\n", port_name);
39 return -1;
40 }
41 return fd;
42 };
43
44 void mp3_set_frequency(unsigned int crystal_frequency){
45 mp3_frequency_val = crystal_frequency;
46 };
47
48 int mp3_init(void){
49 mp3_fd = mp3_open_port("/dev/mp3");
50 if(mp3_fd < 1){
51 return 0;
52 };
53 ioctl(mp3_fd, IOCTL_MP3_INIT, mp3_frequency_val);
54 return 1;
55 };
56
57 void mp3_shutdown(void){
58 close(mp3_fd);
59 };
60
61 void mp3_bass(unsigned char t_freq, unsigned char t_amp,
62 unsigned char b_freq, unsigned char b_amp){
63 unsigned int val;
64 if(t_amp > 0xf){
65 t_amp = 0xf;
66 };
67 if(b_amp > 0xf){
68 b_amp = 0xf;
69 };
70 val = t_amp;
71 val <<= 4;
72 val += t_freq;
73 val <<= 4;
74 val += b_amp;
75 val <<= 4;
76 val += b_freq;
77 ioctl(mp3_fd, IOCTL_MP3_BASS, val);
78 };
79
80 void mp3_reset(void){
81 ioctl(mp3_fd, IOCTL_MP3_CLEARBUFFER, 0);
82 ioctl(mp3_fd, IOCTL_MP3_RESET, mp3_frequency_val);
83 ioctl(mp3_fd, IOCTL_MP3_SETVOLUME, volume);
84 };
85
86 unsigned char mp3_send_data_to_buffer(MP3_DATA mp3_data){
87 return write(mp3_fd, (void*)&mp3_data, sizeof(MP3_DATA));
88 };
89
90 unsigned char mp3_play(void){
91 return ioctl(mp3_fd, IOCTL_MP3_PLAY, 0);
92 };
93
94 void mp3_stop(void){
95 ioctl(mp3_fd, IOCTL_MP3_CLEARBUFFER, 0);
96 };
97
98 void mp3_beep(unsigned char freq, unsigned int ms){
99 MP3_BEEP mp3_beep_;
100 mp3_beep_.freq = freq;
101 mp3_beep_.ms = ms;
102 ioctl(mp3_fd, IOCTL_MP3_BEEP, &mp3_beep_);
103 };
104
105 void mp3_set_volume(unsigned char left, unsigned char right){
106 volume = left;
107 volume <<= 8;
108 volume += right;
109
110 ioctl(mp3_fd, IOCTL_MP3_SETVOLUME, volume);
111 };
112
113 unsigned char mp3_buffer_finished(void){
114 return ioctl(mp3_fd, IOCTL_MP3_END_REACHED, 0);
115 };
116
117 unsigned char mp3_get_audio_data(AUDIO_DATA *audio_data){
118 return ioctl(mp3_fd, IOCTL_MP3_GETAUDIODATA, audio_data);
119 };
120
121