-
Notifications
You must be signed in to change notification settings - Fork 1
/
g2tsg_audiere.py
110 lines (95 loc) · 2.55 KB
/
g2tsg_audiere.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
import time
import audiere
from tanooki_utils import *
import win32api
init_continues = 5
continues = 5
device = None
stream = None
length = 0
def init_tanooki():
global device
global stream
device = audiere.open_device()
stream = None
def quit_tanooki():
global stream
if stream and stream.playing:
stream.stop()
def pause_tanooki():
global stream
stream.pause()
def unpause_tanooki():
global stream
stream.play()
def get_volume_tanooki():
global stream
if stream:
return stream.volume
return 1.0
def set_volume_tanooki(volume):
global stream
if stream:
stream.volume = volume
def get_perc_tanooki():
global stream
global length
if stream:
perc = 100*stream.position/float(stream.length)
return [length*(perc/100.0), int(perc)]
return [0,0]
def set_perc_tanooki(value):
global stream
if stream:
stream.position = max(1,int(stream.length*value/100.0))
def play_tanooki_way(music_file, channels, vol):
global device
global stream
global length
path = win32api.GetShortPathName(clean_path(music_file))
length = int(File(path).info.length)
if channels == 1:
dumpWAV(path, 1)
path = 'cache.wav'
stream = device.open_file(path, 1)
stream.play()
set_volume_tanooki(vol)
time.sleep(0.1)
while stream.position > 0:
#print 'remaining'
time.sleep(0.1)
print 'cabo'
def dumpWAV( name, channels ):
import pymedia.audio.acodec as acodec
import pymedia.muxer as muxer
import time, wave, string, os
import pymedia.audio.sound as sound
name1= unicode.split( name, '.' )
name2= string.join( name1[ : len( name1 )- 1 ] )
# Open demuxer first
dm= muxer.Demuxer( name1[ -1 ].lower() )
dec= None
f= open( name, 'rb' )
snd= None
s= " "
while len( s ):
s= f.read( 20000 )
if len( s ):
frames= dm.parse( s )
for fr in frames:
if dec== None:
# Open decoder
dec= acodec.Decoder( dm.streams[ 0 ] )
r= dec.decode( fr[ 1 ] )
if r and r.data:
rate = 2
if channels == 2:
rate = 1
if snd== None:
snd= wave.open('cache.wav', 'wb' )
snd.setparams( (channels, 2, r.sample_rate*rate, 0, 'NONE','') )
resampler= sound.Resampler( (r.sample_rate,r.channels), (int(r.sample_rate*rate),channels) )
data= resampler.resample( r.data )
snd.writeframes( data )
snd.close()