00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00052 #include <dev/board.h>
00053 #include <dev/vs1001k.h>
00054 #include <dev/debug.h>
00055 #include <dev/urom.h>
00056
00057 #include <sys/version.h>
00058 #include <sys/heap.h>
00059 #include <sys/event.h>
00060 #include <sys/timer.h>
00061 #include <sys/thread.h>
00062 #include <sys/bankmem.h>
00063
00064 #include <stdlib.h>
00065 #include <string.h>
00066 #include <stdio.h>
00067 #include <io.h>
00068 #include <fcntl.h>
00069 #include <errno.h>
00070
00071 static int PlayMp3File(char *path);
00072
00096 int main(void)
00097 {
00098
00099 u_long baud = 115200;
00100
00101
00102
00103
00104 NutRegisterDevice(&devUrom, 0, 0);
00105 NutRegisterDevice(&DEV_DEBUG, 0, 0);
00106
00107
00108
00109
00110 freopen(DEV_DEBUG_NAME, "w", stdout);
00111 _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00112
00113
00114
00115
00116 printf("\n\nPlay MP3 files on Nut/OS %s\n", NutVersionString());
00117
00118 #if defined(__AVR__)
00119
00120
00121
00122
00123
00124 if (NutSegBufInit(8192) == 0) {
00125 puts("NutSegBufInit: Fatal error");
00126 }
00127
00128
00129
00130
00131 if (VsPlayerInit() || VsPlayerReset(0)) {
00132 puts("VsPlayer: Fatal error");
00133 }
00134
00135
00136
00137
00138
00139
00140 for (;;) {
00141 VsSetVolume(0, 254);
00142 PlayMp3File("UROM:sound1a.mp3");
00143 NutSleep(1000);
00144
00145 VsSetVolume(0, 0);
00146 PlayMp3File("UROM:sound2a.mp3");
00147 NutSleep(1000);
00148
00149 VsSetVolume(254, 0);
00150 PlayMp3File("UROM:sound3a.mp3");
00151 NutSleep(1000);
00152
00153 VsSetVolume(0, 0);
00154 PlayMp3File("UROM:sound4a.mp3");
00155 NutSleep(1000);
00156 }
00157 #else
00158 for (;;);
00159 #endif
00160 }
00161
00162 #if defined(__AVR__)
00163
00164
00165
00166
00167
00168
00169
00170
00171 static int PlayMp3File(char *path)
00172 {
00173 int fd;
00174 size_t rbytes;
00175 u_char *mp3buf;
00176 int got;
00177 u_char ief;
00178
00179
00180
00181
00182 printf("Play %s: ", path);
00183 if ((fd = _open(path, _O_RDONLY | _O_BINARY)) == -1) {
00184 printf("Error %d\n", errno);
00185 return -1;
00186 }
00187 puts("OK");
00188
00189
00190
00191
00192 printf("[B.RST]");
00193 ief = VsPlayerInterrupts(0);
00194 NutSegBufReset();
00195 VsPlayerInterrupts(ief);
00196
00197 for (;;) {
00198
00199
00200
00201 ief = VsPlayerInterrupts(0);
00202 mp3buf = NutSegBufWriteRequest(&rbytes);
00203 VsPlayerInterrupts(ief);
00204
00205
00206
00207
00208 if (rbytes) {
00209 printf("[B.RD%d]", rbytes);
00210 if ((got = _read(fd, mp3buf, rbytes)) > 0) {
00211 printf("[B.CMT%d]", got);
00212 ief = VsPlayerInterrupts(0);
00213 mp3buf = NutSegBufWriteCommit(got);
00214 VsPlayerInterrupts(ief);
00215 } else {
00216 printf("[EOF]");
00217 break;
00218 }
00219 }
00220
00221
00222
00223
00224 if (VsGetStatus() != VS_STATUS_RUNNING) {
00225 printf("[P.KICK]");
00226 VsPlayerKick();
00227 }
00228
00229
00230
00231
00232 NutThreadYield();
00233 }
00234
00235 _close(fd);
00236
00237
00238
00239
00240 printf("[P.FLUSH]");
00241 VsPlayerFlush();
00242 while (VsGetStatus() != VS_STATUS_EMPTY) {
00243 NutSleep(1);
00244 }
00245
00246
00247
00248
00249 printf("[P.RST]");
00250 VsPlayerReset(0);
00251
00252 printf("\nDone, %u bytes free\n", NutHeapAvailable());
00253 return 0;
00254 }
00255
00256 #endif