コード例 #1
0
ファイル: send.py プロジェクト: peny/quietnet
def make_buffer_from_bit_pattern(pattern, on_freq, off_freq):
    """ Takes a pattern and returns an audio buffer that encodes that pattern """
    # the key's middle value is the bit's value and the left and right bits are the bits before and after
    # the buffers are enveloped to cleanly blend into each other
    buffers = {
        "000": quietnet.tone(off_freq, DATASIZE),
        "100": quietnet.lenvelope(quietnet.tone(off_freq, DATASIZE)),
        "001": quietnet.renvelope(quietnet.tone(off_freq, DATASIZE)),
        "101": quietnet.envelope(quietnet.tone(off_freq, DATASIZE)),
        "010": quietnet.envelope(quietnet.tone(on_freq, DATASIZE)),
        "011": quietnet.lenvelope(quietnet.tone(on_freq, DATASIZE)),
        "110": quietnet.renvelope(quietnet.tone(on_freq, DATASIZE)),
        "111": quietnet.tone(on_freq, DATASIZE)
    }

    last_bit = pattern[-1]
    output_buffer = []
    for i in range(len(pattern)):
        bit = pattern[i]
        if i < len(pattern) - 1:
            next_bit = pattern[i+1]
        else:
            next_bit = pattern[0]
        output_buffer = output_buffer + buffers[last_bit + bit + next_bit]
        last_bit = bit
    return quietnet.pack_buffer(output_buffer)
コード例 #2
0
def make_buffer_from_bit_pattern(pattern, on_freq, off_freq):
    """ Takes a pattern and returns an audio buffer that encodes that pattern """
    # the key's middle value is the bit's value and the left and right bits are the bits before and after
    # the buffers are enveloped to cleanly blend into each other

    last_bit = pattern[-1]
    output_buffer = []
    offset = 0

    for i in range(len(pattern)):
        bit = pattern[i]
        if i < len(pattern) - 1:
            next_bit = pattern[i + 1]
        else:
            next_bit = pattern[0]

        freq = on_freq if bit == '1' else off_freq
        tone = quietnet.tone(freq, DATASIZE, offset=offset)
        output_buffer += quietnet.envelope(tone,
                                           left=last_bit == '0',
                                           right=next_bit == '0')
        offset += DATASIZE
        last_bit = bit

    return quietnet.pack_buffer(output_buffer)
コード例 #3
0
ファイル: send.py プロジェクト: osirislab/CSAW-RED-2018-Quals
def make_custom_buffer_from_bit_pattern(pattern,
                                        zero_freq=FREQ_ZERO,
                                        one_freq=FREQ_ONE,
                                        two_freq=FREQ_TWO,
                                        off_freq=0):
    """ Takes a pattern and returns an audio buffer that encodes that pattern """
    # the key's middle value is the bit's value and the left and right bits are the bits before and after
    # the buffers are enveloped to cleanly blend into each other

    last_bit = pattern[-1]
    output_buffer = []
    offset = 0

    for i in range(len(pattern)):
        bit = pattern[i]
        if i < len(pattern) - 1:
            next_bit = pattern[i + 1]
        else:
            next_bit = pattern[0]

        freq = 0
        if bit == '0':
            print('0')
            freq = zero_freq
        elif bit == '1':
            print('1')
            freq = one_freq
        elif bit == '2':
            print('2')
            freq = two_freq
        else:
            print('0')
            freq = off_freq

        tone = quietnet.tone(freq, DATASIZE, offset=offset)
        output_buffer += quietnet.envelope(tone, left=False, right=False)
        offset += DATASIZE
        last_bit = bit

    return quietnet.pack_buffer(output_buffer)
コード例 #4
0
ファイル: send.py プロジェクト: 821760408-sp/quietnet
def make_buffer_from_bit_pattern(pattern, on_freq, off_freq):
    """ Takes a pattern and returns an audio buffer that encodes that pattern """
    # the key's middle value is the bit's value and the left and right bits are the bits before and after
    # the buffers are enveloped to cleanly blend into each other

    last_bit = pattern[-1]
    output_buffer = []
    offset = 0

    for i in range(len(pattern)):
        bit = pattern[i]
        if i < len(pattern) - 1:
            next_bit = pattern[i+1]
        else:
            next_bit = pattern[0]

        freq = on_freq if bit == '1' else off_freq
        tone = quietnet.tone(freq, DATASIZE, offset=offset)
        output_buffer += quietnet.envelope(tone, left=last_bit=='0', right=next_bit=='0')
        offset += DATASIZE
        last_bit = bit

    return quietnet.pack_buffer(output_buffer)
コード例 #5
0
ファイル: pulse.py プロジェクト: Katee/quietnet-presentation
import pyaudio
import quietnet
import options

FORMAT = pyaudio.paInt16
CHANNELS = options.channels
RATE = options.rate

FREQ = options.freq
FREQ_OFF = 0

DATASIZE = options.datasize

p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, output=True)

buffer = quietnet.envelope(quietnet.tone(FREQ_OFF, DATASIZE)) + quietnet.envelope(quietnet.tone(FREQ, DATASIZE))
buffer = buffer * 10

output_buffer = quietnet.pack_buffer(buffer)

def play_buffer(buffer):
    for sample in buffer:
        stream.write(sample)

while True:
    play_buffer(output_buffer)