Skip to content
Permalink
Browse files

added music for windows. replaying music still doesn't work

  • Loading branch information...
adangert committed May 17, 2019
1 parent c9db418 commit fcec51218feceffe778175cf98790ff1adb9f8d8
Showing with 60 additions and 1 deletion.
  1. BIN PyAudio-0.2.11-cp37-cp37m-win_amd64.whl
  2. +59 −1 piaudio.py
  3. +1 −0 setup_windows.bat
Binary file not shown.
@@ -12,6 +12,8 @@
from sys import platform
if platform == "linux" or platform == "linux2":
import alsaaudio
else:
import pyaudio
import threading
from pydub import AudioSegment
from multiprocessing import Process, Value, Array, Queue, Manager
@@ -20,7 +22,63 @@
import common

def win_audio_loop(fname,ratio,stop_proc):
pass
#define stream chunk
chunk = 1024

#open a wav format music
while(True):
if(stop_proc.value):

pass
elif(fname['song'] != ''):
print(fname['song'])
f = wave.open(fname['song'])
#instantiate PyAudio
p = pyaudio.PyAudio()
#open stream
stream = p.open(format = p.get_format_from_width(f.getsampwidth()),
channels = f.getnchannels(),
rate = f.getframerate(),
output = True)


# Resamples audio data at the rate given by 'ratio' above.
def Resample(data):
# for data in samples:
array = numpy.fromstring(data, dtype=numpy.int16)
# Split data into seperate channels and resample. Divide by two
# since there are two channels. We round to the nearest multiple of
# 32 as the resampling is more efficient the closer the sizes are to
# being powers of two.
num_output_frames = int(array.size / (ratio.value * 2)) & (~0x1f)
reshapel = signal.resample(array[0::2], num_output_frames)
reshaper = signal.resample(array[1::2], num_output_frames)

final = numpy.ones((num_output_frames,2))
final[:, 0] = reshapel
final[:, 1] = reshaper

out_data = final.flatten().astype(numpy.int16).tostring()
return out_data
#read data
data = f.readframes(chunk)

#play stream
while data:
stream.write(data)
data = f.readframes(chunk)
data = Resample(data)
if stop_proc.value:
return



#stop stream
stream.stop_stream()
stream.close()

#close PyAudio
p.terminate()

def audio_loop(fname, ratio, stop_proc):
# TODO: As a future improvment, we could precompute resampled versions of the track
@@ -13,6 +13,7 @@
::pip install numpy
::choco install swig -y
::choco install cmake -y
::pip install PyAudio‑0.2.11‑cp37‑cp37m‑win_amd64.whl ::needs to be downloaded
::set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin
::set PATH="C:\Program Files\CMake\bin\";%PATH%
::set PYTHONPATH="C:\Users\Aaron\Documents\GitHub\JoustMania\psmoveapi\build\Release";%PYTHONPATH%

0 comments on commit fcec512

Please sign in to comment.
You can’t perform that action at this time.