4 Copyright (C) 1998-1999, Michael Pruett <michael@68k.org>
5 Copyright (C) 2001, Silicon Graphics, Inc.
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.
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.
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,
26 This program reads and plays a given audio file using Irix's
27 default audio output device. This file will not work on any
28 operating system other than Irix.
30 The only difference between this program and irixtest is that this
31 program does not load the entire audio track into memory at once.
32 Only a small number of frames are read into a buffer and then
33 written to the audio port. While there are more frames to be
34 read, this process is repeated.
43 #include <sys/types.h>
44 #include <dmedia/audio.h>
45 #include <dmedia/audiofile.h>
49 const int BUFFERED_FRAME_COUNT
= 65536;
53 fprintf(stderr
, "usage: irixread filename\n");
57 main (int argc
, char **argv
)
60 AFframecount count
, frameCount
;
61 int channelCount
, sampleFormat
, sampleWidth
;
67 ALconfig outportconfig
;
72 file
= afOpenFile(argv
[1], "r", NULL
);
73 if (file
== AF_NULL_FILEHANDLE
)
75 fprintf(stderr
, "Could not open file %s.\n", argv
[1]);
79 frameCount
= afGetFrameCount(file
, AF_DEFAULT_TRACK
);
80 frameSize
= afGetVirtualFrameSize(file
, AF_DEFAULT_TRACK
, 1);
81 channelCount
= afGetVirtualChannels(file
, AF_DEFAULT_TRACK
);
82 sampleRate
= afGetRate(file
, AF_DEFAULT_TRACK
);
83 afGetVirtualSampleFormat(file
, AF_DEFAULT_TRACK
, &sampleFormat
,
86 if (sampleFormat
== AF_SAMPFMT_UNSIGNED
)
88 afSetVirtualSampleFormat(file
, AF_DEFAULT_TRACK
,
89 AF_SAMPFMT_TWOSCOMP
, sampleWidth
);
92 printf("frame count: %lld\n", frameCount
);
93 printf("frame size: %d bytes\n", (int) frameSize
);
94 printf("channel count: %d\n", channelCount
);
95 printf("sample rate: %.2f Hz\n", sampleRate
);
96 buffer
= malloc(BUFFERED_FRAME_COUNT
* frameSize
);
98 outportconfig
= alNewConfig();
99 setwidth(outportconfig
, sampleWidth
);
100 setsampleformat(outportconfig
, sampleFormat
);
101 alSetChannels(outportconfig
, channelCount
);
103 count
= afReadFrames(file
, AF_DEFAULT_TRACK
, buffer
, BUFFERED_FRAME_COUNT
);
105 outport
= alOpenPort("irixread", "w", outportconfig
);
106 setrate(outport
, sampleRate
);
110 printf("count = %lld\n", count
);
111 alWriteFrames(outport
, buffer
, count
);
113 count
= afReadFrames(file
, AF_DEFAULT_TRACK
, buffer
,
114 BUFFERED_FRAME_COUNT
);
119 alClosePort(outport
);
120 alFreeConfig(outportconfig
);