3 * Copyright (c) 2006 acmesystems.it - john@acmesystems.it
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.
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.
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
19 * Feedback, Bugs... info@acmesystems.it
33 #define MP3_PRE_BUFFER_COUNT ((128 * 1024) / MP3_CHUNK_SIZE)
36 typedef struct _MP3_FILE
{
37 unsigned char filename
[2048];
40 unsigned char file_end_found
;
44 static MP3_FILE mp3_file
;
46 void mp3_load_id3(FILE *fp
){
47 unsigned char *buf
= malloc(1024);
49 mp3_file
.id3
->album
[0] = '\0';
50 mp3_file
.id3
->artist
[0] = '\0';
51 mp3_file
.id3
->track
[0] = '\0';
55 if( (buf
[0] == 'I') &&
58 unsigned int id3_size
;
60 unsigned int id3_version
= buf
[3];
62 id3_version
+= buf
[4];
67 id3_size
+= buf
[5 + i
];
70 if(id3_version
>>8 == 3){
71 unsigned int id3_pos
= 10;
72 unsigned int id3_tag_size
;
73 unsigned char tag_name
[5];
74 unsigned char tag_data
[257];
77 unsigned int count
= 0;
79 strncpy(tag_name
, &buf
[id3_pos
], 4);
80 id3_tag_size
= buf
[id3_pos
+ 4];
82 id3_tag_size
= buf
[id3_pos
+ 5];
84 id3_tag_size
= buf
[id3_pos
+ 6];
86 id3_tag_size
= buf
[id3_pos
+ 7];
87 if(id3_tag_size
== 0){
90 if(id3_tag_size
> 256){
91 memcpy(&tag_data
[0], &buf
[id3_pos
+ 11] , 256);
93 memcpy(&tag_data
[0], &buf
[id3_pos
+ 11] ,
95 tag_data
[id3_tag_size
-1] = '\0';
97 id3_pos
+= 10 + id3_tag_size
;
98 if(strcmp(tag_name
, "TPE1") == 0){
99 strncpy(mp3_file
.id3
->artist
, tag_data
, 255);
101 if(strcmp(tag_name
, "TALB") == 0){
102 strncpy(mp3_file
.id3
->album
, tag_data
, 255);
104 if(strcmp(tag_name
, "TIT2") == 0){
105 strncpy(mp3_file
.id3
->track
, tag_data
, 255);
107 if(id3_pos
>= id3_size
){
113 printf("ID3 tag found Version 2.%d.%d / size %d\n%s -- %s -- %s\n",
117 mp3_file
.id3
->artist
,
119 mp3_file
.id3
->track
);
121 printf("No ID3 Tag was found\n");
127 int mp3_file_setup(unsigned char *filename
, MP3_FILE_ID3
*id3
){
130 mp3_file
.file_end_found
= 0;
131 strcpy(mp3_file
.filename
, filename
);
132 mp3_file
.fd
= fopen(mp3_file
.filename
, "rb");
135 printf("error opening file %s\n", mp3_file
.filename
);
138 printf("File %s opened Ok\n", mp3_file
.filename
);
139 printf("Reading id3 tag\n");
140 mp3_load_id3(mp3_file
.fd
);
141 fseek(mp3_file
.fd
, 0, SEEK_SET
);
145 printf("Buffering MP3 Data\n");
146 mp3_file
.mp3_data
.state
= MP3_BUFFERING
;
147 for(i
= 0; i
< MP3_PRE_BUFFER_COUNT
- 1; i
++){
148 fread(mp3_file
.mp3_data
.mp3
, MP3_CHUNK_SIZE
, 1, mp3_file
.fd
);
149 mp3_file
.mp3_data
.state
= MP3_PLAYING
;
150 mp3_send_data_to_buffer(mp3_file
.mp3_data
);
153 printf("Starting to play file : %s\n", mp3_file
.filename
);
157 int mp3_file_handle(void){
158 unsigned char transmit_success
= 1;
159 if (!feof(mp3_file
.fd
)) {
160 fread(mp3_file
.mp3_data
.mp3
, MP3_CHUNK_SIZE
, 1, mp3_file
.fd
);
161 transmit_success
= 0;
162 while(!transmit_success
){
163 if(!mp3_send_data_to_buffer(mp3_file
.mp3_data
)){
165 transmit_success
= 0;
167 transmit_success
= 1;
172 if(!mp3_file
.file_end_found
){
173 mp3_file
.mp3_data
.state
= MP3_BUFFER_FINISHED
;
174 mp3_send_data_to_buffer(mp3_file
.mp3_data
);
175 printf("File end reached. Wait till kernel buffer has cleared.\n");
176 mp3_file
.file_end_found
= 1;
178 if(!mp3_buffer_finished()){
186 int mp3_file_cleanup(void){
This page took 0.05039 seconds and 5 git commands to generate.