static void * SgUpdateMikModThread( void *arg ) { while (!sg_thread_termination_requested) { usleep(10000); MikMod_Update(); } return 0; }
static void *snd_thread(void *data) { for(;;) { MikMod_Update(); thd_sleep(5); } return NULL; }
static int AudioChannelThread(int args, void *argp) { while (!done) { MikMod_Update(); /* have to sleep here to allow other threads a chance to process. * with no sleep, this thread will take over when the output is * disabled via MikMod_DisableOutput() * co-operative threading sucks bigtime... */ sceKernelDelayThread(1); } return (0); }
int main() { int i=0, x, y, t; const int COLOURS_LEN = sizeof(COLOURS) / sizeof(int); const int FLAG_LEN = sizeof(FLAG) / sizeof(char) - 1; // Extract module song payload char fname[] = "/tmp/file-XXXXXX"; int fd = mkstemp(fname); if (write(fd, src_music_xm, src_music_xm_len) < 0) return -1; lseek(fd, 0, SEEK_SET); FILE *pFile = fdopen(fd, "rb"); // Load and play the module song MODULE *module; MikMod_RegisterAllDrivers(); MikMod_RegisterAllLoaders(); md_mode |= DMODE_SOFT_MUSIC; MikMod_Init(""); module = Player_LoadFP(pFile, 64, 0); module->wrap = 1; Player_Start(module); // Animation while (1) { MikMod_Update(); for (y = 0; y < COLOURS_LEN; y++) { // line loop printf("\x1b[1;%dm", COLOURS[y]); // set rainbow line colour for (x = 0; x < WIDTH - ANGLE*(COLOURS_LEN-y); x++) // rainbow line putchar(FLAG[(x + (FLAG_LEN-y)+i) % FLAG_LEN]); // print rainbow character printf("\x1b[0m"); // clear colour for (t = ANGLE; t < ANGLE * (COLOURS_LEN-y); t++) // print distance holder putchar(' '); printf("\x1b[1m"); // set bright color for cat puts(CAT[y%COLOURS_LEN + (i%10<COLOURS_LEN ? 0 : COLOURS_LEN)]); // cat } if (_kbhit()) // key pressed? break; i++; usleep(DELAY); // wait x ms printf("\x1b[%dA", COLOURS_LEN); // move up before loop } puts("\x1b[0m"); // reset colours Player_Stop(); Player_Free(module); MikMod_Exit(); return 0; }
static int moda_Decode (THIS_PTR, void* buf, sint32 bufsize) { TFB_ModSoundDecoder* moda = (TFB_ModSoundDecoder*) This; volatile ULONG* poutsize; Player_Start (moda->module); if (!Player_Active()) return 0; poutsize = moda_mmout_SetOutputBuffer (buf, bufsize); MikMod_Update (); return *poutsize; }
int main(int argc, char **argv) { MODULE *module; if (argc<2) { fprintf(stderr, "Usage: ./splay1 file\n"); return 1; } /* register all the drivers */ MikMod_RegisterAllDrivers(); /* register all the module loaders */ MikMod_RegisterAllLoaders(); /* init the library */ md_mode |= DMODE_SOFT_MUSIC | DMODE_NOISEREDUCTION; if (MikMod_Init("")) { fprintf(stderr, "Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno)); return 2; } /* load module */ module = Player_Load(argv[1], 64, 0); if (module) { /* */ printf("Playing %s (%d chn) - SIMD: %s\n", module->songname, module->numchn, md_mode & DMODE_SIMDMIXER ? "yes" : "no"); /* start module */ Player_Start(module); while (Player_Active()) { MikMod_Sleep(10000); MikMod_Update(); } Player_Stop(); Player_Free(module); } else fprintf(stderr, "Could not load module, reason: %s\n", MikMod_strerror(MikMod_errno)); MikMod_Exit(); return 0; }
/*------------------------------------------------------------------------------------- // sdyMOD_Stream - Stream sound-data to buffer. // // Returns number streamed bytes, which can be less // than dwBytes in case the sound has found its end. //-------------------------------------------------------------------------------------*/ sdyDword SDYSTRMAPI MOD_Stream(void *pMOD, sdyByte *lpbyBuffer, sdyDword dwBytes) { /* make values global so that SDY_Update can modify them */ g_lpbyBuffer = lpbyBuffer; g_dwReadBytes = dwBytes; /* Only update when a mod-sound is playing. */ /* */ /* NOTE: only one mod-sound can currently be played at once, */ /* due to the internal structure of the MikMod library! */ if(Player_Active()) /* MikMod_Update() calls SDY_Update() (see above) */ /* so g_lpbyBuffer and g_dwReadBytes will be updated. */ MikMod_Update(); else return 0; return g_dwReaded; }
int main(void) { /* enable interrupts (on the CPU) */ init_interrupts(); /* Initialize audio and video */ audio_init(44100,2); console_init(); /* Initialize key detection */ controller_init(); MikMod_RegisterAllDrivers(); MikMod_RegisterAllLoaders(); md_mode |= DMODE_16BITS; md_mode |= DMODE_SOFT_MUSIC; md_mode |= DMODE_SOFT_SNDFX; //md_mode |= DMODE_STEREO; md_mixfreq = audio_get_frequency(); MikMod_Init(""); if(dfs_init( DFS_DEFAULT_LOCATION ) != DFS_ESUCCESS) { printf("Filesystem failed to start!\n"); } else { direntry_t *list; int count = 0; int page = 0; int cursor = 0; console_set_render_mode(RENDER_MANUAL); console_clear(); list = populate_dir(&count); while(1) { console_clear(); display_dir(list, cursor, page, MAX_LIST, count); console_render(); controller_scan(); struct controller_data keys = get_keys_down(); if(keys.c[0].up) { cursor--; new_scroll_pos(&cursor, &page, MAX_LIST, count); } if(keys.c[0].down) { cursor++; new_scroll_pos(&cursor, &page, MAX_LIST, count); } if(keys.c[0].C_right && list[cursor].type == DT_REG) { /* Module playing loop */ MODULE *module = NULL; /* Concatenate to make file */ char path[512]; strcpy( path, dir ); strcat( path, list[cursor].filename ); module = Player_Load(path, 256, 0); /* Ensure that first part of module doesn't get cut off */ audio_write_silence(); audio_write_silence(); if(module) { char c = '-'; int sw = 0; Player_Start(module); while(1) { if(sw == 5) { console_clear(); display_dir(list, cursor, page, MAX_LIST, count); sw = 0; switch(c) { case '-': c = '\\'; break; case '\\': c = '|'; break; case '|': c = '/'; break; case '/': c = '-'; break; } printf("\n\n\n%c Playing module", c); console_render(); } else { sw++; } MikMod_Update(); controller_scan(); struct controller_data keys = get_keys_down(); if(keys.c[0].C_left || !Player_Active()) { /* End playback */ audio_write_silence(); audio_write_silence(); audio_write_silence(); audio_write_silence(); break; } } Player_Stop(); Player_Free(module); } } if(keys.c[0].L) { /* Open the SD card */ strcpy( dir, "sd://" ); /* Populate new directory */ free_dir(list); list = populate_dir(&count); page = 0; cursor = 0; } if(keys.c[0].R) { /* Open the ROM FS card */ strcpy( dir, "rom://" ); /* Populate new directory */ free_dir(list); list = populate_dir(&count); page = 0; cursor = 0; } if(keys.c[0].A && list[cursor].type == DT_DIR) { /* Change directories */ chdir(list[cursor].filename); /* Populate new directory */ free_dir(list); list = populate_dir(&count); page = 0; cursor = 0; } if(keys.c[0].B) { /* Up! */ chdir(".."); /* Populate new directory */ free_dir(list); list = populate_dir(&count); page = 0; cursor = 0; } } } while(1); return 0; }
void UOpenALAudioSubsystem::Update( FPointRegion Region, FCoords& Coords ) { guard(UOpenALAudioSubsystem::Update); if( !Viewport ) return; AActor *ViewActor = FindViewActor(); guard(UpdateMusic); if( Viewport->Actor->Song != PlayingSong ) { StopMusic(); PlayingSong = Viewport->Actor->Song; if( PlayingSong != NULL ) { MODULE* Module = GetModuleFromUMusic( PlayingSong ); Player_Start( Module ); } } if( Player_Active() ) MikMod_Update(); unguard; // Update the listener. { FVector At = ViewActor->Rotation.Vector(); FVector Up = -(GMath.UnitCoords / ViewActor->Rotation).ZAxis; FLOAT Orientation[6] = { At.X, At.Y, At.Z, Up.X, Up.Y, Up.Z }; alListenerfv( AL_POSITION, &ViewActor->Location.X ); alListenerfv( AL_VELOCITY, &ViewActor->Velocity.X ); alListenerfv( AL_ORIENTATION, Orientation ); } // See if any new ambient sounds need to be started. UBOOL Realtime = Viewport->IsRealtime() && Viewport->Actor->Level->Pauser==TEXT(""); if( Realtime ) { guard(StartAmbience); for( INT i=0; i<Viewport->Actor->GetLevel()->Actors.Num(); i++ ) { AActor* Actor = Viewport->Actor->GetLevel()->Actors(i); if ( Actor && Actor->AmbientSound && FDistSquared(ViewActor->Location,Actor->Location)<=Square(Actor->WorldSoundRadius()) ) { INT Slot = Actor->GetIndex()*16+SLOT_Ambient*2; INT j; // See if there's already an existing slot. for( j=0; j<NumSources; j++ ) if( Sources[j].Slot==Slot ) break; // If not, start playing. if( j==NumSources ) PlaySound( Actor, Slot, Actor->AmbientSound, Actor->Location, AmbientFactor*Actor->SoundVolume/255.0, Actor->WorldSoundRadius(), Actor->SoundPitch/64.0, 1 ); } } unguard; } // Update all playing ambient sounds. guard(UpdateAmbience); for( INT i=0; i<NumSources; i++ ) { FAudioSource& Source = Sources[i]; if( (Source.Slot&14)==SLOT_Ambient*2 ) { check(Source.Actor); if ( FDistSquared(ViewActor->Location,Source.Actor->Location)>Square(Source.Actor->WorldSoundRadius()) || Source.Actor->AmbientSound!=Source.Sound || !Realtime ) { // Ambient sound went out of range. StopSource( Source ); } else { // Update basic sound properties. FLOAT Volume = 2.0 * (AmbientFactor*Source.Actor->SoundVolume/255.0); // XXX: Huh? What does light brightness have to do with it? if( Source.Actor->LightType!=LT_None ) Volume *= Source.Actor->LightBrightness/255.0; Source.Volume = Volume; Source.Radius = Source.Actor->WorldSoundRadius(); const ALuint Id = Source.Id; alSourcef( Id, AL_GAIN, Source.Volume ); alSourcef( Id, AL_MAX_DISTANCE, Source.Radius ); alSourcef( Id, AL_PITCH, Source.Actor->SoundPitch/64.0 ); } } } unguard; // Update all active sounds. guard(UpdateSounds); for( INT Index=0; Index<NumSources; Index++ ) { FAudioSource& Source = Sources[Index]; // We should've been notified about this. if( Source.Actor ) check(Source.Actor->IsValid()); // Check if the sound is playing. if( Source.Slot==0 ) continue; // Check if the sound is finished. ALint state; alGetSourcei( Source.Id, AL_SOURCE_STATE, &state ); if( state==AL_STOPPED ) { StopSource( Source ); continue; } // Update positioning from actor, if available. if( Source.Actor ) { Source.Location = Source.Actor->Location; alSourcefv( Source.Id, AL_POSITION, &Source.Actor->Location.X ); alSourcefv( Source.Id, AL_VELOCITY, &Source.Actor->Velocity.X ); } // Update the priority. Source.Priority = SoundPriority( Source.Location, Source.Volume, Source.Radius ); } unguard; unguard; }
int main(void) { /* sound effects */ SAMPLE *sfx1, *sfx2; /* voices */ int v1, v2; int i; /* register all the drivers */ MikMod_RegisterAllDrivers(); /* initialize the library */ md_mode |= DMODE_SOFT_SNDFX; if (MikMod_Init("")) { fprintf(stderr, "Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno)); return 1; } /* load samples */ sfx1 = Load("first.wav"); if (!sfx1) { MikMod_Exit(); fprintf(stderr, "Could not load the first sound, reason: %s\n", MikMod_strerror(MikMod_errno)); return 1; } sfx2 = Load("second.wav"); if (!sfx2) { Sample_Free(sfx1); MikMod_Exit(); fprintf(stderr, "Could not load the second sound, reason: %s\n", MikMod_strerror(MikMod_errno)); return 1; } /* reserve 2 voices for sound effects */ MikMod_SetNumVoices(-1, 2); /* get ready to play */ MikMod_EnableOutput(); /* play first sample */ v1 = Sample_Play(sfx1, 0, 0); do { MikMod_Update(); MikMod_Sleep(100000); } while (!Voice_Stopped(v1)); for (i = 0; i < 10; i++) { MikMod_Update(); MikMod_Sleep(100000); } /* half a second later, play second sample */ v2 = Sample_Play(sfx2, 0, 0); do { MikMod_Update(); MikMod_Sleep(100000); } while (!Voice_Stopped(v2)); for (i = 0; i < 10; i++) { MikMod_Update(); MikMod_Sleep(100000); } MikMod_DisableOutput(); Sample_Free(sfx2); Sample_Free(sfx1); MikMod_Exit(); return 0; }