Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault(core dumped) #21

Open
dataO1 opened this issue Feb 11, 2022 · 1 comment
Open

Segmentation fault(core dumped) #21

dataO1 opened this issue Feb 11, 2022 · 1 comment

Comments

@dataO1
Copy link

dataO1 commented Feb 11, 2022

I am trying to do tempo detection on a mp3 file decoded by symphonia, but everythime I do let tempo = tempo.do_result(samples).unwrap(); I get a segfault.

I tried to properly handling the result, which didn't help. I also tried the builtin for a standalone solution and pkg-config flags with aubio installed as a library package, which also didn't help. I guess the error is coming from the underlying C code? Maybe the formatting of the samples is wrong or something?

Example Code
   pub fn get_tempo(file_path: &str) -> f32 {
     // let mut reader = WavReader::open("./test.wav").unwrap();
     let mut reader = Player::new_reader(file_path);
     let track = reader.default_track().unwrap();
     let num_samples = track.codec_params.n_frames.unwrap();
     let sample_rate = track.codec_params.sample_rate.unwrap();
     // let sample_format = track.codec_params.sample_format.unwrap();
     let dec_opts: DecoderOptions = DecoderOptions {
         verify: true,
         ..Default::default()
     };
     let mut decoder = symphonia::default::get_codecs()
         .make(&track.codec_params, &dec_opts)
         .unwrap();
     let mut samples = vec![0 as f32; num_samples as usize];
     let mut tempo = Tempo::new(aubio::OnsetMode::Hfc, 1024, 512, sample_rate).unwrap();
     let mut sample_buf: Option<SampleBuffer<f32>> = None;
     while let Ok(p) = reader.next_packet() {
         let audio_buf = decoder.decode(&p).unwrap();
         // let num_samples = audio_buf.frames();
         // Copy the decoded audio buffer into the sample buffer in an interleaved format.
         match &mut sample_buf {
             Some(buf) => {
                 buf.copy_interleaved_ref(audio_buf);
                 let packet_samples = buf.samples();
                 // println!("{:#?}", packet_samples);
                 samples.extend_from_slice(packet_samples);
             }
             None => {
                 println!("init sample buffer!");
                 let spec = *audio_buf.spec();
                 // Get the capacity of the decoded buffer. Note: This is capacity, not length!
                 let duration = audio_buf.capacity() as u64;
                 // Create the f32 sample buffer.
                 sample_buf = Some(SampleBuffer::<f32>::new(duration, spec));
             }
         }
     }
     println!("starting analysis");
     let tempo = match tempo.do_result(samples) {
         Ok(x) => x,
         Err(err) => {
             println!("{:#?}", err);
             0 as f32
         }
     };
     tempo
 }
@RUGMJ
Copy link

RUGMJ commented Jun 24, 2023

Having the same error with pitch detection, did you find a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants