annotate bin/musicPad @ 2418:9bb0eb587d5b

640x480 camera res
author drewp@bigasterisk.com
date Tue, 21 May 2024 11:58:13 -0700
parents 64eeba960168
children
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
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 591
diff changeset
8 from light9.ascoltami.playlist import Playlist
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
9 logging.basicConfig(level=logging.INFO)
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
10 log = logging.getLogger()
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
11
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
12 introPad = 4
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 717
diff changeset
13 postPad = 9 # 5 + autostop + 4
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
14
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 591
diff changeset
15 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
16 for p in playlist.allSongPaths():
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
17 log.info("read %s", p)
1893
64eeba960168 type fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 1866
diff changeset
18 inputWave = wave.open(p, 'rb')
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
19
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
20 outputDir = os.path.join(os.path.dirname(p), "pad")
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
21 try:
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
22 os.makedirs(outputDir)
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
23 except OSError:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 717
diff changeset
24 pass # exists
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
25 outputPath = os.path.join(outputDir, os.path.basename(p))
1893
64eeba960168 type fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 1866
diff changeset
26 outputWave = wave.open(outputPath, 'wb')
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
27 outputWave.setparams(inputWave.getparams())
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
28
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
29 bytesPerSecond = (inputWave.getnchannels() * inputWave.getsampwidth() *
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
30 inputWave.getframerate())
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 717
diff changeset
31
1893
64eeba960168 type fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 1866
diff changeset
32 outputWave.writeframesraw(b"\x00" * (bytesPerSecond * introPad))
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
33 outputWave.writeframesraw(inputWave.readframes(inputWave.getnframes()))
1893
64eeba960168 type fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 1866
diff changeset
34 outputWave.writeframesraw(b"\x00" * (bytesPerSecond * postPad))
546
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
35 outputWave.close()
f5b01841587f new musicPad to add silence pads to songs
drewp@bigasterisk.com
parents:
diff changeset
36 log.info("wrote %s", outputPath)