Using the aux-port with python

712 views Asked by At

I recently started working with python for university, an I would like to be able to display plots from python on my oscilloscope. I have previously used somebody elses code to use my scope as a vector display:

https://www.youtube.com/watch?v=oXR4yCge4AU

In "X Y mode" an oscilloscope uses to varying voltages as x and y coordinates, as seen in the video, and it is often done with sound from a computers left and right audio channels.

So i was thinking that if i could use the values in an array to manipulate the wave of each audio channel, it should be possible to display the plot on the oscilloscope. I have found several examples for running audio or synthesizing regular waveform, but i was wondering if there was a way to control the audio output with more control ?

-- edit --

I found a code example that generates a sine from a function:

import struct
import numpy as np

samplingRate = 44100
freq = 440
samples = 44100

x = np.arange(samples*100)
y = 100*np.sin(2* np.pi * freq * x / samplingRate)

f = open('test.wav', 'wb')
for i in y:
    print(i)
    f.write(struct.pack('b',int(i)))

f.close()

However, if i try to use a more sophisticated function:

x = np.arange(samples*100)
#y = 100*np.sin(2* np.pi * freq * x / samplingRate)
y = 100*(x^4 + 7*x^3 + 8*x^2 + x) * freq / samplingRate

I get the following error:

10.276643990929704
10.166893424036282
10.136961451247165
153.3015873015873
Traceback (most recent call last):
  File "audio_test.py", line 28, in <module>
    f.write(struct.pack('b',int(i)))
struct.error: byte format requires -128 <= number <= 127
0

There are 0 answers