1 | /* |
---|
2 | Audio File Library |
---|
3 | |
---|
4 | Copyright (C) 1998-1999, Michael Pruett <michael@68k.org> |
---|
5 | Copyright (C) 2001, Silicon Graphics, Inc. |
---|
6 | |
---|
7 | This program is free software; you can redistribute it and/or |
---|
8 | modify it under the terms of the GNU General Public License as |
---|
9 | published by the Free Software Foundation; either version 2 of |
---|
10 | the License, or (at your option) any later version. |
---|
11 | |
---|
12 | This program is distributed in the hope that it will be |
---|
13 | useful, but WITHOUT ANY WARRANTY; without even the implied |
---|
14 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
---|
15 | PURPOSE. See the GNU General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU General Public |
---|
18 | License along with this program; if not, write to the Free |
---|
19 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
20 | MA 02111-1307, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | /* |
---|
24 | irixtestloop.c |
---|
25 | |
---|
26 | This file reads the loop points from a file (presumably AIFF) and |
---|
27 | loops that part of the file several times. Audio output is routed |
---|
28 | to IRIX's default audio output device. This program will not |
---|
29 | compile on any platform other than IRIX. |
---|
30 | */ |
---|
31 | |
---|
32 | #include <stdio.h> |
---|
33 | #include <stdlib.h> |
---|
34 | #include <sys/types.h> |
---|
35 | #include <dmedia/audio.h> |
---|
36 | #include <dmedia/audiofile.h> |
---|
37 | |
---|
38 | #include "sgi.h" |
---|
39 | |
---|
40 | const int REPEAT_COUNT = 3; |
---|
41 | |
---|
42 | void usage (void) |
---|
43 | { |
---|
44 | printf("usage: irixtestloop file\n"); |
---|
45 | printf("where file is of a format which contains a loop (e.g. AIFF)\n"); |
---|
46 | exit(-1); |
---|
47 | } |
---|
48 | |
---|
49 | main (int argc, char **argv) |
---|
50 | { |
---|
51 | AFfilehandle file; |
---|
52 | void *buffer; |
---|
53 | |
---|
54 | AFframecount frameCount; |
---|
55 | int frameSize, sampleFormat, sampleWidth, channelCount; |
---|
56 | double sampleRate; |
---|
57 | |
---|
58 | int *loopids, *markids; |
---|
59 | int i, loopCount, markCount; |
---|
60 | int startmarkid, endmarkid; |
---|
61 | AFframecount startloop, endloop; |
---|
62 | |
---|
63 | ALport outport; |
---|
64 | ALconfig outportconfig; |
---|
65 | |
---|
66 | if (argc < 2) |
---|
67 | usage(); |
---|
68 | |
---|
69 | file = afOpenFile(argv[1], "r", NULL); |
---|
70 | frameCount = afGetFrameCount(file, AF_DEFAULT_TRACK); |
---|
71 | frameSize = afGetFrameSize(file, AF_DEFAULT_TRACK, 1); |
---|
72 | channelCount = afGetChannels(file, AF_DEFAULT_TRACK); |
---|
73 | afGetSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); |
---|
74 | sampleRate = afGetRate(file, AF_DEFAULT_TRACK); |
---|
75 | |
---|
76 | printf("frame count: %lld\n", frameCount); |
---|
77 | printf("frame size: %d bytes\n", frameSize); |
---|
78 | printf("channel count: %d\n", channelCount); |
---|
79 | printf("sample rate: %.2f Hz\n", sampleRate); |
---|
80 | |
---|
81 | buffer = malloc(frameCount * frameSize); |
---|
82 | afReadFrames(file, AF_DEFAULT_TRACK, buffer, frameCount); |
---|
83 | |
---|
84 | loopCount = afGetLoopIDs(file, AF_DEFAULT_INST, NULL); |
---|
85 | loopids = malloc(sizeof (int) * loopCount); |
---|
86 | afGetLoopIDs(file, AF_DEFAULT_INST, loopids); |
---|
87 | |
---|
88 | markCount = afGetMarkIDs(file, AF_DEFAULT_TRACK, NULL); |
---|
89 | markids = malloc(sizeof (int) * markCount); |
---|
90 | afGetMarkIDs(file, AF_DEFAULT_TRACK, markids); |
---|
91 | |
---|
92 | printf("loop ids:"); |
---|
93 | for (i=0; i<loopCount; i++) |
---|
94 | printf(" %d", loopids[i]); |
---|
95 | printf("\n"); |
---|
96 | |
---|
97 | printf("mark ids:"); |
---|
98 | for (i=0; i<markCount; i++) |
---|
99 | printf(" %d", markids[i]); |
---|
100 | printf("\n"); |
---|
101 | |
---|
102 | startmarkid = afGetLoopStart(file, AF_DEFAULT_INST, 1); |
---|
103 | endmarkid = afGetLoopEnd(file, AF_DEFAULT_INST, 1); |
---|
104 | startloop = afGetMarkPosition(file, AF_DEFAULT_TRACK, startmarkid); |
---|
105 | endloop = afGetMarkPosition(file, AF_DEFAULT_TRACK, endmarkid); |
---|
106 | |
---|
107 | afCloseFile(file); |
---|
108 | |
---|
109 | outportconfig = alNewConfig(); |
---|
110 | setwidth(outportconfig, sampleWidth); |
---|
111 | setsampleformat(outportconfig, sampleFormat); |
---|
112 | alSetChannels(outportconfig, channelCount); |
---|
113 | |
---|
114 | outport = alOpenPort("irixtestloop", "w", outportconfig); |
---|
115 | setrate(outport, sampleRate); |
---|
116 | |
---|
117 | alWriteFrames(outport, buffer, startloop); |
---|
118 | for (i=0; i<REPEAT_COUNT; i++) |
---|
119 | { |
---|
120 | printf("iteration %d: start %lld, end %lld, length %lld\n", |
---|
121 | i, endloop, startloop, endloop - startloop); |
---|
122 | alWriteFrames(outport, (char *) buffer + startloop * frameSize, |
---|
123 | endloop - startloop); |
---|
124 | } |
---|
125 | |
---|
126 | waitport(outport); |
---|
127 | |
---|
128 | alClosePort(outport); |
---|
129 | alFreeConfig(outportconfig); |
---|
130 | |
---|
131 | free(buffer); |
---|
132 | } |
---|