| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sfsys.h>
- #include <math.h>
- #include <osbind.h>
- char errstr[2400];
- #define MONO (1)
- #define STEREO (2)
- #define ENDOFSTR ('\0')
- #define LEAVESPACE (10*1024)
- void splice_multiline_string(char *str,char *prefix);
- const char* cdp_version = "7.1.0";
- /*RWD Jan 2014 updated getdrivefreespace(), corrected INFO output format for unsigned long */
- /************************************ CHECK_AVAILABLE_DISKSPACE ********************************/
- int main(int argc,char *argv[])
- {
- double srate, secs, mins, hrs;
- unsigned int outsamps = 0, orig_outsamps;
- int m, k, kk, spacecnt;
- char temp[800];
- unsigned int freespace = getdrivefreespace(/*"temp"*/".") - LEAVESPACE;
- unsigned int start = hz1000();
- if((argc==2) && strcmp(argv[1],"--version")==0) {
- fprintf(stdout,"%s\n",cdp_version);
- fflush(stdout);
- return 0;
- }
- //start = hz1000();
- if(argc!=2) {
- fprintf(stdout,"ERROR: Cannot run this process.\n");
- fflush(stdout);
- //TW UPDATE
- while(!(hz1000() - start))
- ;
- return 1;
- }
- if(sscanf(argv[1],"%lf",&srate)!=1) {
- fprintf(stdout,"ERROR: Cannot read sample rate.\n");
- fflush(stdout);
- //TW UPDATE
- while(!(hz1000() - start))
- ;
- return 1;
- }
- sprintf(errstr,"AVAILABLE DISK SPACE\n");
- sprintf(temp,"%u",freespace);
- strcat(errstr,temp);
- spacecnt = 13 - strlen(temp);
- for(k=0;k<spacecnt;k++)
- strcat(errstr," ");
- strcat(errstr,"bytes\n");
- splice_multiline_string(errstr,"INFO:");
- fflush(stdout);
- kk = 0;
- while (kk < 4) {
- errstr[0] = ENDOFSTR;
- switch(kk) {
- case(0): outsamps = freespace/2; break;
- case(1): outsamps = freespace/3; break;
- case(2): outsamps = freespace/4; break;
- case(3): outsamps = freespace/sizeof(float); break;
- }
- sprintf(temp,"%d",outsamps);
- strcat(errstr,temp);
- spacecnt = 13 - strlen(temp);
- for(k=0;k<spacecnt;k++)
- strcat(errstr," ");
- switch(kk) {
- case(0): strcat(errstr,"16-bit samples\n"); break;
- case(1): strcat(errstr,"24-bit samples\n"); break;
- case(2): strcat(errstr,"32-bit samples\n"); break;
- case(3): strcat(errstr,"float samples\n"); break;
- }
- orig_outsamps = outsamps;
- for(m=MONO;m<=STEREO;m++) {
- switch(m) {
- case(MONO):
- outsamps = orig_outsamps;
- sprintf(temp,"IN MONO : ");
- strcat(errstr,temp);
- break;
- case(STEREO):
- outsamps /= 2;
- sprintf(temp,"IN STEREO : ");
- strcat(errstr,temp);
- break;
- }
- secs = (double)outsamps/srate;
- mins = floor(secs/60.0);
- secs -= mins * 60.0;
- hrs = floor(mins/60.0);
- mins -= hrs * 60.0;
- if(hrs > 0.0) {
- sprintf(temp,"%.0lf",hrs);
- strcat(errstr,temp);
- spacecnt = 3 - strlen(temp);
- for(k=0;k<spacecnt;k++)
- strcat(errstr," ");
- strcat(errstr,"hours ");
- } else {
- for(k=0;k<4 + (int)strlen("hours");k++)
- strcat(errstr," ");
- }
- if(mins > 0.0) {
- sprintf(temp,"%.0lf",mins);
- strcat(errstr,temp);
- spacecnt = 3 - strlen(temp);
- for(k=0;k<spacecnt;k++)
- strcat(errstr," ");
- strcat(errstr,"mins ");
- } else {
- for(k=0;k<4 + (int)strlen("mins");k++)
- strcat(errstr," ");
- }
- sprintf(temp,"%.3lf",secs);
- strcat(errstr,temp);
- spacecnt = 7 - strlen(temp);
- for(k=0;k<spacecnt;k++)
- strcat(errstr," ");
- strcat(errstr,"secs\n");
- }
- splice_multiline_string(errstr,"INFO:");
- fflush(stdout);
- kk++;
- }
- //TW UPDATE
- while(!(hz1000() - start))
- ;
- return 0;
- }
- /****************************** SPLICE_MULTILINE_STRING ******************************/
- void splice_multiline_string(char *str,char *prefix)
- {
- char *p, *q, c;
- p = str;
- q = str;
- while(*q != ENDOFSTR) {
- while(*p != '\n' && *p != ENDOFSTR)
- p++;
- c = *p;
- *p = ENDOFSTR;
- fprintf(stdout,"%s %s\n",prefix,q);
- *p = c;
- if(*p == '\n')
- p++;
- while(*p == '\n') {
- fprintf(stdout,"%s \n",prefix);
- p++;
- }
- q = p;
- p++;
- }
- }
|