bool AubioPitch::processFrame(float* frame, int size){// //note this no longer called int j; bool pitchDetected = false; //smpl_t pitch; for (j=0;j<size;j++) { fvec_write_sample(vec, frame[j], 0, pos); if (pos == hopsize-1) { //anr recent change from hopsize // block loop / pitch = aubio_pitchdetection(pitchDetect, vec); pitchDetected = true; printf("PITCH IS %f\n", pitch); // printf("Pitch detected %f\n", pitch); // outlet_float(x->pitchOutlet, pitch); // end of block loop pos = -1; // so it will be zero next j loop // } pos++; } return pitchDetected; }
//anr idea of adding to buffer void AubioPitch::addToBuffer(float* tmpFrame, const int& n){ for (int j=0;j < n;j++) { fvec_write_sample(vec, tmpFrame[j], 0, pos); if (pos == hopsize - 1){ //pitch = aubio_pitchdetection(x->o,x->vec); //outlet_float(x->pitchOutlet, pitch); pitch = aubio_pitchdetection(pitchDetect, vec); pos = -1; } pos++; } }
float AubioPitch::doPitchDetection(float* frame, const int& length){ //fn to do pitch detection without all the buffering etc float newPitch = -1.0; if (length == bufsize){ fvec_t* tmpVec; tmpVec = new_fvec(bufsize,1); for (int j =0;j < length;j++){ fvec_write_sample(tmpVec, frame[j], 0, j); // printf("vec[%i] = %.3f\n", j, frame[j]); } newPitch = aubio_pitchdetection(pitchDetect, tmpVec); // printf("NEW PITCH FOUND %f\n", newPitch); } return newPitch; }
// Jack | Process Callback int process(jack_nframes_t nframes, void *arg) { sample_t * in = (sample_t *) jack_port_get_buffer(input_port, nframes); sample_t * out = (sample_t *) jack_port_get_buffer(output_port, nframes); if (aubio_fvec == NULL || aubio_fvec->data == NULL) { init_aubio(sample_rate); } // jack_nframes_t i; for (i = 0; i < nframes; i++) { // ???: What is the significance of `framecount == hopsize`? if (framecount == hopsize) { image_tones_index++; if (image_tones_index >= image_tones_size) { image_tones_index = 0; } // Build waveform for the next pixel of our original image // TODO: Consider a "feedback" mode. build_tone(image_tones[image_tones_index], 1 - image_tones_amp[image_tones_index], waveform_type); // Write_to_image() according to analyzed samples // TODO: How often are the vars below redeclared? float H, S, L, R, G, B; Sound2Hsl(&H, &S, &L, aubio_pitchdetection(aubio, aubio_fvec), max_amp, pitch_scale, lower_bounds); Hsl2Rgb(&R, &G, &B, H, S, 1 - L); write_to_image(dest_image, R, G, B); framecount = 0; max_amp = 0; } out[i] = cycle[offset]; // !!!: aubio_fvec->data[0][framecount] = (smpl_t) in[i]; if (fabs(in[i]) > max_amp) { max_amp = fabs(in[i]); } offset++; if (offset == samples_per_cycle) { offset = 0; } framecount++; } return 0; }
//-------------------------------------------------------------- void aubioAnalyzer::processAudio (float * input, int bufferSize){ float rmsAmplitude = 0; for (int i = 0; i < bufferSize; i++){ //calculate the root mean square amplitude rmsAmplitude += sqrt(input[i]*input[i]); //put the data into aubio in->data[0][i] = input[i]; } //now we need to get the average rmsAmplitude /= bufferSize; amplitude = rmsAmplitude; //don't update the pitch if the sound is very quiet if( amplitude > 0.001 ){ //finally get the pitch of the sound pitch = aubio_pitchdetection(pitch_output,in); long int p=(int)pitch; if (p!=0){ while(p>440){ p=p/2; } while(p<220){ p=p*2; } } top_pitches[p]+=amplitude; pitch_color=pitch_color.fromHsb(p-222,255, 255); } aubio_beattracking_do(tracker,in,beats); }
//-------------------------------------------------------------- void aubioAnalyzer::processAudio (float * input, int bufferSize){ float rmsAmplitude = 0; for (int i = 0; i < bufferSize; i++){ //calculate the root mean square amplitude rmsAmplitude += sqrt(input[i]*input[i]); //put the data into aubio in->data[0][i] = input[i]; } //now we need to get the average rmsAmplitude /= bufferSize; amplitude = rmsAmplitude; //don't update the pitch if the sound is very quiet if( amplitude > 0.01 ){ //finally get the pitch of the sound pitch = aubio_pitchdetection(pitch_output,in); } }