static void gst_mikmod_loop (GstElement * element) { GstMikMod *mikmod; GstBuffer *buffer_in; g_return_if_fail (element != NULL); g_return_if_fail (GST_IS_MIKMOD (element)); mikmod = GST_MIKMOD (element); srcpad = mikmod->srcpad; mikmod->Buffer = NULL; if (!mikmod->initialized) { while ((buffer_in = GST_BUFFER (gst_pad_pull (mikmod->sinkpad)))) { if (GST_IS_EVENT (buffer_in)) { GstEvent *event = GST_EVENT (buffer_in); if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) break; } else { if (mikmod->Buffer) { mikmod->Buffer = gst_buffer_append (mikmod->Buffer, buffer_in); } else { mikmod->Buffer = buffer_in; } } } if (!GST_PAD_CAPS (mikmod->srcpad)) { if (GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (mikmod->srcpad))) { GST_ELEMENT_ERROR (mikmod, CORE, NEGOTIATION, (NULL), (NULL)); return; } } MikMod_RegisterDriver (&drv_gst); MikMod_RegisterAllLoaders (); MikMod_Init (""); reader = GST_READER_new (mikmod); module = Player_LoadGeneric (reader, 64, 0); gst_buffer_unref (mikmod->Buffer); if (!Player_Active ()) Player_Start (module); mikmod->initialized = TRUE; } if (Player_Active ()) { timestamp = (module->sngtime / 1024.0) * GST_SECOND; drv_gst.Update (); } else { gst_element_set_eos (GST_ELEMENT (mikmod)); gst_pad_push (mikmod->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS))); } }
/** ** Type member function to read from the module ** ** @param buf Buffer to write data to ** @param len Length of the buffer ** ** @return Number of bytes read */ int CSampleMikModStream::Read(void *buf, int len) { int read; // fill up the buffer read = 0; while (this->Len < SOUND_BUFFER_SIZE / 2 && Player_Active()) { memcpy(this->Buffer, this->Buffer + this->Pos, this->Len); this->Pos = 0; CurrentFile = this->Data.MikModFile; read = VC_WriteBytes((SBYTE *)this->Buffer + this->Pos, SOUND_BUFFER_SIZE - (this->Pos + this->Len)); this->Len += read; } if (this->Len < len) { // EOF len = this->Len; } memcpy(buf, this->Buffer + this->Pos, len); this->Len -= len; this->Pos += len; return len; }
static GstStateChangeReturn gst_mikmod_change_state (GstElement * element, GstStateChange transition) { GstMikMod *mikmod; g_return_val_if_fail (GST_IS_MIKMOD (element), GST_STATE_CHANGE_FAILURE); mikmod = GST_MIKMOD (element); GST_DEBUG ("state pending %d", GST_STATE_PENDING (element)); if (GST_STATE_PENDING (element) == GST_STATE_READY) { gst_mikmod_setup (mikmod); if (Player_Active ()) { Player_TogglePause (); Player_SetPosition (0); } mikmod->initialized = FALSE; } if (GST_STATE_PENDING (element) == GST_STATE_PLAYING) { if (Player_Active () && Player_Paused ()) Player_TogglePause (); else if (!Player_Active ()) Player_Start (module); } if (GST_STATE_PENDING (element) == GST_STATE_PAUSED) if (Player_Active () && !Player_Paused ()) Player_TogglePause (); if (GST_STATE_PENDING (element) == GST_STATE_NULL) MikMod_Exit (); if (GST_ELEMENT_CLASS (parent_class)->change_state) return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); return GST_STATE_CHANGE_SUCCESS; }
int mod_decode(OutputBuffer * cb, DecoderControl * dc, char * path) { mod_Data * data; float time = 0.0; int ret; float secPerByte; if(mod_initMikMod() < 0) return -1; if(!(data = mod_open(path))) { ERROR("failed to open mod: %s\n", path); MikMod_Exit(); return -1; } dc->audioFormat.bits = 16; dc->audioFormat.sampleRate = 44100; dc->audioFormat.channels = 2; getOutputAudioFormat(&(dc->audioFormat),&(cb->audioFormat)); secPerByte = 1.0/((dc->audioFormat.bits*dc->audioFormat.channels/8.0)* (float)dc->audioFormat.sampleRate); dc->state = DECODE_STATE_DECODE; while(1) { if(dc->seek) { dc->seekError = 1; dc->seek = 0; } if(dc->stop) break; if(!Player_Active()) break; ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE); time += ret*secPerByte; sendDataToOutputBuffer(cb, NULL, dc, 0, (char *)data->audio_buffer, ret, time, 0, NULL); } flushOutputBuffer(cb); mod_close(data); MikMod_Exit(); if(dc->stop) { dc->state = DECODE_STATE_STOP; dc->stop = 0; } else dc->state = DECODE_STATE_STOP; 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 oslAudioCallback_AudioCallback_MOD(unsigned int i, void* buf, unsigned int length) { //Set up playback //md_mixfreq = osl_modFrequency; //md_mixshift = osl_modShift; if (osl_modPlaying) VC_WriteBytes(buf, length << 2); else memset(buf, 0, length << 2); //Fin de la chanson ^^ if (!Player_Active()) return 0; return 1; }
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; }
int main(int argc, char** argv) { MODULE *module; /* register all the drivers */ MikMod_RegisterAllDrivers(); /* register all the module loaders */ MikMod_RegisterAllLoaders(); /* initialize the library */ md_mode |= DMODE_SOFT_MUSIC; if (MikMod_Init("")) { fprintf(stderr, "Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno)); return -1; } /* load module */ module = Player_Load("music.xm", 64, 0); printf ("module loaded\n"); if (module) { /* start module */ Player_Start(module); while (Player_Active()) { /* we're playing */ gsKit_vsync_wait(); } Player_Stop(); Player_Free(module); } else fprintf(stderr, "Could not load module, reason: %s\n", MikMod_strerror(MikMod_errno)); /* give up */ 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; }
bool SgModFinished () { return !currentmod || !Player_Active (); }
//0-128 int Mix_VolumeMusic(int volume) { musicvolume = volume; if (Player_Active()) Player_SetVolume(musicvolume); return volume; }
//Music part! int Mix_PlayingMusic(void) { return Player_Active(); }
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; }
/** ** Load MikMod. ** ** @param name Filename of the module. ** @param flags Unused. ** ** @return Returns the loaded sample. */ CSample *LoadMikMod(const char *name, int flags) { CSample *sample; MikModData *data; MODULE *module; CFile *f; char s[256]; static int registered = 0; md_mode |= DMODE_STEREO | DMODE_INTERP | DMODE_SURROUND | DMODE_HQMIXER; MikMod_RegisterDriver(&drv_nos); if (!registered) { MikMod_RegisterAllLoaders(); registered = 1; } strcpy_s(s, sizeof(s), name); f = new CFile; if (f->open(name, CL_OPEN_READ) == -1) { delete f; return NULL; } CurrentFile = f; MikMod_Init(""); module = Player_LoadGeneric(&MReader, 64, 0); if (!module) { MikMod_Exit(); f->close(); delete f; return NULL; } if (flags & PlayAudioStream) { sample = new CSampleMikModStream; data = &((CSampleMikModStream *)sample)->Data; } else { sample = new CSampleMikMod; data = &((CSampleMikMod *)sample)->Data; } data->MikModFile = f; data->MikModModule = module; sample->Channels = 2; sample->SampleSize = 16; sample->Frequency = 44100; sample->Pos = 0; if (flags & PlayAudioStream) { sample->Len = 0; sample->Buffer = new unsigned char[SOUND_BUFFER_SIZE]; Player_Start(data->MikModModule); } else { int read; int pos; // FIXME: need to find the correct length sample->Len = 55000000; sample->Buffer = new unsigned char[sample->Len]; pos = 0; Player_Start(data->MikModModule); while (Player_Active()) { read = VC_WriteBytes((SBYTE *)sample->Buffer + pos, sample->Len - pos); pos += read; } Player_Stop(); Player_Free(data->MikModModule); MikMod_Exit(); data->MikModFile->close(); delete data->MikModFile; } return sample; }
static int S_MIKMOD_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer) { if (!Player_Active()) return 0; return (int) VC_WriteBytes((SBYTE *)buffer, bytes); }
int main(void) { SceCtrlData pad, lastpad; int maxchan = 128; BOOL outputEnabled; MODULE *mf = NULL; SAMPLE *sf = NULL; int voice = 0; int pan = 127; int vol = 127; int freq = 22000; pspDebugScreenInit(); SetupCallbacks(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(1); if (!MikMod_InitThreads()) { printf("MikMod thread init failed\n"); } MikMod_RegisterErrorHandler(my_error_handler); /* register all the drivers */ MikMod_RegisterAllDrivers(); /* register all the module loaders */ MikMod_RegisterAllLoaders(); /* initialize the library */ md_mode = DMODE_16BITS|DMODE_STEREO|DMODE_SOFT_SNDFX|DMODE_SOFT_MUSIC; md_reverb = 0; md_pansep = 128; if (MikMod_Init("")) { printf("Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno)); sceKernelExitGame(); return 0; } MikMod_SetNumVoices(-1, 8); /* get ready to play */ sf = Sample_Load("ms0:/sound.wav"); printf("Starting.\n"); MikMod_EnableOutput(); outputEnabled = 1; if ((mikModThreadID = sceKernelCreateThread("MikMod" ,(void*)&AudioChannelThread,0x12,0x10000,0,NULL)) > 0) { sceKernelStartThread(mikModThreadID, 0 , NULL); } else { printf("Play thread create failed!\n"); } sceCtrlReadBufferPositive(&lastpad, 1); do { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons != lastpad.Buttons) { if(pad.Buttons & PSP_CTRL_CROSS) { voice = Sample_Play(sf,0,0); Voice_SetPanning(voice, pan); } if(pad.Buttons & PSP_CTRL_SQUARE) { outputEnabled = !outputEnabled; if(outputEnabled) MikMod_EnableOutput(); else MikMod_DisableOutput(); } if(pad.Buttons & PSP_CTRL_CIRCLE) { mf = Player_Load("ms0:/MUSIC.XM", maxchan, 0); if (NULL != mf) { mf->wrap = 1; Player_Start(mf); } } if(pad.Buttons & PSP_CTRL_TRIANGLE) { if (NULL != mf) { Player_Stop(); Player_Free(mf); /* To stop the song for real, it needs to be freed. I know, weird... */ mf = NULL; } } if(pad.Buttons & PSP_CTRL_SELECT) printf("Player is %s\n", Player_Active()?"On":"Off"); lastpad = pad; } if(pad.Buttons & PSP_CTRL_LTRIGGER) { Voice_SetPanning(voice, (pan<2)?pan:--pan); printf("pan is %d\n", pan); } if(pad.Buttons & PSP_CTRL_RTRIGGER) { Voice_SetPanning(voice, (pan>254)?pan:++pan); printf("pan is %d\n", pan); } if(pad.Buttons & PSP_CTRL_UP) { Voice_SetVolume(voice, (vol>254)?vol:++vol); printf("vol is %d\n", vol); } if(pad.Buttons & PSP_CTRL_DOWN) { Voice_SetVolume(voice, (vol<2)?vol:--vol); printf("vol is %d\n", vol); } if(pad.Buttons & PSP_CTRL_LEFT) { Voice_SetFrequency(voice, (freq<1001)?freq:(freq -=1000)); printf("freq is %d\n", freq); } if(pad.Buttons & PSP_CTRL_RIGHT) { Voice_SetFrequency(voice, (freq>44000)?freq:(freq +=1000)); printf("freq is %d\n", freq); } sceDisplayWaitVblankStart(); } while(!((pad.Buttons & PSP_CTRL_START) || done)); printf("Stopping.\n"); /* allow audio thread to terminate cleanly */ done = 1; if (mikModThreadID > 0) { SceUInt timeout = 100000; sceKernelWaitThreadEnd(mikModThreadID, &timeout); /* not 100% sure if this is necessary after a clean exit, * but just to make sure any resources are freed: */ sceKernelDeleteThread(mikModThreadID); } Player_Stop(); Player_Free(mf); MikMod_Exit(); sceKernelExitGame(); return 0; }