JuliaAudio / PortAudio.jl

PortAudio wrapper for the Julia programming language, compatible with the JuliaAudio family of packages
Other
115 stars 19 forks source link

Add octave shift example #110

Closed JeffFessler closed 2 years ago

JeffFessler commented 2 years ago

This PR provides an example of performing a real-time octave (down) shift using a crude FFT approach. I did not see any examples that show audio processing of an input stream and writing the results to an output stream and I wanted to have an illustration of that for students in my course.

This is independent of #107 though of course they both work on the examples/ directory.

codecov[bot] commented 2 years ago

Codecov Report

Merging #110 (ef0cfcb) into master (78a0a99) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #110   +/-   ##
=======================================
  Coverage   97.38%   97.38%           
=======================================
  Files           2        2           
  Lines         344      344           
=======================================
  Hits          335      335           
  Misses          9        9           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 78a0a99...ef0cfcb. Read the comment docs.

bramtayl commented 2 years ago

Wow, this looks great! It would good to have it only run for a specific amount of time, so we can eventually run it in CI. The pattern I've used in #107 was

@sync begin
    @async while !done
        # refresh the plot
    end
    sleep(seconds)
    done = true
end

There might be better ways to do this.

bramtayl commented 2 years ago

PS, do you want to join as a maintainer?

JeffFessler commented 2 years ago

PS, do you want to join as a maintainer?

Yes, I would be happy to help in that way. I don't know anything about libportaudio but can help on the Julia side. Thanks!

JeffFessler commented 2 years ago

Ok, I implemented the suggested @async model, which was a nice trick for me to learn. Perhaps another way would be to calculate the number of loop iterations from the duration and the buffer length and the sample size: Niters = Int(seconds * sampling_rate / N)

I might slightly prefer that way, because it will look less mysterious to beginnners. Do you have a preference?

bramtayl commented 2 years ago

Do you have a preference?

Nope, whatever works!

JeffFessler commented 2 years ago

Ok, I went with the loop approach and added a bit more documentation and now it is ready for review.

bramtayl commented 2 years ago

This looks good to me!

bramtayl commented 2 years ago

This looks good to me!