15. Media (sound effects, music, video)

Slides:



Advertisements
Similar presentations
Video Production Tutorial Learn how to shoot, edit and export videos from second life.
Advertisements

2.02D Adding Sounds into Computer Animations 2.02 Develop Computer Animations.
CNIT 132 – Week 9 Multimedia. Working with Multimedia Bandwidth is a measure of the amount of data that can be sent through a communication pipeline each.
Royalty Free Music for Schools Do You Have the To Do a Podcast?
Audacity: a step-by-step tutorial Presented by: Terry W. Hoffland.
Technology ICT Option: Audio.
Free Sound Recorder By FreeAudioVideoSoft. Pricing & Installation Software is absolutely FREE With agreement to terms and conditions Installation Requirements:
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Using Audacity Created by: Stephanie Anderson Dublin Unified School District Dublin, California.
Podcast Instructions.
ACE-HIGH MP3 WAV WMA OGG Converter By :: Natharat Kaewrawang
To download PhotoStory: Go to On the left side under Product Resources, click on Downloads.
POWERPOINT 2007 TUTORIAL Features you must know. Adding a new slide  Using the same topic of interest. On Slide 1 make a Title Page.  Right click on.
Making a Playable DVD movie using your digital photos And adding music to the movie.
Windows Movie Maker Getting Started. What is Windows Movie Maker? Windows Movie Maker allows a user to capture (import) audio, create a narration, add.
Activity 2 Mix a WAV file and the sound from a youtube video In this activity, we are going to mix the WAV file created in Activity 1and the sound file.
Sound on the Web. Using Sound on a Web Site Conveying information  pronounce a word or describe a product Set a mood  music to match the web page scene.
Photo Story. How to use Photo Story Photo Story 3 can be located in the Accessories folder on school computers. You will need to have your pictures already.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
How to Create a Podcast. Podcasting “is the distribution of audio or video files, such as radio programs or music videos, over the Internet using either.
Graphics in Python On entry: Run Python 2.78 from N: drive/computing and ICT VLE: Computing home page - check your feedback Success criteria: ●Understands.
Intro to Pygame Lecture 05. What is Pygame? It is a set of Python modules designed for writing games. It makes writing games possible for beginners. import.
Using Audacity Let’s get Started Open Audacity. Getting started…
11. Skier Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
9. Media (sound effects, music, video) Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
5. Animation Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
13. Sprites. Outline 1.Game Things in Pygame (again) 2.The Pygame sprite Module 3.The Sprite Class 4.Groups of Sprites 5.Types of Collision Detection.
Sprites (Images) and Sounds
Sound and more Animations
Section 9.1 Section 9.2 YOU WILL LEARN TO…
Section 9.1 Section 9.2 Identify multimedia design guidelines
MOM! Phineas and Ferb are … Aims:
Sound Music & Sound Effects.
Catapult 2016.
Animations.
PYGAME.
WITH PYGAME ON THE RASPBERRY PI
Let’s Learn 2. Installing Pygame
8. Installing Pygame
9. Drawing.
UltraSonic Sensor VCC is the pin that powers the device, connect to 5V. Trigger is the pin that sends out the burst. Echo is the pin that outputs when.
10. User Input.
Shotcut video editor.
11. Animation Let's Learn Python and Pygame

9. Drawing Let's Learn Python and Pygame
Videos For All Classrooms
Let’s Learn 10. Invaders Saengthong School, June – August 2016
2.02D Adding Sounds into Computer Animations
Adding Music to Your Google Slides Presentation
HTML5 Media.
13. Sprites Let's Learn Python and Pygame
Technology ICT Option: Audio.
8. Starting Pygame Let's Learn Python and Pygame
10. User Input Let's Learn Python and Pygame
14. Pong.
Inserting Sounds.
16. Invaders.
Let’s Learn 7. Sprites Saengthong School, June – August 2016
2.02D Adding Sounds into Computer Animations
Northwest School Division #203
14. Pong Let's Learn Python and Pygame
11. Animation.
Photostory 3.
Technology ICT Option: Audio.
2.02D Adding Sounds into Computer Animations
CoE Software Lab II , Semester 2, Pong.
CoE Software Lab II 1. Pygame Intro , Semester 2,
CoE Software Lab II , Semester 2, Sprites.
Presentation transcript:

15. Media (sound effects, music, video)

Outline Sound Basics Pygame Sound Adding Sounds/Music to Pong Playing Video

1. Sound Basics Some common sound file types: Wave files: e.g. hello.wav. MP3 files: e.g. song.mp3. WMA (Windows Media Audio) files: e.g. song.wma. Ogg Vorbis files: e.g. song.ogg Use Wave files for short sound effects e.g. an explosion, thunder, "game over" Use MP3 or Ogg for long music e.g. the music played in the background during the game

Finding Sounds/Music Online A great list: "55 Great Websites To Download Free Sound Effects" http://www.hongkiat.com/blog/55-great-websites-to-download-free-sound-effects/ I often use findSounds: http://www.findsounds.com/

Sound Editing Sometimes you need to edit sound files: cut out bits of the sound at the start/end convert a sound into another format Great, free tool: audacity http://www.audacityteam.org/ can also record from a microphone

2. Pygame Sound The Pygame mixer module deals with playing sounds/music see http://www.pygame.org/docs/ref/mixer.html It is loaded automatically when you call pygame.init() Or you can type pygame.mixer.init() add arguments to the call to change the default initialization settings

