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

use full decimation instead of fast #133

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions friture/audioproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ def __init__(self):
def analyzelive(self, samples):
samples = self.decimate(samples)

# uncomment the following to disable the decimation altogether
# decimation = 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried setting self.decimation = 1 here, and that just resulted an error on the next line, "Operands cannot be broadcast together with shapes (4096,) (256,)"; so I think this comment is outdated

Copy link
Author

@egitto egitto Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I also tried using self.decimation = 1 and "fixing" the below line to make the shapes line up, but that just resulted in this error instead; I guess the value of self.decimation affects a bunch of places)
image

fft = rfft(samples * repeat(self.window, len(samples)//len(self.window)))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, lol, actually settings self.decimation = 1 works just fine, you just have to do it in the set_maxfreq function so that it never sets it to any non-1 value
image


# FFT for a linear transformation in frequency scale
fft = rfft(samples * self.window)
spectrum = self.norm_square(fft)
Expand All @@ -60,9 +57,9 @@ def decimate(self, samples):
if self.decimation > 1:
samples.shape = len(samples) // self.decimation, self.decimation
# the full way
# samples = samples.mean(axis=1)
# the simplest way
samples = samples[:, 0]
samples = samples.mean(axis=1)
# the fastest way
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I didn't actually profile this, idk how much computation time goes here vs actually doing the fft and rendering)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I just profiled (with a value of self.decimation == 16) and with the faster way, the decimation function takes about 7.05% of a the FFT's duration, and with the slower way it takes about 93.1% of the FFT's duration. So, a pretty significant cost, assuming the FFT is the expensivest part of this process.

# samples = samples[:, 0]
return samples

def set_fftsize(self, fft_size):
Expand Down