コード例 #1
0
	def _mix_track(self, track_filename, stage_change_indication_filename, play_from_second=None):
		""" Mix a track with path "track filename" to play. If another track is playing, fade it out, and fade this in.

		Overall, this takes 15 seconds:
		0:00 - 0:06: playing track fades out
		0:04 - 0:13: transition sounds plays
		0:09 - 0:15: next track mixes in

		:param track_filename: track filename to fade in
		:param stage_change_direction: int, used for transition change indication sound
		:param play_from_second: the time in the track to jump to (just for testing purposes, shouldn't be used otherwise)
		"""
		logging.info("starting mixing")
		start_time_seconds = time.time()

		if len(self.playing_tracks) > 0:
			logging.info("fading out current track to end in {seconds} seconds".format(
				seconds=self.FADEOUT_MAX_AFTER_SIX_SECONDS_RATE / self.SAMPLE_RATE / 2.0))
			track_current_position = (self.playing_tracks[-1].get_position() + self.FADEOUT_MAX_AFTER_SIX_SECONDS_RATE)
			self.tracks_last_playing_position[self.current_playing_track_filename] = track_current_position

			self.playing_tracks[-1].set_volume(0, fadetime=self.FADEOUT_MAX_AFTER_SIX_SECONDS_RATE)

			time.sleep(4 - (time.time() - start_time_seconds))

			# play transition indication
			logging.info("playing transition")
			transition_indication_sound = swmixer.Sound(stage_change_indication_filename)
			transition_channel = transition_indication_sound.play()
			self.playing_transitions.append(transition_channel)

			time.sleep(9 - (time.time() - start_time_seconds))

		# mix in sound scape for stage
		track_sound = swmixer.Sound(track_filename)
		offset = 0

		if play_from_second is not None:
			offset = self.SAMPLE_RATE * play_from_second

		self.current_playing_track_filename = track_filename

		track_last_position = self.tracks_last_playing_position.get(track_filename, None)
		track_channel = track_sound.play(fadein=self.FADEIN_MAX_AFTER_SIX_SECONDS_RATE,
										 offset=track_last_position or offset, loops=100)
		self.playing_tracks.append(track_channel)

		logging.info("starting playing \"{track}\" from {seconds} seconds in".format(
			track=track_filename.split("/")[-1], seconds=(track_last_position or offset) / self.SAMPLE_RATE / 2.0))

		self.performing_a_mix = False
コード例 #2
0
    def _mix_track(self, track_filename):
        """ Mix a track with path "track filename" to play. If another track is playing, fade it out, and fade this in

		:param track_filename: track filename to fade in
		"""
        track_full_path = os.path.join(self.audio_folder, track_filename)
        if self.current_playing_track_filename == track_full_path:
            logging.info("track playing is the same as requested, ignoring")
        else:
            fadein_time = 0

            if len(self.playing_tracks) > 0:
                logging.info(
                    "fading out current track to end in {fadeout} seconds".
                    format(fadeout=self.FADEOUT_AMOUNT))
                self.playing_tracks[-1].set_volume(0,
                                                   fadetime=self.sample_rate *
                                                   self.FADEOUT_AMOUNT)
                fadein_time = self.sample_rate * self.FADEIN_AMOUNT
                logging.info("set fade")

            # fade in of one second
            track_sound = swmixer.Sound(track_full_path)
            track_channel = track_sound.play(fadein=fadein_time)
            self.playing_tracks.append(track_channel)
            self.current_playing_track_filename = track_filename
            logging.info(
                "starting playing {track}".format(track=track_filename))
コード例 #3
0
    def _play_heartbeat(self, heartbeat_track):
        """ Play "heartbeat_track"

		:param heartbeat_track: the filename on system to play
		"""
        heartbeat_sound = swmixer.Sound(heartbeat_track)
        heartbeat_channel = heartbeat_sound.play(volume=1.3)
        self.playing_heartbeats.append(heartbeat_channel)
        logging.info("starting playing heartbeat")
コード例 #4
0
	def _play_heartbeat(self, heartbeat_track):
		""" Play "heartbeat_track"

		:param heartbeat_track: the filename on system to play
		"""
		heartbeat_sound = swmixer.Sound(heartbeat_track)
		heartbeat_channel = heartbeat_sound.play(volume=1.1)
		self.playing_heartbeats.append(heartbeat_channel)
		logging.info("starting playing heartbeat \"{heartbeat_track}\"".format(
			heartbeat_track=heartbeat_track.split("/")[-1]))
コード例 #5
0
ファイル: PlaySoundSWMixer.py プロジェクト: YDutchy/Froque
import swmixer
import time