2.1. Playing a Sound Effect Set the volume: splat = pygame.mixer.Sound("splat.wav") splat.play() this function returns straight away; it does not wait for the sound to finish playing Set the volume: splat.set_volume(0.5) value can vary between 0 (off) to 1 (full) call before play()

Some Code from Pong v.2 many sound effects can be loaded and played restart = pygame.mixer.Sound("restart.wav") restart.set_volume(0.5) hitWall = pygame.mixer.Sound("hitWall.wav") hitWall.set_volume(0.4) restart.play() hitWall.play()

2.2. Play Music To play over and over: Only one piece of music can play at a time pygame.mixer.music.load("bg_music.mp3") pygame.mixer.music.play() # plays once play() returns without waiting for the music to finish To play over and over: pygame.mixer.music.play(-1)

MP3 Problem Pygame cannot play all types of MP3 files. If there is a problem, use Audacity to save the MP3 file as a new MP3 file. Audacity's default settings work with Pygame Or save the MP3 file as an OGG file

Controlling music volume: Stop music: pygame.mixer.music.stop() Controlling music volume: pygame.mixer.music.set_volume(0.3) value is between 0 and 1; call before play()

2.3. Detecting when Music Finishes There are two approaches: 1. send a "user" event to the game loop when the music finishes uses pygame.mixer.music.set_endevent() 2. call pygame.mixer.music.get_busy() to get a True/False answer

playMusic.py import pygame BLACK = (0, 0, 0) WHITE = (255, 255, 255) SONG_ENDED = pygame.constants.USEREVENT + 1 # a constant integer; # must be bigger than the USEREVENT value pygame.init() screen = pygame.display.set_mode([200,100]) screen.fill(WHITE) pygame.display.set_caption("Play Music") pygame.mixer.music.load('ziggy.mp3') # pygame.mixer.music.load('ziggy.ogg') # pygame.mixer.music.load('smashingbaby.wav') # shorter song pygame.mixer.music.set_endevent(SONG_ENDED) music = pygame.mixer.music.play()

clock = pygame.time.Clock() running = True while running: # game loop clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == SONG_ENDED: # This event is sent when the music finishes print("music has finished") screen.fill(WHITE) pygame.display.update() pygame.quit()

2.4. Other Pygame.mixer Features Queue music to play Fade a sound in or out Fade a sound left-to-right Pause a sound Access the separate channels (usually 2) that make up the sound output

3. Adding Sounds/Music to Pong See pong2.py same as pong.py, but with an initMusic() function for loading 4 sound effects and 1 song as background music sound effects for: ball hits a paddle ball hits a wall score a point game over

def initMusic(): global hitPaddle, hitWall, scorePoint, bye # load background music; set volume pygame.mixer.music.load("bg_music.mp3") pygame.mixer.music.set_volume(0.3) pygame.mixer.music.play(-1) # Play forever # load sounds effects; set their volumes hitPaddle = pygame.mixer.Sound("hitPaddle.wav") hitPaddle.set_volume(0.4) hitWall = pygame.mixer.Sound("hitWall.wav") hitWall.set_volume(0.4) scorePoint = pygame.mixer.Sound("scorePoint.wav") scorePoint.set_volume(0.2) bye = pygame.mixer.Sound("gameOver.wav") bye.set_volume(0.6)

Playing the Sound Effects Calls to play() for hitPaddle, hitWall, and scorePoint are added to the if-tests inside BallSprite.update() e.g. if pygame.sprite.spritecollideany(self, horizWalls): # change y-step direction at top and bottom sides hitWall.play() self.yStep = -self.yStep

bye.play() is added when gameOver is set to true inside the game loop if scoreLeft >= WINNING_SCORE: winMsg = "Left Wins!" gameOver = True bye.play() elif scoreRight >= WINNING_SCORE: winMsg = "Right Wins!"

4. Playing Video The pygame.movie module is used to play MPG (MPEG-1) and AVI videos see http://www.pygame.org/docs/ref/movie.html not all MPG / AVI formats are supported Can play, pause, rewind, skip, set the volume, check if the movie is running (busy) Not that useful for most games

playMovie.py import pygame pygame.init() pygame.mixer.quit() # so video sound can be heard movie = pygame.movie.Movie('sff.mpg') # movie = pygame.movie.Movie('sff.avi') screen = pygame.display.set_mode(movie.get_size()) movie_screen = pygame.Surface(movie.get_size()).convert() movie.set_display(movie_screen) movie.play()

clock = pygame. time. Clock() running = True while running: clock clock = pygame.time.Clock() running = True while running: clock.tick(60) # faster than usual for event in pygame.event.get(): if event.type == pygame.QUIT: movie.stop() running = False if not movie.get_busy(): # not busy == finished movie.stop() # close down movie player screen.blit(movie_screen,(0,0)) # display pygame.display.update() pygame.quit()

Finding Movie Clips YouTube videos + downloader e.g. ClipConverter (http://www.clipconverter.cc/) Pygame recommends that you use ffmpeg (http://ffmpeg.org/) to convert a video file to the correct type of MPG file format MPEG-1 video, MPEG-1 Audio Layer III (MP3) sound

Using ffmpeg My vid.bat file supplies the right arguments to ffmpeg.exe put in the ffmpeg bin/ directory call from the command prompt in the bin/ directory vid.bat cats.3pg # creates cats.mpg vid.bat sff.avi # creates sff.mpg