0
|
1
|
|
2 # Package: rdyncall
|
|
3 # File: demo/playtune.R
|
|
4 # Description: play a nice oldsch00l tune.
|
|
5 # Uses: SDL/audio, SDL_mixer
|
|
6
|
|
7 rsrc <- function(name) system.file(paste("demo-files",name,sep=.Platform$file.sep), package="rdyncall")
|
|
8 music <- NULL
|
|
9 init <- function()
|
|
10 {
|
|
11 require(rdyncall)
|
|
12 dynport(SDL)
|
|
13 SDL_Init(SDL_INIT_AUDIO)
|
|
14 dynport(SDL_mixer)
|
|
15 Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 4096)
|
|
16 music <<- Mix_LoadMUS(rsrc("external.xm"))
|
|
17 }
|
|
18 cleanup <- function()
|
|
19 {
|
|
20 stopTune()
|
|
21 Mix_FreeMusic(music)
|
|
22 Mix_CloseAudio()
|
|
23 SDL_Quit()
|
|
24 }
|
|
25
|
|
26 playTune <- function() {
|
|
27 Mix_PlayMusic(music, 1)
|
|
28 cat("playing music... [to stop, call 'stopTune()']\n")
|
|
29 }
|
|
30 pauseTune <- function() Mix_PauseMusic()
|
|
31 stopTune <- function() Mix_HaltMusic()
|
|
32
|
|
33 init()
|
|
34 playTune()
|
|
35
|