root/trunk/libffado/tests/streaming/teststreaming2.c

Revision 554, 7.7 kB (checked in by ppalmers, 17 years ago)

Merge echoaudio branch into trunk.

This adds support for the Echo Audiofire devices to FFADO. Possibly also other devices working with the Apple Class Driver will work with this code. It is not fully complete yet, but the main rework is
done.

First of all the IAvDevice class/interface is renamed to FFADODevice, in order to separate the AV/C code from the FFADO API code. A device supported by FFADO implements a FFADODevice.

The BeBoB device has been split up into three groups:
- libavc/* : all code and commands that are specified by AV/C specs. Note that a lot of the code that used to be in BeBoB::AvDevice? now resides in AVC::Unit
- genericavc/* : a FFADODevice that uses AV/C descriptors & commands for discovery and config
- bebob/* : the bebob FFADODevice that inherits from GenericAVC::AvDevice? but that uses BridgeCo? commands for discovery

Everything has been moved as high as possible in the class hierarchy. If necessary, a subclass that uses device specific commands is introduced (e.g. BeBoB::Plug inherits from AVC::Plug and uses the
BridgeCo? extended plug info command to discover it's properties).

There are some other fixes along the way that have been done too.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2007 by by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * FFADO is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * FFADO is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with FFADO; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA.
22  */
23
24
25 /**
26  * Test application for the direct decode stream API
27  *
28  */
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #include <signal.h>
39
40 #include "libffado/ffado.h"
41
42 #include "debugtools.h"
43
44 int run;
45
46 static void sighandler (int sig)
47 {
48         run = 0;
49 }
50
51 int main(int argc, char *argv[])
52 {
53
54         #define PERIOD_SIZE 1024
55
56         int samplesread=0, sampleswritten=0;
57         int nb_in_channels=0, nb_out_channels=0;
58         int retval=0;
59         int i=0;
60         int start_flag=0;
61
62         int nb_periods=0;
63
64         ffado_sample_t **audiobuffer;
65         ffado_sample_t *nullbuffer;
66        
67         run=1;
68
69         printf("Ffado streaming test application (2)\n");
70
71         signal (SIGINT, sighandler);
72         signal (SIGPIPE, sighandler);
73
74         ffado_device_info_t device_info;
75
76         ffado_options_t dev_options;
77
78         dev_options.sample_rate=44100;
79         dev_options.period_size=PERIOD_SIZE;
80
81         dev_options.nb_buffers=3;
82
83         dev_options.port=0;
84         dev_options.node_id=-1;
85        
86         dev_options.realtime=0;
87         dev_options.packetizer_priority=60;
88        
89         dev_options.directions=0;
90        
91         dev_options.verbose=5;
92        
93         dev_options.slave_mode=0;
94         dev_options.snoop_mode=0;
95
96         ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options);
97         if (!dev) {
98                 fprintf(stderr,"Could not init Ffado Streaming layer\n");
99                 exit(-1);
100         }
101
102         nb_in_channels=ffado_streaming_get_nb_capture_streams(dev);
103         nb_out_channels=ffado_streaming_get_nb_playback_streams(dev);
104
105         /* allocate intermediate buffers */
106         audiobuffer=calloc(nb_in_channels,sizeof(ffado_sample_t *));
107         for (i=0;i<nb_in_channels;i++) {
108                 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t));
109                        
110                 switch (ffado_streaming_get_capture_stream_type(dev,i)) {
111                         case ffado_stream_type_audio:
112                                 /* assign the audiobuffer to the stream */
113                                 ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i]));
114                                 ffado_streaming_set_capture_buffer_type(dev, i, ffado_buffer_type_int24);
115                                 break;
116                                 // this is done with read/write routines because the nb of bytes can differ.
117                         case ffado_stream_type_midi:
118                         default:
119                                 break;
120                 }
121         }
122        
123         nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t));
124
125 #if 1
126         for (i=0;i<nb_out_channels;i++) {
127                 switch (ffado_streaming_get_capture_stream_type(dev,i)) {
128                         case ffado_stream_type_audio:
129                                 if (i<nb_in_channels) {
130                                         /* assign the audiobuffer to the stream */
131                                         ffado_streaming_set_playback_stream_buffer(dev, i, (char *)audiobuffer[i]);
132                                 } else {
133                                         ffado_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer);
134                                 }
135                                 ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_int24);
136                                 break;
137                                 // this is done with read/write routines because the nb of bytes can differ.
138                         case ffado_stream_type_midi:
139                         default:
140                                 break;
141                 }
142         }
143 #endif
144        
145         /* open the files to write to*/
146         FILE* fid_out[nb_out_channels];
147         FILE* fid_in[nb_in_channels];
148         char name[256];
149
150         for (i=0;i<nb_out_channels;i++) {
151                 snprintf(name,sizeof(name),"out_ch_%02d",i);
152
153                 fid_out[i]=fopen(name,"w");
154
155                 ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name));
156                 fprintf(fid_out[i],"Channel name: %s\n",name);
157                 switch (ffado_streaming_get_playback_stream_type(dev,i)) {
158                 case ffado_stream_type_audio:
159                         fprintf(fid_out[i],"Channel type: audio\n");
160                         break;
161                 case ffado_stream_type_midi:
162                         fprintf(fid_out[i],"Channel type: midi\n");
163                         break;
164                 case ffado_stream_type_unknown:
165                         fprintf(fid_out[i],"Channel type: unknown\n");
166                         break;
167                 default:
168                 case ffado_stream_type_invalid:
169                         fprintf(fid_out[i],"Channel type: invalid\n");
170                         break;
171                 }
172
173         }
174         for (i=0;i<nb_in_channels;i++) {
175                 snprintf(name,sizeof(name),"in_ch_%02d",i);
176                 fid_in[i]=fopen(name,"w");
177
178                 ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name));
179                 fprintf(fid_in[i], "Channel name: %s\n",name);
180                 switch (ffado_streaming_get_capture_stream_type(dev,i)) {
181                 case ffado_stream_type_audio:
182                         fprintf(fid_in[i], "Channel type: audio\n");
183                         break;
184                 case ffado_stream_type_midi:
185                         fprintf(fid_in[i], "Channel type: midi\n");
186                         break;
187                 case ffado_stream_type_unknown:
188                         fprintf(fid_in[i],"Channel type: unknown\n");
189                         break;
190                 default:
191                 case ffado_stream_type_invalid:
192                         fprintf(fid_in[i],"Channel type: invalid\n");
193                         break;
194                 }
195         }
196
197 FILE *of=fopen("foo.dat","w");
198
199         // prepare and start the streaming layer
200         ffado_streaming_prepare(dev);
201         start_flag = ffado_streaming_start(dev);
202
203         fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels);
204         while(run && start_flag==0) {
205                 retval = ffado_streaming_wait(dev);
206                 if (retval < 0) {
207                         fprintf(stderr,"Xrun\n");
208                         ffado_streaming_reset(dev);
209                         continue;
210                 }
211                
212                 for (i=0;i<nb_in_channels;i++) {
213                         memset(audiobuffer[i],0xCC,(PERIOD_SIZE+1)*sizeof(ffado_sample_t));
214                 }
215
216 //              ffado_streaming_transfer_buffers(dev);
217                 ffado_streaming_transfer_capture_buffers(dev);
218                 ffado_streaming_transfer_playback_buffers(dev);
219                
220                 nb_periods++;
221
222                 if((nb_periods % 32)==0) {
223                         fprintf(stderr,"\r%05d periods",nb_periods);
224                 }
225
226                 for(i=0;i<nb_in_channels;i++) {
227                        
228                        
229                         switch (ffado_streaming_get_capture_stream_type(dev,i)) {
230                         case ffado_stream_type_audio:
231                                 // no need to get the buffers manually, we have set the API internal buffers to the audiobuffer[i]'s
232 //                              //samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);
233                                 samplesread=PERIOD_SIZE;
234                                 break;
235                         case ffado_stream_type_midi:
236                                 samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);
237                                 break;
238                         default:
239                                 ;
240                         }
241        
242 //                      fprintf(fid_in[i], "---- Period read  (%d samples) ----\n",samplesread);
243 //                      hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(ffado_sample_t)+1);
244 // FIXME: Dump analog1 as raw data to a separate binary file for testing
245 //if (i==2) {
246 //  fwrite(audiobuffer[i],sizeof(ffado_sample_t),samplesread,of);
247 //}
248                 }
249
250                 for(i=0;i<nb_out_channels;i++) {
251                         ffado_sample_t *buff;
252                         if (i<nb_in_channels) {
253                                 buff=audiobuffer[i];
254                         } else {
255                                 buff=nullbuffer;
256                         }
257                        
258                         switch (ffado_streaming_get_playback_stream_type(dev,i)) {
259                         case ffado_stream_type_audio:
260 //// Calling ffado_streaming_write() causes problems since the buffer is external here.
261 //// Just mirror the read case since it seems to work.
262 ////                            sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE);
263                                 sampleswritten=PERIOD_SIZE;
264                                 break;
265                         case ffado_stream_type_midi:
266                                 sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE);
267                                 break;
268                         default:
269                                 ;
270                         }
271 //                      fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten);
272 //                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t));
273                 }
274
275         }
276
277         fprintf(stderr,"\n");
278
279         fprintf(stderr,"Exiting receive loop\n");
280        
281         ffado_streaming_stop(dev);
282
283         ffado_streaming_finish(dev);
284         fclose(of);
285
286         for (i=0;i<nb_out_channels;i++) {
287                 fclose(fid_out[i]);
288
289         }
290         for (i=0;i<nb_in_channels;i++) {
291                 fclose(fid_in[i]);
292         }
293        
294         for (i=0;i<nb_in_channels;i++) {
295                 free(audiobuffer[i]);
296         }
297         free(nullbuffer);
298         free(audiobuffer);
299
300   return EXIT_SUCCESS;
301 }
Note: See TracBrowser for help on using the browser.