Merge pull request #936 from michaeljbishop/add-mix-reservechannels
Add Mix_ReserveChannels
This commit is contained in:
Коммит
4b2e7f4c10
|
@ -1235,6 +1235,7 @@ var LibrarySDL = {
|
|||
|
||||
Mix_Init: function(flags) {
|
||||
if (!flags) return 0;
|
||||
SDL.channelMinimumNumber = 0;
|
||||
return 8; /* MIX_INIT_OGG */
|
||||
},
|
||||
Mix_Quit: function(){},
|
||||
|
@ -1317,7 +1318,9 @@ var LibrarySDL = {
|
|||
Mix_FreeChunk: function(id) {
|
||||
SDL.audios[id] = null;
|
||||
},
|
||||
|
||||
Mix_ReserveChannels: function(num) {
|
||||
SDL.channelMinimumNumber = num;
|
||||
},
|
||||
Mix_PlayChannel: function(channel, id, loops) {
|
||||
// TODO: handle loops
|
||||
|
||||
|
@ -1330,8 +1333,8 @@ var LibrarySDL = {
|
|||
// If the user asks us to allocate a channel automatically, get the first
|
||||
// free one.
|
||||
if (channel == -1) {
|
||||
channel = 0;
|
||||
for (var i = 0; i < SDL.numChannels; i++) {
|
||||
channel = SDL.channelMinimumNumber;
|
||||
for (var i = SDL.channelMinimumNumber; i < SDL.numChannels; i++) {
|
||||
if (!SDL.channels[i].audio) {
|
||||
channel = i;
|
||||
break;
|
||||
|
@ -1403,6 +1406,7 @@ var LibrarySDL = {
|
|||
audio.play();
|
||||
}
|
||||
audio.volume = channelInfo.volume;
|
||||
audio.paused = false;
|
||||
return channel;
|
||||
},
|
||||
Mix_PlayChannelTimed: 'Mix_PlayChannel', // XXX ignore Timing
|
||||
|
@ -1493,44 +1497,45 @@ var LibrarySDL = {
|
|||
|
||||
// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_38.html#SEC38
|
||||
// "Note: Does not check if the channel has been paused."
|
||||
Mix_Playing: function(id) {
|
||||
if (id === -1) {
|
||||
Mix_Playing: function(channel) {
|
||||
if (channel === -1) {
|
||||
var count = 0;
|
||||
for (var i = 0; i < SDL.audios.length; i++) {
|
||||
count += SDL.Mix_Playing(i);
|
||||
for (var i = 0; i < SDL.channels.length; i++) {
|
||||
count += _Mix_Playing(i);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
var info = SDL.audios[id];
|
||||
var info = SDL.channels[channel];
|
||||
if (info && info.audio && !info.audio.paused) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
Mix_Pause: function(id) {
|
||||
if (id === -1) {
|
||||
for (var i = 0; i<SDL.audios.length;i++) {
|
||||
SDL.Mix_Pause(i);
|
||||
Mix_Pause: function(channel) {
|
||||
if (channel === -1) {
|
||||
for (var i = 0; i<SDL.channels.length;i++) {
|
||||
_Mix_Pause(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var info = SDL.audios[id];
|
||||
var info = SDL.channels[channel];
|
||||
if (info && info.audio) {
|
||||
info.audio.pause();
|
||||
info.audio.paused = true;
|
||||
}
|
||||
},
|
||||
|
||||
// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_39.html#SEC39
|
||||
Mix_Paused: function(id) {
|
||||
if (id === -1) {
|
||||
Mix_Paused: function(channel) {
|
||||
if (channel === -1) {
|
||||
var pausedCount = 0;
|
||||
for (var i = 0; i<SDL.audios.length;i++) {
|
||||
pausedCount += SDL.Mix_Paused(i);
|
||||
for (var i = 0; i<SDL.channels.length;i++) {
|
||||
pausedCount += _Mix_Paused(i);
|
||||
}
|
||||
return pausedCount;
|
||||
}
|
||||
var info = SDL.audios[id];
|
||||
var info = SDL.channels[channel];
|
||||
if (info && info.audio && info.audio.paused) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -1542,14 +1547,14 @@ var LibrarySDL = {
|
|||
},
|
||||
|
||||
// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_33.html#SEC33
|
||||
Mix_Resume: function(id) {
|
||||
if (id === -1) {
|
||||
for (var i = 0; i<SDL.audios.length;i++) {
|
||||
SDL.Mix_Resume(i);
|
||||
Mix_Resume: function(channel) {
|
||||
if (channel === -1) {
|
||||
for (var i = 0; i<SDL.channels.length;i++) {
|
||||
_Mix_Resume(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var info = SDL.audios[id];
|
||||
var info = SDL.channels[channel];
|
||||
if (info && info.audio) {
|
||||
info.audio.play();
|
||||
}
|
||||
|
|
|
@ -10779,6 +10779,15 @@ elif 'browser' in str(sys.argv):
|
|||
Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '--preload-file', 'bad.ogg', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play", "_play2"]']).communicate()
|
||||
self.run_browser('page.html', '', '/report_result?1')
|
||||
|
||||
def test_sdl_audio_mix(self):
|
||||
shutil.copyfile(path_from_root('tests', 'sounds', 'pluck.ogg'), os.path.join(self.get_dir(), 'sound.ogg'))
|
||||
shutil.copyfile(path_from_root('tests', 'sounds', 'the_entertainer.ogg'), os.path.join(self.get_dir(), 'music.ogg'))
|
||||
open(os.path.join(self.get_dir(), 'sdl_audio_mix.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_mix.c')).read()))
|
||||
|
||||
# use closure to check for a possible bug with closure minifying away newer Audio() attributes
|
||||
Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_mix.c'), '--preload-file', 'sound.ogg', '--preload-file', 'music.ogg', '-o', 'page.html']).communicate()
|
||||
self.run_browser('page.html', '', '/report_result?1')
|
||||
|
||||
def test_sdl_audio_quickload(self):
|
||||
open(os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_quickload.c')).read()))
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#include <stdio.h>
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_mixer.h>
|
||||
#include <assert.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
static Mix_Chunk *sound = NULL;
|
||||
static Mix_Music *music = NULL;
|
||||
|
||||
static int soundChannel = 0;
|
||||
|
||||
void one_iter();
|
||||
void one_iter() {
|
||||
static int frames = 0;
|
||||
frames++;
|
||||
|
||||
switch( frames ) {
|
||||
case 1:
|
||||
soundChannel = Mix_PlayChannel(-1, sound, 0);
|
||||
printf("channel = %d", soundChannel);
|
||||
assert(soundChannel != -1 && soundChannel != 0);
|
||||
break;
|
||||
case 2:
|
||||
printf("channel %d is playing = %d", soundChannel, Mix_Playing(soundChannel));
|
||||
assert(Mix_Playing(soundChannel));
|
||||
break;
|
||||
case 30:
|
||||
Mix_Pause(soundChannel);
|
||||
Mix_PlayMusic(music, 1);
|
||||
break;
|
||||
case 31:
|
||||
assert(Mix_Paused(soundChannel));
|
||||
assert(Mix_PlayingMusic());
|
||||
break;
|
||||
case 60:
|
||||
Mix_Resume(soundChannel);
|
||||
Mix_PauseMusic();
|
||||
break;
|
||||
case 61:
|
||||
assert(Mix_Playing(soundChannel));
|
||||
assert(Mix_PausedMusic());
|
||||
break;
|
||||
case 90:
|
||||
Mix_ResumeMusic();
|
||||
break;
|
||||
case 91:
|
||||
assert(Mix_PlayingMusic());
|
||||
break;
|
||||
case 120:
|
||||
Mix_HaltChannel(soundChannel);
|
||||
Mix_HaltMusic();
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
SDL_Init(SDL_INIT_AUDIO);
|
||||
Mix_Init(MIX_INIT_OGG);
|
||||
|
||||
// This reserves channel 0 for other purposes.
|
||||
// We are just going to verify that we are not
|
||||
// allocated channel 0 when we call Mix_PlayChannel(-1, ...)
|
||||
Mix_ReserveChannels(1);
|
||||
|
||||
int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
|
||||
assert(ret == 0);
|
||||
|
||||
sound = Mix_LoadWAV("sound.ogg");
|
||||
assert(sound);
|
||||
music = Mix_LoadMUS("music.ogg");
|
||||
assert(music);
|
||||
|
||||
emscripten_set_main_loop(one_iter, 30, 0);
|
||||
|
||||
// force a quit
|
||||
while(Mix_Init(0))
|
||||
Mix_Quit();
|
||||
Mix_CloseAudio();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Загрузка…
Ссылка в новой задаче