source: trunk/third/audiofile/test/irixread.c @ 18227

Revision 18227, 3.2 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18226, which included commits to RCS files with non-trunk default branches.
Line 
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        irixread.c
25
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.
29
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.
35*/
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <sys/types.h>
40#include <dmedia/audio.h>
41#include <dmedia/audiofile.h>
42
43#include "sgi.h"
44
45const int BUFFERED_FRAME_COUNT = 65536;
46
47void usage (void)
48{
49        fprintf(stderr, "usage: irixread filename\n");
50        exit(-1);
51}
52
53main (int argc, char **argv)
54{
55        AFfilehandle    file;
56        AFframecount    count, frameCount;
57        int             channelCount, sampleFormat, sampleWidth;
58        float           frameSize;
59        void            *buffer;
60        double          sampleRate;
61
62        ALport          outport;
63        ALconfig        outportconfig;
64
65        if (argc < 2)
66                usage();
67
68        file = afOpenFile(argv[1], "r", NULL);
69        if (file == AF_NULL_FILEHANDLE)
70        {
71                fprintf(stderr, "Could not open file %s.\n", argv[1]);
72                exit(EXIT_FAILURE);
73        }
74
75        frameCount = afGetFrameCount(file, AF_DEFAULT_TRACK);
76        frameSize = afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1);
77        channelCount = afGetVirtualChannels(file, AF_DEFAULT_TRACK);
78        sampleRate = afGetRate(file, AF_DEFAULT_TRACK);
79        afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat,
80                &sampleWidth);
81
82        if (sampleFormat == AF_SAMPFMT_UNSIGNED)
83        {
84                afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK,
85                        AF_SAMPFMT_TWOSCOMP, sampleWidth);
86        }
87
88        printf("frame count: %lld\n", frameCount);
89        printf("frame size: %d bytes\n", (int) frameSize);
90        printf("channel count: %d\n", channelCount);
91        printf("sample rate: %.2f Hz\n", sampleRate);
92        buffer = malloc(BUFFERED_FRAME_COUNT * frameSize);
93
94        outportconfig = alNewConfig();
95        setwidth(outportconfig, sampleWidth);
96        setsampleformat(outportconfig, sampleFormat);
97        alSetChannels(outportconfig, channelCount);
98
99        count = afReadFrames(file, AF_DEFAULT_TRACK, buffer, BUFFERED_FRAME_COUNT);
100
101        outport = alOpenPort("irixread", "w", outportconfig);
102        setrate(outport, sampleRate);
103
104        do
105        {
106                printf("count = %lld\n", count);
107                alWriteFrames(outport, buffer, count);
108
109                count = afReadFrames(file, AF_DEFAULT_TRACK, buffer,
110                        BUFFERED_FRAME_COUNT);
111        } while (count > 0);
112
113        waitport(outport);
114
115        alClosePort(outport);
116        alFreeConfig(outportconfig);
117
118        afCloseFile(file);
119}
Note: See TracBrowser for help on using the repository browser.