|
|
1.1 root 1:
2: /*
3: * chaintest.c - this test shows how to chain sounds together, such that the
4: * completion of one initiates another.
5: */
6:
7: #import <sound/sound.h>
8: #import <stdio.h>
9:
10: #define BUF_SIZE 8192
11: #define BUF_MAX 8
12:
13: static int buf_ptr, buf_max;
14: static SNDSoundStruct *buffers[BUF_MAX];
15:
16: //
17: // The termination function gets called when the previously played sound
18: // completes
19: //
20: int end(SNDSoundStruct *s, int tag, int err)
21: {
22: if (err) fprintf(stderr,"error while playing sound %d\n",tag);
23: if (buf_ptr < buf_max) {
24: err = SNDStartPlaying(buffers[buf_ptr], buf_ptr, 5,0,0,end);
25: if (err) fprintf(stderr,"cannot start playing %d (%s)\n",buf_ptr,
26: SNDSoundError(err));
27: buf_ptr++;
28: }
29: }
30:
31: main (int argc, char *argv[])
32: {
33: int size, err, i, j;
34: int x = 0;
35:
36: if (argc < 2) {
37: fprintf(stderr,"usage: chaintest file ...\n");
38: exit(1);
39: }
40: if (argc >= BUF_MAX) {
41: fprintf(stderr,"too many files (max is %d)\n",BUF_MAX);
42: exit(1);
43: }
44:
45: //
46: // read the soundfiles into the buffers
47: //
48: for (j=1; j<argc; j++) {
49: err = SNDReadSoundfile(argv[j],&buffers[j]);
50: if (err) {
51: fprintf(stderr,"Error : %s\n",SNDSoundError(err));
52: exit(1);
53: }
54: }
55:
56: //
57: // Enqueue the first couple of files
58: //
59: buf_ptr = 1;
60: buf_max = argc;
61: for (j=1; j<3; j++) {
62: err = SNDStartPlaying(buffers[j],buf_ptr++,5,0,0,end);
63: if (err) {
64: fprintf(stderr,"Error : %s\n",SNDSoundError(err));
65: exit(1);
66: }
67: }
68:
69: //
70: // wait for everything to complete
71: //
72: SNDWait(0);
73:
74: exit(0);
75: }
76:
77:
78:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.