Skip to content

Instantly share code, notes, and snippets.

@akotulu
Forked from xyb/ir_nikon.py
Created May 26, 2017 16:19
Show Gist options
  • Save akotulu/4058212587e4db3519915242293386ad to your computer and use it in GitHub Desktop.
Save akotulu/4058212587e4db3519915242293386ad to your computer and use it in GitHub Desktop.
Converting IR code of Nikon remote trigger to a wave file.
#!/usr/bin/env python
import sys
from itertools import *
from wavebender import *
def half_wave(frequency=19000, framerate=44100, amplitude=0.5,
skip_frame=0):
for s in sine_wave(frequency, framerate, amplitude,
skip_frame=skip_frame):
if s > 0:
yield s
elif s < 0:
yield -s
else:
yield 0.0
def ir_wave1(us, frequency=19000, framerate=44100):
nsamples = framerate * float(us) / 1000000
return islice(sine_wave(frequency, framerate, 1.0), nsamples)
def ir_wave2(us, frequency=19000, framerate=44100):
nsamples = framerate * float(us) / 1000000
skip = 0.5 * framerate / frequency # 180 degree
data = sine_wave(frequency, framerate, 1.0, skip_frame=skip)
return islice(data, nsamples)
def ir_off(us, framerate=44100):
if us < 0:
us = -us
nsamples = framerate * float(us) / 1000000
return islice(repeat(0), nsamples)
def ir_left(us):
if us > 0:
return ir_wave1(us)
else:
return ir_off(us)
def ir_right(us):
if us > 0:
return ir_wave2(us)
else:
return ir_off(us)
def ir_channels(seq):
'''
seq = [100, -100, 200] # 100us on, 100us off, 200us on
'''
ch1 = [ir_left(us) for us in seq]
ch2 = [ir_right(us) for us in seq]
return [[chain.from_iterable(ch1)], [chain.from_iterable(ch2)]]
def nikon():
# http://ilpleut.be/code-nikonremote
return ir_channels([2000, -27830, 390, -1580, 410, -3580, 400,
-63200,
2000, -27830, 390, -1580, 410, -3580, 400])
if __name__ == '__main__':
channels = nikon()
samples = compute_samples(channels)
write_wavefile(open('nikon-trigger.wave', samples)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment