-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsoundapp_demo.txt
64 lines (53 loc) · 1.75 KB
/
soundapp_demo.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <_xeneva.h>
#include <sys\_keproc.h>
#include <sys\_kefile.h>
#include <stdlib.h>
#include <sys\iocodes.h>
#include <string.h>
/*
* main -- sound app demo, note that
* here all direct xeneva related api are
* used, no third party api is used
*/
int main(int argc, char* arv[]) {
_KePrint("Sound demo \n");
/* open the sound device-file, it is in /dev directory */
int snd = _KeOpenFile("/dev/sound", FILE_OPEN_WRITE);
/* allocate an ioctl structure where required information
* will be putted */
XEFileIOControl ioctl;
memset(&ioctl, 0, sizeof(XEFileIOControl));
/* uint_1 holds the millisecond to sleep after
* one frame playback */
ioctl.uint_1 = 10;
/* most important aurora_syscall_magic number, without
* this, iocontrol system call will not work */
ioctl.syscall_magic = AURORA_SYSCALL_MAGIC;
/* register the app to sound layer, as it will create
* a private dsp-box for this app */
_KeFileIoControl(snd, SOUND_REGISTER_SNDPLR, &ioctl);
/* now open your sound file, note that here demo is playing
* a raw wave file with 48kHZ-16bit format, to play mp3 or
* other format, one needs another conversion layer of samples */
int song = _KeOpenFile("/snd.wav", FILE_OPEN_READ_ONLY);
void* songbuf = malloc(4096);
memset(songbuf, 0, 4096);
_KeReadFile(song, songbuf, 4096);
XEFileStatus fs;
_KeFileStat(song, &fs);
while (1) {
/* with each frame read the sound, write it
* to sound device, the sound device will automatically
* put the app to sleep for smooth playback for some
* milli-seconds
*/
_KeWriteFile(snd, songbuf, 4096);
_KeReadFile(song, songbuf, 4096);
_KeFileStat(song, &fs);
/* after we finish playing the sound, we exit */
if (fs.eof) {
_KeCloseFile(song);
_KeProcessExit();
}
}
}