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

Resample Example does not work. #158

Open
patrickvonplaten opened this issue May 1, 2021 · 1 comment
Open

Resample Example does not work. #158

patrickvonplaten opened this issue May 1, 2021 · 1 comment

Comments

@patrickvonplaten
Copy link

patrickvonplaten commented May 1, 2021

Hey,

thanks a lot for the nice library!

When trying to run the official resampling example - here, I'm getting some import errors.

Here the code:

// An example of using `sample` to efficiently perform decent quality sample rate conversion on a
// WAV file entirely on the stack.

use dasp::{interpolate::sinc::Sinc, ring_buffer, signal, Sample, Signal};
use hound::{WavReader, WavWriter};

fn main() {
    // Find and load the wav.
    let assets = find_folder::Search::ParentsThenKids(5, 5)
        .for_folder("assets")
        .unwrap();
    let reader = WavReader::open(assets.join("two_vowels.wav")).unwrap();

    // Get the wav spec and create a target with the new desired sample rate.
    let spec = reader.spec();
    let mut target = spec;
    target.sample_rate = 10_000;

    // Read the interleaved samples and convert them to a signal.
    let samples = reader
        .into_samples()
        .filter_map(Result::ok)
        .map(i16::to_sample::<f64>);
    let signal = signal::from_interleaved_samples_iter(samples);

    // Convert the signal's sample rate using `Sinc` interpolation.
    let ring_buffer = ring_buffer::Fixed::from([[0.0]; 100]);
    let sinc = Sinc::new(ring_buffer);
    let new_signal = signal.from_hz_to_hz(sinc, spec.sample_rate as f64, target.sample_rate as f64);

    // Write the result to a new file.
    let mut writer = WavWriter::create(assets.join("two_vowels_10k.wav"), target).unwrap();
    for frame in new_signal.until_exhausted() {
        writer.write_sample(frame[0].to_sample::<i16>()).unwrap();
    }
}

which gives:

error[E0433]: failed to resolve: could not find `interpolate` in `dasp`
 --> src/main.rs:4:12
  |
4 | use dasp::{interpolate::sinc::Sinc, ring_buffer, signal, Sample, Signal};
  |            ^^^^^^^^^^^ could not find `interpolate` in `dasp`

error[E0432]: unresolved imports `dasp::ring_buffer`, `dasp::signal`, `dasp::Signal`
 --> src/main.rs:4:37
  |
4 | use dasp::{interpolate::sinc::Sinc, ring_buffer, signal, Sample, Signal};
  |                                     ^^^^^^^^^^^  ^^^^^^          ^^^^^^ no `Signal` in the root
  |                                     |            |
  |                                     |            no `signal` in the root
  |                                     no `ring_buffer` in the root

error[E0433]: failed to resolve: use of undeclared crate or module `find_folder`
 --> src/main.rs:9:18
  |
9 |     let assets = find_folder::Search::ParentsThenKids(5, 5)
  |                  ^^^^^^^^^^^ use of undeclared crate or module `find_folder`

error[E0433]: failed to resolve: use of undeclared type `Sinc`
  --> src/main.rs:28:16
   |
28 |     let sinc = Sinc::new(ring_buffer);
   |                ^^^^ use of undeclared type `Sinc`

When run in main.rs.

Do you know how to successfully fix it?

@Jerboas86
Copy link

Resample example works fine to me.

Are you sure that you didn't forget the features attribute on dasp dependency in your cargo.toml.
To help debug, you can compare your cargo.toml with mine.

[package]
name = "dasp"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "^1.0"
cpal = "^0.13"
dasp = {version = "^0.11", features= ["all"]}
hound = "^3.4"
find_folder = "0.3"

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