Example #1
0
int main(int argc, char *argv[])
{
	int errorexit = 0;
	
    if (argc>1) {
      g_rate = (argc>2?atoi(argv[2]):RATE);
    } else {
    	errorexit = 1;
    }
    if (g_rate > MAXRATE) {
    	errorexit=1;
    }
    	
    if (errorexit) {
      fprintf(stderr, "Usage:   %s wavfile.wav [sample rate]\n",argv[0]);
      fprintf(stderr, "	default sample rate = %d\n",RATE);
      fprintf(stderr, "	maximum samplerate = %d\n",MAXRATE);
      return 1;
    }

    // locals
    uint32_t starttime = time(NULL) ;
    uint8_t ft ; 
    char inputfile[255], outputfile[255] ;
    
    // string hygeine
    memset( inputfile  , 0 , 255 ) ;
    memset( outputfile , 0 , 255 ) ;
    
    // assign values to globals

    double temp1, temp2, temp3 ;
    temp1 = (double)( 1 << (BITS - 1) ) ;
    temp2 = VOLPCT / 100.0 ;
    temp3 = temp1 * temp2 ;
    g_scale = (uint32_t)temp3 ;
    
    g_twopioverrate = 2.0 * M_PI / g_rate ;
    g_uspersample = 1000000.0 / (double)g_rate ;

    g_theta = 0.0 ;
    g_samples = 0.0 ;
    g_fudge = 0.0 ;

    printf( "Constants check:\n" ) ;
    printf( "      rate = %d\n" , g_rate ) ;
    printf( "      BITS = %d\n" , BITS ) ;
    printf( "    VOLPCT = %d\n" , VOLPCT ) ; 
    printf( "     scale = %d\n" , g_scale ) ;
    printf( "   us/samp = %f\n" , g_uspersample ) ;
    printf( "   2p/rate = %f\n\n" , g_twopioverrate ) ;
    
    // set filenames    
    strncpy( inputfile , argv[1] , strlen( argv[1] ) ) ;
    ft = filetype( inputfile ) ;
    if ( ft == FILETYPE_ERR ) 
    {
        printf( "Exiting.\n" ) ;
        return 2 ;
    }
    
    strncpy( outputfile, inputfile , strlen( inputfile ) ) ;
    
#ifdef AUDIO_AIFF    
    strcat( outputfile , ".aiff" ) ;
#endif
#ifdef AUDIO_WAV    
    strcat( outputfile , ".wav" ) ;
#endif
    
    printf( "Input  file is [%s].\n" , inputfile ) ;
    printf( "Output file is [%s].\n" , outputfile ) ;
    
    // prep
    
    g_imgfp = fopen( inputfile , "r" ) ;
    g_outfp = fopen( outputfile , "w" ) ;
    printf( "FILE ptrs opened.\n" ) ;
    
    if ( ft == FILETYPE_JPG ) 
    { g_imgp = gdImageCreateFromJpeg( g_imgfp ) ; }
    else if ( ft == FILETYPE_PNG ) 
    { g_imgp = gdImageCreateFromPng( g_imgfp ) ; }
    else
    {
        printf( "Some weird error!\n" ) ;
        return 3 ;
    }    
    
    printf( "Image ptr opened.\n" ) ;

    // go!

    addvisheader() ;
    buildaudio() ;
    addvistrailer() ;
    
#ifdef AUDIO_AIFF    
    writefile_aiff() ;
#endif
#ifdef AUDIO_WAV
    writefile_wav();
#endif    

    // cleanup

    fclose( g_imgfp ) ;
    fclose( g_outfp ) ;
    
    // brag
    
    uint32_t endtime = time(NULL) ;
    printf( "Created soundfile in %d seconds.\n" , ( endtime - starttime ) ) ;
    
    return 0 ;
}
Example #2
0
int main(int argc, char *argv[]) {

    char *protocol; 
	int option;

    g_rate = RATE;
    while ((option = getopt(argc, argv, "r:p:")) != -1) {
        switch (option) {
            case 'r':
                g_rate = (atoi(optarg));
                break;
            case 'p':
                protocol = optarg;
                break;
        }
    }

    //Set VIS codes
    if ( strcmp(protocol, "m1") == 0 ) {
        g_protocol = 44; //Martin 1
    }
    else if ( strcmp(protocol,"m2") == 0) {
        g_protocol = 40; //Martin 2
    }
    else if ( strcmp(protocol,"s1") == 0) {
        g_protocol = 60; //Scottie 1
    }
    else if ( strcmp(protocol,"s2") == 0) {
        g_protocol = 56; //Scottie 2
    }
    else if ( strcmp(protocol,"sdx") == 0) {
        g_protocol = 76; //Scottie DX
    }
    else if ( strcmp(protocol,"r36") == 0) {
        g_protocol = 8; //Robot 36
    }
    else {
        printf("Unrecognized protocol option %s, defaulting to Martin 1...\n\n", protocol);
        g_protocol = 44;
    }


    // locals
    uint32_t starttime = time(NULL) ;
    uint8_t ft ; 
    char inputfile[255], outputfile[255] ;
    
    // string hygeine
    memset( inputfile  , 0 , 255 ) ;
    memset( outputfile , 0 , 255 ) ;
    
    // assign values to globals

    double temp1, temp2, temp3 ;
    temp1 = (double)( 1 << (BITS - 1) ) ;
    temp2 = VOLPCT / 100.0 ;
    temp3 = temp1 * temp2 ;
    g_scale = (uint32_t)temp3 ;
    
    g_twopioverrate = 2.0 * M_PI / g_rate ;
    g_uspersample = 1000000.0 / (double)g_rate ;

    g_theta = 0.0 ;
    g_samples = 0.0 ;
    g_fudge = 0.0 ;

    printf( "Constants check:\n" ) ;
    printf( "      rate = %d\n" , g_rate ) ;
    printf( "  VIS code = %d\n" , g_protocol);
    printf( "      BITS = %d\n" , BITS ) ;
    printf( "    VOLPCT = %d\n" , VOLPCT ) ; 
    printf( "     scale = %d\n" , g_scale ) ;
    printf( "   us/samp = %f\n" , g_uspersample ) ;
    printf( "   2p/rate = %f\n\n" , g_twopioverrate ) ;
    
    // set filenames    
    strncpy( inputfile , argv[optind] , strlen( argv[optind] ) ) ;
    ft = filetype( inputfile ) ;
    if ( ft == FILETYPE_ERR ) 
    {
        printf( "Exiting.\n" ) ;
        return 2 ;
    }
    
    strncpy( outputfile, inputfile , strlen( inputfile ) ) ;
    
#ifdef AUDIO_AIFF    
    strcat( outputfile , ".aiff" ) ;
#endif
#ifdef AUDIO_WAV    
    strcat( outputfile , ".wav" ) ;
#endif
    
    printf( "Input  file is [%s].\n" , inputfile ) ;
    printf( "Output file is [%s].\n" , outputfile ) ;
    
    // prep
    
    g_imgfp = fopen( inputfile , "r" ) ;
    g_outfp = fopen( outputfile , "w" ) ;
    printf( "FILE ptrs opened.\n" ) ;
    
    if ( ft == FILETYPE_JPG ) 
    { g_imgp = gdImageCreateFromJpeg( g_imgfp ) ; }
    else if ( ft == FILETYPE_PNG ) 
    { g_imgp = gdImageCreateFromPng( g_imgfp ) ; }
    else {
        printf( "Some weird error!\n" ) ;
        return 3 ;
    }    
    
    printf( "Image ptr opened.\n" ) ;

    // go!

    addvisheader() ;
    
    //Selects audio format mode
    switch (g_protocol) {
        case 44: //Martin 1
            buildaudio_m(457.6);
            break;
        case 40: //Martin 2
            buildaudio_m(228.8);
            break;
        case 60: //Scottie 1
            buildaudio_s(432.0);
            break;
        case 56: //Scottie 2
            buildaudio_s(275.2);
            break;
        case 76: //Scottie DX
            buildaudio_s(1080.0);
            break;
        case 8: //Robot 36
            buildaudio_r36();
            break;
        default:
            printf("Something went horribly wrong: unknown protocol while building audio!\n");
            exit(2);
            break;
    }


    addvistrailer() ;
    
#ifdef AUDIO_AIFF    
    writefile_aiff() ;
#endif
#ifdef AUDIO_WAV
    writefile_wav();
#endif    

    // cleanup

    fclose( g_imgfp ) ;
    fclose( g_outfp ) ;
    
    // brag
    
    uint32_t endtime = time(NULL) ;
    printf( "Created soundfile in %d seconds.\n" , ( endtime - starttime ) ) ;
    
    return 0 ;
}