コード例 #1
0
def sinus(freq): # return a 1-second sine wave
       from math import sin, pi
       factor = 2.0*pi*float(freq)/float(RATE)
       list = range(RATE)
       for i in list:
               list[i] = int(sin(float(i) * factor) * 127.0)
       return audio.num2chr(list)
コード例 #2
0
def softclip(s):
       if '\177' not in s and '\200' not in s:
               return s
       num = audio.chr2num(s)
       extremes = (-128, 127)
       for i in range(1, len(num)-1):
               if num[i] in extremes:
                       num[i] = (num[i-1] + num[i+1]) / 2
       return audio.num2chr(num)
コード例 #3
0
def unbias(s):
       if not s: return s
       a = audio.chr2num(s)
       sum = 0
       for i in a: sum = sum + i
       bias = (sum + len(a)/2) / len(a)
       print 'Bias value:', bias
       if bias:
               for i in range(len(a)):
                       a[i] = a[i] - bias
               s = audio.num2chr(a)
       return s
コード例 #4
0
ファイル: auds.py プロジェクト: asottile/ancient-pythons
def stretch(s, a, b):
	y = audio.chr2num(s)
	m = len(y)
	out = []
	n = m * b / a
	# i, j will walk through y and out (step 1)
	# ib, ja are i*b, j*a and are kept as close together as possible
	i, ib = 0, 0
	j, ja = 0, 0
	for j in range(n):
		ja = ja+a
		while ib < ja:
			i = i+1
			ib = ib+b
		if i >= m:
			break
		if ib == ja:
			out.append(y[i])
		else:
			out.append((y[i]*(ja-(ib-b)) + y[i-1]*(ib-ja)) / b)
	return audio.num2chr(out)
コード例 #5
0
def stretch(s, a, b):
    y = audio.chr2num(s)
    m = len(y)
    out = []
    n = m * b / a
    # i, j will walk through y and out (step 1)
    # ib, ja are i*b, j*a and are kept as close together as possible
    i, ib = 0, 0
    j, ja = 0, 0
    for j in range(n):
        ja = ja + a
        while ib < ja:
            i = i + 1
            ib = ib + b
        if i >= m:
            break
        if ib == ja:
            out.append(y[i])
        else:
            out.append((y[i] * (ja - (ib - b)) + y[i - 1] * (ib - ja)) / b)
    return audio.num2chr(out)
コード例 #6
0
       # i, j will walk through y and out (step 1)
       # ib, ja are i*b, j*a and are kept as close together as possible
       i, ib = 0, 0
       j, ja = 0, 0
       for j in range(n):
               ja = ja+a
               while ib < ja:
                       i = i+1
                       ib = ib+b
               if i >= m:
                       break
               if ib = ja:
                       out.append(y[i])
               else:
                       out.append((y[i]*(ja-(ib-b)) + y[i-1]*(ib-ja)) / b)
       return audio.num2chr(out)

def sinus(freq): # return a 1-second sine wave
       from math import sin, pi
       factor = 2.0*pi*float(freq)/float(RATE)
       list = range(RATE)
       for i in list:
               list[i] = int(sin(float(i) * factor) * 127.0)
       return audio.num2chr(list)

def softclip(s):
       if '\177' not in s and '\200' not in s:
               return s
       num = audio.chr2num(s)
       extremes = (-128, 127)
       for i in range(1, len(num)-1):