Granular synthesis: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
[[User:Max_Dovey | Max Dovey]] is working on manipulating audio recordings about the limits of time.
[[User:Max_Dovey | Max Dovey]] is working on manipulating audio recordings about the limits of time.


samplebits.py
'''samplebits.py'''
<source lang="python">
<source lang="python">
import sys, struct  
import sys, struct  
Line 33: Line 33:
</source>
</source>


2raw.sh
And the command to play the audio through the python script, starts from an input audio, pipes the (raw) bytes through the python script, and finally piped back to sox's play command to play. Note the matching options to be able to in and out of a raw format.
<source lang="bash">
#!/bin/bash
sox $1 -t raw -e unsigned-integer -r 44100 -c 1 -
</source>


play pipeline
<source lang="bash">
<source lang="bash">
./2raw.sh 1.0000001.aiff | python samplebits.py | play -t raw -e unsigned-integer -r 44100 -c 1 -b 16 -  
sox 1.0000001.aiff -t raw -e unsigned-integer -r 44100 -c 1 - | python samplebits.py | play -t raw -e unsigned-integer -r 44100 -c 1 -b 16 -  
</source>
</source>

Revision as of 11:27, 14 October 2014

Max Dovey is working on manipulating audio recordings about the limits of time.

samplebits.py

import sys, struct 

c = 0
samples = []
numsamples = 17640 # 0.4 sec
# numsamples = 1764  # 0.040 sec == 40 ms == 0.040 * 44100 => 1764
# numsamples = 176 # 0.004 sec == 4 ms == 0.004 * 44100
# numsamples = 44 # 0.001 sec == 1 ms == 0.001 * 44100
# numsamples = 441 #0.01 sec == 1dec == 0.01 * 44100 = 441
# numsamples = 44 #0.001 sec == 1centi == 0.001 * 44100 = 44.1
# numsamples = int(4.41) #0.0001 sec == 1milli == 0.0001 * 44100 = 4.41
# numsamples = int(1) #0.000001 sec == 1micro == 0.000001 * 44100 = 0.0441

loop = 10

while True:
    sample = sys.stdin.read(2*numsamples)
    if not sample:
        break

    samples = struct.unpack("H"*numsamples, sample)

    # sys.stderr.write(str(n)+"/n")
    # o = max(35000,n)
    # take your slice and repeat
    for i in range(loop):
        out = struct.pack("H"*numsamples, *samples)
        sys.stdout.write(out)

And the command to play the audio through the python script, starts from an input audio, pipes the (raw) bytes through the python script, and finally piped back to sox's play command to play. Note the matching options to be able to in and out of a raw format.

sox 1.0000001.aiff -t raw -e unsigned-integer -r 44100 -c 1 - | python samplebits.py | play -t raw -e unsigned-integer -r 44100 -c 1 -b 16 -