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

Revision 742, 5.9 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2007 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  * This program 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 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
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.realtime=1;
82         dev_options.packetizer_priority=60;
83
84         dev_options.verbose=5;
85        
86         dev_options.slave_mode=0;
87         dev_options.snoop_mode=0;
88    
89         ffado_device_t *dev=ffado_streaming_init(device_info, dev_options);
90
91         if (!dev) {
92                 fprintf(stderr,"Could not init FFADO Streaming layer\n");
93                 exit(-1);
94         }
95
96         nb_in_channels=ffado_streaming_get_nb_capture_streams(dev);
97         nb_out_channels=ffado_streaming_get_nb_playback_streams(dev);
98
99         /* allocate intermediate buffers */
100         audiobuffer=calloc(nb_in_channels,sizeof(ffado_sample_t *));
101         for (i=0;i<nb_in_channels;i++) {
102                 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t));
103         }
104        
105         nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t));
106        
107         /* open the files to write to*/
108         FILE* fid_out[nb_out_channels];
109         FILE* fid_in[nb_in_channels];
110         char name[256];
111
112         for (i=0;i<nb_out_channels;i++) {
113                 snprintf(name,sizeof(name),"out_ch_%02d",i);
114
115                 fid_out[i]=fopen(name,"w");
116
117                 ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name));
118                 fprintf(fid_out[i],"Channel name: %s\n",name);
119                 switch (ffado_streaming_get_playback_stream_type(dev,i)) {
120                 case ffado_stream_type_audio:
121                         fprintf(fid_out[i],"Channel type: audio\n");
122                         break;
123                 case ffado_stream_type_midi:
124                         fprintf(fid_out[i],"Channel type: midi\n");
125                         break;
126                 case ffado_stream_type_unknown:
127                         fprintf(fid_out[i],"Channel type: unknown\n");
128                         break;
129                 default:
130                 case ffado_stream_type_invalid:
131                         fprintf(fid_out[i],"Channel type: invalid\n");
132                         break;
133                 }
134
135         }
136         for (i=0;i<nb_in_channels;i++) {
137                 snprintf(name,sizeof(name),"in_ch_%02d",i);
138                 fid_in[i]=fopen(name,"w");
139
140                 ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name));
141                 fprintf(fid_in[i], "Channel name: %s\n",name);
142                 switch (ffado_streaming_get_capture_stream_type(dev,i)) {
143                 case ffado_stream_type_audio:
144                         fprintf(fid_in[i], "Channel type: audio\n");
145                         break;
146                 case ffado_stream_type_midi:
147                         fprintf(fid_in[i], "Channel type: midi\n");
148                         break;
149                 case ffado_stream_type_unknown:
150                         fprintf(fid_in[i],"Channel type: unknown\n");
151                         break;
152                 default:
153                 case ffado_stream_type_invalid:
154                         fprintf(fid_in[i],"Channel type: invalid\n");
155                         break;
156                 }
157         }
158
159         ffado_streaming_prepare(dev);
160         start_flag = ffado_streaming_start(dev);
161
162         fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels);
163         while(run && start_flag==0) {
164                 retval = ffado_streaming_wait(dev);
165                 if (retval < 0) {
166                         fprintf(stderr,"Xrun\n");
167                         ffado_streaming_reset(dev);
168                         continue;
169                 }
170
171 //              ffado_streaming_transfer_buffers(dev);
172                 ffado_streaming_transfer_capture_buffers(dev);
173                 ffado_streaming_transfer_playback_buffers(dev);
174                
175                 nb_periods++;
176
177                 if((nb_periods % 32)==0) {
178                         fprintf(stderr,"\r%05d periods",nb_periods);
179                 }
180
181                 for(i=0;i<nb_in_channels;i++) {
182                         switch (ffado_streaming_get_capture_stream_type(dev,i)) {
183                         case ffado_stream_type_audio:
184                                 samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);
185                                 break;
186                         case ffado_stream_type_midi:
187                                 samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);
188                                 break;
189                         default:
190                                 ;
191                         }
192 //                      fprintf(fid_in[i], "---- Period read  (%d samples) ----\n",samplesread);
193 //                      hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(ffado_sample_t));
194                 }
195
196                 for(i=0;i<nb_out_channels;i++) {
197                         ffado_sample_t *buff;
198                         if (i<nb_in_channels) {
199                                 buff=audiobuffer[i];
200                         } else {
201                                 buff=nullbuffer;
202                         }
203                        
204                         switch (ffado_streaming_get_playback_stream_type(dev,i)) {
205                         case ffado_stream_type_audio:
206                                 sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE);
207                                 break;
208                         case ffado_stream_type_midi:
209                                 sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE);
210                                 break;
211                         default:
212                                 ;
213                         }
214 //                      fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten);
215 //                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t));
216                 }
217
218         }
219
220         fprintf(stderr,"\n");
221
222         fprintf(stderr,"Exiting receive loop\n");
223        
224         ffado_streaming_stop(dev);
225
226         ffado_streaming_finish(dev);
227
228         for (i=0;i<nb_out_channels;i++) {
229                 fclose(fid_out[i]);
230
231         }
232         for (i=0;i<nb_in_channels;i++) {
233                 fclose(fid_in[i]);
234         }
235        
236         for (i=0;i<nb_in_channels;i++) {
237                 free(audiobuffer[i]);
238         }
239         free(nullbuffer);
240         free(audiobuffer);
241
242   return EXIT_SUCCESS;
243 }
Note: See TracBrowser for help on using the browser.