first commit
[tas2555sw-android/tas2555-util.git] / main.c
1 /*
2 ** =============================================================================
3 ** Copyright (c) 2016  Texas Instruments Inc.
4 **
5 ** This program is free software; you can redistribute it and/or modify it under
6 ** the terms of the GNU General Public License as published by the Free Software 
7 ** Foundation; version 2.
8 **
9 ** This program is distributed in the hope that it will be useful, but WITHOUT
10 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 ** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 **
13 ** You should have received a copy of the GNU General Public License along with
14 ** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 ** Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 **
17 ** File:
18 **     main.c
19 **
20 ** Description:
21 **     test program for TAS2555 Android Linux drivers
22 **
23 ** =============================================================================
24 */
26 #include <sys/cdefs.h>
27 #include <sys/stat.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <time.h>
31 #include <math.h>
32 #include <ctype.h>
33 #include <stdio.h>
34 #include <unistd.h>
35 #include <errno.h>
36 #include <stdarg.h>
37 #include <fcntl.h>
38 #include "ti_audio.h"
40 static void usage(){
42         fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
43                 "usage: ti_audio -r book page register [count]               (read, hexdecimal)",
44                 "       ti_audio -w book page register value1 [value2 ...]  (write, hexdecimal)",
45                 "       ti_audio -d on                            (turn on the debug msg, bool)",
46                 "       ti_audio -p [n]                                 (get/[set] DSP program)",
47                 "       ti_audio -c [n]                           (get/[set] DSP configuration)",
48                 "       ti_audio -s [n]                        (get/[set] sample rate, decimal)",
49                 "       ti_audio -b [n]                           (get/[set] bit rate, decimal)",
50                 "       ti_audio -v [n]                             (get/[set] volume, decimal)",
51                 "       ti_audio -o on                              (turn on/off TAS2555, bool)",
52                 "       ti_audio -t                                            (get firmware timestamp)",
53                 "NOTE: 1. all numbers are Hexadecimal numbers without prefix 0x .",
54                 TIAUDIO_VERSION);       
55 }
57 static int str2hexchar(char *argv, unsigned char *pUInt8_Val){
58         int str_len = strlen(argv), i, result = -1, j;
59         unsigned char val[2] = {0};
61         if(str_len > 2){
62                 fprintf(stderr, "invalid parameters\n");
63                 goto err;
64         }
66         for(i = (str_len-1), j=0; i >= 0; i--, j++){
67                 if((argv[i] <= '9')&&(argv[i] >= '0')){
68                         val[j] = argv[i] - 0x30;
69                 }else if((argv[i] <='f')&&(argv[i]>= 'a')){
70                         val[j] = argv[i] - 0x57;
71                 }else if((argv[i] <='F')&&(argv[i]>= 'A')){
72                         val[j] = argv[i] - 0x37;
73                 }else{
74                         fprintf(stderr, "reg/data out of range\n");
75                         goto err;
76                 }
77         }
78         
79         *pUInt8_Val = (unsigned char)(val[0]|(val[1]<<4));
80         result = 0;
81         
82 err:
83         return result;
84 }
86 static int str2hexshort(char *argv, unsigned short *pUInt16_Val){
87         int str_len = strlen(argv), i, j, result = -1;
88         unsigned char val[4] = {0};
90         if(str_len > 4){
91                 fprintf(stderr, "invalid parameters\n");
92                 goto err;
93         }
95         for(i = (str_len-1), j=0; i >= 0; i--, j++){
96                 if((argv[i] <= '9')&&(argv[i] >= '0')){
97                         val[j] = argv[i] - 0x30;
98                 }else if((argv[i] <='f')&&(argv[i]>= 'a')){
99                         val[j] = argv[i] - 0x57;
100                 }else if((argv[i] <='F')&&(argv[i]>= 'A')){
101                         val[j] = argv[i] - 0x37;
102                 }else{
103                         fprintf(stderr, "reg/data out of range\n");
104                         goto err;
105                 }
106         }
107         
108         *pUInt16_Val = (unsigned short)(val[0]|(val[1]<<4)|(val[2]<<8)|(val[3]<<12));
109         result = 0;
111 err:
112         return result;
115 static int str2decimal(char *argv, unsigned int *pUInt32_Val){
116         int max_len = strlen(MAX_INT_STR), i, result = -1, j;
117         int str_len = strlen(argv);
118         unsigned int nValue = 0;
119         unsigned char temp;
121         if(str_len > max_len){
122                 fprintf(stderr, "invalid parameters\n");
123                 goto err;
124         }
125         
126         for(i = 0; i <str_len; i++){
127                 if((argv[i] <= '9')&&(argv[i] >= '0')){
128                         temp = argv[i] - 0x30;
129                         nValue += (temp * pow(10, i));
130                 }else{
131                         fprintf(stderr, "reg/data out of range\n");
132                         goto err;
133                 }
134         }
135         
136         *pUInt32_Val = nValue;
137         result = 0;
138         
139 err:
140         return result;
143 static int TiAudio_Reg_Write(int fileHandle, int argc, char **argv){
144         int err = -1;
145         unsigned char *pBuff = NULL, book, page, reg,value, len;
146         unsigned int whole_reg = 0;
147         unsigned int temp_reg = 0;
148         int i=0, reg_count = 0;
149         
150         if(argc < 6){
151                 fprintf(stderr, "invalid para numbers\n");
152                 goto err;
153         }
154         
155         reg_count = argc - 5;
157         pBuff = (unsigned char *)malloc(reg_count + 5);
158         if(pBuff == NULL){
159                 fprintf(stderr, "not enough mem\n");
160                 goto err;               
161         }
162         
163         pBuff[0] = TIAUDIO_CMD_REG_WITE;
164         
165         err = str2hexchar(argv[2], &book);
166         if(err < 0){
167                 goto err;
168         }
169         
170         err = str2hexchar(argv[3], &page);
171         if(err < 0){
172                 goto err;
173         }
174         
175         err = str2hexchar(argv[4], &reg);
176         if(err < 0){
177                 goto err;
178         }
179         
180         whole_reg = TAS2555_REG(book, page, reg);
181         pBuff[1] = (whole_reg & 0xff000000) >> 24;
182         pBuff[2] = (whole_reg & 0x00ff0000) >> 16;
183         pBuff[3] = (whole_reg & 0x0000ff00) >> 8;
184         pBuff[4] = (whole_reg & 0x000000ff) ;
185         
186         for(i=0; i< reg_count; i++){
187                 err = str2hexchar(argv[i+5], &value);
188                 if(err < 0){
189                         goto err;
190                 }
191                 pBuff[i + 5] = value;
192         }
193         
194         err = write(fileHandle, pBuff, reg_count+5);
195         if(err != (reg_count+5)){
196                 fprintf(stderr, "write err=%d\n", err);
197         }else{
198                 for(i=0; i< reg_count; i++){
199                         temp_reg = whole_reg + i;
200                         fprintf(stderr, "W B[%d]P[%d]R[%d]=0x%x\n", TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i + 5] );
201                 }
202         }       
204 err:
205         if(pBuff != NULL)
206                 free(pBuff);    
207         
208         return err;
211 static int TiAudio_Reg_Read(int fileHandle, int argc, char **argv){
212         int err = -1;
213         unsigned char *pBuff = NULL, book, page, reg,value, len;
214         unsigned int whole_reg = 0;
215         unsigned int temp_reg = 0;
216         int i=0, reg_count = 0;
217         
218         if((argc != 5) &&(argc != 6))  {
219                 fprintf(stderr, "invalid para numbers\n");
220                 goto err;
221         }
222         
223         if(argc == 5)
224                 reg_count = 1;
225         else{
226                 err = str2hexchar(argv[5], &len);
227                 if(err < 0){
228                         goto err;
229                 }
230                 reg_count = len;
231         }
232         
233         pBuff = (unsigned char *)malloc(reg_count + 5);
234         if(pBuff == NULL){
235                 fprintf(stderr, "not enough mem\n");
236                 goto err;               
237         }
238         
239         pBuff[0] = TIAUDIO_CMD_REG_READ;
240         
241         err = str2hexchar(argv[2], &book);
242         if(err < 0){
243                 goto err;
244         }
245         
246         err = str2hexchar(argv[3], &page);
247         if(err < 0){
248                 goto err;
249         }
250         
251         err = str2hexchar(argv[4], &reg);
252         if(err < 0){
253                 goto err;
254         }
255         
256         whole_reg = TAS2555_REG(book, page, reg);
257         pBuff[1] = (whole_reg & 0xff000000) >> 24;
258         pBuff[2] = (whole_reg & 0x00ff0000) >> 16;
259         pBuff[3] = (whole_reg & 0x0000ff00) >> 8;
260         pBuff[4] = (whole_reg & 0x000000ff) ;
261                 
262         err = write(fileHandle, pBuff, 5);
263         if(err != 5){
264                 fprintf(stderr, "read err=%d\n", err);
265                 goto err;
266         }
267         
268         err = read(fileHandle, pBuff, reg_count);
269         if(err != reg_count){
270                 fprintf(stderr, "read err=%d\n", err);
271                 goto err;
272         }else{
273                 for(i=0; i< reg_count; i++){
274                         temp_reg = whole_reg + i;
275                         fprintf(stderr, "R B[%d]P[%d]R[%d]=0x%x\n", TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i]);
276                 }
277         }       
279 err:
280         if(pBuff != NULL)
281                 free(pBuff);    
282         
283         return err;
286 static int TiAudio_Debug_On(int fileHandle, int argc, char **argv){
287         int err = -1;
288         unsigned char pBuff[2], on;
289         unsigned int whole_reg = 0;
290         unsigned int temp_reg = 0;
291         int i=0, reg_count = 0;
292         
293         if(argc != 3) {
294                 fprintf(stderr, "invalid para numbers\n");
295                 goto err;
296         }
297         
298         pBuff[0] = TIAUDIO_CMD_DEBUG_ON;
299         
300         err = str2hexchar(argv[2], &on);
301         if(err < 0){
302                 goto err;
303         }
304         
305         pBuff[1] = on; 
306         
307         err = write(fileHandle, pBuff, 2);
308         if(err != 2){
309                 fprintf(stderr, "set err=%d\n", err);
310                 goto err;
311         }
312         
313         if(on == 0){
314                 fprintf(stderr, "DBG msg Off\n");
315         }else{
316                 fprintf(stderr, "DBG msg On\n");
317         }
318         
319 err:
321         return err;
324 static int TiAudio_Program(int fileHandle, int argc, char **argv){
325         int err = -1;
326         unsigned char pBuff[PROGRAM_BUF_SIZE], bSet = 0, nProgram;
327         
328         if(argc == 2){
329                 bSet = 0;
330         }else if(argc == 3){
331                 bSet = 1;
332         }else{
333                 fprintf(stderr, "invalid para numbers\n");
334                 goto err;
335         }
336         
337         pBuff[0] = TIAUDIO_CMD_PROGRAM;
338         
339         if(bSet == 1){
340                 err = str2hexchar(argv[2], &nProgram);
341                 if(err < 0){
342                         goto err;
343                 }
344                 
345                 pBuff[1] = nProgram;
346         }
347         
348         err = write(fileHandle, pBuff, (1+bSet));
349         if(err != (bSet+1)){
350                 fprintf(stderr, "write err=%d\n", err);
351                 goto err;
352         }
353         
354         if(bSet == 1){
355                 fprintf(stderr, "Program Set to %d\n", nProgram);
356         }else{
357                 err = read(fileHandle, pBuff, PROGRAM_BUF_SIZE);
358                 if(err != PROGRAM_BUF_SIZE){
359                         fprintf(stderr, "read err=%d\n", err);
360                         goto err;
361                 }else{
362                         unsigned char nPrograms = pBuff[0];
363                         unsigned char nCurProgram = pBuff[1];
364                         unsigned char *pName = &pBuff[2];
365                         unsigned char *pDescription = &pBuff[2 + FW_NAME_SIZE];
366                         fprintf(stderr, "Total Programs   : %d\n", nPrograms);
367                         fprintf(stderr, "Current Programs : %d\n", nCurProgram);
368                         fprintf(stderr, "\t Name: %s\n", pName);
369                         fprintf(stderr, "\t Description : %s\n", pDescription);
370                 }
371         }
373 err:
375         return err;
378 static int TiAudio_Configuration(int fileHandle, int argc, char **argv){
379         int err = -1;
380         unsigned char pBuff[CONFIGURATION_BUF_SIZE], bSet = 0, nConfiguration;
381         
382         if(argc == 2){
383                 bSet = 0;
384         }else if(argc == 3){
385                 bSet = 1;
386         }else{
387                 fprintf(stderr, "invalid para numbers\n");
388                 goto err;
389         }
390         
391         pBuff[0] = TIAUDIO_CMD_CONFIGURATION;
392         
393         if(bSet == 1){
394                 err = str2hexchar(argv[2], &nConfiguration);
395                 if(err < 0){
396                         goto err;
397                 }
398                 
399                 pBuff[1] = nConfiguration;
400         }
401         
402         err = write(fileHandle, pBuff, (1+bSet));
403         if(err != (bSet+1)){
404                 fprintf(stderr, "write err=%d\n", err);
405                 goto err;
406         }
407         
408         if(bSet == 1){
409                 fprintf(stderr, "Configuration Set to %d\n", nConfiguration);
410         }else{
411                 err = read(fileHandle, pBuff, CONFIGURATION_BUF_SIZE);
412                 if(err != CONFIGURATION_BUF_SIZE){
413                         fprintf(stderr, "read err=%d\n", err);
414                         goto err;
415                 }else{
416                         unsigned char nConfigurations = pBuff[0];
417                         unsigned char nCurConfiguration = pBuff[1];
418                         unsigned char *pName = &pBuff[2];
419                         unsigned char nProgram = pBuff[2 + FW_NAME_SIZE];
420                         unsigned char nPLL = pBuff[3 + FW_NAME_SIZE];
421                         unsigned int nSampleRate = pBuff[4 + FW_NAME_SIZE] + 
422                                 ((unsigned int)pBuff[5 + FW_NAME_SIZE] << 8) +
423                                 ((unsigned int)pBuff[6 + FW_NAME_SIZE] << 16) +
424                                 ((unsigned int)pBuff[7 + FW_NAME_SIZE] << 24);                  
425                         unsigned char *pDescription = &pBuff[8 + FW_NAME_SIZE];
426                         fprintf(stderr, "Total Configurations : %d\n", nConfigurations);
427                         fprintf(stderr, "Current Configuration: %d\n", nCurConfiguration);
428                         fprintf(stderr, "\t Name: %s\n", pName);
429                         fprintf(stderr, "\t Description : %s\n", pDescription);
430                         fprintf(stderr, "\t nProgram: %d\n", nProgram);
431                         fprintf(stderr, "\t nPLL: %d\n", nPLL);
432                         fprintf(stderr, "\t nSampleRate: %d\n", nSampleRate);
433                 }
434         }
436 err:
438         return err;
441 static int TiAudio_SampleRate(int fileHandle, int argc, char **argv){
442         int err = -1;
443         unsigned char pBuff[5];
444         unsigned char bSet = 0;
445         unsigned int nSampleRate;
446         
447         if(argc == 2){
448                 bSet = 0;
449         }else if(argc == 3){
450                 bSet = 1;
451         }else{
452                 fprintf(stderr, "invalid para numbers\n");
453                 goto err;
454         }
455         
456         pBuff[0] = TIAUDIO_CMD_SAMPLERATE;
457         
458         if(bSet == 1){
459                 if(strcmp(argv[2], SR_STR_48K) == 0)
460                         nSampleRate = SR_NUM_48K;
461                 else if(strcmp(argv[2], SR_STR_44K) == 0)
462                         nSampleRate = SR_NUM_44K;
463                 else if(strcmp(argv[2], SR_STR_16K) == 0)
464                         nSampleRate = SR_NUM_16K;
465                 else{
466                         fprintf(stderr, "invalid para numbers\n");
467                         goto err;
468                 }
469                 
470                 pBuff[1] = (nSampleRate&0xff000000)>>24;
471                 pBuff[2] = (nSampleRate&0x00ff0000)>>16;
472                 pBuff[3] = (nSampleRate&0x0000ff00)>>8;
473                 pBuff[4] = (nSampleRate&0x000000ff);
474         }
475         
476         err = write(fileHandle, pBuff, 1+(bSet?4:0));
477         if(err != (1+bSet?(4):(0))){
478                 fprintf(stderr, "write err=%d\n", err);
479                 goto err;
480         }
481         
482         if(bSet == 1){
483                 fprintf(stderr, "Sample Rate Set to %d\n", nSampleRate);
484         }else{
485                 err = read(fileHandle, pBuff, 4);
486                 if(err != 4){
487                         fprintf(stderr, "read err=%d\n", err);
488                         goto err;
489                 }else{
490                         nSampleRate = pBuff[0] + 
491                                 ((unsigned int)pBuff[1] << 8) +
492                                 ((unsigned int)pBuff[2] << 16) +
493                                 ((unsigned int)pBuff[3] << 24);                 
494                         fprintf(stderr, "\t nSampleRate: %d\n", nSampleRate);
495                 }
496         }
498 err:
500         return err;
503 static int TiAudio_BitRate(int fileHandle, int argc, char **argv){
504         int err = -1;
505         unsigned char pBuff[5];
506         unsigned char bSet = 0;
507         unsigned int nBitRate;
508         
509         if(argc == 2){
510                 bSet = 0;
511         }else if(argc == 3){
512                 bSet = 1;
513         }else{
514                 fprintf(stderr, "invalid para numbers\n");
515                 goto err;
516         }
517         
518         pBuff[0] = TIAUDIO_CMD_BITRATE;
519         
520         if(bSet == 1){
521                 if(strcmp(argv[2], "32") == 0)
522                         nBitRate = 32;
523                 else if(strcmp(argv[2], "24") == 0)
524                         nBitRate = 24;
525                 else if(strcmp(argv[2], "20") == 0)
526                         nBitRate = 20;
527                 else if(strcmp(argv[2], "16") == 0)
528                         nBitRate = 16;                  
529                 else{
530                         fprintf(stderr, "invalid para numbers\n");
531                         goto err;
532                 }
533                 
534                 pBuff[1] = nBitRate;
535         }
536         
537         err = write(fileHandle, pBuff, (1+bSet));
538         if(err != (1+bSet)){
539                 fprintf(stderr, "write err=%d\n", err);
540                 goto err;
541         }
542         
543         if(bSet == 1){
544                 fprintf(stderr, "BitRate Set to %d\n", nBitRate);
545         }else{
546                 err = read(fileHandle, pBuff, 4);
547                 if(err != 4){
548                         fprintf(stderr, "read err=%d\n", err);
549                         goto err;
550                 }else{
551                         nBitRate = pBuff[0] + 
552                                 ((unsigned int)pBuff[1] << 8) +
553                                 ((unsigned int)pBuff[2] << 16) +
554                                 ((unsigned int)pBuff[3] << 24);                 
555                         fprintf(stderr, "\t BitRate: %d\n", nBitRate);
556                 }
557         }
559 err:
561         return err;
564 static int TiAudio_DACVolume(int fileHandle, int argc, char **argv){
565         int err = -1;
566         unsigned char pBuff[5];
567         unsigned char bSet = 0;
568         unsigned int nVol;
569         
570         if(argc == 2){
571                 bSet = 0;
572         }else if(argc == 3){
573                 bSet = 1;
574         }else{
575                 fprintf(stderr, "invalid para numbers\n");
576                 goto err;
577         }
578         
579         pBuff[0] = TIAUDIO_CMD_DACVOLUME;
580         
581         if(bSet == 1){
582                 err = str2decimal(argv[2], &nVol);
583                 if(err < 0){
584                         goto err;
585                 }
586                 
587                 pBuff[1] = nVol;
588         }
589         
590         err = write(fileHandle, pBuff, (1+bSet));
591         if(err != (1+bSet)){
592                 fprintf(stderr, "write err=%d\n", err);
593                 goto err;
594         }
595         
596         if(bSet == 1){
597                 fprintf(stderr, "DAC Volume Set to %d\n", nVol);
598         }else{
599                 err = read(fileHandle, pBuff, 1);
600                 if(err != 1){
601                         fprintf(stderr, "read err=%d\n", err);
602                         goto err;
603                 }else{
604                         nVol = pBuff[0];                
605                         fprintf(stderr, "\t nSampleRate: %d\n", nVol);
606                 }
607         }
609 err:
611         return err;
614 static int TiAudio_SpeakerOn(int fileHandle, int argc, char **argv){
615         int err = -1;
616         unsigned char pBuff[2], on;
617         unsigned int whole_reg = 0;
618         unsigned int temp_reg = 0;
619         int i=0, reg_count = 0;
620         
621         if(argc != 3) {
622                 fprintf(stderr, "invalid para numbers\n");
623                 goto err;
624         }
625         
626         pBuff[0] = TIAUDIO_CMD_SPEAKER;
627         
628         err = str2hexchar(argv[2], &on);
629         if(err < 0){
630                 goto err;
631         }
632         
633         pBuff[1] = on; 
634         
635         err = write(fileHandle, pBuff, 2);
636         if(err != 2){
637                 fprintf(stderr, "set err=%d\n", err);
638                 goto err;
639         }
640         
641         if(on == 0){
642                 fprintf(stderr, "TAS2555 Power Off\n");
643         }else{
644                 fprintf(stderr, "TAS2555 Power On\n");
645         }
646         
647 err:
649         return err;
652 static int TiAudio_Timestamp(int fileHandle, int argc, char **argv){
653         int err = -1;
654         unsigned char pBuff[4];
655         unsigned int nTimestamp = 0;
656         
657         pBuff[0] = TIAUDIO_CMD_FW_TIMESTAMP;
658         
659         err = write(fileHandle, pBuff, 1);
660         if(err != 1){
661                 fprintf(stderr, "write err=%d\n", err);
662                 goto err;
663         }
664         
665         err = read(fileHandle, pBuff, 4);
666         if(err != 4){
667                 fprintf(stderr, "read err=%d\n", err);
668                 goto err;
669         }else{
670                 unsigned int nTimestamp = pBuff[0] + 
671                         ((unsigned int)pBuff[1] << 8) +
672                         ((unsigned int)pBuff[2] << 16) +
673                         ((unsigned int)pBuff[3] << 24);
674         
675                 time_t t = (time_t)nTimestamp;  
676                 struct tm *p;  
677                 p=gmtime(&t);  
678                 char s[100];  
679                 strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", p);  
680                 fprintf(stderr, "FW Timestamp : %d: %s\n", (int)t, s); 
681         }
683 err:
685         return err;
688 static int getDevHandle(){
689         int fileHandle = -1, i;
690         fileHandle = open(TI_AUDIO_NAME, O_RDWR);
691         if(fileHandle < 0 ){
692                 fprintf(stderr, "[ERROR]file(%s) open_RDWR error\n", TI_AUDIO_NAME);
693         }               
695         return fileHandle;
698 int main(int argc, char **argv)
700         int ret = 0;
701         int ch;
702         int fileHandle = -1;
704         fileHandle = getDevHandle();
705         if(fileHandle < 0 ){
706                 fprintf(stderr, " file handle err=%d\n", fileHandle);
707                 return ret;
708         }
709         
710         if(argc == 1){
711                 usage();
712                 return 0;
713         }
715         while ((ch = getopt(argc, argv, "wrdpcsbvot")) != -1) {
716                 switch (ch) {
717                 case 'w': 
718                         ret = TiAudio_Reg_Write(fileHandle, argc, argv);                        
719                         break;
720                 case 'r':
721                         ret = TiAudio_Reg_Read(fileHandle, argc, argv);
722                         break;
723                 case 'd':
724                         ret = TiAudio_Debug_On(fileHandle, argc, argv);
725                         break;          
726                 case 'p':
727                         ret = TiAudio_Program(fileHandle, argc, argv);
728                         break;                                  
729                 case 'c':
730                         ret = TiAudio_Configuration(fileHandle, argc, argv);
731                         break;          
732                 case 's':
733                         ret = TiAudio_SampleRate(fileHandle, argc, argv);
734                         break;          
735                 case 'b':
736                         ret = TiAudio_BitRate(fileHandle, argc, argv);
737                         break;
738                 case 'v':
739                         ret = TiAudio_DACVolume(fileHandle, argc, argv);
740                         break;          
741                 case 'o':
742                         ret = TiAudio_SpeakerOn(fileHandle, argc, argv);
743                         break;                          
744                 case 't':
745                         ret = TiAudio_Timestamp(fileHandle, argc, argv);
746                         break;                                  
747                 default:
748                         usage();
749                         break;
750                 }
751         }
753         if(fileHandle > 0 )
754                 close(fileHandle);
755         
756         return ret;