annotate R/rdyncall/demo/playtune.R @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 # Package: rdyncall
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 # File: demo/playtune.R
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 # Description: play a nice oldsch00l tune.
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 # Uses: SDL/audio, SDL_mixer
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 rsrc <- function(name) system.file(paste("demo-files",name,sep=.Platform$file.sep), package="rdyncall")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 music <- NULL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 init <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 require(rdyncall)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 dynport(SDL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 SDL_Init(SDL_INIT_AUDIO)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 dynport(SDL_mixer)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 4096)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 music <<- Mix_LoadMUS(rsrc("external.xm"))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 cleanup <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 stopTune()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 Mix_FreeMusic(music)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 Mix_CloseAudio()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 SDL_Quit()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 playTune <- function() {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 Mix_PlayMusic(music, 1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 cat("playing music... [to stop, call 'stopTune()']\n")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 pauseTune <- function() Mix_PauseMusic()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 stopTune <- function() Mix_HaltMusic()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 init()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 playTune()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35