swmixer.init(samplerate=44100, chunksize=1024, stereo=True)
swmixer.start()

snd1 = swmixer.Sound("main.wav")
snd2 = swmixer.Sound("test2.wav")
snd3 = swmixer.Sound("test.wav")

snd3.play(loops=-1, volume=0.3)
while True:
    totalValue = 0
    for i in range(0, 15):
        #data = arduino.readline()[:-2]
        value = arduino.readline()[:-2]
        if value:
            print value
            totalValue += int(value)
    print totalValue
    if totalValue > 2:
        snd2.play(volume=0.4)
        time.sleep(4.0)
        snd1.play(volume=0.3)
        time.sleep(8.0)
    elif totalValue > 0:
        snd1.play(volume=0.7)
        time.sleep(5)
    time.sleep(1)
    print "LOL"
    snd2.play(volume=0.7)
コード例 #6
0
def playLaser1(timer1 = []):
	if(lightlevell > 800):
            a = swmixer.Sound('/home/pi/laserharp-sounds/1.wav')
            swmixer.play(-1)
            print ("1")
コード例 #7
0
def playLaser6(timer6 = []):
	if(lightlevel6 > 800):
            f = swmixer.Sound('/home/pi/laserharp-sounds/6.wav')
            swmixer.play(-1)
            print("6")
コード例 #8
0
def playLaser5(timer5 = []):
	if(lightlevel5 > 800):
            e = swmixer.Sound('/home/pi/laserharp-sounds/5.wav')
            swmixer.play(-1)
            print("5")
コード例 #9
0
def playLaser4(timer4 = []):
	if(lightlevel4 > 800):
            d = swmixer.Sound('/home/pi/laserharp-sounds/4.wav')
            swmixer.play(-1)
            print("4")
コード例 #10
0
def playLaser3(timer3 = []):
	if(lightlevel3 > 800):
            c = swmixer.Sound('/home/pi/laserharp-sounds/3.wav')
            swmixer.play(-1)
            print ("3")
コード例 #11
0
def playLaser2(timer2 = []):
	if(lightlevel2 > 800):
            b = swmixer.Sound('/home/pi/laserharp-sounds/2.wav')
            swmixer.play(-1)
            print ("2")
コード例 #12
0
ファイル: test4.py プロジェクト: ohisama/PyAudioMixer
import sys
import swmixer
import numpy

swmixer.init(samplerate=44100, chunksize=1024, stereo=False, microphone=True)
snd = swmixer.Sound("test1.wav")
snd.play(loops=-1)

micdata = []
frame = 0

while True:
    swmixer.tick()
    frame += 1
    if frame < 50:
        micdata = numpy.append(micdata, swmixer.get_microphone())
    if frame == 50:
        micsnd = swmixer.Sound(data=micdata)
        micsnd.play()
        micdata = []
        frame = 0

    

コード例 #13
0
ファイル: test3.py プロジェクト: ohisama/PyAudioMixer
import sys
import swmixer
import pygame

swmixer.init(samplerate=44100, chunksize=1024, stereo=False)
snd = swmixer.Sound("test1.wav")
pygame.display.init()
screen = pygame.display.set_mode((1024, 768))

snd.play()
x = 0
while True:
    swmixer.tick()
    x += 1
    screen.fill((0, 0, 0))
    pygame.draw.rect(screen, (0, 255, 0), (x, 100, 50, 50))
    pygame.display.flip()
    for evt in pygame.event.get():
        if evt.type == pygame.QUIT: sys.exit()
コード例 #14
0
import swmixer
import time

swmixer.init(samplerate=44100, chunksize=1024, stereo=True)
swmixer.start()
snd1 = swmixer.StreamingSound("Beat_77.mp3")
snd2 = swmixer.Sound("test2.wav")
print snd1.get_length(), snd2.get_length()
snd1.play(volume=0.2)
snd2.play()
time.sleep(10.0)  #don't quit before we hear the sound!
コード例 #15
0
import swmixer
import time

swmixer.init(samplerate=44100, chunksize=1024, stereo=False)
swmixer.start()
snd = swmixer.Sound("sounds/piano2.wav")
snd.play()
time.sleep(10.0) #don't quit before we hear the sound!
コード例 #16
0
import swmixer
import time

swmixer.init(samplerate=44100, chunksize=1024, stereo=False)
swmixer.start()
snd1 = swmixer.Sound("test1.wav")
snd2 = swmixer.Sound("test2.wav")
snd1.play(loops=-1)
snd2.play()
time.sleep(10.0)  #don't quit before we hear the sound!