Correction of annoying cracks

Due to the fact that we cut the sound at n seconds and not at the end of the period.

Sidenote : dropped numpy part in sound4python, not happy with it.
This commit is contained in:
hackEns 2013-12-12 12:24:41 +01:00
parent 5a4fe91ce1
commit e6fbaa2ffd
3 changed files with 19 additions and 17 deletions

View File

@ -16,7 +16,7 @@
# =============================================================================
from sound4python import sound
from multiprocessing oimport Process
from multiprocessing import Process
import math
import serial
import sys

View File

@ -41,16 +41,17 @@ def sound(itr,samprate=16000,autoscale=True,output=False):
waveWrite.setframerate(samprate) # 8kHz default
wroteFrames=False
# Not satisfied by the numpy implementation, buzzing and so...
#Let's try to create sound from NumPy vector
if( foundNumpy ):
if( type(itr)==np.array ):
if( itr.ndim == 1 or itr.shape.count(1) == itr.ndim - 1 ):
waveWrite.writeframes( (mult*itr.flatten()).astype(np.int16).tostring() )
wroteFrames=True
else: #we have np, but the iterable isn't a vector
waveWrite.writeframes( (mult*np.array(itr)).astype(np.int16).tostring() )
wroteFrames=True
if( not wroteFrames and not foundNumpy ):
#if( foundNumpy ):
# if( type(itr)==np.array ):
# if( itr.ndim == 1 or itr.shape.count(1) == itr.ndim - 1 ):
# waveWrite.writeframes( (mult*itr.flatten()).astype(np.int16).tostring() )
# wroteFrames=True
# else: #we have np, but the iterable isn't a vector
# waveWrite.writeframes( (mult*np.array(itr)).astype(np.int16).tostring() )
# wroteFrames=True
#if( not wroteFrames and not foundNumpy ):
#python w/o np doesn't have "short"/"int16", "@h" is "native,aligned short"
# BAD : waveWrite.writeframes( struct.pack(len(itr)*"@h",[int(mult*itm) for itm in itr]) )
writeValues = []

View File

@ -73,6 +73,7 @@ running = True
while running:
char = getch()
if char == "q":
print("Exiting...")
running = False
continue
elif char == "a":
@ -93,7 +94,7 @@ while running:
continue
print("Playing "+char.upper())
processes.append(Process(target=play_wave, args=(frequency, 0.2)))
processes.append(Process(target=play_wave, args=(frequency, math.floor(0.2 * frequency + 1) / frequency)))
processes[-1].start()
for i in processes: