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

Revision 554, 7.9 kB (checked in by ppalmers, 16 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  * for floating point use
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 256
55
56         int samplesread=0;
57 //      int sampleswritten=0;
58         int nb_in_channels=0, nb_out_channels=0;
59         int retval=0;
60         int i=0;
61         int start_flag = 0;
62
63         int nb_periods=0;
64
65         float **audiobuffers_in;
66         ffado_sample_t **audiobuffers_out;
67         ffado_sample_t *nullbuffer;
68        
69         run=1;
70
71         printf("Ffado streaming test application (3)\n");
72
73         signal (SIGINT, sighandler);
74         signal (SIGPIPE, sighandler);
75
76         ffado_device_info_t device_info;
77         memset(&device_info,0,sizeof(ffado_device_info_t));
78
79         ffado_options_t dev_options;
80         memset(&dev_options,0,sizeof(ffado_options_t));
81
82         dev_options.sample_rate=44100;
83         dev_options.period_size=PERIOD_SIZE;
84
85         dev_options.nb_buffers=3;
86
87         dev_options.port=0;
88         dev_options.node_id=-1;
89
90         dev_options.realtime=1;
91         dev_options.packetizer_priority=70;
92        
93         dev_options.directions=0;
94        
95         dev_options.verbose=5;
96        
97         dev_options.slave_mode=0;
98         dev_options.snoop_mode=0;
99        
100         ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options);
101
102         if (!dev) {
103                 fprintf(stderr,"Could not init Ffado Streaming layer\n");
104                 exit(-1);
105         }
106
107         nb_in_channels=ffado_streaming_get_nb_capture_streams(dev);
108         nb_out_channels=ffado_streaming_get_nb_playback_streams(dev);
109
110         /* allocate intermediate buffers */
111         audiobuffers_in=calloc(nb_in_channels,sizeof(float *));
112         audiobuffers_out=calloc(nb_in_channels,sizeof(ffado_sample_t));
113         for (i=0;i<nb_in_channels;i++) {
114                 audiobuffers_in[i]=calloc(PERIOD_SIZE+1,sizeof(float));
115                 audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t));
116                        
117                 switch (ffado_streaming_get_capture_stream_type(dev,i)) {
118                         case ffado_stream_type_audio:
119                                 /* assign the audiobuffer to the stream */
120                                 ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i]));
121                                 ffado_streaming_set_capture_buffer_type(dev, i, ffado_buffer_type_float);
122                                 ffado_streaming_playback_stream_onoff(dev, i, 1);
123                                 break;
124                                 // this is done with read/write routines because the nb of bytes can differ.
125                         case ffado_stream_type_midi:
126                         default:
127                                 break;
128                 }
129         }
130        
131         nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t));
132        
133         for (i=0;i<nb_out_channels;i++) {
134                 switch (ffado_streaming_get_playback_stream_type(dev,i)) {
135                         case ffado_stream_type_audio:
136                                 if (i<nb_in_channels) {
137                                         /* assign the audiobuffer to the stream */
138                                         ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i]));
139                                         ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_float);
140                                         ffado_streaming_playback_stream_onoff(dev, i, 1);
141                                 } else {
142                                         ffado_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer);
143                                         ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_float);
144                                         ffado_streaming_playback_stream_onoff(dev, i, 1);
145                                 }
146                                 break;
147                                 // this is done with read/write routines because the nb of bytes can differ.
148                         case ffado_stream_type_midi:
149                         default:
150                                 break;
151                 }
152         }
153        
154         /* open the files to write to*/
155         FILE* fid_out[nb_out_channels];
156         FILE* fid_in[nb_in_channels];
157         char name[256];
158
159         for (i=0;i<nb_out_channels;i++) {
160                 snprintf(name,sizeof(name),"out_ch_%02d",i);
161
162                 fid_out[i]=fopen(name,"w");
163
164                 ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name));
165                 fprintf(fid_out[i],"Channel name: %s\n",name);
166                 switch (ffado_streaming_get_playback_stream_type(dev,i)) {
167                 case ffado_stream_type_audio:
168                         fprintf(fid_out[i],"Channel type: audio\n");
169                         break;
170                 case ffado_stream_type_midi:
171                         fprintf(fid_out[i],"Channel type: midi\n");
172                         break;
173                 case ffado_stream_type_unknown:
174                         fprintf(fid_out[i],"Channel type: unknown\n");
175                         break;
176                 default:
177                 case ffado_stream_type_invalid:
178                         fprintf(fid_out[i],"Channel type: invalid\n");
179                         break;
180                 }
181
182         }
183         for (i=0;i<nb_in_channels;i++) {
184                 snprintf(name,sizeof(name),"in_ch_%02d",i);
185                 fid_in[i]=fopen(name,"w");
186
187                 ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name));
188                 fprintf(fid_in[i], "Channel name: %s\n",name);
189                 switch (ffado_streaming_get_capture_stream_type(dev,i)) {
190                 case ffado_stream_type_audio:
191                         fprintf(fid_in[i], "Channel type: audio\n");
192                         break;
193                 case ffado_stream_type_midi:
194                         fprintf(fid_in[i], "Channel type: midi\n");
195                         break;
196                 case ffado_stream_type_unknown:
197                         fprintf(fid_in[i],"Channel type: unknown\n");
198                         break;
199                 default:
200                 case ffado_stream_type_invalid:
201                         fprintf(fid_in[i],"Channel type: invalid\n");
202                         break;
203                 }
204         }
205
206         // start the streaming layer
207         ffado_streaming_prepare(dev);
208         start_flag = ffado_streaming_start(dev);
209
210         fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels);
211         while(run && start_flag==0) {
212                 retval = ffado_streaming_wait(dev);
213                 if (retval < 0) {
214                         fprintf(stderr,"Xrun\n");
215                         ffado_streaming_reset(dev);
216                         continue;
217                 }
218                
219 //              ffado_streaming_transfer_buffers(dev);
220                 ffado_streaming_transfer_capture_buffers(dev);
221                 ffado_streaming_transfer_playback_buffers(dev);
222                
223                 nb_periods++;
224
225                 if((nb_periods % 32)==0) {
226 //                      fprintf(stderr,"\r%05d periods",nb_periods);
227                 }
228
229                 for(i=0;i<nb_in_channels;i++) {
230                        
231                        
232                         switch (ffado_streaming_get_capture_stream_type(dev,i)) {
233                         case ffado_stream_type_audio:
234                                 // no need to get the buffers manually, we have set the API internal buffers to the audiobuffer[i]'s
235 //                              //samplesread=freebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);
236                                 samplesread=PERIOD_SIZE;
237                                 break;
238                         case ffado_stream_type_midi:
239                                 samplesread=ffado_streaming_read(dev, i, audiobuffers_out[i], PERIOD_SIZE);
240                                 break;
241                         default: break;
242                         }
243        
244 //                      fprintf(fid_in[i], "---- Period read  (%d samples) ----\n",samplesread);
245 //                      hexDumpToFile(fid_in[i],(unsigned char*)audiobuffers_in[i],samplesread*sizeof(float)+1);
246                 }
247
248                 for(i=0;i<nb_out_channels;i++) {
249                         ffado_sample_t *buff;
250                         int sampleswritten=0;
251                         if (i<nb_in_channels) {
252                                 buff=audiobuffers_out[i];
253                         } else {
254                                 buff=nullbuffer;
255                         }
256                        
257                         switch (ffado_streaming_get_playback_stream_type(dev,i)) {
258                         case ffado_stream_type_audio:
259 //                              sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE);
260                                 sampleswritten=PERIOD_SIZE;
261                                 break;
262                         case ffado_stream_type_midi:
263 //                              sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE);
264                                 break;
265                         default: break;
266                         }
267 //                      fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten);
268 //                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t));
269                 }
270
271         }
272
273         fprintf(stderr,"\n");
274
275         fprintf(stderr,"Exiting receive loop\n");
276        
277         ffado_streaming_stop(dev);
278
279         ffado_streaming_finish(dev);
280
281         for (i=0;i<nb_out_channels;i++) {
282                 fclose(fid_out[i]);
283
284         }
285         for (i=0;i<nb_in_channels;i++) {
286                 fclose(fid_in[i]);
287         }
288        
289         for (i=0;i<nb_in_channels;i++) {
290                 free(audiobuffers_in[i]);
291                 free(audiobuffers_out[i]);
292         }
293         free(nullbuffer);
294         free(audiobuffers_in);
295         free(audiobuffers_out);
296
297   return EXIT_SUCCESS;
298 }
Note: See TracBrowser for help on using the browser.