4

I'm trying to build a sort of pedal [¹] in order to distort a varying input sound.

As I'm starting from the ground, I'm trying to generate in python a continuous sound and to vary the frequency of this sound as I slide a scrollbar (or a similar widget).

I've tried to use the tkSnack python library for the generation of the sound but it pauses between the generated tones. Instead of this behaviour, I want my script to play continuously the sound even if it is changing.

I've obtained a good result with my arduino thanks to the simple function tone() [²]. Probably the latency times are so low that the sound seems to be continuous. Is it possible to do a similar thing on my computer with python libraries on Linux?

Thanks to who is gonna help me! :)

[¹] http://en.wikipedia.org/wiki/Effects_pedal

[²] http://arduino.cc/en/Reference/Tone

S.Lott
  • 384,516
  • 81
  • 508
  • 779
Franc
  • 102
  • 1
  • 4

2 Answers2

4

Hello i used this formula last year to build a pedal

M = 2*D/(1-D);
x = (1+M)*(x)./(1+k*abs(x));

X = input Signal

D = distortion test some values like 0.1, 0.5, 0.9, etc and see the results.

This can be used in realtime inputline + python + pyaudio, the sound looks like one Overdrive ...

Update:

Real-Time primitive pedal distortion write in Python

#ederwander
import pyaudio 
import numpy as np 
import wave 

chunk = 1024 
FORMAT = pyaudio.paInt16 
CHANNELS = 1 
RATE = 8800 
K=0 
DISTORTION = 0.61

p = pyaudio.PyAudio() 

stream = p.open(format = FORMAT, 
                channels = CHANNELS, 
                rate = RATE, 
                input = True, 
                output = True, 
                frames_per_buffer = chunk) 


print "Eng Eder de Souza - ederwander" 
print "Primitive Pedal" 


while(True): 

    data = stream.read(chunk) 
    data = np.fromstring(data, dtype=np.int16)  
    M = 2*DISTORTION/(1-DISTORTION);
    data = (1+M)*(data)/(1+K*abs(data));
    data = np.array(data, dtype='int16') 
    signal = wave.struct.pack("%dh"%(len(data)), *list(data))
    stream.write(signal) 

stream.stop_stream() 
stream.close() 
p.terminate() 

Change de Variable DISTORTION to see diferent results:

i changed a bit my source to make play recorded samples, i did Make some test, i get this audio: http://www.freesound.org/people/eriatarka/sounds/15753/ and then applied the formula described here, you can listen the changed file here: http://www.freesound.org/people/ederwander/sounds/146277/

ederwander
  • 3,410
  • 1
  • 18
  • 23
  • Hello, thanks for your answer! I was tinkering with pyaudio but I cannot achieve my aim.. It cannot generate sounds of a given frequency and then alter them. I've never faced the sound processing before and I don't really know where to start from.. any hint? – Franc Feb 11 '12 at 10:27
  • What is K doing in this example? It looks like it's always zero, so "(1+M)*(data)/(1+K*abs(data))" could be rewritten as just "(1+M)*(data)". – btubbs Jul 11 '17 at 05:29
1

PyAudio provides python bindings for portaudio. You can do real-time audio processing with it, though Python isn't a high performance language for numerics.

Russell Borogove
  • 18,516
  • 4
  • 43
  • 50