Hello, I've got a few codes that use "arrayrange" within numpy. It happens that the new version of numpy apparently doesn't recognize "arrayrange"... I've tried to change it to "arange", but it doesn't work... So, for example, the code below used to create a sine wave file, but it's not working anymore... Does anyone have any clue of what may be a solution for this? Thanks!!! Miguel # Basic sound generation # Generate a sine wave and stick it in an AIFC file # Assumes mono, 16-bit sound # SRate, duration, and frequency are variables from numpy import arange, sin, pi from array import array import aifc print "----------------" SRate = 44100.0 # sampling rate of the output file durSecs = 1.0 #its duration in seconds durSamps = int(SRate * durSecs) # resulting number of samples freq = 330 #frequency of the sine wave in Hz (cycles per second) maxShort = 2** 15 # the largest possible signed 16-bit integer # Make a floating point sinewave array using two handy functions from NumPy: t = arange(0, durSecs, 1.0/SRate) sineWave = sin(2*pi*freq*t) # print "max value of sine is: " + str( max(sineWave)) # Now write it into a 16-bit integer array, adjusting the values to "fill" that format sineWaveArray = array('h', [0]*len(sineWave)) for i in range(0, len(sineWave)): sineWaveArray[i] = int(sineWave[i] * maxShort) # Finally, write it to an AIFF file filename = str(freq) + ".aiff" out = aifc.open(filename, "wb") out.aiff() #out.setparams((1, 2, 44100, 100, 'NONE', 'not compressed')) out.setparams((1, 2, int(SRate), int(durSamps), 'NONE', 'not compressed')) out.writeframes(sineWaveArray.tostring()) # this is the crucial step: the .tostring() method forces this into the string format that AIFC requires out.close() print "Successfully wrote a sine wave of frequency " + str(freq) + " to file: " + filename
Miguel Oliveira, Jr. wrote:
Hello,
I've got a few codes that use "arrayrange" within numpy. It happens that the new version of numpy apparently doesn't recognize "arrayrange"... I've tried to change it to "arange", but it doesn't work... So, for example, the code below used to create a sine wave file, but it's not working anymore... Does anyone have any clue of what may be a solution for this?
arange() is the appropriate replacement for arrayrange(); arrayrange() was just an alias to arange(). What did you expect it to do that it isn't doing? -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Hi Robert, I'm expecting that the code generates a sine wave sound file in aiff format... Apparently the code worked before when arrayrange() was used... Thanks! M. On 14 Mar 2007, at 17:31, Robert Kern wrote:
Miguel Oliveira, Jr. wrote:
Hello,
I've got a few codes that use "arrayrange" within numpy. It happens that the new version of numpy apparently doesn't recognize "arrayrange"... I've tried to change it to "arange", but it doesn't work... So, for example, the code below used to create a sine wave file, but it's not working anymore... Does anyone have any clue of what may be a solution for this?
arange() is the appropriate replacement for arrayrange(); arrayrange () was just an alias to arange(). What did you expect it to do that it isn't doing?
-- Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Miguel Oliveira, Jr. wrote:
Hi Robert,
I'm expecting that the code generates a sine wave sound file in aiff format... Apparently the code worked before when arrayrange() was used...
Then the problem lies somewhere else; a number of other things changed between Numeric and numpy. arrayrange() *was* arange(). If you think the problem is still with arange(), then you need to show us what you think arange() *by itself* should be producing and what it is actually producing. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
I would use something like this: t = linspace(0, durSecs, durSecs*SRate) Do you know the 'Numpy Example List' http://www.scipy.org/Numpy_Example_List Regards Eike. PS: Ah, you did subscribe.
Hi Eike! Yes, I did subscribe! Thanks once again for your reply... I'm sorry but I don't know exactly what you mean... Do you think I should replace t = arange(0, durSecs, 1.0/SRate) by t = linspace(0, durSecs, durSecs*SRate)? That won't work... Maybe I am missing something?... The resulting file should be am aiff sine wave... Best, Miguel On 14 Mar 2007, at 17:55, Eike Welk wrote:
I would use something like this: t = linspace(0, durSecs, durSecs*SRate)
Do you know the 'Numpy Example List' http://www.scipy.org/Numpy_Example_List
Regards Eike.
PS: Ah, you did subscribe.
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Miguel Oliveira, Jr. wrote:
Hi Eike!
Yes, I did subscribe! Thanks once again for your reply... I'm sorry but I don't know exactly what you mean... Do you think I should replace t = arange(0, durSecs, 1.0/SRate) by t = linspace(0, durSecs, durSecs*SRate)?
That won't work...
*How* does it not work? -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (3)
-
Eike Welk
-
Miguel Oliveira, Jr.
-
Robert Kern