2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
5 Demo for oss.library to playback audio samples.
6 It can play raw audio files containing 16 bit signed PCM data in little endian format.
7 Chaning the format isn't possible for now.
8 Default number of channels is 2 (stereo) and default playback rate is 44100 (CD quality).
17 #include <proto/oss.h>
18 #include <proto/exec.h>
19 #include <proto/dos.h>
21 #define DSP_DRIVER_NAME "/dev/dsp"
23 #define BUFFERSIZE 0x57300
25 static struct Library
*OSSBase
;
27 static void cleanup(void *buffer
, BPTR infh
, BOOL closeoss
)
29 if(closeoss
) OSS_Close();
30 if(OSSBase
) CloseLibrary(OSSBase
);
36 int main (int argc
, char *argv
[])
40 int format
, channels
, rate
;
41 int readlength
, written
, ok
;
42 void *buffer
, *bufptr
;
45 format
= 0; //AFMT_S16_LE;
49 format
= atoi(argv
[2]);
50 channels
= atoi(argv
[3]);
52 } else if (argc
!= 2) {
53 printf ("Usage:\nplayoss <filename> [<format> <channels> <rate>]\n");
57 buffer
= malloc(BUFFERSIZE
);
59 printf ("malloc error\n");
64 infh
= Open(path
, MODE_OLDFILE
);
66 printf ("error %ld opening file %s\n", IoErr(), path
);
67 cleanup(buffer
, NULL
, FALSE
);
71 OSSBase
= OpenLibrary("oss.library", 0);
74 printf("Could not open oss.library!\n");
75 cleanup(buffer
, infh
, FALSE
);
79 ok
= OSS_Open(DSP_DRIVER_NAME
, FALSE
, TRUE
, TRUE
);
81 printf ("error opening DSP\n");
82 cleanup(buffer
, infh
, FALSE
);
86 if( !OSS_SetFormat_S16LE() ) {
87 printf("error setting format\n");
88 cleanup(buffer
, infh
, TRUE
);
92 if( !OSS_SetNumChannels(channels
) ) {
93 printf("error setting channels\n");
94 cleanup(buffer
, infh
, TRUE
);
98 if( !OSS_SetWriteRate(rate
, &rate
) ) {
99 printf("error setting write rate\n");
100 cleanup(buffer
, infh
, TRUE
);
103 printf ("File: %s\nFormat: %d\nChannels: %d\nRate: %d\n", path
, format
, channels
, rate
);
105 while( (readlength
= Read(infh
, buffer
, BUFFERSIZE
)) > 0 ) {
106 // printf("read %d\n", readlength);
109 written
= OSS_Write(bufptr
, readlength
);
110 // printf("written %d\n", written);
112 printf ("error writing audio %d\n", written
);
113 cleanup(buffer
, infh
, TRUE
);
118 readlength
-= written
;
119 } while( readlength
> 0 );
122 if( readlength
< 0 ) {
123 printf ("error %ld reading file\n", IoErr());
124 cleanup(buffer
, infh
, TRUE
);
128 cleanup(buffer
, infh
, TRUE
);