annotate bin/musicPad @ 1093:544a98a016bc

web Ignore-this: 6539e6ec1859b9fa11d90d528932b0
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 05 Jun 2014 08:08:24 +0000
parents d8202a0a7fd5
children 7772cc48e016
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
717
d8202a0a7fd5 fix up musicpad and wavecurve. ascoltami2 can now use relative paths in the config
Drew Perttula <drewp@bigasterisk.com>
parents: 623
diff changeset
1 #!bin/python
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
2 """
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
3 rewrite all the songs with silence at the start and end
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
4 """
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
5 import sys, wave, logging, os
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
6 sys.path.append(".")
623
46d319974176 move networking settings to config.n3
drewp@bigasterisk.com
parents: 617
diff changeset
7 from light9 import showconfig
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
8 from light9.namespaces import L9
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 591
diff changeset
9 from light9.ascoltami.playlist import Playlist
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
10 logging.basicConfig(level=logging.INFO)
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
11 log = logging.getLogger()
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
12
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
13 introPad = 4
591
58e2e6ca1ff1 pad time change
drewp@bigasterisk.com
parents: 546
diff changeset
14 postPad = 9 # 5 + autostop + 4
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
15
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 591
diff changeset
16 playlist = Playlist.fromShow(showconfig.getGraph(), showconfig.showUri())
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 591
diff changeset
17 for p in playlist.allSongPaths():
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
18 log.info("read %s", p)
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
19 inputWave = wave.open(p, 'r')
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
20
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
21 outputDir = os.path.join(os.path.dirname(p), "pad")
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
22 try:
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
23 os.makedirs(outputDir)
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
24 except OSError:
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
25 pass # exists
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
26 outputPath = os.path.join(outputDir, os.path.basename(p))
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
27 outputWave = wave.open(outputPath, 'w')
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
28 outputWave.setparams(inputWave.getparams())
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
29
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
30 bytesPerSecond = (inputWave.getnchannels() * inputWave.getsampwidth() *
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
31 inputWave.getframerate())
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
32
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
33 outputWave.writeframesraw("\x00" * (bytesPerSecond * introPad))
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
34 outputWave.writeframesraw(inputWave.readframes(inputWave.getnframes()))
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
35 outputWave.writeframesraw("\x00" * (bytesPerSecond * postPad))
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
36 outputWave.close()
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
37 log.info("wrote %s", outputPath)
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
38
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
39