Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Examples / Low-level / Test-7.1 / Test-7.1.c
blob091625f4813c34e5d6ff3eb7bbc5826650fbe216
2 #include <config.h>
4 #include <devices/ahi.h>
5 #include <proto/ahi.h>
6 #include <proto/exec.h>
8 #include <math.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
13 #include "version.h"
15 static const char version[] = "$VER: Test-7.1 " VERS "\n\r";
17 struct Library* AHIBase = NULL;
19 static int Test71( ULONG );
21 int
22 main( int argc, char* argv[] ) {
23 int rc = RETURN_OK;
25 if( argc != 2 ) {
26 fprintf( stderr, "Usage: %s <audio mode id>\n", argv[ 0 ] );
27 rc = RETURN_ERROR;
29 else {
30 struct MsgPort* mp = CreateMsgPort();
32 if( mp != NULL ) {
33 struct AHIRequest* io = (struct AHIRequest *)
34 CreateIORequest( mp, sizeof( struct AHIRequest ) );
36 if( io != NULL ) {
37 // We use 32 bit, 8 channel samples, so we need version 6.
38 io->ahir_Version = 6;
40 if( OpenDevice( AHINAME, AHI_NO_UNIT, (struct IORequest *) io, 0 )
41 == 0 ) {
42 AHIBase = (struct Library *) io->ahir_Std.io_Device;
44 rc = Test71( strtol( argv[ 1 ], NULL, 0 ) );
46 CloseDevice( (struct IORequest *) io );
48 else {
49 fprintf( stderr, "Unable to open '" AHINAME "' version 6.\n" );
50 rc = RETURN_FAIL;
53 DeleteIORequest( (struct IORequest *) io );
55 else {
56 fprintf( stderr, "Unable to create IO request.\n" );
57 rc = RETURN_FAIL;
60 DeleteMsgPort( mp );
62 else {
63 fprintf( stderr, "Unable to create message port.\n" );
64 rc = RETURN_FAIL;
68 return rc;
71 #define LENGTH 1000
72 //#define SINE
74 int
75 Test71( ULONG mode_id ) {
76 char name[ 64 ];
77 int rc = RETURN_OK;
78 LONG* sample;
80 sample = malloc( sizeof(LONG) * 8 * (LENGTH+1) );
82 if( sample != NULL ) {
83 struct AHIAudioCtrl* actrl;
84 int i;
86 for( i = 0; i < (LENGTH+1); ++i ) {
87 sample[ i * 8 + 0 ] = 0;
88 sample[ i * 8 + 1 ] = 0;
89 sample[ i * 8 + 2 ] = 0;
90 sample[ i * 8 + 3 ] = 0;
91 sample[ i * 8 + 4 ] = 0;
92 sample[ i * 8 + 5 ] = 0;
93 sample[ i * 8 + 6 ] = 0;
94 #ifdef SINE
95 sample[ i * 8 + 7 ] = 0x7fffffff*sin(2*M_PI*i/LENGTH);
96 #else
97 sample[ i * 8 + 7 ] = i < (LENGTH/2) ? 0x7fffffff : 0x80000000;
98 #endif
102 name[0] = 0;
103 AHI_GetAudioAttrs( mode_id, NULL,
104 AHIDB_Name, (ULONG) &name,
105 AHIDB_BufferLen, 64,
106 TAG_DONE );
108 printf( "Testing mode 0x%08lx (%s)\n", mode_id, name );
110 actrl = AHI_AllocAudio( AHIA_AudioID, mode_id,
111 AHIA_MixFreq, 44100,
112 AHIA_Channels, 1,
113 AHIA_Sounds, 8,
114 TAG_DONE );
116 if( actrl != NULL ) {
117 struct AHISampleInfo sample_fl = { AHIST_L7_1, sample + 7, LENGTH };
118 struct AHISampleInfo sample_fr = { AHIST_L7_1, sample + 6, LENGTH };
119 struct AHISampleInfo sample_rl = { AHIST_L7_1, sample + 5, LENGTH };
120 struct AHISampleInfo sample_rr = { AHIST_L7_1, sample + 4, LENGTH };
121 struct AHISampleInfo sample_sl = { AHIST_L7_1, sample + 3, LENGTH };
122 struct AHISampleInfo sample_sr = { AHIST_L7_1, sample + 2, LENGTH };
123 struct AHISampleInfo sample_c = { AHIST_L7_1, sample + 1, LENGTH };
124 struct AHISampleInfo sample_lfe = { AHIST_L7_1, sample + 0, LENGTH };
126 if( AHI_LoadSound( 0, AHIST_SAMPLE, &sample_fl, actrl) == AHIE_OK &&
127 AHI_LoadSound( 1, AHIST_SAMPLE, &sample_fr, actrl) == AHIE_OK &&
128 AHI_LoadSound( 2, AHIST_SAMPLE, &sample_rl, actrl) == AHIE_OK &&
129 AHI_LoadSound( 3, AHIST_SAMPLE, &sample_rr, actrl) == AHIE_OK &&
130 AHI_LoadSound( 4, AHIST_SAMPLE, &sample_sl, actrl) == AHIE_OK &&
131 AHI_LoadSound( 5, AHIST_SAMPLE, &sample_sr, actrl) == AHIE_OK &&
132 AHI_LoadSound( 6, AHIST_SAMPLE, &sample_c, actrl) == AHIE_OK &&
133 AHI_LoadSound( 7, AHIST_SAMPLE, &sample_lfe, actrl) == AHIE_OK ) {
135 if( AHI_ControlAudio( actrl,
136 AHIC_Play, TRUE,
137 TAG_DONE ) == AHIE_OK ) {
138 AHI_Play( actrl,
139 AHIP_BeginChannel, 0,
140 AHIP_Sound, 0,
141 AHIP_Freq, 44100,
142 AHIP_Vol, 0x10000,
143 AHIP_Pan, 0x8000,
144 AHIP_EndChannel, 0,
145 TAG_DONE );
146 printf( "Front Left.\n" );
147 sleep( 1 );
149 AHI_SetSound( 0, 1, 0, 0, actrl, AHISF_IMM );
150 printf( "Front Right.\n" );
151 sleep( 1 );
153 AHI_SetSound( 0, 2, 0, 0, actrl, AHISF_IMM );
154 printf( "Rear Left.\n" );
155 sleep( 1 );
157 AHI_SetSound( 0, 3, 0, 0, actrl, AHISF_IMM );
158 printf( "Rear Right.\n" );
159 sleep( 1 );
161 AHI_SetSound( 0, 4, 0, 0, actrl, AHISF_IMM );
162 printf( "Surround Left.\n" );
163 sleep( 1 );
165 AHI_SetSound( 0, 5, 0, 0, actrl, AHISF_IMM );
166 printf( "Surround Right.\n" );
167 sleep( 1 );
169 AHI_SetSound( 0, 6, 0, 0, actrl, AHISF_IMM );
170 printf( "Center.\n" );
171 sleep( 1 );
173 AHI_SetSound( 0, 7, 0, 0, actrl, AHISF_IMM );
174 printf( "LFE.\n" );
175 sleep( 1 );
177 AHI_ControlAudio( actrl,
178 AHIC_Play, FALSE,
179 TAG_DONE );
181 else {
182 fprintf( stderr, "Unable start playback.\n" );
183 rc = RETURN_ERROR;
186 // AHI_FreeAudio() will unload the sounds
188 else {
189 fprintf( stderr, "Unable load sounds.\n" );
190 rc = RETURN_ERROR;
193 AHI_FreeAudio( actrl );
195 else {
196 fprintf( stderr, "Unable to allocate audio.\n" );
197 rc = RETURN_ERROR;
201 else {
202 fprintf( stderr, "Unable to allocate memory for sample.\n" );
205 free( sample );
207 return rc;