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

Revision 554, 6.0 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  * Test application for the per-stream decode API
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include <signal.h>
37
38 #include "libffado/ffado.h"
39
40 #include "debugtools.h"
41
42 int run;
43
44 static void sighandler (int sig)
45 {
46         run = 0;
47 }
48
49 int main(int argc, char *argv[])
50 {
51
52         #define PERIOD_SIZE 1024
53
54         int samplesread=0, sampleswritten=0;
55         int nb_in_channels=0, nb_out_channels=0;
56         int retval=0;
57         int i=0;
58         int start_flag = 0;
59
60         int nb_periods=0;
61
62         ffado_sample_t **audiobuffer;
63         ffado_sample_t *nullbuffer;
64        
65         run=1;
66
67         printf("Ffado streaming test application\n");
68
69         signal (SIGINT, sighandler);
70         signal (SIGPIPE, sighandler);
71
72         ffado_device_info_t device_info;
73
74         ffado_options_t dev_options;
75
76         dev_options.sample_rate=44100;
77         dev_options.period_size=PERIOD_SIZE;
78
79         dev_options.nb_buffers=3;
80
81         dev_options.port=0;
82         dev_options.node_id=-1;
83        
84         dev_options.realtime=1;
85         dev_options.packetizer_priority=60;
86
87         dev_options.directions=0;
88        
89         dev_options.verbose=5;
90        
91         dev_options.slave_mode=0;
92         dev_options.snoop_mode=0;
93    
94         ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options);
95
96         if (!dev) {
97                 fprintf(stderr,"Could not init FFADO Streaming layer\n");
98                 exit(-1);
99         }
100
101         nb_in_channels=ffado_streaming_get_nb_capture_streams(dev);
102         nb_out_channels=ffado_streaming_get_nb_playback_streams(dev);
103
104         /* allocate intermediate buffers */
105         audiobuffer=calloc(nb_in_channels,sizeof(ffado_sample_t *));
106         for (i=0;i<nb_in_channels;i++) {
107                 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t));
108         }
109        
110         nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t));
111        
112         /* open the files to write to*/
113         FILE* fid_out[nb_out_channels];
114         FILE* fid_in[nb_in_channels];
115         char name[256];
116
117         for (i=0;i<nb_out_channels;i++) {
118                 snprintf(name,sizeof(name),"out_ch_%02d",i);
119
120                 fid_out[i]=fopen(name,"w");
121
122                 ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name));
123                 fprintf(fid_out[i],"Channel name: %s\n",name);
124                 switch (ffado_streaming_get_playback_stream_type(dev,i)) {
125                 case ffado_stream_type_audio:
126                         fprintf(fid_out[i],"Channel type: audio\n");
127                         break;
128                 case ffado_stream_type_midi:
129                         fprintf(fid_out[i],"Channel type: midi\n");
130                         break;
131                 case ffado_stream_type_unknown:
132                         fprintf(fid_out[i],"Channel type: unknown\n");
133                         break;
134                 default:
135                 case ffado_stream_type_invalid:
136                         fprintf(fid_out[i],"Channel type: invalid\n");
137                         break;
138                 }
139
140         }
141         for (i=0;i<nb_in_channels;i++) {
142                 snprintf(name,sizeof(name),"in_ch_%02d",i);
143                 fid_in[i]=fopen(name,"w");
144
145                 ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name));
146                 fprintf(fid_in[i], "Channel name: %s\n",name);
147                 switch (ffado_streaming_get_capture_stream_type(dev,i)) {
148                 case ffado_stream_type_audio:
149                         fprintf(fid_in[i], "Channel type: audio\n");
150                         break;
151                 case ffado_stream_type_midi:
152                         fprintf(fid_in[i], "Channel type: midi\n");
153                         break;
154                 case ffado_stream_type_unknown:
155                         fprintf(fid_in[i],"Channel type: unknown\n");
156                         break;
157                 default:
158                 case ffado_stream_type_invalid:
159                         fprintf(fid_in[i],"Channel type: invalid\n");
160                         break;
161                 }
162         }
163
164         ffado_streaming_prepare(dev);
165         start_flag = ffado_streaming_start(dev);
166
167         fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels);
168         while(run && start_flag==0) {
169                 retval = ffado_streaming_wait(dev);
170                 if (retval < 0) {
171                         fprintf(stderr,"Xrun\n");
172                         ffado_streaming_reset(dev);
173                         continue;
174                 }
175
176 //              ffado_streaming_transfer_buffers(dev);
177                 ffado_streaming_transfer_capture_buffers(dev);
178                 ffado_streaming_transfer_playback_buffers(dev);
179                
180                 nb_periods++;
181
182                 if((nb_periods % 32)==0) {
183                         fprintf(stderr,"\r%05d periods",nb_periods);
184                 }
185
186                 for(i=0;i<nb_in_channels;i++) {
187                         switch (ffado_streaming_get_capture_stream_type(dev,i)) {
188                         case ffado_stream_type_audio:
189                                 samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);
190                                 break;
191                         case ffado_stream_type_midi:
192                                 samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);
193                                 break;
194                         default:
195                                 ;
196                         }
197 //                      fprintf(fid_in[i], "---- Period read  (%d samples) ----\n",samplesread);
198 //                      hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(ffado_sample_t));
199                 }
200
201                 for(i=0;i<nb_out_channels;i++) {
202                         ffado_sample_t *buff;
203                         if (i<nb_in_channels) {
204                                 buff=audiobuffer[i];
205                         } else {
206                                 buff=nullbuffer;
207                         }
208                        
209                         switch (ffado_streaming_get_playback_stream_type(dev,i)) {
210                         case ffado_stream_type_audio:
211                                 sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE);
212                                 break;
213                         case ffado_stream_type_midi:
214                                 sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE);
215                                 break;
216                         default:
217                                 ;
218                         }
219 //                      fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten);
220 //                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t));
221                 }
222
223         }
224
225         fprintf(stderr,"\n");
226
227         fprintf(stderr,"Exiting receive loop\n");
228        
229         ffado_streaming_stop(dev);
230
231         ffado_streaming_finish(dev);
232
233         for (i=0;i<nb_out_channels;i++) {
234                 fclose(fid_out[i]);
235
236         }
237         for (i=0;i<nb_in_channels;i++) {
238                 fclose(fid_in[i]);
239         }
240        
241         for (i=0;i<nb_in_channels;i++) {
242                 free(audiobuffer[i]);
243         }
244         free(nullbuffer);
245         free(audiobuffer);
246
247   return EXIT_SUCCESS;
248 }
Note: See TracBrowser for help on using the browser.