Hacked in audio support.
This commit is contained in:
parent
74a3f8b6c0
commit
66beddb844
|
@ -3,6 +3,7 @@
|
||||||
import sv, SV
|
import sv, SV
|
||||||
import VFile
|
import VFile
|
||||||
import gl, GL, DEVICE
|
import gl, GL, DEVICE
|
||||||
|
import al, AL
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
@ -13,21 +14,28 @@ import string
|
||||||
def main():
|
def main():
|
||||||
QSIZE = 16
|
QSIZE = 16
|
||||||
TIME = 5
|
TIME = 5
|
||||||
|
audio = 0
|
||||||
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'q:t:')
|
opts, args = getopt.getopt(sys.argv[1:], 'aq:t:')
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if opt == '-q':
|
if opt == '-a':
|
||||||
|
audio = 1
|
||||||
|
elif opt == '-q':
|
||||||
QSIZE = string.atoi(arg)
|
QSIZE = string.atoi(arg)
|
||||||
elif opt == '-t':
|
elif opt == '-t':
|
||||||
TIME = string.atoi(arg)
|
TIME = string.atoi(arg)
|
||||||
|
|
||||||
if args:
|
if args:
|
||||||
filename = args[0]
|
filename = args[0]
|
||||||
if args[1:]:
|
|
||||||
print 'Warning: only first filename arg is used'
|
|
||||||
else:
|
else:
|
||||||
filename = 'film.video'
|
filename = 'film.video'
|
||||||
|
|
||||||
|
if audio:
|
||||||
|
if args[1:]:
|
||||||
|
audiofilename = args[1]
|
||||||
|
else:
|
||||||
|
audiofilename = 'film.aiff'
|
||||||
|
|
||||||
gl.foreground()
|
gl.foreground()
|
||||||
|
|
||||||
x, y = SV.PAL_XMAX / 4, SV.PAL_YMAX / 4
|
x, y = SV.PAL_XMAX / 4, SV.PAL_YMAX / 4
|
||||||
|
@ -61,6 +69,7 @@ def main():
|
||||||
|
|
||||||
print 'Click left mouse to start recording', TIME, 'seconds'
|
print 'Click left mouse to start recording', TIME, 'seconds'
|
||||||
ofile = None
|
ofile = None
|
||||||
|
afile = None
|
||||||
# Mouse down opens the file & freezes window
|
# Mouse down opens the file & freezes window
|
||||||
# Mouse up starts recording frames
|
# Mouse up starts recording frames
|
||||||
|
|
||||||
|
@ -81,9 +90,14 @@ def main():
|
||||||
gl.prefsize(x, y)
|
gl.prefsize(x, y)
|
||||||
gl.winconstraints()
|
gl.winconstraints()
|
||||||
gl.wintitle('* ' + filename)
|
gl.wintitle('* ' + filename)
|
||||||
|
if audio:
|
||||||
|
afile = initaudio(audiofilename)
|
||||||
continue
|
continue
|
||||||
|
# Mouse up -- start actual recording
|
||||||
# Mouse up -- actual recording
|
global recording, stop_recording
|
||||||
|
if audio:
|
||||||
|
stop_recording = 0
|
||||||
|
recording.release()
|
||||||
t0 = time.millitimer()
|
t0 = time.millitimer()
|
||||||
v.StartCapture()
|
v.StartCapture()
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -91,11 +105,10 @@ def main():
|
||||||
if t >= TIME*1000:
|
if t >= TIME*1000:
|
||||||
break
|
break
|
||||||
if v.GetCaptured() > 2:
|
if v.GetCaptured() > 2:
|
||||||
print '(1)',
|
|
||||||
doframe(v, ofile, x, y, t)
|
doframe(v, ofile, x, y, t)
|
||||||
v.StopCapture()
|
v.StopCapture()
|
||||||
|
stop_recording = 1
|
||||||
while v.GetCaptured() > 0:
|
while v.GetCaptured() > 0:
|
||||||
print '(2)',
|
|
||||||
doframe(v, ofile, x, y, t)
|
doframe(v, ofile, x, y, t)
|
||||||
t = time.millitimer() - t0
|
t = time.millitimer() - t0
|
||||||
gl.wintitle(filename)
|
gl.wintitle(filename)
|
||||||
|
@ -109,6 +122,8 @@ def main():
|
||||||
# Quit
|
# Quit
|
||||||
if ofile:
|
if ofile:
|
||||||
ofile.close()
|
ofile.close()
|
||||||
|
if afile:
|
||||||
|
afile.destroy()
|
||||||
posix._exit(0)
|
posix._exit(0)
|
||||||
# EndCapture dumps core...
|
# EndCapture dumps core...
|
||||||
v.EndCapture()
|
v.EndCapture()
|
||||||
|
@ -121,4 +136,36 @@ def doframe(v, ofile, x, y, t):
|
||||||
cd.UnlockCaptureData()
|
cd.UnlockCaptureData()
|
||||||
ofile.writeframe(t, data, None)
|
ofile.writeframe(t, data, None)
|
||||||
|
|
||||||
|
AQSIZE = 16000
|
||||||
|
|
||||||
|
def initaudio(filename):
|
||||||
|
import thread, aiff
|
||||||
|
global recording, stop_recording
|
||||||
|
afile = aiff.Aiff().init(filename, 'w')
|
||||||
|
afile.nchannels = AL.MONO
|
||||||
|
afile.sampwidth = AL.SAMPLE_8
|
||||||
|
params = [AL.INPUT_RATE, 0]
|
||||||
|
al.getparams(AL.DEFAULT_DEVICE, params)
|
||||||
|
print 'rate =', params[1]
|
||||||
|
afile.samprate = params[1]
|
||||||
|
c = al.newconfig()
|
||||||
|
c.setchannels(AL.MONO)
|
||||||
|
c.setqueuesize(AQSIZE)
|
||||||
|
c.setwidth(AL.SAMPLE_8)
|
||||||
|
aport = al.openport(filename, 'r', c)
|
||||||
|
recording = thread.allocate_lock()
|
||||||
|
recording.acquire()
|
||||||
|
stop_recording = 0
|
||||||
|
thread.start_new_thread(recorder, (afile, aport))
|
||||||
|
return afile
|
||||||
|
|
||||||
|
def recorder(afile, aport):
|
||||||
|
# XXX recording more than one fragment doesn't work
|
||||||
|
# XXX (the thread never dies)
|
||||||
|
recording.acquire()
|
||||||
|
while not stop_recording:
|
||||||
|
data = aport.readsamps(AQSIZE/2)
|
||||||
|
afile.writesampsraw(data)
|
||||||
|
del data
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue