On 09/20/2010 10:37 AM, j wade wrote:
> I am attempting to create a .wav file from an array in sage using the
> package wavfile.  I am importing a .wav file using the package
> wavfile, and then using the python wavelets package 'pywt' to create
> the array.  Here are the commands:
> 
> import pywt, scipy, numpy
> from scipy.io import wavfile
> x=wavfile.read('/directory/file.wav')
> (cA, cD)=pywt.dwt(x[1],'db1')
> xnew=pywt.idwt(cA,cD,'db1')
> wavfile.write("noisyholanew.wav",44100, xnew)
> 
> The last command generates the following error message:
> ------------------------------------------------------------------
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "_sage_input_23.py", line 10, in <module>
>     exec compile(u'open("___code___.py","w").write("# -*- coding:
> utf-8 -*-\\n" +
> _support_.preparse_worksheet_cell(base64.b64decode("d2F2ZmlsZS53cml0ZSgibm9pc3lob2xhbmV3LndhdiIsNDQxMDAsIHhuZXcp"),globals())
> +"\\n"); execfile(os.path.abspath("___code___.py"))
>   File "", line 1, in <module>
> 
>   File "/tmp/tmpJPm6LZ/___code___.py", line 3, in <module>
>     exec
> compile(u'wavfile.write("noisyholanew.wav",_sage_const_44100 , xnew)
>   File "", line 1, in <module>
> 
>   File "/home/jeremy/Programs/sage-4.5.3/local/lib/python2.6/site-
> packages/scipy/io/wavfile.py", line 99, in write
>     fid.write(struct.pack('ihHIIHH', 16, 1, noc, rate, sbytes, ba,
> bits))
> SystemError: Objects/longobject.c:336: bad argument to internal
> function
> 
> noisyholanew.wav
> -------------------------------------------------------------------
> 
> xnew is the array.  type(xnew) returns <type 'numpy.ndarray'>.
> 
> When I run this series of commands in a python shell, I receive no
> error, and a .wav file is generated.
> 
> I would like to be able to run this series of commands in sage as
> well.
> 
> I am using Sage 4.5.3 (compiled from source) and Python 2.6.4 on
> Ubuntu 9.10.

I followed Minh's instructions

http://groups.google.com/group/sage-support/browse_thread/thread/6c2b30e1690b9d7e/b18651943453a4b5#b18651943453a4b5

to install PyWavelets in Sage 4.6.alpha1 and get ultimately the same
SystemError with the Sage command-line interpreter:

sage: import pywt, scipy, numpy
sage: from scipy.io import wavfile
sage: x=wavfile.read('moo.wav')
Reading fmt chunk
Reading data chunk
sage: (cA, cD)=pywt.dwt(x[1],'db1')
sage: xnew=pywt.idwt(cA,cD,'db1')
sage: wavfile.write("noisyholanew.wav",44100, xnew)
/mnt/usb1/scratch/mpatel/tmp/sage-4.6.alpha1-pywt/local/bin/sage-ipython:1:
DeprecationWarning: struct integer overflow masking is deprecated
  #!/usr/bin/env python
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)

/mnt/usb1/scratch/mpatel/tmp/sage-4.6.alpha1-pywt/<ipython console> in
<module>()

/mnt/usb1/scratch/mpatel/tmp/sage-4.6.alpha1-pywt/local/lib/python2.6/site-packages/scipy/io/wavfile.pyc
in write(filename, rate, data)
     97     sbytes = rate*(bits / 8)*noc
     98     ba = noc * (bits / 8)
---> 99     fid.write(struct.pack('ihHIIHH', 16, 1, noc, rate, sbytes,
ba, bits))
    100     # data chunk

    101     fid.write('data')

SystemError: Objects/longobject.c:336: bad argument to internal function
sage:

But I get no visible errors with './sage -python' or './sage -ipython'.

I don't know if the problem is in the Sage library, Python, NumPy,
and/or PyWavelets.  Maybe one of

http://projects.scipy.org/numpy/ticket/1110
http://www.mail-archive.com/[email protected]/msg00362.html
http://lists.tiker.net/pipermail/pycuda/2009-November/001951.html

will help?

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to