0

I'm trying to obtain 2 separate arrays from a 2 column array of 44100 values. One of the arrays should have 0s for the right column and the other values kept intact, and the other vice-versa for the left column. So far, I have the following code:

def tone(f, sf, duration):  # frequency, sampling frequency and duration

   sample_times = np.arange(0,duration,1/sf)
   max_amplitude = 2**15 - 1
   cos_wave = np.cos(2 * np.pi * f * sample_times) * max_amplitude
   return cos_wave.astype("int16") # returns an array of dtype =int16

sf = 44100
f = random.randrange (20, 18000)
duration = 1

cos_wave = tone(f, sf, duration)

print(cos_wave.dtype)

 # Generate stereo sound by putting it in 2 columns
both_channels = cos_wave.reshape((int(sf/2), 2))
both_channels = both_channels.astype ('int16')
print (both_channels)
`# Fill one column with zeros to get mono sound for each channel`
copy_both_channels = np.copy (both_channels)
print (copy_both_channels)
both_channels[:, 0] =  0 # 1st column filled with zeros

The problem is that I'm modifying the initial array (both_channels) when filling one of the columns with 0s. I tried using the np.copy(arr) function but that didn't help either as it doesn't fill the columns with 0s. Can anyone tell me of a way to achieve this?

3
  • I don't know if it can help you but I found this : enter link description here Commented May 6, 2021 at 11:56
  • You assign to the initial both_channels array, yet you find it a problem that it changes? Commented May 6, 2021 at 12:01
  • Yes, that was exactly the problem, thanks for the clarification! Commented May 6, 2021 at 16:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.