int analyze (char *filename) { float resnum_freq; float resnum_amp; float resnum_env; int i, d; float resnum; current_sample_array = audio_decode(current_sample_array, filename); // Decode audio track resnum_env = envelope_sort((int16_t*)current_sample_array); // Attack sort // TODO better implementation of final sort resnum_amp = amp_sort((int16_t*)current_sample_array); // Amplitude sort resnum_freq = freq_sort((int16_t*)current_sample_array); // Freq sort resnum = resnum_amp + resnum_freq + resnum_env; if(debug) printf("FINAL RESULT: %f\n", resnum); if(resnum == 0) { if(debug) printf("Can't conclude...\n"); return 2; } else if(resnum > 0) { if(debug) printf("Loud\n"); return 0; } else if(resnum < 0) { if(debug) printf("Calm\n"); return 1; } }
/* This callback is called each time the sndstream driver needs some more data. It will tell us how much it needs in bytes. */ static void* xing_callback(snd_stream_hnd_t hnd, int size, int * actual) { static int frames = 0; IN_OUT x; /* Check for file not started or file finished */ if (mp3_fd == 0) return NULL; /* Dump the last PCM packet */ pcm_empty(pcm_discard); /* Loop decoding until we have a full buffer */ while (pcm_count < size) { /* Pull in some more data (and check for EOF) */ if (bs_fill() < 0 || bs_count < frame_bytes) { printf("Decode completed\r\n"); goto errorout; } /* Decode a frame */ x = audio_decode(&mpeg, bs_ptr, (short*)pcm_ptr); if (x.in_bytes <= 0) { printf("Bad sync in MPEG file\r\n"); goto errorout; } bs_ptr += x.in_bytes; bs_count -= x.in_bytes; pcm_ptr += x.out_bytes; pcm_count += x.out_bytes; frames++; /*if (!(frames % 64)) { printf("Decoded %d frames \r", frames); }*/ } pcm_discard = *actual = size; /* Got it successfully */ return pcm_buffer; errorout: fs_close(mp3_fd); mp3_fd = 0; return NULL; }