Subversion Repositories freemyipod

Rev

Rev 715 | Rev 717 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 715 Rev 716
Line 22... Line 22...
22
 
22
 
23
 
23
 
24
#include "emcoreapp.h"
24
#include "emcoreapp.h"
25
#include "beep.h"
25
#include "beep.h"
26
 
26
 
-
 
27
struct note
-
 
28
{
27
void playsong(void *buf, size_t size);
29
    unsigned int cycles;
-
 
30
    unsigned int length;
-
 
31
};
28
 
32
 
29
static void main()
33
static void main()
30
{
34
{
31
    if (0x47324e49 != get_platform_id()) // IN2G
35
    if (0x47324e49 != get_platform_id()) // IN2G
32
    {
36
    {
Line 34... Line 38...
34
        return;
38
        return;
35
    }
39
    }
36
    
40
    
37
    size_t size;
41
    size_t size;
38
    int fd;
42
    int fd;
39
    void *buf;
43
    struct note *buf;
40
    unsigned char play;
44
    unsigned int i, count;
41
 
45
 
42
    play = 0;
-
 
43
    fd = file_open("/song.dat", O_RDONLY);
46
    fd = file_open("/song.dat", O_RDONLY);
44
    
47
    
45
    if (fd <= 0)
48
    if (fd <= 0)
46
    {
49
    {
47
        cputs(3, "Unable to open /song.dat!\n");
50
        cputs(3, "Unable to open /song.dat!\n");
Line 49... Line 52...
49
    }
52
    }
50
    
53
    
51
    cputs(3, "File opened\n");
54
    cputs(3, "File opened\n");
52
    size = filesize(fd);
55
    size = filesize(fd);
53
        
56
        
54
    if (size <= 0)
57
    if (0 == size)
55
    {
58
    {
56
        close(fd);
59
        close(fd);
57
        cputs(3, "Unable to get file size or file is empty!\n");
60
        cputs(3, "Unable to get file size or file is empty!\n");
58
        return;
61
        return;
59
    }
62
    }
Line 66... Line 69...
66
        cputs(3, "Invalid file, unable to continue!\n");
69
        cputs(3, "Invalid file, unable to continue!\n");
67
        return;
70
        return;
68
    }
71
    }
69
    
72
    
70
    buf = memalign(0x10, size);
73
    buf = memalign(0x10, size);
71
        
74
    
72
    if (!buf)
75
    if (!buf)
73
    {
76
    {
74
        close(fd);
77
        close(fd);
75
        cputs(3, "Memory allocation failed!\n");
78
        cputs(3, "Memory allocation failed!\n");
76
        return;
79
        return;
Line 85... Line 88...
85
    }
88
    }
86
    
89
    
87
    cputs(3, "Read successful\n");
90
    cputs(3, "Read successful\n");
88
    close(fd);
91
    close(fd);
89
    cputs(3, "File closed\n");
92
    cputs(3, "File closed\n");
90
    playsong(buf, size);
-
 
91
    free(buf);
-
 
92
}
-
 
93
 
-
 
94
void playsong(void *buf, size_t size) {
-
 
95
    int i;
-
 
96
    unsigned int *cycles, *lengths, count;
-
 
97
    
93
    
98
    count = size / 8;
94
    count = size / 8;
99
    cycles = malloc(count * sizeof(unsigned int));
-
 
100
    lengths = malloc(count * sizeof(unsigned int));
-
 
101
    
95
    
102
    for (i = 0; i < count; ++i)
96
    for (i = 0; i < count; ++i)
103
    {
97
    {
104
        cycles[i] = *((unsigned int *)(buf) + i + i);
-
 
105
        lengths[i] = *((unsigned int *)(buf) + i + i + 1);
-
 
106
    }
-
 
107
    
-
 
108
    for (i = 0; i < count; ++i)
-
 
109
    {
-
 
110
        if (0 == cycles[i])
98
        if (0 == buf[i].length)
111
        {
99
        {
112
            sleep(lengths[i]);
100
            sleep(buf[i].length);
113
            continue;
101
            continue;
114
        }
102
        }
115
        
103
        
116
        singlebeep(cycles[i], lengths[i]);
104
        singlebeep(buf[i].cycles, buf[i].length);
117
    }
105
    }
118
    
106
    
119
    free(lengths);
-
 
120
    free(cycles);
107
    free(buf);
121
}
108
}
122
 
109
 
123
EMCORE_APP_HEADER("Beeper", main, 127)
110
EMCORE_APP_HEADER("Beeper", main, 127)