static mrb_value mrb_sdl2_mixer_set_music_position(mrb_state *mrb, mrb_value self) { mrb_int pos; mrb_get_args(mrb, "i", &pos); return mrb_fixnum_value(Mix_SetMusicPosition(pos)); }
void Music::setPosition(double seconds) { this->rewind(); if (Mix_SetMusicPosition(seconds) == -1) { Log::error("Mix_SetMusicPosition: Couldn't do that:" + std::string(Mix_GetError())); } }
void cAudio :: Set_Music_Position( float position ) const { if( !m_music_enabled || !m_initialised || Is_Music_Fading() == MIX_FADING_OUT ) { return; } Mix_SetMusicPosition( position ); }
void cAudio :: SetMusicPosition( double position ) { if( !bMusic || !bInitialised || isMusicFading() == 2 ) { return; } Mix_SetMusicPosition( position ); }
/* function: Mix_SetMusicPosition */ static int toluaI_sound_sound_set_position_music00(lua_State* tolua_S) { if ( !tolua_istype(tolua_S,1,LUA_TNUMBER,0) || !tolua_isnoobj(tolua_S,2) ) goto tolua_lerror; else { s32b pos = ((s32b) tolua_getnumber(tolua_S,1,0)); { s32b toluaI_ret = (s32b) Mix_SetMusicPosition(pos); tolua_pushnumber(tolua_S,(long)toluaI_ret); } } return 1; tolua_lerror: tolua_error(tolua_S,"#ferror in function 'set_position_music'."); return 0; }
int main( int argc, char* args[] ) { int quit = false; if( init() == false ) { return false; } if( load_files() == false ) { return false; } apply_surface( 0, 0, background, screen ); message = TTF_RenderText_Solid( font, "Start game", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 100, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Options", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 200, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Exit", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 300, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Press 9 to play/pause the music", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 400, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Press 0 to stop the music", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 500, message, screen ); SDL_FreeSurface( message ); if( SDL_Flip( screen ) == -1 ) { return false; } while( quit == false ) { while( SDL_PollEvent( &event ) ) { if( event.type == SDL_KEYDOWN ) { if( event.key.keysym.sym == SDLK_6) { Mix_RewindMusic(); if(Mix_SetMusicPosition(60.0)==-1) { return false; } } else if( event.key.keysym.sym == SDLK_9 ) { if( Mix_PlayingMusic() == 0 ) { if( Mix_PlayMusic( music, -1 ) == -1 ) { return false; } } else { if( Mix_PausedMusic() == 1 ) { Mix_ResumeMusic(); } else { Mix_PauseMusic(); } } } else if( event.key.keysym.sym == SDLK_0 ) { Mix_HaltMusic(); } } if( event.type == SDL_QUIT ) { quit = true; } } } clean_up(); return 0; }
bool Music::SetPosition(double pSeconds) { return Mix_SetMusicPosition(pSeconds) == 0; }
void Mix_RewindMusic(void) { Mix_SetMusicPosition(0.0); }
int main(int argc, char **argv) { int audio_rate,audio_channels; Uint16 audio_format; Uint32 t; Mix_Music *music; int volume=SDL_MIX_MAXVOLUME; /* initialize SDL for audio and video */ if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO)<0) cleanExit("SDL_Init"); atexit(SDL_Quit); int initted=Mix_Init(0); printf("Before Mix_Init SDL_mixer supported: "); print_init_flags(initted); initted=Mix_Init(~0); printf("After Mix_Init SDL_mixer supported: "); print_init_flags(initted); Mix_Quit(); if(argc<2 || argc>4) { fprintf(stderr,"Usage: %s filename [depth] [any 3rd argument...]\n" " filename is any music file supported by your SDL_mixer library\n" " depth is screen depth, default is 8bits\n" " if there is a third argument given, we go fullscreen for maximum fun!\n", *argv); return 1; } /* open a screen for the wav output */ if(!(s=SDL_SetVideoMode(W,H,(argc>2?atoi(argv[2]):8),(argc>3?SDL_FULLSCREEN:0)|SDL_HWSURFACE|SDL_DOUBLEBUF))) cleanExit("SDL_SetVideoMode"); SDL_WM_SetCaption("sdlwav - SDL_mixer demo","sdlwav"); /* hide the annoying mouse pointer */ SDL_ShowCursor(SDL_DISABLE); /* get the colors we use */ white=SDL_MapRGB(s->format,0xff,0xff,0xff); black=SDL_MapRGB(s->format,0,0,0); /* initialize sdl mixer, open up the audio device */ if(Mix_OpenAudio(44100,MIX_DEFAULT_FORMAT,2,BUFFER)<0) cleanExit("Mix_OpenAudio"); /* we play no samples, so deallocate the default 8 channels... */ Mix_AllocateChannels(0); /* print out some info on the formats this run of SDL_mixer supports */ { int i,n=Mix_GetNumChunkDecoders(); printf("There are %d available chunk(sample) decoders:\n",n); for(i=0; i<n; ++i) printf(" %s\n", Mix_GetChunkDecoder(i)); n = Mix_GetNumMusicDecoders(); printf("There are %d available music decoders:\n",n); for(i=0; i<n; ++i) printf(" %s\n", Mix_GetMusicDecoder(i)); } /* print out some info on the audio device and stream */ Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); bits=audio_format&0xFF; sample_size=bits/8+audio_channels; rate=audio_rate; printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate, bits, audio_channels>1?"stereo":"mono", BUFFER ); /* calculate some parameters for the wav display */ dy=s->h/2.0/(float)(0x1<<bits); /* load the song */ if(!(music=Mix_LoadMUS(argv[1]))) cleanExit("Mix_LoadMUS(\"%s\")",argv[1]); { Mix_MusicType type=Mix_GetMusicType(music); printf("Music type: %s\n", type==MUS_NONE?"MUS_NONE": type==MUS_CMD?"MUS_CMD": type==MUS_WAV?"MUS_WAV": /*type==MUS_MOD_MODPLUG?"MUS_MOD_MODPLUG":*/ type==MUS_MOD?"MUS_MOD": type==MUS_MID?"MUS_MID": type==MUS_OGG?"MUS_OGG": type==MUS_MP3?"MUS_MP3": type==MUS_MP3_MAD?"MUS_MP3_MAD": type==MUS_FLAC?"MUS_FLAC": "Unknown"); } /* set the post mix processor up */ Mix_SetPostMix(postmix,argv[1]); SDL_FillRect(s,NULL,black); SDL_Flip(s); SDL_FillRect(s,NULL,black); SDL_Flip(s); /* start playing and displaying the wav */ /* wait for escape key of the quit event to finish */ t=SDL_GetTicks(); if(Mix_PlayMusic(music, 1)==-1) cleanExit("Mix_PlayMusic(0x%p,1)",music); Mix_VolumeMusic(volume); while((Mix_PlayingMusic() || Mix_PausedMusic()) && !done) { SDL_Event e; while(SDL_PollEvent(&e)) { switch(e.type) { case SDL_KEYDOWN: switch(e.key.keysym.sym) { case SDLK_ESCAPE: done=1; break; case SDLK_LEFT: if(e.key.keysym.mod&KMOD_SHIFT) { Mix_RewindMusic(); position=0; } else { int pos=position/audio_rate-1; if(pos<0) pos=0; Mix_SetMusicPosition(pos); position=pos*audio_rate; } break; case SDLK_RIGHT: switch(Mix_GetMusicType(NULL)) { case MUS_MP3: Mix_SetMusicPosition(+5); position+=5*audio_rate; break; case MUS_OGG: case MUS_FLAC: case MUS_MP3_MAD: /*case MUS_MOD_MODPLUG:*/ Mix_SetMusicPosition(position/audio_rate+1); position+=audio_rate; break; default: printf("cannot fast-forward this type of music\n"); break; } break; case SDLK_UP: volume=(volume+1)<<1; if(volume>SDL_MIX_MAXVOLUME) volume=SDL_MIX_MAXVOLUME; Mix_VolumeMusic(volume); break; case SDLK_DOWN: volume>>=1; Mix_VolumeMusic(volume); break; case SDLK_SPACE: if(Mix_PausedMusic()) Mix_ResumeMusic(); else Mix_PauseMusic(); break; default: break; } break; case SDL_QUIT: done=1; break; default: break; } } /* the postmix processor tells us when there's new data to draw */ if(need_refresh) refresh(); SDL_Delay(0); } t=SDL_GetTicks()-t; /* free & close */ Mix_FreeMusic(music); Mix_CloseAudio(); SDL_Quit(); /* show a silly statistic */ printf("fps=%.2f\n",((float)flips)/(t/1000.0)); return(0); }
bool SDLAudio::SetMUSPOS(double position) { Mix_SetMusicPosition(position); return true; }
void Stream::Seek(int ms, int channel) { Mix_SetMusicPosition(ms/1000); }
void ONScripter::flushEventSub( SDL_Event &event ) { if ( event.type == ONS_MUSIC_EVENT ){ if ( music_play_loop_flag || (cd_play_loop_flag && !cdaudio_flag ) ){ stopBGM( true ); if (music_file_name){ playSound(music_file_name, SOUND_MUSIC, true); Mix_SetMusicPosition( music_loopback_offset ); } else playCDAudio(); } else{ stopBGM( false ); } } else if ((event.type == ONS_BGMFADE_EVENT) && (event.user.code == BGM_FADEOUT)){ Uint32 cur_fade_duration = mp3fadeout_duration_internal; if (skip_mode & (SKIP_NORMAL | SKIP_TO_EOP) || ctrl_pressed_status) { cur_fade_duration = 0; Mix_VolumeMusic( 0 ); } Uint32 tmp = SDL_GetTicks() - mp3fade_start; if ( tmp < cur_fade_duration ) { tmp = cur_fade_duration - tmp; tmp *= music_volume; tmp /= cur_fade_duration; Mix_VolumeMusic( tmp * MIX_MAX_VOLUME / 100 ); } else { char *ext = NULL; if (fadeout_music_file_name) ext = strrchr(fadeout_music_file_name, '.'); if (ext && (strcmp(ext+1, "OGG") && strcmp(ext+1, "ogg"))){ // set break event to return to script processing when playing music other than ogg SDL_Event event; event.type = ONS_BREAK_EVENT; SDL_PushEvent( &event ); } stopBGM( false ); } } else if ((event.type == ONS_BGMFADE_EVENT) && (event.user.code == BGM_FADEIN)){ Uint32 cur_fade_duration = mp3fadein_duration_internal; if (skip_mode & (SKIP_NORMAL | SKIP_TO_EOP) || ctrl_pressed_status) { cur_fade_duration = 0; Mix_VolumeMusic( music_volume * MIX_MAX_VOLUME / 100 ); } Uint32 tmp = SDL_GetTicks() - mp3fade_start; if ( tmp < cur_fade_duration ) { tmp *= music_volume; tmp /= cur_fade_duration; Mix_VolumeMusic( tmp * MIX_MAX_VOLUME / 100 ); } else { if (timer_bgmfade_id) SDL_RemoveTimer( timer_bgmfade_id ); timer_bgmfade_id = NULL; mp3fadeout_duration_internal = 0; char *ext = NULL; if (music_file_name) ext = strrchr(music_file_name, '.'); if (ext && (strcmp(ext+1, "OGG") && strcmp(ext+1, "ogg"))){ // set break event to return to script processing when playing music other than ogg SDL_Event event; event.type = ONS_BREAK_EVENT; SDL_PushEvent( &event ); } } } else if ( event.type == ONS_CDAUDIO_EVENT ){ if ( cd_play_loop_flag ){ stopBGM( true ); playCDAudio(); } else{ stopBGM( false ); } } else if ( event.type == ONS_MIDI_EVENT ){ ext_music_play_once_flag = !midi_play_loop_flag; Mix_FreeMusic( midi_info ); playMIDI(midi_play_loop_flag); } else if ( event.type == ONS_CHUNK_EVENT ){ // for processing btntim2 and automode correctly if ( wave_sample[event.user.code] ){ Mix_FreeChunk( wave_sample[event.user.code] ); wave_sample[event.user.code] = NULL; if (event.user.code == MIX_LOOPBGM_CHANNEL0 && loop_bgm_name[1] && wave_sample[MIX_LOOPBGM_CHANNEL1]) Mix_PlayChannel(MIX_LOOPBGM_CHANNEL1, wave_sample[MIX_LOOPBGM_CHANNEL1], -1); } } }