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

Cannot get subbands to work with Python #67

Open
sebpiq opened this issue Sep 24, 2014 · 2 comments
Open

Cannot get subbands to work with Python #67

sebpiq opened this issue Sep 24, 2014 · 2 comments

Comments

@sebpiq
Copy link

sebpiq commented Sep 24, 2014

Hi again ... sorry for the spam.

I am actually working on a Python wrapper to libxtract to make things more easy ... but as I said in #66 there's a bunch of things I cannot get to work. An example of which is subbands. That might be because I misunderstood something. Here is a sample of code (which needs matplotlib to plot data and numpy) that tries to get things to work. Spectrum apparently works fine (I clearly get a peak at 10 000hz), but subbands is just returning weird results.

from libxtract import xtract
import matplotlib.pyplot as plt
import numpy

def _list_to_doubleArray(a_list):
    mem = a_list
    a_list = xtract.doubleArray(len(mem))
    for i, arg in enumerate(mem): a_list[i] = arg
    return a_list

def _pointer_to_list(pointer, length):
    return [pointer[i] for i in range(0, length)]

sample_count = 2**15
sample_rate = 44100.0
subband_count = 1024
f0 = 10000

# Generate samples
time = numpy.arange(0, sample_count, 1) * 1 / sample_rate
samples = numpy.sin(2 * numpy.pi * f0 * time)

# Calculate spectrum
xtract.xtract_init_fft(sample_count, xtract.XTRACT_SPECTRUM)
spectrum = xtract.doubleArray(sample_count)
argv = [ sample_rate / sample_count, xtract.XTRACT_MAGNITUDE_SPECTRUM, 0, 1 ]
xtract.xtract_spectrum(_list_to_doubleArray(samples), sample_count, _list_to_doubleArray(argv), spectrum)

# Calculate subbands
subbands = xtract.doubleArray(subband_count)
argv = [ xtract.XTRACT_MEAN, subband_count, xtract.XTRACT_LINEAR_SUBBANDS, 0 ]
xtract.xtract_subbands(spectrum, sample_count / 2, _list_to_doubleArray(argv), subbands)

# plot
fig, axes = plt.subplots(nrows=2, ncols=1)
axes[0].scatter(range(0, subband_count), _pointer_to_list(subbands, subband_count))
axes[1].plot(_pointer_to_list(spectrum, sample_count)[sample_count / 2:], _pointer_to_list(spectrum, sample_count / 2))
plt.show()
@sebpiq
Copy link
Author

sebpiq commented Sep 24, 2014

Another weird thing being that if I use XTRACT_SUM instead of mean, I get a nice Segmentation fault (core dumped).

@jamiebullock
Copy link
Owner

Hi, this isn't spam, but very useful and much appreciated feedback and contribution to the project.

I will look into these issues ASAP.

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