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).
11 #define __OSS_NOLIBBASE__
19 #include <proto/oss.h>
20 #include <proto/exec.h>
21 #include <proto/dos.h>
23 #define DSP_DRIVER_NAME "/dev/dsp"
25 #define BUFFERSIZE 0x57300
27 static struct Library
*OSSBase
;
29 static void cleanup(void *buffer
, BPTR infh
, BOOL closeoss
)
31 if(closeoss
) OSS_Close();
32 if(OSSBase
) CloseLibrary(OSSBase
);
38 int main (int argc
, char *argv
[])
42 int format
, channels
, rate
;
43 int readlength
, written
, ok
;
44 void *buffer
, *bufptr
;
47 format
= 0; //AFMT_S16_LE;
51 format
= atoi(argv
[2]);
52 channels
= atoi(argv
[3]);
54 } else if (argc
!= 2) {
55 printf ("Usage:\nplayoss <filename> [<format> <channels> <rate>]\n");
59 buffer
= malloc(BUFFERSIZE
);
61 printf ("malloc error\n");
66 infh
= Open(path
, MODE_OLDFILE
);
68 printf ("error %ld opening file %s\n", IoErr(), path
);
69 cleanup(buffer
, NULL
, FALSE
);
73 OSSBase
= OpenLibrary("oss.library", 0);
76 printf("Could not open oss.library!\n");
77 cleanup(buffer
, infh
, FALSE
);
81 ok
= OSS_Open(DSP_DRIVER_NAME
, FALSE
, TRUE
, TRUE
);
83 printf ("error opening DSP\n");
84 cleanup(buffer
, infh
, FALSE
);
88 if( !OSS_SetFormat_S16LE() ) {
89 printf("error setting format\n");
90 cleanup(buffer
, infh
, TRUE
);
94 if( !OSS_SetNumChannels(channels
) ) {
95 printf("error setting channels\n");
96 cleanup(buffer
, infh
, TRUE
);
100 if( !OSS_SetWriteRate(rate
, &rate
) ) {
101 printf("error setting write rate\n");
102 cleanup(buffer
, infh
, TRUE
);
105 printf ("File: %s\nFormat: %d\nChannels: %d\nRate: %d\n", path
, format
, channels
, rate
);
107 while( (readlength
= Read(infh
, buffer
, BUFFERSIZE
)) > 0 ) {
108 // printf("read %d\n", readlength);
111 written
= OSS_Write(bufptr
, readlength
);
112 // printf("written %d\n", written);
114 printf ("error writing audio %d\n", written
);
115 cleanup(buffer
, infh
, TRUE
);
120 readlength
-= written
;
121 } while( readlength
> 0 );
124 if( readlength
< 0 ) {
125 printf ("error %ld reading file\n", IoErr());
126 cleanup(buffer
, infh
, TRUE
);
130 cleanup(buffer
, infh
, TRUE
);