diff options
author | Max Horn | 2009-02-15 22:34:41 +0000 |
---|---|---|
committer | Max Horn | 2009-02-15 22:34:41 +0000 |
commit | 29611bc7ead4d3d5fc9df63c04dd9e2577805557 (patch) | |
tree | 42d26aab7ab2e7e97fe5b4763281d8071d878eed /engines/sci/sfx | |
parent | 921e6ff5cf3944c1a62a3ad9a91c29bb21aa9942 (diff) | |
download | scummvm-rg350-29611bc7ead4d3d5fc9df63c04dd9e2577805557.tar.gz scummvm-rg350-29611bc7ead4d3d5fc9df63c04dd9e2577805557.tar.bz2 scummvm-rg350-29611bc7ead4d3d5fc9df63c04dd9e2577805557.zip |
SCI: Run astyle to make the code be more compliant with our Code Formatting Guidelines: sfx dir
svn-id: r38322
Diffstat (limited to 'engines/sci/sfx')
50 files changed, 2108 insertions, 2526 deletions
diff --git a/engines/sci/sfx/adlib.cpp b/engines/sci/sfx/adlib.cpp index c84a087820..bff6e76a72 100644 --- a/engines/sci/sfx/adlib.cpp +++ b/engines/sci/sfx/adlib.cpp @@ -22,14 +22,13 @@ adlib_instr adlib_sbi[96]; void -make_sbi(adlib_def *one, guint8 *buffer) -{ +make_sbi(adlib_def *one, guint8 *buffer) { memset(buffer, 0, sizeof(adlib_instr)); #if 0 - printf ("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x ", one->keyscale1, one->freqmod1, one->feedback1, one->attackrate1, one->sustainvol1, one->envelope1, one->decayrate1, one->releaserate1, one->volume1, one->ampmod1, one->vibrato1, one->keybdscale1, one->algorithm1, one->waveform1); + printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x ", one->keyscale1, one->freqmod1, one->feedback1, one->attackrate1, one->sustainvol1, one->envelope1, one->decayrate1, one->releaserate1, one->volume1, one->ampmod1, one->vibrato1, one->keybdscale1, one->algorithm1, one->waveform1); - printf (" %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x ", one->keyscale2, one->freqmod2, one->feedback2, one->attackrate2, one->sustainvol2, one->envelope2, one->decayrate2, one->releaserate2, one->volume2, one->ampmod2, one->vibrato2, one->keybdscale2, one->algorithm2, one->waveform2); + printf(" %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x ", one->keyscale2, one->freqmod2, one->feedback2, one->attackrate2, one->sustainvol2, one->envelope2, one->decayrate2, one->releaserate2, one->volume2, one->ampmod2, one->vibrato2, one->keybdscale2, one->algorithm2, one->waveform2); printf("\n"); #endif @@ -60,7 +59,7 @@ make_sbi(adlib_def *one, guint8 *buffer) buffer[9] |= (one->waveform2 & 0x3); buffer[10] |= ((one->feedback1 & 0x7) << 1); - buffer[10] |= (1-(one->algorithm1 & 0x1)); + buffer[10] |= (1 - (one->algorithm1 & 0x1)); return; } diff --git a/engines/sci/sfx/adlib.h b/engines/sci/sfx/adlib.h index 67572581b5..4bba47ce3e 100644 --- a/engines/sci/sfx/adlib.h +++ b/engines/sci/sfx/adlib.h @@ -29,34 +29,34 @@ #define ADLIB_VOICES 12 typedef struct _sci_adlib_def { - guint8 keyscale1; /* 0-3 !*/ - guint8 freqmod1; /* 0-15 !*/ - guint8 feedback1; /* 0-7 !*/ - guint8 attackrate1; /* 0-15 !*/ - guint8 sustainvol1; /* 0-15 !*/ - guint8 envelope1; /* t/f !*/ - guint8 decayrate1; /* 0-15 !*/ - guint8 releaserate1; /* 0-15 !*/ - guint8 volume1; /* 0-63 !*/ - guint8 ampmod1; /* t/f !*/ - guint8 vibrato1; /* t/f !*/ - guint8 keybdscale1; /* t/f !*/ - guint8 algorithm1; /* 0,1 REVERSED */ - guint8 keyscale2; /* 0-3 !*/ - guint8 freqmod2; /* 0-15 !*/ - guint8 feedback2; /* 0-7 UNUSED */ - guint8 attackrate2; /* 0-15 !*/ - guint8 sustainvol2; /* 0-15 !*/ - guint8 envelope2; /* t/f !*/ - guint8 decayrate2; /* 0-15 !*/ - guint8 releaserate2; /* 0-15 !*/ - guint8 volume2; /* 0-63 !*/ - guint8 ampmod2; /* t/f !*/ - guint8 vibrato2; /* t/f !*/ - guint8 keybdscale2; /* t/f !*/ - guint8 algorithm2; /* 0,1 UNUSED */ - guint8 waveform1; /* 0-3 !*/ - guint8 waveform2; /* 0-3 !*/ + guint8 keyscale1; /* 0-3 !*/ + guint8 freqmod1; /* 0-15 !*/ + guint8 feedback1; /* 0-7 !*/ + guint8 attackrate1; /* 0-15 !*/ + guint8 sustainvol1; /* 0-15 !*/ + guint8 envelope1; /* t/f !*/ + guint8 decayrate1; /* 0-15 !*/ + guint8 releaserate1; /* 0-15 !*/ + guint8 volume1; /* 0-63 !*/ + guint8 ampmod1; /* t/f !*/ + guint8 vibrato1; /* t/f !*/ + guint8 keybdscale1; /* t/f !*/ + guint8 algorithm1; /* 0,1 REVERSED */ + guint8 keyscale2; /* 0-3 !*/ + guint8 freqmod2; /* 0-15 !*/ + guint8 feedback2; /* 0-7 UNUSED */ + guint8 attackrate2; /* 0-15 !*/ + guint8 sustainvol2; /* 0-15 !*/ + guint8 envelope2; /* t/f !*/ + guint8 decayrate2; /* 0-15 !*/ + guint8 releaserate2; /* 0-15 !*/ + guint8 volume2; /* 0-63 !*/ + guint8 ampmod2; /* t/f !*/ + guint8 vibrato2; /* t/f !*/ + guint8 keybdscale2; /* t/f !*/ + guint8 algorithm2; /* 0,1 UNUSED */ + guint8 waveform1; /* 0-3 !*/ + guint8 waveform2; /* 0-3 !*/ } adlib_def; typedef unsigned char adlib_instr[12]; diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index 4f48326ed7..902872742d 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -52,21 +52,18 @@ Common::Mutex* callbackMutex; #define MILLION 1000000 int -sfx_pcm_available() -{ +sfx_pcm_available() { return (pcm_device != NULL); } void -sfx_reset_player(void) -{ +sfx_reset_player(void) { if (player) player->stop(); } tell_synth_func * -sfx_get_player_tell_func(void) -{ +sfx_get_player_tell_func(void) { if (player) return player->tell_synth; else @@ -74,8 +71,7 @@ sfx_get_player_tell_func(void) } int -sfx_get_player_polyphony(void) -{ +sfx_get_player_polyphony(void) { if (player) return player->polyphony; else @@ -83,15 +79,13 @@ sfx_get_player_polyphony(void) } static long -time_minus(GTimeVal t1, GTimeVal t2) -{ +time_minus(GTimeVal t1, GTimeVal t2) { return (t1.tv_sec - t2.tv_sec) * MILLION - + (t1.tv_usec - t2.tv_usec); + + (t1.tv_usec - t2.tv_usec); } static GTimeVal -time_plus(GTimeVal t1, long delta) -{ +time_plus(GTimeVal t1, long delta) { if (delta > 0) t1.tv_usec += delta % MILLION; else @@ -109,12 +103,11 @@ time_plus(GTimeVal t1, long delta) static void -_freeze_time(sfx_state_t *self) -{ +_freeze_time(sfx_state_t *self) { /* Freezes the top song delay time */ GTimeVal ctime; long delta; - + song_t *song = self->song; sci_get_current_time(&ctime); @@ -132,8 +125,7 @@ _freeze_time(sfx_state_t *self) #if 0 // Unreferenced - removed static void -_dump_playing_list(sfx_state_t *self, char *msg) -{ +_dump_playing_list(sfx_state_t *self, char *msg) { song_t *song = self->song; fprintf(stderr, "[] Song list : [ "); @@ -156,8 +148,7 @@ _dump_playing_list(sfx_state_t *self, char *msg) #endif static void -_dump_songs(sfx_state_t *self) -{ +_dump_songs(sfx_state_t *self) { #if 0 song_t *song = self->song; @@ -165,7 +156,7 @@ _dump_songs(sfx_state_t *self) song = *(self->songlib.lib); while (song) { fprintf(stderr, " **\tHandle %08x (p%d): status %d\n", - song->handle, song->priority, song->status); + song->handle, song->priority, song->status); SIMSG_SEND(song->it, SIMSG_PRINT(1)); song = song->next; } @@ -179,8 +170,7 @@ _dump_songs(sfx_state_t *self) static void -_thaw_time(sfx_state_t *self) -{ +_thaw_time(sfx_state_t *self) { /* inverse of _freeze_time() */ GTimeVal ctime; song_t *song = self->song; @@ -195,11 +185,10 @@ _thaw_time(sfx_state_t *self) } static int -is_playing(sfx_state_t *self, song_t *song) -{ +is_playing(sfx_state_t *self, song_t *song) { song_t *playing_song = self->song; -/* _dump_playing_list(self, "is-playing");*/ + /* _dump_playing_list(self, "is-playing");*/ while (playing_song) { if (playing_song == song) @@ -210,8 +199,7 @@ is_playing(sfx_state_t *self, song_t *song) } static void -_sfx_set_song_status(sfx_state_t *self, song_t *song, int status) -{ +_sfx_set_song_status(sfx_state_t *self, song_t *song, int status) { switch (status) { case SOUND_STATUS_STOPPED: @@ -250,7 +238,7 @@ _sfx_set_song_status(sfx_state_t *self, song_t *song, int status) default: fprintf(stderr, "%s L%d: Attempt to set invalid song" - " state %d!\n", __FILE__, __LINE__, status); + " state %d!\n", __FILE__, __LINE__, status); return; } @@ -259,12 +247,11 @@ _sfx_set_song_status(sfx_state_t *self, song_t *song, int status) /* Update internal state iff only one song may be played */ static void -_update_single_song(sfx_state_t *self) -{ +_update_single_song(sfx_state_t *self) { song_t *newsong = song_lib_find_active(self->songlib); if (newsong != self->song) { - + _freeze_time(self); /* Store song delay time */ if (player) @@ -273,11 +260,11 @@ _update_single_song(sfx_state_t *self) if (newsong) { if (!newsong->it) return; /* Restore in progress and not ready for this yet */ - + /* Change song */ if (newsong->status == SOUND_STATUS_WAITING) _sfx_set_song_status(self, newsong, - SOUND_STATUS_PLAYING); + SOUND_STATUS_PLAYING); /* Change instrument mappings */ } else { @@ -286,41 +273,40 @@ _update_single_song(sfx_state_t *self) if (self->song) { if (self->song->status == SOUND_STATUS_PLAYING) _sfx_set_song_status(self, newsong, - SOUND_STATUS_WAITING); + SOUND_STATUS_WAITING); } - + if (self->debug & SFX_DEBUG_SONGS) { sciprintf("[SFX] Changing active song:"); if (!self->song) sciprintf(" New song:"); else sciprintf(" pausing %08lx, now playing", - self->song->handle); - + self->song->handle); + if (newsong) sciprintf(" %08lx\n", newsong->handle); else sciprintf(" none\n"); } - - + + self->song = newsong; _thaw_time(self); /* Recover song delay time */ - + if (newsong && player) { song_iterator_t *clonesong - = songit_clone(newsong->it, newsong->delay); - + = songit_clone(newsong->it, newsong->delay); + player->add_iterator(clonesong, - newsong->wakeup_time); + newsong->wakeup_time); } } } static void -_update_multi_song(sfx_state_t *self) -{ +_update_multi_song(sfx_state_t *self) { song_t *oldfirst = self->song; song_t *oldseeker; song_t *newsong = song_lib_find_active(self->songlib); @@ -330,11 +316,11 @@ _update_multi_song(sfx_state_t *self) ** active. */ GTimeVal tv; sci_get_current_time(&tv); -/* _dump_playing_list(self, "before");*/ + /* _dump_playing_list(self, "before");*/ _freeze_time(self); /* Store song delay time */ for (newseeker = newsong; newseeker; - newseeker = newseeker->next_playing) { + newseeker = newseeker->next_playing) { if (!newseeker->it) return; /* Restore in progress and not ready for this yet */ } @@ -342,7 +328,7 @@ _update_multi_song(sfx_state_t *self) /* First, put all old songs into the 'stopping' list and ** mark their 'next-playing' as not_playing_anymore. */ for (oldseeker = oldfirst; oldseeker; - oldseeker = oldseeker->next_stopping) { + oldseeker = oldseeker->next_stopping) { oldseeker->next_stopping = oldseeker->next_playing; oldseeker->next_playing = ¬_playing_anymore; @@ -351,10 +337,10 @@ _update_multi_song(sfx_state_t *self) /* Second, re-generate the new song queue. */ for (newseeker = newsong; newseeker; - newseeker = newseeker->next_playing) { + newseeker = newseeker->next_playing) { newseeker->next_playing - = song_lib_find_next_active(self->songlib, - newseeker); + = song_lib_find_next_active(self->songlib, + newseeker); if (newseeker == newseeker->next_playing) { BREAKPOINT(); } } @@ -365,42 +351,41 @@ _update_multi_song(sfx_state_t *self) /* Third, stop all old songs */ for (oldseeker = oldfirst; oldseeker; - oldseeker = oldseeker->next_stopping) + oldseeker = oldseeker->next_stopping) if (oldseeker->next_playing == ¬_playing_anymore) { _sfx_set_song_status(self, oldseeker, - SOUND_STATUS_SUSPENDED); + SOUND_STATUS_SUSPENDED); if (self->debug & SFX_DEBUG_SONGS) { sciprintf("[SFX] Stopping song %lx\n", oldseeker->handle); } if (player && oldseeker->it) player->iterator_message - (songit_make_message(oldseeker->it->ID, SIMSG_STOP)); + (songit_make_message(oldseeker->it->ID, SIMSG_STOP)); oldseeker->next_playing = NULL; /* Clear this pointer; we don't need the tag anymore */ } for (newseeker = newsong; newseeker; - newseeker = newseeker->next_playing) { + newseeker = newseeker->next_playing) { if (newseeker->status != SOUND_STATUS_PLAYING && player) { if (self->debug & SFX_DEBUG_SONGS) sciprintf("[SFX] Adding song %lx\n", newseeker->it->ID); player->add_iterator(songit_clone(newseeker->it, - newseeker->delay), - tv); + newseeker->delay), + tv); } _sfx_set_song_status(self, newseeker, - SOUND_STATUS_PLAYING); + SOUND_STATUS_PLAYING); } self->song = newsong; _thaw_time(self); -/* _dump_playing_list(self, "after");*/ + /* _dump_playing_list(self, "after");*/ } /* Update internal state */ static void -_update(sfx_state_t *self) -{ +_update(sfx_state_t *self) { if (self->flags & SFX_STATE_FLAG_MULTIPLAY) _update_multi_song(self); else @@ -411,8 +396,7 @@ _update(sfx_state_t *self) static int _sfx_timer_active = 0; /* Timer toggle */ int -sfx_play_iterator_pcm(song_iterator_t *it, song_handle_t handle) -{ +sfx_play_iterator_pcm(song_iterator_t *it, song_handle_t handle) { #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Playing PCM: %08lx\n", handle); #endif @@ -428,8 +412,7 @@ sfx_play_iterator_pcm(song_iterator_t *it, song_handle_t handle) } static void -_sfx_timer_callback(void *data) -{ +_sfx_timer_callback(void *data) { if (_sfx_timer_active) { Common::StackLock lock(*callbackMutex); /* First run the player, to give it a chance to fill @@ -446,8 +429,7 @@ _sfx_timer_callback(void *data) } void -sfx_init(sfx_state_t *self, resource_mgr_t *resmgr, int flags) -{ +sfx_init(sfx_state_t *self, resource_mgr_t *resmgr, int flags) { callbackMutex = new Common::Mutex(); song_lib_init(&self->songlib); self->song = NULL; @@ -501,7 +483,7 @@ sfx_init(sfx_state_t *self, resource_mgr_t *resmgr, int flags) } sciprintf("[SFX] Initialised timer '%s', v%s\n", - timer->name, timer->version); + timer->name, timer->version); } /* With no PCM device and no player, we don't need a timer */ /*----------------*/ @@ -533,7 +515,7 @@ sfx_init(sfx_state_t *self, resource_mgr_t *resmgr, int flags) if (!resmgr) { sciprintf("[SFX] Warning: No resource manager present, cannot initialise player\n"); player = NULL; - } else if (player->init(resmgr, timer? timer->delay_ms : 0)) { + } else if (player->init(resmgr, timer ? timer->delay_ms : 0)) { sciprintf("[SFX] Song player '%s' reported error, disabled\n", player->name); player = NULL; } @@ -547,8 +529,7 @@ sfx_init(sfx_state_t *self, resource_mgr_t *resmgr, int flags) } void -sfx_exit(sfx_state_t *self) -{ +sfx_exit(sfx_state_t *self) { callbackMutex->lock(); _sfx_timer_active = 0; #ifdef DEBUG_SONG_API @@ -582,14 +563,12 @@ sfx_exit(sfx_state_t *self) } static inline int -time_le(GTimeVal a, GTimeVal b) -{ +time_le(GTimeVal a, GTimeVal b) { return time_minus(a, b) <= 0; } void -sfx_suspend(sfx_state_t *self, int suspend) -{ +sfx_suspend(sfx_state_t *self, int suspend) { #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Suspending? = %d\n", suspend); #endif @@ -634,8 +613,7 @@ sfx_poll(sfx_state_t *self, song_handle_t *handle, int *cue) } int -sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) -{ +sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) { GTimeVal ctime; song_t *song = self->song; @@ -658,13 +636,13 @@ sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) if (!time_le(song->wakeup_time, ctime)) return 0; /* Patience, young hacker! */ result = songit_next(&(song->it), buf, cue, - IT_READER_MASK_ALL); + IT_READER_MASK_ALL); switch (result) { case SI_FINISHED: _sfx_set_song_status(self, song, - SOUND_STATUS_STOPPED); + SOUND_STATUS_STOPPED); _update(self); /* ...fall through... */ case SI_LOOP: @@ -689,8 +667,8 @@ sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) default: if (result > 0) song->wakeup_time = - time_plus(song->wakeup_time, - result * SOUND_TICK); + time_plus(song->wakeup_time, + result * SOUND_TICK); /* Delay */ break; } @@ -706,8 +684,7 @@ sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) /*****************/ int -sfx_add_song(sfx_state_t *self, song_iterator_t *it, int priority, song_handle_t handle, int number) -{ +sfx_add_song(sfx_state_t *self, song_iterator_t *it, int priority, song_handle_t handle, int number) { song_t *song = song_lib_find(self->songlib, handle); #ifdef DEBUG_SONG_API @@ -732,9 +709,9 @@ sfx_add_song(sfx_state_t *self, song_iterator_t *it, int priority, song_handle_t fprintf(stderr, "Overwriting old song (%08lx) ...\n", handle); if (song->status == SOUND_STATUS_PLAYING - || song->status == SOUND_STATUS_SUSPENDED) { + || song->status == SOUND_STATUS_SUSPENDED) { fprintf(stderr, "Unexpected (error): Song %ld still playing/suspended (%d)\n", - handle, song->status); + handle, song->status); songit_free(it); return -1; } else @@ -756,8 +733,7 @@ sfx_add_song(sfx_state_t *self, song_iterator_t *it, int priority, song_handle_t void -sfx_remove_song(sfx_state_t *self, song_handle_t handle) -{ +sfx_remove_song(sfx_state_t *self, song_handle_t handle) { #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Removing song: %08lx\n", handle); #endif @@ -777,26 +753,24 @@ sfx_remove_song(sfx_state_t *self, song_handle_t handle) #define ASSERT_SONG(s) if (!(s)) { fprintf(stderr, "Looking up song handle %08lx failed in %s, L%d\n", handle, __FILE__, __LINE__); return; } void -sfx_song_set_status(sfx_state_t *self, song_handle_t handle, int status) -{ +sfx_song_set_status(sfx_state_t *self, song_handle_t handle, int status) { song_t *song = song_lib_find(self->songlib, handle); ASSERT_SONG(song); #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Setting song status to %d" - " (0:stop, 1:play, 2:susp, 3:wait): %08lx\n", status, handle); + " (0:stop, 1:play, 2:susp, 3:wait): %08lx\n", status, handle); #endif - _sfx_set_song_status(self, song, status); + _sfx_set_song_status(self, song, status); _update(self); } void -sfx_song_set_fade(sfx_state_t *self, song_handle_t handle, - fade_params_t *params) -{ +sfx_song_set_fade(sfx_state_t *self, song_handle_t handle, + fade_params_t *params) { #ifdef DEBUG_SONG_API - static const char *stopmsg[] = {"??? Should not happen", "Do not stop afterwards","Stop afterwards"}; + static const char *stopmsg[] = {"??? Should not happen", "Do not stop afterwards", "Stop afterwards"}; #endif song_t *song = song_lib_find(self->songlib, handle); @@ -804,9 +778,9 @@ sfx_song_set_fade(sfx_state_t *self, song_handle_t handle, #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Setting fade params of %08lx to " - "final volume %d in steps of %d per %d ticks. %s.\n", - handle, fade->final_volume, fade->step_size, fade->ticks_per_step, - stopmsg[fade->action]); + "final volume %d in steps of %d per %d ticks. %s.\n", + handle, fade->final_volume, fade->step_size, fade->ticks_per_step, + stopmsg[fade->action]); #endif SIMSG_SEND_FADE(song->it, params); @@ -815,13 +789,12 @@ sfx_song_set_fade(sfx_state_t *self, song_handle_t handle, } void -sfx_song_renice(sfx_state_t *self, song_handle_t handle, int priority) -{ +sfx_song_renice(sfx_state_t *self, song_handle_t handle, int priority) { song_t *song = song_lib_find(self->songlib, handle); ASSERT_SONG(song); #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Renicing song %08lx to %d\n", - handle, priority); + handle, priority); #endif song->priority = priority; @@ -830,16 +803,15 @@ sfx_song_renice(sfx_state_t *self, song_handle_t handle, int priority) } void -sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops) -{ +sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops) { song_t *song = song_lib_find(self->songlib, handle); song_iterator_message_t msg - = songit_make_message(handle, SIMSG_SET_LOOPS(loops)); + = songit_make_message(handle, SIMSG_SET_LOOPS(loops)); ASSERT_SONG(song); #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Setting loops on %08lx to %d\n", - handle, loops); + handle, loops); #endif songit_handle_message(&(song->it), msg); song->loops = ((base_song_iterator_t *) song->it)->loops; @@ -850,17 +822,16 @@ sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops) } void -sfx_song_set_hold(sfx_state_t *self, song_handle_t handle, int hold) -{ +sfx_song_set_hold(sfx_state_t *self, song_handle_t handle, int hold) { song_t *song = song_lib_find(self->songlib, handle); song_iterator_message_t msg - = songit_make_message(handle, SIMSG_SET_HOLD(hold)); + = songit_make_message(handle, SIMSG_SET_HOLD(hold)); ASSERT_SONG(song); song->hold = hold; #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Setting hold on %08lx to %d\n", - handle, loops); + handle, loops); #endif songit_handle_message(&(song->it), msg); @@ -871,49 +842,47 @@ sfx_song_set_hold(sfx_state_t *self, song_handle_t handle, int hold) /* Different from the one in iterator.c */ static const int MIDI_cmdlen[16] = {0, 0, 0, 0, 0, 0, 0, 0, - 3, 3, 0, 3, 2, 0, 3, 0}; + 3, 3, 0, 3, 2, 0, 3, 0 + }; static const song_handle_t midi_send_base = 0xffff0000; int sfx_send_midi(sfx_state_t *self, song_handle_t handle, int channel, - int command, int arg1, int arg2) -{ + int command, int arg1, int arg2) { byte buffer[5]; tell_synth_func *tell = sfx_get_player_tell_func(); /* Yes, in that order. SCI channel mutes are actually done via a counting semaphore. 0 means to decrement the counter, 1 to increment it. */ - static const char *channel_state[] = {"ON","OFF"}; + static const char *channel_state[] = {"ON", "OFF"}; if (command == 0xb0 && - arg1 == SCI_MIDI_CHANNEL_MUTE) - { + arg1 == SCI_MIDI_CHANNEL_MUTE) { sciprintf("TODO: channel mute (channel %d %s)!\n", channel, - channel_state[arg2]); + channel_state[arg2]); /* We need to have a GET_PLAYMASK interface to use here. SET_PLAYMASK we've got. */ return SFX_OK; - } + } buffer[0] = channel | command; /* No channel remapping yet */ - switch (command) - { + switch (command) { case 0x80 : case 0x90 : case 0xb0 : - buffer[1] = arg1&0xff; - buffer[2] = arg2&0xff; + buffer[1] = arg1 & 0xff; + buffer[2] = arg2 & 0xff; break; case 0xc0 : - buffer[1] = arg1&0xff; + buffer[1] = arg1 & 0xff; break; case 0xe0 : - buffer[1] = (arg1&0x7f) | 0x80; - buffer[2] = (arg1&0xff00) >> 7; + buffer[1] = (arg1 & 0x7f) | 0x80; + buffer[2] = (arg1 & 0xff00) >> 7; break; default: sciprintf("Unexpected explicit MIDI command %02x\n", command); @@ -926,21 +895,18 @@ sfx_send_midi(sfx_state_t *self, song_handle_t handle, int channel, } int -sfx_get_volume(sfx_state_t *self) -{ +sfx_get_volume(sfx_state_t *self) { fprintf(stderr, "FIXME: Implement volume\n"); return 0; } void -sfx_set_volume(sfx_state_t *self, int volume) -{ +sfx_set_volume(sfx_state_t *self, int volume) { fprintf(stderr, "FIXME: Implement volume\n"); } void -sfx_all_stop(sfx_state_t *self) -{ +sfx_all_stop(sfx_state_t *self) { #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] All stop\n"); #endif diff --git a/engines/sci/sfx/device.h b/engines/sci/sfx/device.h index 19a17726a2..335d7d63d1 100644 --- a/engines/sci/sfx/device.h +++ b/engines/sci/sfx/device.h @@ -32,7 +32,7 @@ /* Various types of resources */ #define SFX_DEVICE_NONE 0 #define SFX_DEVICE_MIDI 1 /* midi writer */ -#define SFX_DEVICE_OPL2 2 /* OPL/2 sequencer */ +#define SFX_DEVICE_OPL2 2 /* OPL/2 sequencer */ struct _midi_device { const char *name; diff --git a/engines/sci/sfx/device/alsa-midi.cpp b/engines/sci/sfx/device/alsa-midi.cpp index 67ca995916..8df0658d8b 100644 --- a/engines/sci/sfx/device/alsa-midi.cpp +++ b/engines/sci/sfx/device/alsa-midi.cpp @@ -44,19 +44,18 @@ static int subport_nr = 0; static const char *seq_name = "default"; static void -_set_tempo(void) -{ +_set_tempo(void) { int resolution = 60; int tempo = 1; snd_seq_queue_tempo_t *queue_tempo; snd_seq_queue_tempo_malloc(&queue_tempo); - memset(queue_tempo, 0, snd_seq_queue_tempo_sizeof()); - snd_seq_queue_tempo_set_ppq(queue_tempo, resolution); - snd_seq_queue_tempo_set_tempo(queue_tempo, 1000000/tempo); + memset(queue_tempo, 0, snd_seq_queue_tempo_sizeof()); + snd_seq_queue_tempo_set_ppq(queue_tempo, resolution); + snd_seq_queue_tempo_set_tempo(queue_tempo, 1000000 / tempo); - snd_seq_set_queue_tempo(seq, queue, queue_tempo); + snd_seq_set_queue_tempo(seq, queue, queue_tempo); snd_seq_queue_tempo_free(queue_tempo); @@ -74,8 +73,7 @@ _set_tempo(void) static int -am_subscribe_to_ports(void) -{ +am_subscribe_to_ports(void) { if ((port_out = snd_seq_connect_to(seq, port_out, port_nr, subport_nr)) < 0) { fprintf(stderr, "[SFX] Could not connect to ALSA sequencer port: %s\n", snd_strerror(port_out)); return SFX_ERROR; @@ -85,8 +83,7 @@ am_subscribe_to_ports(void) static int -aminit(midi_writer_t *self) -{ +aminit(midi_writer_t *self) { int err; snd_midi_event_new(4096, &parser); @@ -96,15 +93,15 @@ aminit(midi_writer_t *self) if (snd_seq_open(&seq, seq_name, SND_SEQ_OPEN_OUTPUT, SND_SEQ_NONBLOCK)) { fprintf(stderr, "[SFX] Failed to open ALSA MIDI sequencer '%s' for output\n", - seq_name); + seq_name); return SFX_ERROR; } if ((port_out = snd_seq_create_simple_port(seq, "FreeSCI", - SND_SEQ_PORT_CAP_WRITE | - SND_SEQ_PORT_CAP_SUBS_WRITE | - SND_SEQ_PORT_CAP_READ, - SND_SEQ_PORT_TYPE_MIDI_GENERIC)) < 0) { + SND_SEQ_PORT_CAP_WRITE | + SND_SEQ_PORT_CAP_SUBS_WRITE | + SND_SEQ_PORT_CAP_READ, + SND_SEQ_PORT_TYPE_MIDI_GENERIC)) < 0) { fprintf(stderr, "[SFX] Could not create ALSA sequencer port\n"); return SFX_ERROR; } @@ -120,7 +117,7 @@ aminit(midi_writer_t *self) if ((err = snd_seq_drain_output(seq))) { fflush(NULL); fprintf(stderr, "[SFX] Error while draining: %s\n", - snd_strerror(err)); + snd_strerror(err)); return SFX_ERROR; } @@ -128,15 +125,13 @@ aminit(midi_writer_t *self) } static int -amsetopt(midi_writer_t *self, char *name, char *value) -{ +amsetopt(midi_writer_t *self, char *name, char *value) { return SFX_ERROR; } static int -amwrite(midi_writer_t *self, unsigned char *buf, int len) -{ +amwrite(midi_writer_t *self, unsigned char *buf, int len) { snd_seq_event_t evt; #if 0 @@ -176,14 +171,12 @@ amwrite(midi_writer_t *self, unsigned char *buf, int len) } static void -amdelay(midi_writer_t *self, int ticks) -{ +amdelay(midi_writer_t *self, int ticks) { delta += ticks; } static void -amreset_timer(midi_writer_t *self) -{ +amreset_timer(midi_writer_t *self) { snd_seq_drain_output(seq); snd_seq_stop_queue(seq, queue, NULL); @@ -206,8 +199,7 @@ amreset_timer(midi_writer_t *self) } static void -amclose(midi_writer_t *self) -{ +amclose(midi_writer_t *self) { snd_midi_event_free(parser); parser = NULL; } diff --git a/engines/sci/sfx/device/camd-midi.cpp b/engines/sci/sfx/device/camd-midi.cpp index 3af12f196e..8017b436d5 100644 --- a/engines/sci/sfx/device/camd-midi.cpp +++ b/engines/sci/sfx/device/camd-midi.cpp @@ -63,8 +63,7 @@ static struct MidiNode *midi_node = NULL; } static int -camd_init(midi_writer_t *self) -{ +camd_init(midi_writer_t *self) { sciprintf("[SFX] Initialising CAMD raw MIDI backend, v%s\n", SCI_CAMD_MIDI_VERSION); CamdBase = IExec->OpenLibrary("camd.library", 36L); @@ -72,8 +71,8 @@ camd_init(midi_writer_t *self) ABORT("Could not open 'camd.library'"); ICamd = (struct CamdIFace *) IExec->GetInterface(CamdBase, "main", 1, NULL); - if (!ICamd) - ABORT("Error while retrieving CAMD interface\n"); + if (!ICamd) + ABORT("Error while retrieving CAMD interface\n"); midi_node = ICamd->CreateMidi(MIDI_MsgQueue, 0L, MIDI_SysExSize, 4096L, MIDI_Name, "freesci", TAG_END); if (!midi_node) @@ -89,16 +88,14 @@ camd_init(midi_writer_t *self) } static int -camd_set_option(midi_writer_t *self, char *name, char *value) -{ +camd_set_option(midi_writer_t *self, char *name, char *value) { return SFX_ERROR; } #define MAX_MIDI_LEN 3 static int -camd_write(midi_writer_t *self, unsigned char *buffer, int len) -{ +camd_write(midi_writer_t *self, unsigned char *buffer, int len) { if (len == 0) return SFX_OK; @@ -119,7 +116,7 @@ camd_write(midi_writer_t *self, unsigned char *buffer, int len) if (len > MAX_MIDI_LEN) sciprintf("[SFX] Warning: Truncated MIDI message to fit CAMD format (sent %d: %02x %02x %02x, real length %d)\n", - MAX_MIDI_LEN, buffer[0], buffer[1], buffer[2], len); + MAX_MIDI_LEN, buffer[0], buffer[1], buffer[2], len); ICamd->PutMidi(midi_link, data); } @@ -128,21 +125,18 @@ camd_write(midi_writer_t *self, unsigned char *buffer, int len) } static void -camd_delay(midi_writer_t *self, int ticks) -{ +camd_delay(midi_writer_t *self, int ticks) { } static void -camd_reset_timer(midi_writer_t *self) -{ +camd_reset_timer(midi_writer_t *self) { } static void -camd_close(midi_writer_t *self) -{ +camd_close(midi_writer_t *self) { #ifdef NO_OP return; -#endif +#endif if (CamdBase) IExec->CloseLibrary(CamdBase); } diff --git a/engines/sci/sfx/device/devices.cpp b/engines/sci/sfx/device/devices.cpp index f51c928d7e..6a89ee5df6 100644 --- a/engines/sci/sfx/device/devices.cpp +++ b/engines/sci/sfx/device/devices.cpp @@ -49,16 +49,16 @@ extern struct _midi_device sfx_device_midi_camd; static struct _midi_device *devices_midi[] = { #ifndef SCUMMVM #ifdef HAVE_PROTO_CAMD_H - &sfx_device_midi_camd, + &sfx_device_midi_camd, #endif #ifdef HAVE_ALSA - &sfx_device_midi_alsa, + &sfx_device_midi_alsa, #endif #ifdef UNIX - &sfx_device_midi_unixraw, + &sfx_device_midi_unixraw, #endif #endif // SCUMMVM - NULL + NULL }; static struct _midi_device *devices_opl2[] = { @@ -76,8 +76,7 @@ struct _midi_device **devices[] = { static struct _midi_device * -find_dev(int type, char *name) -{ + find_dev(int type, char *name) { int i = 0; if (!type) @@ -94,19 +93,18 @@ find_dev(int type, char *name) void * -sfx_find_device(int type, char *name) -{ +sfx_find_device(int type, char *name) { struct _midi_device *dev = find_dev(type, name); if (dev) { if (dev->init(dev)) { fprintf(stderr, "[SFX] Opening device '%s' failed\n", - dev->name); + dev->name); return NULL; } return dev; }; - + return NULL; } diff --git a/engines/sci/sfx/device/unixraw-midi.cpp b/engines/sci/sfx/device/unixraw-midi.cpp index 69ce3890fc..0d9e92b20b 100644 --- a/engines/sci/sfx/device/unixraw-midi.cpp +++ b/engines/sci/sfx/device/unixraw-midi.cpp @@ -42,11 +42,10 @@ static int fd; static const char *devicename = "/dev/midi"; static int -unixraw_init(midi_writer_t *self) -{ +unixraw_init(midi_writer_t *self) { sciprintf("[SFX] Initialising UNIX raw MIDI backend, v%s\n", SCI_UNIXRAW_MIDI_VERSION); - fd = open(devicename, O_WRONLY|O_SYNC); + fd = open(devicename, O_WRONLY | O_SYNC); if (!IS_VALID_FD(fd)) { sciprintf("[SFX] Failed to open %s\n", devicename); @@ -57,14 +56,12 @@ unixraw_init(midi_writer_t *self) } static int -unixraw_set_option(midi_writer_t *self, char *name, char *value) -{ +unixraw_set_option(midi_writer_t *self, char *name, char *value) { return SFX_ERROR; } static int -unixraw_write(midi_writer_t *self, unsigned char *buffer, int len) -{ +unixraw_write(midi_writer_t *self, unsigned char *buffer, int len) { if (write(fd, buffer, len) != len) { sciprintf("[SFX] MIDI write error\n"); return SFX_ERROR; @@ -73,18 +70,15 @@ unixraw_write(midi_writer_t *self, unsigned char *buffer, int len) } static void -unixraw_delay(midi_writer_t *self, int ticks) -{ +unixraw_delay(midi_writer_t *self, int ticks) { } static void -unixraw_reset_timer(midi_writer_t *self) -{ +unixraw_reset_timer(midi_writer_t *self) { } static void -unixraw_close(midi_writer_t *self) -{ +unixraw_close(midi_writer_t *self) { close(fd); } diff --git a/engines/sci/sfx/iterator.cpp b/engines/sci/sfx/iterator.cpp index 618207239f..bcaf4759b8 100644 --- a/engines/sci/sfx/iterator.cpp +++ b/engines/sci/sfx/iterator.cpp @@ -33,14 +33,14 @@ #include "sci/include/sci_memory.h" static const int MIDI_cmdlen[16] = {0, 0, 0, 0, 0, 0, 0, 0, - 2, 2, 2, 2, 1, 1, 2, 0}; + 2, 2, 2, 2, 1, 1, 2, 0 + }; /*#define DEBUG_DECODING*/ /*#define DEBUG_VERBOSE*/ void -print_tabs_id(int nr, songit_id_t id) -{ +print_tabs_id(int nr, songit_id_t id) { while (nr-- > 0) fprintf(stderr, "\t"); @@ -49,8 +49,7 @@ print_tabs_id(int nr, songit_id_t id) #ifndef HAVE_MEMCHR static void * -memchr(void *_data, int c, int n) -{ +memchr(void *_data, int c, int n) { unsigned char *data = (unsigned char *) _data; while (n && !(*data == c)) { @@ -66,8 +65,7 @@ memchr(void *_data, int c, int n) #endif static void -_common_init(base_song_iterator_t *self) -{ +_common_init(base_song_iterator_t *self) { self->fade.action = FADE_ACTION_NONE; self->resetflag = 0; self->loops = 0; @@ -101,18 +99,17 @@ _common_init(base_song_iterator_t *self) static inline int -_parse_ticks(byte *data, int *offset_p, int size) -{ +_parse_ticks(byte *data, int *offset_p, int size) { int ticks = 0; int tempticks; int offset = 0; do { tempticks = data[offset++]; - ticks += (tempticks == SCI_MIDI_TIME_EXPANSION_PREFIX)? - SCI_MIDI_TIME_EXPANSION_LENGTH : tempticks; + ticks += (tempticks == SCI_MIDI_TIME_EXPANSION_PREFIX) ? + SCI_MIDI_TIME_EXPANSION_LENGTH : tempticks; } while (tempticks == SCI_MIDI_TIME_EXPANSION_PREFIX - && offset < size); + && offset < size); if (offset_p) *offset_p = offset; @@ -123,30 +120,27 @@ _parse_ticks(byte *data, int *offset_p, int size) static int _sci0_read_next_command(sci0_song_iterator_t *self, - unsigned char *buf, int *result); + unsigned char *buf, int *result); static int _sci0_get_pcm_data(sci0_song_iterator_t *self, - sfx_pcm_config_t *format, - int *xoffset, - unsigned int *xsize); + sfx_pcm_config_t *format, + int *xoffset, + unsigned int *xsize); #define PARSE_FLAG_LOOPS_UNLIMITED (1 << 0) /* Unlimited # of loops? */ #define PARSE_FLAG_PARAMETRIC_CUE (1 << 1) /* Assume that cues take an additional "cue value" argument */ /* This implements a difference between SCI0 and SCI1 cues. */ void -_reset_synth_channels(base_song_iterator_t *self, song_iterator_channel_t *channel) -{ +_reset_synth_channels(base_song_iterator_t *self, song_iterator_channel_t *channel) { int i; byte buf[5]; tell_synth_func *tell = sfx_get_player_tell_func(); - for (i = 0; i < MIDI_CHANNELS; i++) - { - if (channel->saw_notes & (1 << i)) - { + for (i = 0; i < MIDI_CHANNELS; i++) { + if (channel->saw_notes & (1 << i)) { buf[0] = 0xe0 | i; /* Pitch bend */ buf[1] = 0x80; /* Wheel center */ buf[2] = 0x40; @@ -159,9 +153,8 @@ _reset_synth_channels(base_song_iterator_t *self, song_iterator_channel_t *chann static int _parse_sci_midi_command(base_song_iterator_t *self, unsigned char *buf, int *result, - song_iterator_channel_t *channel, - int flags) -{ + song_iterator_channel_t *channel, + int flags) { unsigned char cmd; int paramsleft; int midi_op; @@ -177,8 +170,7 @@ _parse_sci_midi_command(base_song_iterator_t *self, unsigned char *buf, int *res cmd = channel->last_cmd; } - if (cmd == 0xfe) - { + if (cmd == 0xfe) { fprintf(stderr, "song iterator subsystem: Corrupted sound resource detected.\n"); return SI_FINISHED; } @@ -189,17 +181,17 @@ _parse_sci_midi_command(base_song_iterator_t *self, unsigned char *buf, int *res channel->saw_notes |= 1 << midi_channel; #if 0 -if (1) { - fprintf(stderr, "[IT]: off=%x, cmd=%02x, takes %d args ", - channel->offset - 1, cmd, paramsleft); - fprintf(stderr, "[%02x %02x <%02x> %02x %02x %02x]\n", - self->data[channel->offset-3], - self->data[channel->offset-2], - self->data[channel->offset-1], - self->data[channel->offset], - self->data[channel->offset+1], - self->data[channel->offset+2]); -} + if (1) { + fprintf(stderr, "[IT]: off=%x, cmd=%02x, takes %d args ", + channel->offset - 1, cmd, paramsleft); + fprintf(stderr, "[%02x %02x <%02x> %02x %02x %02x]\n", + self->data[channel->offset-3], + self->data[channel->offset-2], + self->data[channel->offset-1], + self->data[channel->offset], + self->data[channel->offset+1], + self->data[channel->offset+2]); + } #endif buf[0] = cmd; @@ -216,21 +208,21 @@ if (1) { /* Are we supposed to play this channel? */ if ( /* First, exclude "global" properties-- such as cues-- from consideration */ - (midi_op < 0xf - && !(cmd == SCI_MIDI_SET_SIGNAL) - && !(SCI_MIDI_CONTROLLER(cmd) - && buf[1] == SCI_MIDI_CUMULATIVE_CUE)) + (midi_op < 0xf + && !(cmd == SCI_MIDI_SET_SIGNAL) + && !(SCI_MIDI_CONTROLLER(cmd) + && buf[1] == SCI_MIDI_CUMULATIVE_CUE)) /* Next, check if the channel is allowed */ - && (!((1 << midi_channel) & channel->playmask))) + && (!((1 << midi_channel) & channel->playmask))) return /* Execute next command */ - self->next((song_iterator_t *) self, buf, result); + self->next((song_iterator_t *) self, buf, result); if (cmd == SCI_MIDI_EOT) { /* End of track? */ _reset_synth_channels(self, channel); -/* fprintf(stderr, "eot; loops = %d, notesplayed=%d\n", self->loops, channel->notes_played);*/ + /* fprintf(stderr, "eot; loops = %d, notesplayed=%d\n", self->loops, channel->notes_played);*/ if (self->loops > 1 /* && channel->notes_played*/) { /* If allowed, decrement the number of loops */ if (!(flags & PARSE_FLAG_LOOPS_UNLIMITED)) @@ -243,7 +235,7 @@ if (1) { else fprintf(stderr, "(%d)", self->loops); fprintf(stderr, " %x -> %x\n", - channel->offset, channel->loop_offset); + channel->offset, channel->loop_offset); #endif channel->offset = channel->loop_offset; channel->notes_played = 0; @@ -256,9 +248,9 @@ if (1) { channel->state = SI_STATE_FINISHED; #ifdef DEBUG_DECODING fprintf(stderr, "%s L%d: (%p):%d EOT because" - " %d notes, %d loops\n", - __FILE__, __LINE__, self, channel->id, - channel->notes_played, self->loops); + " %d notes, %d loops\n", + __FILE__, __LINE__, self, channel->id, + channel->notes_played, self->loops); #endif return SI_FINISHED; } @@ -269,7 +261,7 @@ if (1) { channel->loop_timepos = channel->total_timepos; return /* Execute next command */ - self->next((song_iterator_t *) self, buf, result); + self->next((song_iterator_t *) self, buf, result); } else { /* Used to be conditional <= 127 */ *result = buf[1]; /* Absolute cue */ @@ -283,7 +275,7 @@ if (1) { self->ccc += buf[2]; else { /* No parameter to CC */ self->ccc++; -/* channel->offset--; */ + /* channel->offset--; */ } *result = self->ccc; return SI_RELATIVE_CUE; @@ -297,22 +289,21 @@ if (1) { #if 0 { - int i; - int voices = 0; - for (i = 0; i < ((sci1_song_iterator_t *) self)->channels_nr; i++) - { - voices += self->polyphony[i]; - } - - sciprintf("SET_POLYPHONY(%d, %d) for a total of %d voices\n", midi_channel, buf[2], voices); - sciprintf("[iterator-1] DEBUG: Polyphony = [ "); - for (i = 0; i < ((sci1_song_iterator_t *) self)->channels_nr; i++) - sciprintf("%d ", self->polyphony[i]); - sciprintf("]\n"); - sciprintf("[iterator-1] DEBUG: Importance = [ "); - for (i = 0; i < ((sci1_song_iterator_t *) self)->channels_nr; i++) - sciprintf("%d ", self->importance[i]); - sciprintf("]\n"); + int i; + int voices = 0; + for (i = 0; i < ((sci1_song_iterator_t *) self)->channels_nr; i++) { + voices += self->polyphony[i]; + } + + sciprintf("SET_POLYPHONY(%d, %d) for a total of %d voices\n", midi_channel, buf[2], voices); + sciprintf("[iterator-1] DEBUG: Polyphony = [ "); + for (i = 0; i < ((sci1_song_iterator_t *) self)->channels_nr; i++) + sciprintf("%d ", self->polyphony[i]); + sciprintf("]\n"); + sciprintf("[iterator-1] DEBUG: Importance = [ "); + for (i = 0; i < ((sci1_song_iterator_t *) self)->channels_nr; i++) + sciprintf("%d ", self->importance[i]); + sciprintf("]\n"); } #endif break; @@ -324,20 +315,18 @@ if (1) { sciprintf("CHANNEL_MUTE(%d, %d)\n", midi_channel, buf[2]); break; - case SCI_MIDI_HOLD: - { + case SCI_MIDI_HOLD: { // Safe cast: This controller is only used in SCI1 sci1_song_iterator_t *self1 = (sci1_song_iterator_t *) self; - if (buf[2] == self1->hold) - { + if (buf[2] == self1->hold) { channel->offset = channel->initial_offset; channel->notes_played = 0; channel->state = SI_STATE_COMMAND; channel->total_timepos = 0; - - self1->channels_looped = self1->active_channels-1; - + + self1->channels_looped = self1->active_channels - 1; + return SI_LOOP; } @@ -349,7 +338,7 @@ if (1) { case 0x73: /* UNKNOWN NYI (happens in Hoyle) */ case 0xd1: /* UNKNOWN NYI (happens in KQ4 when riding the unicorn) */ return /* Execute next command */ - self->next((song_iterator_t *) self, buf, result); + self->next((song_iterator_t *) self, buf, result); case 0x01: /* modulation */ case 0x07: /* volume */ @@ -375,16 +364,15 @@ if (1) { static int _sci_midi_process_state(base_song_iterator_t *self, unsigned char *buf, int *result, - song_iterator_channel_t *channel, - int flags) -{ + song_iterator_channel_t *channel, + int flags) { CHECK_FOR_END(0); switch (channel->state) { case SI_STATE_PCM: { if (*(self->data + channel->offset) == 0 - && *(self->data + channel->offset + 1) == SCI_MIDI_EOT) + && *(self->data + channel->offset + 1) == SCI_MIDI_EOT) /* Fake one extra tick to trick the interpreter into not killing the song iterator right away */ channel->state = SI_STATE_PCM_MAGIC_DELTA; else @@ -417,8 +405,8 @@ _sci_midi_process_state(base_song_iterator_t *self, unsigned char *buf, int *res case SI_STATE_DELTA_TIME: { int offset; int ticks = _parse_ticks(self->data + channel->offset, - &offset, - self->size - channel->offset); + &offset, + self->size - channel->offset); channel->offset += offset; channel->delay += ticks; @@ -432,7 +420,7 @@ _sci_midi_process_state(base_song_iterator_t *self, unsigned char *buf, int *res return ticks; } - /* continute otherwise... */ + /* continute otherwise... */ case SI_STATE_COMMAND: { int retval; @@ -440,15 +428,15 @@ _sci_midi_process_state(base_song_iterator_t *self, unsigned char *buf, int *res channel->timepos_increment = 0; retval = _parse_sci_midi_command(self, buf, result, - channel, flags); + channel, flags); if (retval == SI_FINISHED) { if (self->active_channels) --(self->active_channels); #ifdef DEBUG_DECODING fprintf(stderr, "%s L%d: (%p):%d Finished channel, %d channels left\n", - __FILE__, __LINE__, self, channel->id, - self->active_channels); + __FILE__, __LINE__, self, channel->id, + self->active_channels); #endif /* If we still have channels left... */ if (self->active_channels) { @@ -464,7 +452,7 @@ _sci_midi_process_state(base_song_iterator_t *self, unsigned char *buf, int *res default: fprintf(stderr, SIPFX "Invalid iterator state %d!\n", - channel->state); + channel->state); BREAKPOINT(); return SI_FINISHED; } @@ -472,43 +460,39 @@ _sci_midi_process_state(base_song_iterator_t *self, unsigned char *buf, int *res static inline int _sci_midi_process(base_song_iterator_t *self, unsigned char *buf, int *result, - song_iterator_channel_t *channel, - int flags) -{ + song_iterator_channel_t *channel, + int flags) { return _sci_midi_process_state(self, buf, result, - channel, - flags); + channel, + flags); } static int _sci0_read_next_command(sci0_song_iterator_t *self, unsigned char *buf, - int *result) -{ + int *result) { return _sci_midi_process((base_song_iterator_t *) self, buf, result, - &(self->channel), - PARSE_FLAG_PARAMETRIC_CUE); + &(self->channel), + PARSE_FLAG_PARAMETRIC_CUE); } static inline int -_sci0_header_magic_p(unsigned char *data, int offset, int size) -{ +_sci0_header_magic_p(unsigned char *data, int offset, int size) { if (offset + 0x10 > size) return 0; return - (data[offset] == 0x1a) - && (data[offset + 1] == 0x00) - && (data[offset + 2] == 0x01) - && (data[offset + 3] == 0x00); + (data[offset] == 0x1a) + && (data[offset + 1] == 0x00) + && (data[offset + 2] == 0x01) + && (data[offset + 3] == 0x00); } static int _sci0_get_pcm_data(sci0_song_iterator_t *self, - sfx_pcm_config_t *format, - int *xoffset, - unsigned int *xsize) -{ + sfx_pcm_config_t *format, + int *xoffset, + unsigned int *xsize) { int tries = 2; int found_it = 0; unsigned char *pcm_data; @@ -522,12 +506,12 @@ _sci0_get_pcm_data(sci0_song_iterator_t *self, while ((tries--) && (offset < self->size) && (!found_it)) { /* Search through the garbage manually */ unsigned char *fc = (unsigned char*)memchr(self->data + offset, - SCI0_END_OF_SONG, - self->size - offset); + SCI0_END_OF_SONG, + self->size - offset); if (!fc) { fprintf(stderr, SIPFX "Warning: Playing unterminated" - " song!\n"); + " song!\n"); return 1; } @@ -541,8 +525,8 @@ _sci0_get_pcm_data(sci0_song_iterator_t *self, if (!found_it) { fprintf(stderr, SIPFX - "Warning: Song indicates presence of PCM, but" - " none found (finally at offset %04x)\n", offset); + "Warning: Song indicates presence of PCM, but" + " none found (finally at offset %04x)\n", offset); return 1; } @@ -560,9 +544,9 @@ _sci0_get_pcm_data(sci0_song_iterator_t *self, int d = offset + SCI0_PCM_DATA_OFFSET + size - self->size; fprintf(stderr, SIPFX - "Warning: PCM advertizes %d bytes of data, but %d" - " bytes are trailing in the resource!\n", - size, self->size - (offset + SCI0_PCM_DATA_OFFSET)); + "Warning: PCM advertizes %d bytes of data, but %d" + " bytes are trailing in the resource!\n", + size, self->size - (offset + SCI0_PCM_DATA_OFFSET)); if (d > 0) size -= d; /* Fix this */ @@ -572,11 +556,10 @@ _sci0_get_pcm_data(sci0_song_iterator_t *self, *xsize = size; return 0; - } +} static sfx_pcm_feed_t * -_sci0_check_pcm(sci0_song_iterator_t *self) -{ +_sci0_check_pcm(sci0_song_iterator_t *self) { sfx_pcm_config_t format; int offset; unsigned int size; @@ -584,25 +567,24 @@ _sci0_check_pcm(sci0_song_iterator_t *self) return NULL; self->channel.state - = SI_STATE_FINISHED; /* Don't play both PCM and music */ + = SI_STATE_FINISHED; /* Don't play both PCM and music */ return sfx_iterator_make_feed(self->data, - offset + SCI0_PCM_DATA_OFFSET, - size, - format); + offset + SCI0_PCM_DATA_OFFSET, + size, + format); } static song_iterator_t * -_sci0_handle_message(sci0_song_iterator_t *self, song_iterator_message_t msg) -{ +_sci0_handle_message(sci0_song_iterator_t *self, song_iterator_message_t msg) { if (msg.recipient == _SIMSG_BASE) { switch (msg.type) { case _SIMSG_BASEMSG_PRINT: print_tabs_id(msg.args[0].i, self->ID); fprintf(stderr, "SCI0: dev=%d, active-chan=%d, size=%d, loops=%d\n", - self->device_id, self->active_channels, self->size, - self->loops); + self->device_id, self->active_channels, self->size, + self->loops); break; case _SIMSG_BASEMSG_SET_LOOPS: @@ -615,7 +597,7 @@ _sci0_handle_message(sci0_song_iterator_t *self, song_iterator_message_t msg) memcpy(mem, self, tsize); sci_refcount_incref(mem->data); #ifdef DEBUG_VERBOSE -fprintf(stderr, "** CLONE INCREF for new %p from %p at %p\n", mem, self, mem->data); + fprintf(stderr, "** CLONE INCREF for new %p from %p at %p\n", mem, self, mem->data); #endif return (struct _song_iterator *) mem; /* Assume caller has another copy of this */ } @@ -637,10 +619,10 @@ fprintf(stderr, "** CLONE INCREF for new %p from %p at %p\n", mem, self, mem->da for (i = 0; i < MIDI_CHANNELS; i++) if (self->data[2 + (i << 1)] & self->device_id - && i != MIDI_RHYTHM_CHANNEL) + && i != MIDI_RHYTHM_CHANNEL) self->channel.playmask |= (1 << i); } - break; + break; case _SIMSG_BASEMSG_SET_RHYTHM: self->channel.playmask &= ~(1 << MIDI_RHYTHM_CHANNEL); @@ -648,8 +630,7 @@ fprintf(stderr, "** CLONE INCREF for new %p from %p at %p\n", mem, self, mem->da self->channel.playmask |= (1 << MIDI_RHYTHM_CHANNEL); break; - case _SIMSG_BASEMSG_SET_FADE: - { + case _SIMSG_BASEMSG_SET_FADE: { fade_params_t *fp = (fade_params_t *) msg.args[0].p; self->fade.action = fp->action; self->fade.final_volume = fp->final_volume; @@ -668,15 +649,13 @@ fprintf(stderr, "** CLONE INCREF for new %p from %p at %p\n", mem, self, mem->da } static int -_sci0_get_timepos(sci0_song_iterator_t *self) -{ - return self->channel.total_timepos; +_sci0_get_timepos(sci0_song_iterator_t *self) { + return self->channel.total_timepos; } static void _base_init_channel(song_iterator_channel_t *channel, int id, int offset, - int end) -{ + int end) { channel->playmask = PLAYMASK_NONE; /* Disable all channels */ channel->id = id; channel->notes_played = 0; @@ -688,23 +667,22 @@ _base_init_channel(song_iterator_channel_t *channel, int id, int offset, channel->last_cmd = 0xfe; channel->offset - = channel->loop_offset - = channel->initial_offset - = offset; + = channel->loop_offset + = channel->initial_offset + = offset; channel->end = end; channel->saw_notes = 0; } static void -_sci0_init(sci0_song_iterator_t *self) -{ +_sci0_init(sci0_song_iterator_t *self) { _common_init((base_song_iterator_t *) self); self->ccc = 0; /* Reset cumulative cue counter */ self->active_channels = 1; _base_init_channel(&(self->channel), 0, SCI0_MIDI_OFFSET, self->size); - _reset_synth_channels((base_song_iterator_t *) self, - &(self->channel)); + _reset_synth_channels((base_song_iterator_t *) self, + &(self->channel)); self->delay_remaining = 0; if (self->data[0] == 2) /* Do we have an embedded PCM? */ @@ -713,10 +691,9 @@ _sci0_init(sci0_song_iterator_t *self) static void -_sci0_cleanup(sci0_song_iterator_t *self) -{ +_sci0_cleanup(sci0_song_iterator_t *self) { #ifdef DEBUG_VERBOSE -fprintf(stderr, "** FREEING it %p: data at %p\n", self, self->data); + fprintf(stderr, "** FREEING it %p: data at %p\n", self, self->data); #endif if (self->data) sci_refcount_decref(self->data); @@ -745,8 +722,7 @@ static int sci0_to_sci1_device_map[][2] = { #define SCI1_CHANDATA(off) self->data[channel->offset + (off)] static int -_sci1_sample_init(sci1_song_iterator_t *self, int offset) -{ +_sci1_sample_init(sci1_song_iterator_t *self, int offset) { sci1_sample_t *sample, **seekerp; int rate; int length; @@ -756,7 +732,7 @@ _sci1_sample_init(sci1_song_iterator_t *self, int offset) CHECK_FOR_END_ABSOLUTE((unsigned int)offset + 10); if (self->data[offset + 1] != 0) sciprintf("[iterator-1] In sample at offset 0x04x: Byte #1 is %02x instead of zero\n", - self->data[offset + 1]); + self->data[offset + 1]); rate = getInt16(self->data + offset + 2); length = getUInt16(self->data + offset + 4); @@ -772,7 +748,7 @@ _sci1_sample_init(sci1_song_iterator_t *self, int offset) #ifdef DEBUG_VERBOSE fprintf(stderr, "[SAMPLE] %x/%x/%x/%x l=%x\n", - offset + 10, begin, end, self->size, length); + offset + 10, begin, end, self->size, length); #endif sample->format.format = SFX_PCM_FORMAT_U8; @@ -795,8 +771,7 @@ _sci1_sample_init(sci1_song_iterator_t *self, int offset) static int -_sci1_song_init(sci1_song_iterator_t *self) -{ +_sci1_song_init(sci1_song_iterator_t *self) { sci1_sample_t *seeker; int last_time; unsigned int offset = 0; @@ -805,15 +780,14 @@ _sci1_song_init(sci1_song_iterator_t *self) // self->device_id = 0x0c; CHECK_FOR_END_ABSOLUTE(0); - if (SONGDATA(0) == 0xf0) - { + if (SONGDATA(0) == 0xf0) { self->priority = SONGDATA(1); offset += 8; } while (SONGDATA(0) != 0xff - && SONGDATA(0) != self->device_id) { + && SONGDATA(0) != self->device_id) { offset++; CHECK_FOR_END_ABSOLUTE(offset + 1); while (SONGDATA(0) != 0xff) { @@ -825,8 +799,8 @@ _sci1_song_init(sci1_song_iterator_t *self) if (SONGDATA(0) == 0xff) { sciprintf("[iterator-1] Song does not support" - " hardware 0x%02x\n", - self->device_id); + " hardware 0x%02x\n", + self->device_id); return 1; } @@ -851,32 +825,32 @@ _sci1_song_init(sci1_song_iterator_t *self) /* Regular MIDI channel */ if (self->channels_nr >= MIDI_CHANNELS) { sciprintf("[iterator-1] Warning: Song has more than %d channels, cutting them off\n", - MIDI_CHANNELS); + MIDI_CHANNELS); break; /* Scan for remaining samples */ } else { int channel_nr - = self->data[track_offset] & 0xf; + = self->data[track_offset] & 0xf; song_iterator_channel_t *channel = - &(self->channels[self->channels_nr++]); + &(self->channels[self->channels_nr++]); if (self->data[track_offset] & 0xf0) - printf("Channel %d has mapping bits %02x\n", + printf("Channel %d has mapping bits %02x\n", channel_nr, self->data[track_offset] & 0xf0); _base_init_channel(channel, - channel_nr, - /* Skip over header bytes: */ - track_offset + 2, - track_offset + end); - _reset_synth_channels((base_song_iterator_t *) self, - channel); + channel_nr, + /* Skip over header bytes: */ + track_offset + 2, + track_offset + end); + _reset_synth_channels((base_song_iterator_t *) self, + channel); self->polyphony[self->channels_nr - 1] - = SCI1_CHANDATA(-1); - self->importance[self->channels_nr - 1] - = self->polyphony[self->channels_nr - 1] >> 4; + = SCI1_CHANDATA(-1); + self->importance[self->channels_nr - 1] + = self->polyphony[self->channels_nr - 1] >> 4; self->polyphony[self->channels_nr - 1] &= 15; - + channel->playmask = ~0; /* Enable all */ self->channel_mask |= (1 << channel_nr); @@ -896,7 +870,7 @@ _sci1_song_init(sci1_song_iterator_t *self) while (seeker) { int prev_last_time = last_time; sciprintf("[iterator-1] Detected sample: %d Hz, %d bytes at time %d\n", - seeker->format.rate, seeker->size, seeker->delta); + seeker->format.rate, seeker->size, seeker->delta); last_time = seeker->delta; seeker->delta -= prev_last_time; seeker = seeker->next; @@ -908,12 +882,11 @@ _sci1_song_init(sci1_song_iterator_t *self) #undef SONGDATA static inline int -_sci1_get_smallest_delta(sci1_song_iterator_t *self) -{ +_sci1_get_smallest_delta(sci1_song_iterator_t *self) { int i, d = -1; for (i = 0; i < self->channels_nr; i++) if (self->channels[i].state == SI_STATE_COMMAND - && (d == -1 || self->channels[i].delay < d)) + && (d == -1 || self->channels[i].delay < d)) d = self->channels[i].delay; if (self->next_sample && self->next_sample->delta < d) @@ -923,8 +896,7 @@ _sci1_get_smallest_delta(sci1_song_iterator_t *self) } static inline void -_sci1_update_delta(sci1_song_iterator_t *self, int delta) -{ +_sci1_update_delta(sci1_song_iterator_t *self, int delta) { int i; if (self->next_sample) @@ -936,13 +908,12 @@ _sci1_update_delta(sci1_song_iterator_t *self, int delta) } static inline int -_sci1_no_delta_time(sci1_song_iterator_t *self) -{ /* Checks that none of the channels is waiting for its delta to be read */ +_sci1_no_delta_time(sci1_song_iterator_t *self) { /* Checks that none of the channels is waiting for its delta to be read */ int i; for (i = 0; i < self->channels_nr; i++) if (self->channels[i].state == SI_STATE_DELTA_TIME) - return 0; + return 0; return 1; } @@ -950,26 +921,25 @@ _sci1_no_delta_time(sci1_song_iterator_t *self) #if 0 // Unreferenced - removed static void -_sci1_dump_state(sci1_song_iterator_t *self) -{ +_sci1_dump_state(sci1_song_iterator_t *self) { int i; sciprintf("-- [%p] ------------------------\n", self); for (i = 0; i < self->channels_nr; i++) { int j; sciprintf("%d(s%02d): d-%d:\t(%x/%x) ", - self->channels[i].id, - self->channels[i].state, - self->channels[i].delay, - self->channels[i].offset, - self->channels[i].end); + self->channels[i].id, + self->channels[i].state, + self->channels[i].delay, + self->channels[i].offset, + self->channels[i].end); for (j = -3; j < 9; j++) { if (j == 0) sciprintf(">"); else sciprintf(" "); - sciprintf("%02x", self->data[self->channels[i].offset+j]); + sciprintf("%02x", self->data[self->channels[i].offset + j]); if (j == 0) sciprintf("<"); @@ -980,7 +950,7 @@ _sci1_dump_state(sci1_song_iterator_t *self) } if (self->next_sample) { sciprintf("\t[sample %d]\n", - self->next_sample->delta); + self->next_sample->delta); } sciprintf("------------------------------------------\n"); } @@ -990,18 +960,17 @@ _sci1_dump_state(sci1_song_iterator_t *self) #define COMMAND_INDEX_PCM -2 static inline int /* Determine the channel # of the next active event, or -1 */ -_sci1_command_index(sci1_song_iterator_t *self) -{ +_sci1_command_index(sci1_song_iterator_t *self) { int i; int base_delay = 0x7ffffff; int best_chan = COMMAND_INDEX_NONE; for (i = 0; i < self->channels_nr; i++) if ((self->channels[i].state != SI_STATE_PENDING) - && (self->channels[i].state != SI_STATE_FINISHED)) { - + && (self->channels[i].state != SI_STATE_FINISHED)) { + if ((self->channels[i].state == SI_STATE_DELTA_TIME) - && (self->channels[i].delay == 0)) + && (self->channels[i].delay == 0)) return i; /* First, read all unknown delta times */ @@ -1019,16 +988,15 @@ _sci1_command_index(sci1_song_iterator_t *self) static sfx_pcm_feed_t * -_sci1_get_pcm(sci1_song_iterator_t *self) -{ +_sci1_get_pcm(sci1_song_iterator_t *self) { if (self->next_sample - && self->next_sample->delta <= 0) { + && self->next_sample->delta <= 0) { sci1_sample_t *sample = self->next_sample; sfx_pcm_feed_t *feed - = sfx_iterator_make_feed(self->data, - sample->data - self->data, - sample->size, - sample->format); + = sfx_iterator_make_feed(self->data, + sample->data - self->data, + sample->size, + sample->format); self->next_sample = self->next_sample->next; @@ -1042,14 +1010,13 @@ _sci1_get_pcm(sci1_song_iterator_t *self) static int _sci1_process_next_command(sci1_song_iterator_t *self, - unsigned char *buf, int *result) -{ + unsigned char *buf, int *result) { int retval = -42; /* Shouldn't happen, but gcc doesn't agree */ int chan; if (!self->initialised) { sciprintf("[iterator-1] DEBUG: Initialising for %d\n", - self->device_id); + self->device_id); self->initialised = 1; if (_sci1_song_init(self)) return SI_FINISHED; @@ -1074,7 +1041,7 @@ _sci1_process_next_command(sci1_song_iterator_t *self, if (self->next_sample->announced) { /* Already announced; let's discard it */ sfx_pcm_feed_t *feed - = _sci1_get_pcm(self); + = _sci1_get_pcm(self); feed->destroy(feed); } else { int delay = self->next_sample->delta; @@ -1089,45 +1056,45 @@ _sci1_process_next_command(sci1_song_iterator_t *self, } } else { /* Not a PCM */ - retval = _sci_midi_process((base_song_iterator_t *) self, - buf, result, - &(self->channels[chan]), - PARSE_FLAG_LOOPS_UNLIMITED); + retval = _sci_midi_process((base_song_iterator_t *) self, + buf, result, + &(self->channels[chan]), + PARSE_FLAG_LOOPS_UNLIMITED); - if (retval == SI_LOOP) { - self->channels_looped++; - self->channels[chan].state = SI_STATE_PENDING; - self->channels[chan].delay = 0; + if (retval == SI_LOOP) { + self->channels_looped++; + self->channels[chan].state = SI_STATE_PENDING; + self->channels[chan].delay = 0; - if (self->channels_looped == self->active_channels) { - int i; + if (self->channels_looped == self->active_channels) { + int i; - /* Everyone's ready: Let's loop */ - for (i = 0; i < self->channels_nr; i++) - if (self->channels[i].state - == SI_STATE_PENDING) - self->channels[i].state + /* Everyone's ready: Let's loop */ + for (i = 0; i < self->channels_nr; i++) + if (self->channels[i].state + == SI_STATE_PENDING) + self->channels[i].state = SI_STATE_DELTA_TIME; - self->channels_looped = 0; - return SI_LOOP; - } - } else if (retval == SI_FINISHED) { + self->channels_looped = 0; + return SI_LOOP; + } + } else if (retval == SI_FINISHED) { #ifdef DEBUG - fprintf(stderr, "FINISHED some channel\n"); + fprintf(stderr, "FINISHED some channel\n"); #endif - } else if (retval > 0) { - int sd ; - sd = _sci1_get_smallest_delta(self); + } else if (retval > 0) { + int sd ; + sd = _sci1_get_smallest_delta(self); - if (_sci1_no_delta_time(self) && sd) { - /* No other channel is ready */ - _sci1_update_delta(self, sd); + if (_sci1_no_delta_time(self) && sd) { + /* No other channel is ready */ + _sci1_update_delta(self, sd); - /* Only from here do we return delta times */ - return sd; + /* Only from here do we return delta times */ + return sd; + } } - } } /* Not a PCM */ @@ -1137,9 +1104,8 @@ _sci1_process_next_command(sci1_song_iterator_t *self, } static struct _song_iterator * -_sci1_handle_message(sci1_song_iterator_t *self, - song_iterator_message_t msg) -{ + _sci1_handle_message(sci1_song_iterator_t *self, + song_iterator_message_t msg) { if (msg.recipient == _SIMSG_BASE) { /* May extend this in the future */ switch (msg.type) { @@ -1152,9 +1118,9 @@ _sci1_handle_message(sci1_song_iterator_t *self, print_tabs_id(msg.args[0].i, self->ID); fprintf(stderr, "SCI1: chan-nr=%d, playmask=%04x\n", - self->channels_nr, playmask); + self->channels_nr, playmask); } - break; + break; case _SIMSG_BASEMSG_CLONE: { int tsize = sizeof(sci1_song_iterator_t); @@ -1172,7 +1138,7 @@ _sci1_handle_message(sci1_song_iterator_t *self, /* Clone chain of samples */ while (*samplep) { sci1_sample_t *newsample - = (sci1_sample_t*)sci_malloc(sizeof(sci1_sample_t)); + = (sci1_sample_t*)sci_malloc(sizeof(sci1_sample_t)); memcpy(newsample, *samplep, sizeof(sci1_sample_t)); *samplep = newsample; @@ -1195,54 +1161,55 @@ _sci1_handle_message(sci1_song_iterator_t *self, break; } - case _SIMSG_BASEMSG_SET_PLAYMASK: if (msg.ID == self->ID) { - self->channel_mask = 0; + case _SIMSG_BASEMSG_SET_PLAYMASK: + if (msg.ID == self->ID) { + self->channel_mask = 0; - self->device_id + self->device_id = sci0_to_sci1_device_map - [sci_ffs(msg.args[0].i & 0xff) - 1] - [sfx_pcm_available()] - ; - - if (self->device_id == 0xff) { - sciprintf("[iterator-1] Warning: Device %d(%d) not supported", - msg.args[0].i & 0xff, sfx_pcm_available()); - } - if (self->initialised) { - int i; - int toffset = -1; - - for (i = 0; i < self->channels_nr; i++) - if (self->channels[i].state != SI_STATE_FINISHED - && self->channels[i].total_timepos > toffset) { - toffset = self->channels[i].total_timepos - + self->channels[i].timepos_increment - - self->channels[i].delay; - } - - /* Find an active channel so that we can - ** get the correct time offset */ + [sci_ffs(msg.args[0].i & 0xff) - 1] + [sfx_pcm_available()] + ; - _sci1_song_init(self); + if (self->device_id == 0xff) { + sciprintf("[iterator-1] Warning: Device %d(%d) not supported", + msg.args[0].i & 0xff, sfx_pcm_available()); + } + if (self->initialised) { + int i; + int toffset = -1; + + for (i = 0; i < self->channels_nr; i++) + if (self->channels[i].state != SI_STATE_FINISHED + && self->channels[i].total_timepos > toffset) { + toffset = self->channels[i].total_timepos + + self->channels[i].timepos_increment + - self->channels[i].delay; + } + + /* Find an active channel so that we can + ** get the correct time offset */ + + _sci1_song_init(self); + + toffset -= self->delay_remaining; + self->delay_remaining = 0; + + if (toffset > 0) + return new_fast_forward_iterator((song_iterator_t *) self, + toffset); + } else { + _sci1_song_init(self); + self->initialised = 1; + } - toffset -= self->delay_remaining; - self->delay_remaining = 0; + break; - if (toffset > 0) - return new_fast_forward_iterator((song_iterator_t *) self, - toffset); - } else { - _sci1_song_init(self); - self->initialised = 1; } - break; - - } - case _SIMSG_BASEMSG_SET_LOOPS: if (msg.ID == self->ID) - self->loops = (msg.args[0].i > 32767)? 99 : 0; + self->loops = (msg.args[0].i > 32767) ? 99 : 0; /* 99 is arbitrary, but we can't use '1' because of ** the way we're testing in the decoding section. */ break; @@ -1254,8 +1221,7 @@ _sci1_handle_message(sci1_song_iterator_t *self, /* Ignore */ break; - case _SIMSG_BASEMSG_SET_FADE: - { + case _SIMSG_BASEMSG_SET_FADE: { fade_params_t *fp = (fade_params_t *) msg.args[0].p; self->fade.action = fp->action; self->fade.final_volume = fp->final_volume; @@ -1266,7 +1232,7 @@ _sci1_handle_message(sci1_song_iterator_t *self, default: fprintf(stderr, SIPFX "Unsupported command %d to" - " SCI1 iterator", msg.type); + " SCI1 iterator", msg.type); } return (song_iterator_t *) self; } @@ -1276,15 +1242,13 @@ _sci1_handle_message(sci1_song_iterator_t *self, static int _sci1_read_next_command(sci1_song_iterator_t *self, - unsigned char *buf, int *result) -{ + unsigned char *buf, int *result) { return _sci1_process_next_command(self, buf, result); } static void -_sci1_init(sci1_song_iterator_t *self) -{ +_sci1_init(sci1_song_iterator_t *self) { _common_init((base_song_iterator_t *) self); self->ccc = 127; self->device_id = 0x00; /* Default to Sound Blaster/Adlib for purposes @@ -1300,8 +1264,7 @@ _sci1_init(sci1_song_iterator_t *self) } static void -_sci1_cleanup(sci1_song_iterator_t *it) -{ +_sci1_cleanup(sci1_song_iterator_t *it) { sci1_sample_t *sample_seeker = it->next_sample; while (sample_seeker) { sci1_sample_t *old_sample = sample_seeker; @@ -1313,8 +1276,7 @@ _sci1_cleanup(sci1_song_iterator_t *it) } static int -_sci1_get_timepos(sci1_song_iterator_t *self) -{ +_sci1_get_timepos(sci1_song_iterator_t *self) { int max = 0; int i; @@ -1331,15 +1293,13 @@ _sci1_get_timepos(sci1_song_iterator_t *self) static void -_cleanup_iterator_init(song_iterator_t *it) -{ +_cleanup_iterator_init(song_iterator_t *it) { } static song_iterator_t * -_cleanup_iterator_handle_message(song_iterator_t *i, song_iterator_message_t msg) -{ +_cleanup_iterator_handle_message(song_iterator_t *i, song_iterator_message_t msg) { if (msg.recipient == _SIMSG_BASEMSG_PRINT - && msg.type == _SIMSG_BASEMSG_PRINT) { + && msg.type == _SIMSG_BASEMSG_PRINT) { print_tabs_id(msg.args[0].i, i->ID); fprintf(stderr, "CLEANUP\n"); } @@ -1348,8 +1308,7 @@ _cleanup_iterator_handle_message(song_iterator_t *i, song_iterator_message_t msg } static int -_cleanup_iterator_next(song_iterator_t *self, unsigned char *buf, int *result) -{ +_cleanup_iterator_next(song_iterator_t *self, unsigned char *buf, int *result) { /* Task: Return channel-notes-off for each channel */ if (self->channel_mask) { int bs = sci_ffs(self->channel_mask) - 1; @@ -1365,8 +1324,7 @@ _cleanup_iterator_next(song_iterator_t *self, unsigned char *buf, int *result) } song_iterator_t * -new_cleanup_iterator(unsigned int channels) -{ +new_cleanup_iterator(unsigned int channels) { song_iterator_t *it = (song_iterator_t*)sci_malloc(sizeof(song_iterator_t)); it->channel_mask = channels; it->ID = 17; @@ -1388,8 +1346,7 @@ new_cleanup_iterator(unsigned int channels) static int _ff_read_next_command(fast_forward_song_iterator_t *self, - byte *buf, int *result) -{ + byte *buf, int *result) { int rv; if (self->delta <= 0) @@ -1413,15 +1370,13 @@ _ff_read_next_command(fast_forward_song_iterator_t *self, } static sfx_pcm_feed_t * -_ff_check_pcm(fast_forward_song_iterator_t *self) -{ +_ff_check_pcm(fast_forward_song_iterator_t *self) { return self->delegate->get_pcm_feed(self->delegate); } static song_iterator_t * _ff_handle_message(fast_forward_song_iterator_t *self, - song_iterator_message_t msg) -{ + song_iterator_message_t msg) { if (msg.recipient == _SIMSG_PLASTICWRAP) switch (msg.type) { @@ -1465,27 +1420,23 @@ _ff_handle_message(fast_forward_song_iterator_t *self, static void -_ff_init(fast_forward_song_iterator_t *self) -{ +_ff_init(fast_forward_song_iterator_t *self) { return; } static int -_ff_get_timepos(fast_forward_song_iterator_t *self) -{ +_ff_get_timepos(fast_forward_song_iterator_t *self) { return self->delegate->get_timepos(self->delegate); } song_iterator_t * -new_fast_forward_iterator(song_iterator_t *capsit, int delta) -{ +new_fast_forward_iterator(song_iterator_t *capsit, int delta) { fast_forward_song_iterator_t *it = - (fast_forward_song_iterator_t*)sci_malloc(sizeof(fast_forward_song_iterator_t)); + (fast_forward_song_iterator_t*)sci_malloc(sizeof(fast_forward_song_iterator_t)); - if (capsit == NULL) - { - free(it); - return NULL; + if (capsit == NULL) { + free(it); + return NULL; } it->ID = 0; @@ -1494,18 +1445,18 @@ new_fast_forward_iterator(song_iterator_t *capsit, int delta) it->death_listeners_nr = 0; it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) - _ff_read_next_command; - it->get_pcm_feed = (sfx_pcm_feed_t *(*)(song_iterator_t *)) - _ff_check_pcm; - it->handle_message = (song_iterator_t *(*)(song_iterator_t *, - song_iterator_message_t)) - _ff_handle_message; + _ff_read_next_command; + it->get_pcm_feed = (sfx_pcm_feed_t * (*)(song_iterator_t *)) + _ff_check_pcm; + it->handle_message = (song_iterator_t * (*)(song_iterator_t *, + song_iterator_message_t)) + _ff_handle_message; it->get_timepos = (int(*)(song_iterator_t *))_ff_get_timepos; it->init = (void(*)(song_iterator_t *)) - _ff_init; + _ff_init; it->cleanup = NULL; it->channel_mask = capsit->channel_mask; - + return (song_iterator_t *) it; } @@ -1518,8 +1469,7 @@ new_fast_forward_iterator(song_iterator_t *capsit, int delta) static int _tee_read_next_command(tee_song_iterator_t *it, unsigned char *buf, - int *result) -{ + int *result) { static int ready_masks[2] = {TEE_LEFT_READY, TEE_RIGHT_READY}; static int active_masks[2] = {TEE_LEFT_ACTIVE, TEE_RIGHT_ACTIVE}; static int pcm_masks[2] = {TEE_LEFT_PCM, TEE_RIGHT_PCM}; @@ -1538,7 +1488,7 @@ _tee_read_next_command(tee_song_iterator_t *it, unsigned char *buf, return SI_MORPH; if ((it->status & (TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE)) - != (TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE)) { + != (TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE)) { /* Not all are is active? */ int which = 0; #ifdef DEBUG_TEE_ITERATOR @@ -1557,7 +1507,7 @@ _tee_read_next_command(tee_song_iterator_t *it, unsigned char *buf, /* First, check for unreported PCMs */ for (i = TEE_LEFT; i <= TEE_RIGHT; i++) if ((it->status & (ready_masks[i] | pcm_masks[i])) - == (ready_masks[i] | pcm_masks[i])) { + == (ready_masks[i] | pcm_masks[i])) { it->status &= ~ready_masks[i]; return SI_PCM; } @@ -1567,27 +1517,27 @@ _tee_read_next_command(tee_song_iterator_t *it, unsigned char *buf, /* Buffers aren't ready yet */ it->children[i].retval = - songit_next(&(it->children[i].it), - it->children[i].buf, - &(it->children[i].result), - IT_READER_MASK_ALL - | IT_READER_MAY_FREE - | IT_READER_MAY_CLEAN); + songit_next(&(it->children[i].it), + it->children[i].buf, + &(it->children[i].result), + IT_READER_MASK_ALL + | IT_READER_MAY_FREE + | IT_READER_MAY_CLEAN); it->status |= ready_masks[i]; #ifdef DEBUG_TEE_ITERATOR fprintf(stderr, "\t Must check %d: %d\n", i, - it->children[i].retval); + it->children[i].retval); #endif if (it->children[i].retval == SI_ABSOLUTE_CUE || - it->children[i].retval == SI_RELATIVE_CUE) - return it->children[i].retval; + it->children[i].retval == SI_RELATIVE_CUE) + return it->children[i].retval; if (it->children[i].retval == SI_FINISHED) { it->status &= ~active_masks[i]; /* Recurse to complete */ #ifdef DEBUG_TEE_ITERATOR -fprintf(stderr, "\t Child %d signalled completion, recursing w/ status %02x\n", i, it->status); + fprintf(stderr, "\t Child %d signalled completion, recursing w/ status %02x\n", i, it->status); #endif return _tee_read_next_command(it, buf, result); } else if (it->children[i].retval == SI_PCM) { @@ -1602,21 +1552,21 @@ fprintf(stderr, "\t Child %d signalled completion, recursing w/ status %02x\n", retid = TEE_LEFT; if ((it->children[TEE_LEFT].retval > 0) - /* Asked to delay */ - && (it->children[TEE_RIGHT].retval <= it->children[TEE_LEFT].retval)) + /* Asked to delay */ + && (it->children[TEE_RIGHT].retval <= it->children[TEE_LEFT].retval)) /* Is not delaying or not delaying as much */ retid = TEE_RIGHT; #ifdef DEBUG_TEE_ITERATOR -fprintf(stderr, "\tl:%d / r:%d / chose %d\n", - it->children[TEE_LEFT].retval, it->children[TEE_RIGHT].retval, retid); + fprintf(stderr, "\tl:%d / r:%d / chose %d\n", + it->children[TEE_LEFT].retval, it->children[TEE_RIGHT].retval, retid); #endif #if 0 if (it->children[retid].retval == 0) { /* Perform remapping, if neccessary */ byte *buf = it->children[retid].buf; if (*buf != SCI_MIDI_SET_SIGNAL - && *buf < 0xf0) { /* Not a generic command */ + && *buf < 0xf0) { /* Not a generic command */ int chan = *buf & 0xf; int op = *buf & 0xf0; @@ -1629,9 +1579,9 @@ fprintf(stderr, "\tl:%d / r:%d / chose %d\n", /* Adjust delta times */ if (it->children[retid].retval > 0 - && it->children[1-retid].retval > 0) { + && it->children[1-retid].retval > 0) { if (it->children[1-retid].retval - == it->children[retid].retval) + == it->children[retid].retval) /* If both children wait the same amount of time, ** we have to re-fetch commands from both */ it->status &= ~ready_masks[1-retid]; @@ -1639,7 +1589,7 @@ fprintf(stderr, "\tl:%d / r:%d / chose %d\n", /* If they don't, we can/must re-use the other ** child's delay time */ it->children[1-retid].retval - -= it->children[retid].retval; + -= it->children[retid].retval; } it->status &= ~ready_masks[retid]; @@ -1650,8 +1600,7 @@ fprintf(stderr, "\tl:%d / r:%d / chose %d\n", } static sfx_pcm_feed_t * -_tee_check_pcm(tee_song_iterator_t *it) -{ +_tee_check_pcm(tee_song_iterator_t *it) { static int pcm_masks[2] = {TEE_LEFT_PCM, TEE_RIGHT_PCM}; int i; @@ -1660,15 +1609,14 @@ _tee_check_pcm(tee_song_iterator_t *it) it->status &= ~pcm_masks[i]; return it->children[i].it-> - get_pcm_feed(it->children[i].it); + get_pcm_feed(it->children[i].it); } return NULL; /* No iterator */ } static song_iterator_t * -_tee_handle_message(tee_song_iterator_t *self, song_iterator_message_t msg) -{ +_tee_handle_message(tee_song_iterator_t *self, song_iterator_message_t msg) { if (msg.recipient == _SIMSG_BASE) { switch (msg.type) { @@ -1680,15 +1628,15 @@ _tee_handle_message(tee_song_iterator_t *self, song_iterator_message_t msg) case _SIMSG_BASEMSG_CLONE: { tee_song_iterator_t *newit - = (tee_song_iterator_t*)sci_malloc(sizeof(tee_song_iterator_t)); + = (tee_song_iterator_t*)sci_malloc(sizeof(tee_song_iterator_t)); memcpy(newit, self, sizeof(tee_song_iterator_t)); if (newit->children[TEE_LEFT].it) newit->children[TEE_LEFT].it = - songit_clone(newit->children[TEE_LEFT].it, msg.args[0].i); + songit_clone(newit->children[TEE_LEFT].it, msg.args[0].i); if (newit->children[TEE_RIGHT].it) newit->children[TEE_RIGHT].it = - songit_clone(newit->children[TEE_RIGHT].it, msg.args[0].i); + songit_clone(newit->children[TEE_RIGHT].it, msg.args[0].i); return (song_iterator_t *) newit; } @@ -1720,7 +1668,7 @@ _tee_handle_message(tee_song_iterator_t *self, song_iterator_message_t msg) return old_it; } else { sciprintf("[tee-iterator] WARNING:" - " Morphing without need\n"); + " Morphing without need\n"); return (song_iterator_t *) self; } @@ -1738,8 +1686,7 @@ _tee_handle_message(tee_song_iterator_t *self, song_iterator_message_t msg) } static void -_tee_init(tee_song_iterator_t *it) -{ +_tee_init(tee_song_iterator_t *it) { it->status = TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE; it->children[TEE_LEFT].it->init(it->children[TEE_LEFT].it); it->children[TEE_RIGHT].it->init(it->children[TEE_RIGHT].it); @@ -1748,8 +1695,7 @@ _tee_init(tee_song_iterator_t *it) #if 0 // Unreferenced - removed static void -_tee_free(tee_song_iterator_t *it) -{ +_tee_free(tee_song_iterator_t *it) { int i; for (i = TEE_LEFT; i <= TEE_RIGHT; i++) if (it->children[i].it && it->may_destroy) @@ -1759,8 +1705,7 @@ _tee_free(tee_song_iterator_t *it) static void songit_tee_death_notification(tee_song_iterator_t *self, - song_iterator_t *corpse) -{ + song_iterator_t *corpse) { if (corpse == self->children[TEE_LEFT].it) { self->status &= ~TEE_LEFT_ACTIVE; self->children[TEE_LEFT].it = NULL; @@ -1774,8 +1719,7 @@ songit_tee_death_notification(tee_song_iterator_t *self, song_iterator_t * -songit_new_tee(song_iterator_t *left, song_iterator_t *right, int may_destroy) -{ +songit_new_tee(song_iterator_t *left, song_iterator_t *right, int may_destroy) { int i; int firstfree = 1; /* First free channel */ int incomplete_map = 0; @@ -1794,28 +1738,28 @@ songit_new_tee(song_iterator_t *left, song_iterator_t *right, int may_destroy) /* By default, don't remap */ for (i = 0; i < 16; i++) it->children[TEE_LEFT].channel_remap[i] - = it->children[TEE_RIGHT].channel_remap[i] = i; + = it->children[TEE_RIGHT].channel_remap[i] = i; /* Default to lhs channels */ it->channel_mask = left->channel_mask; for (i = 0; i < 16; i++) if (it->channel_mask & (1 << i) & right->channel_mask - && (i != MIDI_RHYTHM_CHANNEL) /* Share rhythm */) { /*conflict*/ + && (i != MIDI_RHYTHM_CHANNEL) /* Share rhythm */) { /*conflict*/ while ((firstfree == MIDI_RHYTHM_CHANNEL) - /* Either if it's the rhythm channel or if it's taken */ - || (firstfree < MIDI_CHANNELS - && ((1 << firstfree) & it->channel_mask))) + /* Either if it's the rhythm channel or if it's taken */ + || (firstfree < MIDI_CHANNELS + && ((1 << firstfree) & it->channel_mask))) ++firstfree; if (firstfree == MIDI_CHANNELS) { incomplete_map = 1; fprintf(stderr, "[songit-tee <%08lx,%08lx>] " - "Could not remap right channel #%d:" - " Out of channels\n", - left->ID, right->ID, i); + "Could not remap right channel #%d:" + " Out of channels\n", + left->ID, right->ID, i); } else { it->children[TEE_RIGHT].channel_remap[i] - = firstfree; + = firstfree; it->channel_mask |= (1 << firstfree); } @@ -1824,39 +1768,39 @@ songit_new_tee(song_iterator_t *left, song_iterator_t *right, int may_destroy) if (incomplete_map) { int c; fprintf(stderr, "[songit-tee <%08lx,%08lx>] Channels:" - " %04x <- %04x | %04x\n", - left->ID, right->ID, - it->channel_mask, - left->channel_mask, right->channel_mask); - for (c =0 ; c < 2; c++) - for (i =0 ; i < 16; i++) + " %04x <- %04x | %04x\n", + left->ID, right->ID, + it->channel_mask, + left->channel_mask, right->channel_mask); + for (c = 0 ; c < 2; c++) + for (i = 0 ; i < 16; i++) fprintf(stderr, " map [%d][%d] -> %d\n", - c, i, it->children[c].channel_remap[i]); + c, i, it->children[c].channel_remap[i]); } #endif it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) - _tee_read_next_command; + _tee_read_next_command; - it->get_pcm_feed = (sfx_pcm_feed_t*(*)(song_iterator_t *)) - _tee_check_pcm; + it->get_pcm_feed = (sfx_pcm_feed_t * (*)(song_iterator_t *)) + _tee_check_pcm; - it->handle_message = (song_iterator_t *(*)(song_iterator_t *, - song_iterator_message_t)) - _tee_handle_message; + it->handle_message = (song_iterator_t * (*)(song_iterator_t *, + song_iterator_message_t)) + _tee_handle_message; it->init = (void(*)(song_iterator_t *)) - _tee_init; + _tee_init; it->get_timepos = NULL; song_iterator_add_death_listener((song_iterator_t *)it, - left, (void (*)(void *, void*)) - songit_tee_death_notification); + left, (void (*)(void *, void*)) + songit_tee_death_notification); song_iterator_add_death_listener((song_iterator_t *)it, - right, (void (*)(void *, void*)) - songit_tee_death_notification); + right, (void (*)(void *, void*)) + songit_tee_death_notification); it->cleanup = NULL; @@ -1869,8 +1813,7 @@ songit_new_tee(song_iterator_t *left, song_iterator_t *right, int may_destroy) /*************************************/ int -songit_next(song_iterator_t **it, unsigned char *buf, int *result, int mask) -{ +songit_next(song_iterator_t **it, unsigned char *buf, int *result, int mask) { int retval; if (!*it) @@ -1887,10 +1830,10 @@ songit_next(song_iterator_t **it, unsigned char *buf, int *result, int mask) if (retval == SI_FINISHED) fprintf(stderr, "[song-iterator] Song finished. mask = %04x, cm=%04x\n", - mask, (*it)->channel_mask); + mask, (*it)->channel_mask); if (retval == SI_FINISHED - && (mask & IT_READER_MAY_CLEAN) - && (*it)->channel_mask) { /* This last test will fail + && (mask & IT_READER_MAY_CLEAN) + && (*it)->channel_mask) { /* This last test will fail ** with a terminated ** cleanup iterator */ int channel_mask = (*it)->channel_mask; @@ -1900,20 +1843,20 @@ songit_next(song_iterator_t **it, unsigned char *buf, int *result, int mask) *it = new_cleanup_iterator(channel_mask); retval = -9999; /* Continue */ } - } while (! ( /* Until one of the following holds */ - (retval > 0 && (mask & IT_READER_MASK_DELAY)) - || (retval == 0 && (mask & IT_READER_MASK_MIDI)) - || (retval == SI_LOOP && (mask & IT_READER_MASK_LOOP)) - || (retval == SI_ABSOLUTE_CUE && - (mask & IT_READER_MASK_CUE)) - || (retval == SI_RELATIVE_CUE && - (mask & IT_READER_MASK_CUE)) - || (retval == SI_PCM && (mask & IT_READER_MASK_PCM)) - || (retval == SI_FINISHED) - )); + } while (!( /* Until one of the following holds */ + (retval > 0 && (mask & IT_READER_MASK_DELAY)) + || (retval == 0 && (mask & IT_READER_MASK_MIDI)) + || (retval == SI_LOOP && (mask & IT_READER_MASK_LOOP)) + || (retval == SI_ABSOLUTE_CUE && + (mask & IT_READER_MASK_CUE)) + || (retval == SI_RELATIVE_CUE && + (mask & IT_READER_MASK_CUE)) + || (retval == SI_PCM && (mask & IT_READER_MASK_PCM)) + || (retval == SI_FINISHED) + )); if (retval == SI_FINISHED - && (mask & IT_READER_MAY_FREE)) { + && (mask & IT_READER_MAY_FREE)) { songit_free(*it); *it = NULL; } @@ -1924,65 +1867,64 @@ songit_next(song_iterator_t **it, unsigned char *buf, int *result, int mask) song_iterator_t * -songit_new(unsigned char *data, unsigned int size, int type, songit_id_t id) -{ +songit_new(unsigned char *data, unsigned int size, int type, songit_id_t id) { base_song_iterator_t *it; int i; if (!data || size < 22) { fprintf(stderr, SIPFX "Attempt to instantiate song iterator for null" - " song data\n"); + " song data\n"); return NULL; } switch (type) { - case SCI_SONG_ITERATOR_TYPE_SCI0: - /**-- Playing SCI0 sound resources --**/ - it = (base_song_iterator_t*)sci_malloc(sizeof(sci0_song_iterator_t)); - it->channel_mask = 0xffff; /* Allocate all channels by default */ - - for (i = 0; i < MIDI_CHANNELS; i++) - it->polyphony[i] = data[1 + (i << 1)]; - - it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) - _sci0_read_next_command; - it->get_pcm_feed = (sfx_pcm_feed_t*(*)(song_iterator_t *)) - _sci0_check_pcm; - it->handle_message = (song_iterator_t *(*)(song_iterator_t *, song_iterator_message_t)) - _sci0_handle_message; - it->init = (void(*)(song_iterator_t *))_sci0_init; - it->cleanup = (void(*)(song_iterator_t *))_sci0_cleanup; - ((sci0_song_iterator_t *)it)->channel.state - = SI_STATE_UNINITIALISED; - it->get_timepos = (int(*)(song_iterator_t *))_sci0_get_timepos; - break; - - case SCI_SONG_ITERATOR_TYPE_SCI1: - /**-- SCI01 or later sound resource --**/ - it = (base_song_iterator_t*)sci_malloc(sizeof(sci1_song_iterator_t)); - it->channel_mask = 0; /* Defer channel allocation */ - - for (i = 0; i < MIDI_CHANNELS; i++) - it->polyphony[i] = 0; /* Unknown */ - - it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) - _sci1_read_next_command; - it->get_pcm_feed = (sfx_pcm_feed_t*(*)(song_iterator_t *)) - _sci1_get_pcm; - it->handle_message = (song_iterator_t *(*)(song_iterator_t *, song_iterator_message_t)) - _sci1_handle_message; - it->init = (void(*)(song_iterator_t *))_sci1_init; - it->cleanup = (void(*)(song_iterator_t *))_sci1_cleanup; - it->get_timepos = (int(*)(song_iterator_t *))_sci1_get_timepos; - break; - - default: - /**-- Invalid/unsupported sound resources --**/ - fprintf(stderr, SIPFX "Attempt to instantiate invalid/unknown" - " song iterator type %d\n", type); - return NULL; + case SCI_SONG_ITERATOR_TYPE_SCI0: + /**-- Playing SCI0 sound resources --**/ + it = (base_song_iterator_t*)sci_malloc(sizeof(sci0_song_iterator_t)); + it->channel_mask = 0xffff; /* Allocate all channels by default */ + + for (i = 0; i < MIDI_CHANNELS; i++) + it->polyphony[i] = data[1 + (i << 1)]; + + it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) + _sci0_read_next_command; + it->get_pcm_feed = (sfx_pcm_feed_t * (*)(song_iterator_t *)) + _sci0_check_pcm; + it->handle_message = (song_iterator_t * (*)(song_iterator_t *, song_iterator_message_t)) + _sci0_handle_message; + it->init = (void(*)(song_iterator_t *))_sci0_init; + it->cleanup = (void(*)(song_iterator_t *))_sci0_cleanup; + ((sci0_song_iterator_t *)it)->channel.state + = SI_STATE_UNINITIALISED; + it->get_timepos = (int(*)(song_iterator_t *))_sci0_get_timepos; + break; + + case SCI_SONG_ITERATOR_TYPE_SCI1: + /**-- SCI01 or later sound resource --**/ + it = (base_song_iterator_t*)sci_malloc(sizeof(sci1_song_iterator_t)); + it->channel_mask = 0; /* Defer channel allocation */ + + for (i = 0; i < MIDI_CHANNELS; i++) + it->polyphony[i] = 0; /* Unknown */ + + it->next = (int(*)(song_iterator_t *, unsigned char *, int *)) + _sci1_read_next_command; + it->get_pcm_feed = (sfx_pcm_feed_t * (*)(song_iterator_t *)) + _sci1_get_pcm; + it->handle_message = (song_iterator_t * (*)(song_iterator_t *, song_iterator_message_t)) + _sci1_handle_message; + it->init = (void(*)(song_iterator_t *))_sci1_init; + it->cleanup = (void(*)(song_iterator_t *))_sci1_cleanup; + it->get_timepos = (int(*)(song_iterator_t *))_sci1_get_timepos; + break; + + default: + /**-- Invalid/unsupported sound resources --**/ + fprintf(stderr, SIPFX "Attempt to instantiate invalid/unknown" + " song iterator type %d\n", type); + return NULL; } it->ID = id; @@ -1997,8 +1939,7 @@ songit_new(unsigned char *data, unsigned int size, int type, songit_id_t id) } void -songit_free(song_iterator_t *it) -{ +songit_free(song_iterator_t *it) { if (it) { int i; @@ -2013,8 +1954,7 @@ songit_free(song_iterator_t *it) } song_iterator_message_t -songit_make_message(songit_id_t id, int recipient, int type, int a1, int a2) -{ +songit_make_message(songit_id_t id, int recipient, int type, int a1, int a2) { song_iterator_message_t rv; rv.ID = id; rv.recipient = recipient; @@ -2026,8 +1966,7 @@ songit_make_message(songit_id_t id, int recipient, int type, int a1, int a2) } song_iterator_message_t -songit_make_ptr_message(songit_id_t id, int recipient, int type, void * a1, int a2) -{ +songit_make_ptr_message(songit_id_t id, int recipient, int type, void * a1, int a2) { song_iterator_message_t rv; rv.ID = id; rv.recipient = recipient; @@ -2040,8 +1979,7 @@ songit_make_ptr_message(songit_id_t id, int recipient, int type, void * a1, int int -songit_handle_message(song_iterator_t **it_reg_p, song_iterator_message_t msg) -{ +songit_handle_message(song_iterator_t **it_reg_p, song_iterator_message_t msg) { song_iterator_t *it = *it_reg_p; song_iterator_t *newit; @@ -2055,8 +1993,7 @@ songit_handle_message(song_iterator_t **it_reg_p, song_iterator_message_t msg) } song_iterator_t * -songit_clone(song_iterator_t *it, int delta) -{ +songit_clone(song_iterator_t *it, int delta) { SIMSG_SEND(it, SIMSG_CLONE(delta)); it->death_listeners_nr = 0; it->flags |= SONGIT_FLAG_CLONE; @@ -2065,12 +2002,11 @@ songit_clone(song_iterator_t *it, int delta) void song_iterator_add_death_listener(song_iterator_t *it, - void *client, - void (*notify) (void *self, void *notifier)) -{ + void *client, + void (*notify)(void *self, void *notifier)) { if (it->death_listeners_nr >= SONGIT_MAX_LISTENERS) { fprintf(stderr, "FATAL: Too many death listeners for song" - " iterator\n"); + " iterator\n"); BREAKPOINT(); exit(1); } @@ -2083,32 +2019,30 @@ song_iterator_add_death_listener(song_iterator_t *it, void song_iterator_remove_death_listener(song_iterator_t *it, - void *client) -{ + void *client) { int i; for (i = 0; i < it->death_listeners_nr; i++) { if (it->death_listeners[i].self == client) { --it->death_listeners_nr; /* Overwrite, if this wasn't the last one */ - if (i+1 < it->death_listeners_nr) + if (i + 1 < it->death_listeners_nr) it->death_listeners[i] - = it->death_listeners[it->death_listeners_nr]; + = it->death_listeners[it->death_listeners_nr]; return; } } fprintf(stderr, "FATAL: Could not remove death listener from " - "song iterator\n"); + "song iterator\n"); BREAKPOINT(); exit(1); } song_iterator_t * -sfx_iterator_combine(song_iterator_t *it1, song_iterator_t *it2) -{ +sfx_iterator_combine(song_iterator_t *it1, song_iterator_t *it2) { if (it1 == NULL) return it2; if (it2 == NULL) diff --git a/engines/sci/sfx/lists/gm_patches.cpp b/engines/sci/sfx/lists/gm_patches.cpp index b959a87461..0e32d5f7b5 100644 --- a/engines/sci/sfx/lists/gm_patches.cpp +++ b/engines/sci/sfx/lists/gm_patches.cpp @@ -19,180 +19,182 @@ ***************************************************************************/ char *GM_Patch[128] = { -/*000*/ "Acoustic Grand Piano", -/*001*/ "Bright Acoustic Piano", -/*002*/ "Electric Grand Piano", -/*003*/ "Honky-tonk Piano", -/*004*/ "Electric Piano 1", -/*005*/ "Electric Piano 2", -/*006*/ "Harpsichord", -/*007*/ "Clavinet", -/*008*/ "Celesta", -/*009*/ "Glockenspiel", -/*010*/ "Music Box", -/*011*/ "Vibraphone", -/*012*/ "Marimba", -/*013*/ "Xylophone", -/*014*/ "Tubular Bells", -/*015*/ "Dulcimer", -/*016*/ "Drawbar Organ", -/*017*/ "Percussive Organ", -/*018*/ "Rock Organ", -/*019*/ "Church Organ", -/*020*/ "Reed Organ", -/*021*/ "Accordion", -/*022*/ "Harmonica", -/*023*/ "Tango Accordion", -/*024*/ "Acoustic Guitar (nylon)", -/*025*/ "Acoustic Guitar (steel)", -/*026*/ "Electric Guitar (jazz)", -/*027*/ "Electric Guitar (clean)", -/*028*/ "Electric Guitar (muted)", -/*029*/ "Overdriven Guitar", -/*030*/ "Distortion Guitar", -/*031*/ "Guitar Harmonics", -/*032*/ "Acoustic Bass", -/*033*/ "Electric Bass (finger)", -/*034*/ "Electric Bass (pick)", -/*035*/ "Fretless Bass", -/*036*/ "Slap Bass 1", -/*037*/ "Slap Bass 2", -/*038*/ "Synth Bass 1", -/*039*/ "Synth Bass 2", -/*040*/ "Violin", -/*041*/ "Viola", -/*042*/ "Cello", -/*043*/ "Contrabass", -/*044*/ "Tremolo Strings", -/*045*/ "Pizzicato Strings", -/*046*/ "Orchestral Harp", -/*047*/ "Timpani", -/*048*/ "String Ensemble 1", -/*049*/ "String Ensemble 2", -/*050*/ "SynthStrings 1", -/*051*/ "SynthStrings 2", -/*052*/ "Choir Aahs", -/*053*/ "Voice Oohs", -/*054*/ "Synth Voice", -/*055*/ "Orchestra Hit", -/*056*/ "Trumpet", -/*057*/ "Trombone", -/*058*/ "Tuba", -/*059*/ "Muted Trumpet", -/*060*/ "French Horn", -/*061*/ "Brass Section", -/*062*/ "SynthBrass 1", -/*063*/ "SynthBrass 2", -/*064*/ "Soprano Sax", -/*065*/ "Alto Sax", -/*066*/ "Tenor Sax", -/*067*/ "Baritone Sax", -/*068*/ "Oboe", -/*069*/ "English Horn", -/*070*/ "Bassoon", -/*071*/ "Clarinet", -/*072*/ "Piccolo", -/*073*/ "Flute", -/*074*/ "Recorder", -/*075*/ "Pan Flute", -/*076*/ "Blown Bottle", -/*077*/ "Shakuhachi", -/*078*/ "Whistle", -/*079*/ "Ocarina", -/*080*/ "Lead 1 (square)", -/*081*/ "Lead 2 (sawtooth)", -/*082*/ "Lead 3 (calliope)", -/*083*/ "Lead 4 (chiff)", -/*084*/ "Lead 5 (charang)", -/*085*/ "Lead 6 (voice)", -/*086*/ "Lead 7 (fifths)", -/*087*/ "Lead 8 (bass+lead)", -/*088*/ "Pad 1 (new age)", -/*089*/ "Pad 2 (warm)", -/*090*/ "Pad 3 (polysynth)", -/*091*/ "Pad 4 (choir)", -/*092*/ "Pad 5 (bowed)", -/*093*/ "Pad 6 (metallic)", -/*094*/ "Pad 7 (halo)", -/*095*/ "Pad 8 (sweep)", -/*096*/ "FX 1 (rain)", -/*097*/ "FX 2 (soundtrack)", -/*098*/ "FX 3 (crystal)", -/*099*/ "FX 4 (atmosphere)", -/*100*/ "FX 5 (brightness)", -/*101*/ "FX 6 (goblins)", -/*102*/ "FX 7 (echoes)", -/*103*/ "FX 8 (sci-fi)", -/*104*/ "Sitar", -/*105*/ "Banjo", -/*106*/ "Shamisen", -/*107*/ "Koto", -/*108*/ "Kalimba", -/*109*/ "Bag pipe", -/*110*/ "Fiddle", -/*111*/ "Shannai", -/*112*/ "Tinkle Bell", -/*113*/ "Agogo", -/*114*/ "Steel Drums", -/*115*/ "Woodblock", -/*116*/ "Taiko Drum", -/*117*/ "Melodic Tom", -/*118*/ "Synth Drum", -/*119*/ "Reverse Cymbal", -/*120*/ "Guitar Fret Noise", -/*121*/ "Breath Noise", -/*122*/ "Seashore", -/*123*/ "Bird Tweet", -/*124*/ "Telephone Ring", -/*125*/ "Helicopter", -/*126*/ "Applause", -/*127*/ "Gunshot" }; + /*000*/ "Acoustic Grand Piano", + /*001*/ "Bright Acoustic Piano", + /*002*/ "Electric Grand Piano", + /*003*/ "Honky-tonk Piano", + /*004*/ "Electric Piano 1", + /*005*/ "Electric Piano 2", + /*006*/ "Harpsichord", + /*007*/ "Clavinet", + /*008*/ "Celesta", + /*009*/ "Glockenspiel", + /*010*/ "Music Box", + /*011*/ "Vibraphone", + /*012*/ "Marimba", + /*013*/ "Xylophone", + /*014*/ "Tubular Bells", + /*015*/ "Dulcimer", + /*016*/ "Drawbar Organ", + /*017*/ "Percussive Organ", + /*018*/ "Rock Organ", + /*019*/ "Church Organ", + /*020*/ "Reed Organ", + /*021*/ "Accordion", + /*022*/ "Harmonica", + /*023*/ "Tango Accordion", + /*024*/ "Acoustic Guitar (nylon)", + /*025*/ "Acoustic Guitar (steel)", + /*026*/ "Electric Guitar (jazz)", + /*027*/ "Electric Guitar (clean)", + /*028*/ "Electric Guitar (muted)", + /*029*/ "Overdriven Guitar", + /*030*/ "Distortion Guitar", + /*031*/ "Guitar Harmonics", + /*032*/ "Acoustic Bass", + /*033*/ "Electric Bass (finger)", + /*034*/ "Electric Bass (pick)", + /*035*/ "Fretless Bass", + /*036*/ "Slap Bass 1", + /*037*/ "Slap Bass 2", + /*038*/ "Synth Bass 1", + /*039*/ "Synth Bass 2", + /*040*/ "Violin", + /*041*/ "Viola", + /*042*/ "Cello", + /*043*/ "Contrabass", + /*044*/ "Tremolo Strings", + /*045*/ "Pizzicato Strings", + /*046*/ "Orchestral Harp", + /*047*/ "Timpani", + /*048*/ "String Ensemble 1", + /*049*/ "String Ensemble 2", + /*050*/ "SynthStrings 1", + /*051*/ "SynthStrings 2", + /*052*/ "Choir Aahs", + /*053*/ "Voice Oohs", + /*054*/ "Synth Voice", + /*055*/ "Orchestra Hit", + /*056*/ "Trumpet", + /*057*/ "Trombone", + /*058*/ "Tuba", + /*059*/ "Muted Trumpet", + /*060*/ "French Horn", + /*061*/ "Brass Section", + /*062*/ "SynthBrass 1", + /*063*/ "SynthBrass 2", + /*064*/ "Soprano Sax", + /*065*/ "Alto Sax", + /*066*/ "Tenor Sax", + /*067*/ "Baritone Sax", + /*068*/ "Oboe", + /*069*/ "English Horn", + /*070*/ "Bassoon", + /*071*/ "Clarinet", + /*072*/ "Piccolo", + /*073*/ "Flute", + /*074*/ "Recorder", + /*075*/ "Pan Flute", + /*076*/ "Blown Bottle", + /*077*/ "Shakuhachi", + /*078*/ "Whistle", + /*079*/ "Ocarina", + /*080*/ "Lead 1 (square)", + /*081*/ "Lead 2 (sawtooth)", + /*082*/ "Lead 3 (calliope)", + /*083*/ "Lead 4 (chiff)", + /*084*/ "Lead 5 (charang)", + /*085*/ "Lead 6 (voice)", + /*086*/ "Lead 7 (fifths)", + /*087*/ "Lead 8 (bass+lead)", + /*088*/ "Pad 1 (new age)", + /*089*/ "Pad 2 (warm)", + /*090*/ "Pad 3 (polysynth)", + /*091*/ "Pad 4 (choir)", + /*092*/ "Pad 5 (bowed)", + /*093*/ "Pad 6 (metallic)", + /*094*/ "Pad 7 (halo)", + /*095*/ "Pad 8 (sweep)", + /*096*/ "FX 1 (rain)", + /*097*/ "FX 2 (soundtrack)", + /*098*/ "FX 3 (crystal)", + /*099*/ "FX 4 (atmosphere)", + /*100*/ "FX 5 (brightness)", + /*101*/ "FX 6 (goblins)", + /*102*/ "FX 7 (echoes)", + /*103*/ "FX 8 (sci-fi)", + /*104*/ "Sitar", + /*105*/ "Banjo", + /*106*/ "Shamisen", + /*107*/ "Koto", + /*108*/ "Kalimba", + /*109*/ "Bag pipe", + /*110*/ "Fiddle", + /*111*/ "Shannai", + /*112*/ "Tinkle Bell", + /*113*/ "Agogo", + /*114*/ "Steel Drums", + /*115*/ "Woodblock", + /*116*/ "Taiko Drum", + /*117*/ "Melodic Tom", + /*118*/ "Synth Drum", + /*119*/ "Reverse Cymbal", + /*120*/ "Guitar Fret Noise", + /*121*/ "Breath Noise", + /*122*/ "Seashore", + /*123*/ "Bird Tweet", + /*124*/ "Telephone Ring", + /*125*/ "Helicopter", + /*126*/ "Applause", + /*127*/ "Gunshot" +}; char *GM_RhythmKey[47] = { -/*035*/ "Acoustic Bass Drum", -/*036*/ "Bass Drum 1", -/*037*/ "Side Stick", -/*038*/ "Acoustic Snare", -/*039*/ "Hand Clap", -/*040*/ "Electric Snare", -/*041*/ "Low Floor Tom", -/*042*/ "Closed Hi-Hat", -/*043*/ "High Floor Tom", -/*044*/ "Pedal Hi-Hat", -/*045*/ "Low Tom", -/*046*/ "Open Hi-Hat", -/*047*/ "Low-Mid Tom", -/*048*/ "Hi-Mid Tom", -/*049*/ "Crash Cymbal 1", -/*050*/ "High Tom", -/*051*/ "Ride Cymbal 1", -/*052*/ "Chinese Cymbal", -/*053*/ "Ride Bell", -/*054*/ "Tambourine", -/*055*/ "Splash Cymbal", -/*056*/ "Cowbell", -/*057*/ "Crash Cymbal 2", -/*058*/ "Vibraslap", -/*059*/ "Ride Cymbal 2", -/*060*/ "Hi Bongo", -/*061*/ "Low Bongo", -/*062*/ "Mute Hi Conga", -/*063*/ "Open Hi Conga", -/*064*/ "Low Conga", -/*065*/ "High Timbale", -/*066*/ "Low Timbale", -/*067*/ "High Agogo", -/*068*/ "Low Agogo", -/*069*/ "Cabasa", -/*070*/ "Maracas", -/*071*/ "Short Whistle", -/*072*/ "Long Whistle", -/*073*/ "Short Guiro", -/*074*/ "Long Guiro", -/*075*/ "Claves", -/*076*/ "Hi Wood Block", -/*077*/ "Low Wood Block", -/*078*/ "Mute Cuica", -/*079*/ "Open Cuica", -/*080*/ "Mute Triangle" -/*081*/ "Open Triangle" }; + /*035*/ "Acoustic Bass Drum", + /*036*/ "Bass Drum 1", + /*037*/ "Side Stick", + /*038*/ "Acoustic Snare", + /*039*/ "Hand Clap", + /*040*/ "Electric Snare", + /*041*/ "Low Floor Tom", + /*042*/ "Closed Hi-Hat", + /*043*/ "High Floor Tom", + /*044*/ "Pedal Hi-Hat", + /*045*/ "Low Tom", + /*046*/ "Open Hi-Hat", + /*047*/ "Low-Mid Tom", + /*048*/ "Hi-Mid Tom", + /*049*/ "Crash Cymbal 1", + /*050*/ "High Tom", + /*051*/ "Ride Cymbal 1", + /*052*/ "Chinese Cymbal", + /*053*/ "Ride Bell", + /*054*/ "Tambourine", + /*055*/ "Splash Cymbal", + /*056*/ "Cowbell", + /*057*/ "Crash Cymbal 2", + /*058*/ "Vibraslap", + /*059*/ "Ride Cymbal 2", + /*060*/ "Hi Bongo", + /*061*/ "Low Bongo", + /*062*/ "Mute Hi Conga", + /*063*/ "Open Hi Conga", + /*064*/ "Low Conga", + /*065*/ "High Timbale", + /*066*/ "Low Timbale", + /*067*/ "High Agogo", + /*068*/ "Low Agogo", + /*069*/ "Cabasa", + /*070*/ "Maracas", + /*071*/ "Short Whistle", + /*072*/ "Long Whistle", + /*073*/ "Short Guiro", + /*074*/ "Long Guiro", + /*075*/ "Claves", + /*076*/ "Hi Wood Block", + /*077*/ "Low Wood Block", + /*078*/ "Mute Cuica", + /*079*/ "Open Cuica", + /*080*/ "Mute Triangle" + /*081*/ "Open Triangle" +}; diff --git a/engines/sci/sfx/lists/mt32_timbres.cpp b/engines/sci/sfx/lists/mt32_timbres.cpp index 776ff5dbb7..6cbf1c415a 100644 --- a/engines/sci/sfx/lists/mt32_timbres.cpp +++ b/engines/sci/sfx/lists/mt32_timbres.cpp @@ -19,163 +19,165 @@ ***************************************************************************/ char *MT32_Timbre[128] = { -/*000*/ "AcouPiano1", -/*001*/ "AcouPiano2", -/*002*/ "AcouPiano3", -/*003*/ "ElecPiano1", -/*004*/ "ElecPiano2", -/*005*/ "ElecPiano3", -/*006*/ "ElecPiano4", -/*007*/ "Honkytonk ", -/*008*/ "Elec Org 1", -/*009*/ "Elec Org 2", -/*010*/ "Elec Org 3", -/*011*/ "Elec Org 4", -/*012*/ "Pipe Org 1", -/*013*/ "Pipe Org 2", -/*014*/ "Pipe Org 3", -/*015*/ "Accordion ", -/*016*/ "Harpsi 1 ", -/*017*/ "Harpsi 2 ", -/*018*/ "Harpsi 3 ", -/*019*/ "Clavi 1 ", -/*020*/ "Clavi 2 ", -/*021*/ "Clavi 3 ", -/*022*/ "Celesta 1 ", -/*023*/ "Celesta 2 ", -/*024*/ "Syn Brass1", -/*025*/ "Syn Brass2", -/*026*/ "Syn Brass3", -/*027*/ "Syn Brass4", -/*028*/ "Syn Bass 1", -/*029*/ "Syn Bass 2", -/*030*/ "Syn Bass 3", -/*031*/ "Syn Bass 4", -/*032*/ "Fantasy ", -/*033*/ "Harmo Pan ", -/*034*/ "Chorale ", -/*035*/ "Glasses ", -/*036*/ "Soundtrack", -/*037*/ "Atmosphere", -/*038*/ "Warm Bell ", -/*039*/ "Funny Vox ", -/*040*/ "Echo Bell ", -/*041*/ "Ice Rain ", -/*042*/ "Oboe 2001 ", -/*043*/ "Echo Pan ", -/*044*/ "DoctorSolo", -/*045*/ "Schooldaze", -/*046*/ "BellSinger", -/*047*/ "SquareWave", -/*048*/ "Str Sect 1", -/*049*/ "Str Sect 2", -/*050*/ "Str Sect 3", -/*051*/ "Pizzicato ", -/*052*/ "Violin 1 ", -/*053*/ "Violin 2 ", -/*054*/ "Cello 1 ", -/*055*/ "Cello 2 ", -/*056*/ "Contrabass", -/*057*/ "Harp 1 ", -/*058*/ "Harp 2 ", -/*059*/ "Guitar 1 ", -/*060*/ "Guitar 2 ", -/*061*/ "Elec Gtr 1", -/*062*/ "Elec Gtr 2", -/*063*/ "Sitar ", -/*064*/ "Acou Bass1", -/*065*/ "Acou Bass2", -/*066*/ "Elec Bass1", -/*067*/ "Elec Bass2", -/*068*/ "Slap Bass1", -/*069*/ "Slap Bass2", -/*070*/ "Fretless 1", -/*071*/ "Fretless 2", -/*072*/ "Flute 1 ", -/*073*/ "Flute 2 ", -/*074*/ "Piccolo 1 ", -/*075*/ "Piccolo 2 ", -/*076*/ "Recorder ", -/*077*/ "Panpipes ", -/*078*/ "Sax 1 ", -/*079*/ "Sax 2 ", -/*080*/ "Sax 3 ", -/*081*/ "Sax 4 ", -/*082*/ "Clarinet 1", -/*083*/ "Clarinet 2", -/*084*/ "Oboe ", -/*085*/ "Engl Horn ", -/*086*/ "Bassoon ", -/*087*/ "Harmonica ", -/*088*/ "Trumpet 1 ", -/*089*/ "Trumpet 2 ", -/*090*/ "Trombone 1", -/*091*/ "Trombone 2", -/*092*/ "Fr Horn 1 ", -/*093*/ "Fr Horn 2 ", -/*094*/ "Tuba ", -/*095*/ "Brs Sect 1", -/*096*/ "Brs Sect 2", -/*097*/ "Vibe 1 ", -/*098*/ "Vibe 2 ", -/*099*/ "Syn Mallet", -/*100*/ "Wind Bell ", -/*101*/ "Glock ", -/*102*/ "Tube Bell ", -/*103*/ "Xylophone ", -/*104*/ "Marimba ", -/*105*/ "Koto ", -/*106*/ "Sho ", -/*107*/ "Shakuhachi", -/*108*/ "Whistle 1 ", -/*109*/ "Whistle 2 ", -/*110*/ "BottleBlow", -/*111*/ "BreathPipe", -/*112*/ "Timpani ", -/*113*/ "MelodicTom", -/*114*/ "Deep Snare", -/*115*/ "Elec Perc1", -/*116*/ "Elec Perc2", -/*117*/ "Taiko ", -/*118*/ "Taiko Rim ", -/*119*/ "Cymbal ", -/*120*/ "Castanets ", -/*121*/ "Triangle ", -/*122*/ "Orche Hit ", -/*123*/ "Telephone ", -/*124*/ "Bird Tweet", -/*125*/ "OneNoteJam", -/*126*/ "WaterBells", -/*127*/ "JungleTune" }; + /*000*/ "AcouPiano1", + /*001*/ "AcouPiano2", + /*002*/ "AcouPiano3", + /*003*/ "ElecPiano1", + /*004*/ "ElecPiano2", + /*005*/ "ElecPiano3", + /*006*/ "ElecPiano4", + /*007*/ "Honkytonk ", + /*008*/ "Elec Org 1", + /*009*/ "Elec Org 2", + /*010*/ "Elec Org 3", + /*011*/ "Elec Org 4", + /*012*/ "Pipe Org 1", + /*013*/ "Pipe Org 2", + /*014*/ "Pipe Org 3", + /*015*/ "Accordion ", + /*016*/ "Harpsi 1 ", + /*017*/ "Harpsi 2 ", + /*018*/ "Harpsi 3 ", + /*019*/ "Clavi 1 ", + /*020*/ "Clavi 2 ", + /*021*/ "Clavi 3 ", + /*022*/ "Celesta 1 ", + /*023*/ "Celesta 2 ", + /*024*/ "Syn Brass1", + /*025*/ "Syn Brass2", + /*026*/ "Syn Brass3", + /*027*/ "Syn Brass4", + /*028*/ "Syn Bass 1", + /*029*/ "Syn Bass 2", + /*030*/ "Syn Bass 3", + /*031*/ "Syn Bass 4", + /*032*/ "Fantasy ", + /*033*/ "Harmo Pan ", + /*034*/ "Chorale ", + /*035*/ "Glasses ", + /*036*/ "Soundtrack", + /*037*/ "Atmosphere", + /*038*/ "Warm Bell ", + /*039*/ "Funny Vox ", + /*040*/ "Echo Bell ", + /*041*/ "Ice Rain ", + /*042*/ "Oboe 2001 ", + /*043*/ "Echo Pan ", + /*044*/ "DoctorSolo", + /*045*/ "Schooldaze", + /*046*/ "BellSinger", + /*047*/ "SquareWave", + /*048*/ "Str Sect 1", + /*049*/ "Str Sect 2", + /*050*/ "Str Sect 3", + /*051*/ "Pizzicato ", + /*052*/ "Violin 1 ", + /*053*/ "Violin 2 ", + /*054*/ "Cello 1 ", + /*055*/ "Cello 2 ", + /*056*/ "Contrabass", + /*057*/ "Harp 1 ", + /*058*/ "Harp 2 ", + /*059*/ "Guitar 1 ", + /*060*/ "Guitar 2 ", + /*061*/ "Elec Gtr 1", + /*062*/ "Elec Gtr 2", + /*063*/ "Sitar ", + /*064*/ "Acou Bass1", + /*065*/ "Acou Bass2", + /*066*/ "Elec Bass1", + /*067*/ "Elec Bass2", + /*068*/ "Slap Bass1", + /*069*/ "Slap Bass2", + /*070*/ "Fretless 1", + /*071*/ "Fretless 2", + /*072*/ "Flute 1 ", + /*073*/ "Flute 2 ", + /*074*/ "Piccolo 1 ", + /*075*/ "Piccolo 2 ", + /*076*/ "Recorder ", + /*077*/ "Panpipes ", + /*078*/ "Sax 1 ", + /*079*/ "Sax 2 ", + /*080*/ "Sax 3 ", + /*081*/ "Sax 4 ", + /*082*/ "Clarinet 1", + /*083*/ "Clarinet 2", + /*084*/ "Oboe ", + /*085*/ "Engl Horn ", + /*086*/ "Bassoon ", + /*087*/ "Harmonica ", + /*088*/ "Trumpet 1 ", + /*089*/ "Trumpet 2 ", + /*090*/ "Trombone 1", + /*091*/ "Trombone 2", + /*092*/ "Fr Horn 1 ", + /*093*/ "Fr Horn 2 ", + /*094*/ "Tuba ", + /*095*/ "Brs Sect 1", + /*096*/ "Brs Sect 2", + /*097*/ "Vibe 1 ", + /*098*/ "Vibe 2 ", + /*099*/ "Syn Mallet", + /*100*/ "Wind Bell ", + /*101*/ "Glock ", + /*102*/ "Tube Bell ", + /*103*/ "Xylophone ", + /*104*/ "Marimba ", + /*105*/ "Koto ", + /*106*/ "Sho ", + /*107*/ "Shakuhachi", + /*108*/ "Whistle 1 ", + /*109*/ "Whistle 2 ", + /*110*/ "BottleBlow", + /*111*/ "BreathPipe", + /*112*/ "Timpani ", + /*113*/ "MelodicTom", + /*114*/ "Deep Snare", + /*115*/ "Elec Perc1", + /*116*/ "Elec Perc2", + /*117*/ "Taiko ", + /*118*/ "Taiko Rim ", + /*119*/ "Cymbal ", + /*120*/ "Castanets ", + /*121*/ "Triangle ", + /*122*/ "Orche Hit ", + /*123*/ "Telephone ", + /*124*/ "Bird Tweet", + /*125*/ "OneNoteJam", + /*126*/ "WaterBells", + /*127*/ "JungleTune" +}; char *MT32_RhythmTimbre[30] = { -/*00*/ "Acou BD ", -/*01*/ "Acou SD ", -/*02*/ "Acou HiTom", -/*03*/ "AcouMidTom", -/*04*/ "AcouLowTom", -/*05*/ "Elec SD ", -/*06*/ "Clsd HiHat", -/*07*/ "OpenHiHat1", -/*08*/ "Crash Cym ", -/*09*/ "Ride Cym ", -/*10*/ "Rim Shot ", -/*11*/ "Hand Clap ", -/*12*/ "Cowbell ", -/*13*/ "Mt HiConga", -/*14*/ "High Conga", -/*15*/ "Low Conga ", -/*16*/ "Hi Timbale", -/*17*/ "LowTimbale", -/*18*/ "High Bongo", -/*19*/ "Low Bongo ", -/*20*/ "High Agogo", -/*21*/ "Low Agogo ", -/*22*/ "Tambourine", -/*23*/ "Claves ", -/*24*/ "Maracas ", -/*25*/ "SmbaWhis L", -/*26*/ "SmbaWhis S", -/*27*/ "Cabasa ", -/*28*/ "Quijada ", -/*29*/ "OpenHiHat2" }; + /*00*/ "Acou BD ", + /*01*/ "Acou SD ", + /*02*/ "Acou HiTom", + /*03*/ "AcouMidTom", + /*04*/ "AcouLowTom", + /*05*/ "Elec SD ", + /*06*/ "Clsd HiHat", + /*07*/ "OpenHiHat1", + /*08*/ "Crash Cym ", + /*09*/ "Ride Cym ", + /*10*/ "Rim Shot ", + /*11*/ "Hand Clap ", + /*12*/ "Cowbell ", + /*13*/ "Mt HiConga", + /*14*/ "High Conga", + /*15*/ "Low Conga ", + /*16*/ "Hi Timbale", + /*17*/ "LowTimbale", + /*18*/ "High Bongo", + /*19*/ "Low Bongo ", + /*20*/ "High Agogo", + /*21*/ "Low Agogo ", + /*22*/ "Tambourine", + /*23*/ "Claves ", + /*24*/ "Maracas ", + /*25*/ "SmbaWhis L", + /*26*/ "SmbaWhis S", + /*27*/ "Cabasa ", + /*28*/ "Quijada ", + /*29*/ "OpenHiHat2" +}; diff --git a/engines/sci/sfx/mixer/dc.cpp b/engines/sci/sfx/mixer/dc.cpp index 52b3ab5cbb..c3cc465c92 100644 --- a/engines/sci/sfx/mixer/dc.cpp +++ b/engines/sci/sfx/mixer/dc.cpp @@ -65,8 +65,7 @@ TAILQ_HEAD(feed_list, feed_state) feeds; static char buf[BUF_SIZE * 2]; static feed_state_t * -find_feed_state(snd_stream_hnd_t hnd) -{ +find_feed_state(snd_stream_hnd_t hnd) { feed_state_t *state; TAILQ_FOREACH(state, &feeds, entry) { if (state->handle == hnd) @@ -77,8 +76,7 @@ find_feed_state(snd_stream_hnd_t hnd) } static void -query_timestamp(feed_state_t *state) -{ +query_timestamp(feed_state_t *state) { sfx_pcm_feed_t *feed = state->feed; if (feed->get_timestamp) { @@ -117,8 +115,7 @@ query_timestamp(feed_state_t *state) } void -U8_to_S16(char *buf, int frames, int stereo) -{ +U8_to_S16(char *buf, int frames, int stereo) { int samples = frames * (stereo ? 2 : 1); int i; @@ -129,8 +126,7 @@ U8_to_S16(char *buf, int frames, int stereo) } static void * -callback(snd_stream_hnd_t hnd, sfx_timestamp_t timestamp, int bytes_req, int *bytes_recv) -{ +callback(snd_stream_hnd_t hnd, sfx_timestamp_t timestamp, int bytes_req, int *bytes_recv) { feed_state_t *state = find_feed_state(hnd); sfx_pcm_feed_t *feed; int channels, frames_req; @@ -191,8 +187,7 @@ callback(snd_stream_hnd_t hnd, sfx_timestamp_t timestamp, int bytes_req, int *by } static int -mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device) -{ +mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device) { if (snd_stream_init() < 0) { fprintf(stderr, "[dc-mixer] Failed to initialize streaming sound driver\n"); return SFX_ERROR; @@ -204,13 +199,12 @@ mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device) } static void -mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) -{ +mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) { feed_state_t *state = sci_malloc(sizeof(feed_state_t)); long secs, usecs; if ((feed->conf.format != SFX_PCM_FORMAT_S16_LE) && - (feed->conf.format != SFX_PCM_FORMAT_U8)) { + (feed->conf.format != SFX_PCM_FORMAT_U8)) { fprintf(stderr, "[dc-mixer] Unsupported feed format\n"); feed->destroy(feed); return; @@ -234,18 +228,16 @@ mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) sci_gettime(&secs, &usecs); state->time = sfx_new_timestamp(secs, usecs, feed->conf.rate); snd_stream_start(state->handle, feed->conf.rate, - feed->conf.stereo != SFX_PCM_MONO); + feed->conf.stereo != SFX_PCM_MONO); } static void -mix_exit(sfx_pcm_mixer_t *self) -{ +mix_exit(sfx_pcm_mixer_t *self) { snd_stream_shutdown(); } static int -mix_process(sfx_pcm_mixer_t *self) -{ +mix_process(sfx_pcm_mixer_t *self) { feed_state_t *state, *state_next; TAILQ_FOREACH(state, &feeds, entry) { @@ -260,11 +252,10 @@ mix_process(sfx_pcm_mixer_t *self) snd_stream_destroy(state->handle); state->feed->destroy(state->feed); TAILQ_REMOVE(&feeds, state, entry); - } - else if (state->mode == FEED_MODE_RESTART) { + } else if (state->mode == FEED_MODE_RESTART) { snd_stream_stop(state->handle); snd_stream_start(state->handle, state->feed->conf.rate, - state->feed->conf.stereo != SFX_PCM_MONO); + state->feed->conf.stereo != SFX_PCM_MONO); state->mode = FEED_MODE_ALIVE; } state = state_next; @@ -274,24 +265,20 @@ mix_process(sfx_pcm_mixer_t *self) } static void -mix_pause(sfx_pcm_mixer_t *self) -{ +mix_pause(sfx_pcm_mixer_t *self) { } static void -mix_resume(sfx_pcm_mixer_t *self) -{ +mix_resume(sfx_pcm_mixer_t *self) { } static int -pcm_init(sfx_pcm_device_t *self) -{ +pcm_init(sfx_pcm_device_t *self) { return SFX_OK; } static void -pcm_exit(sfx_pcm_device_t *self) -{ +pcm_exit(sfx_pcm_device_t *self) { } sfx_pcm_device_t sfx_pcm_driver_dc = { diff --git a/engines/sci/sfx/mixer/mixers.cpp b/engines/sci/sfx/mixer/mixers.cpp index c0af0e3a53..6bda37487c 100644 --- a/engines/sci/sfx/mixer/mixers.cpp +++ b/engines/sci/sfx/mixer/mixers.cpp @@ -43,8 +43,7 @@ static sfx_pcm_mixer_t *mixers[] = { }; sfx_pcm_mixer_t * -sfx_pcm_find_mixer(char *name) -{ +sfx_pcm_find_mixer(char *name) { int i = 0; if (name) diff --git a/engines/sci/sfx/mixer/soft.cpp b/engines/sci/sfx/mixer/soft.cpp index 7c5b7c12ee..20a4bdc7ad 100644 --- a/engines/sci/sfx/mixer/soft.cpp +++ b/engines/sci/sfx/mixer/soft.cpp @@ -86,8 +86,7 @@ struct mixer_private { static int -mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device) -{ +mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device) { self->dev = device; self->private_bits /* = P */ = sci_malloc(sizeof(struct mixer_private)); P->outbuf = P->writebuf = NULL; @@ -98,15 +97,14 @@ mix_init(sfx_pcm_mixer_t *self, sfx_pcm_device_t *device) P->paused = 0; #ifdef DEBUG sciprintf("[soft-mixer] Initialised device %s v%s (%d Hz, %d/%x)\n", - device->name, device->version, - device->conf.rate, device->conf.stereo, device->conf.format); + device->name, device->version, + device->conf.rate, device->conf.stereo, device->conf.format); #endif return SFX_OK; } static inline unsigned int -gcd(unsigned int a, unsigned int b) -{ +gcd(unsigned int a, unsigned int b) { if (a == b) return a; @@ -122,8 +120,7 @@ gcd(unsigned int a, unsigned int b) } static sfx_pcm_urat_t -urat(unsigned int nom, unsigned int denom) -{ +urat(unsigned int nom, unsigned int denom) { sfx_pcm_urat_t rv; unsigned int g; @@ -141,19 +138,18 @@ urat(unsigned int nom, unsigned int denom) } static void -mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) -{ +mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) { sfx_pcm_feed_state_t *fs; ACQUIRE_LOCK(); if (!self->feeds) { self->feeds_allocd = 2; self->feeds = (sfx_pcm_feed_state_t*)sci_malloc(sizeof(sfx_pcm_feed_state_t) - * self->feeds_allocd); + * self->feeds_allocd); } else if (self->feeds_allocd == self->feeds_nr) { self->feeds_allocd += 2; self->feeds = (sfx_pcm_feed_state_t*)sci_realloc(self->feeds, - sizeof(sfx_pcm_feed_state_t) - * self->feeds_allocd); + sizeof(sfx_pcm_feed_state_t) + * self->feeds_allocd); } fs = self->feeds + self->feeds_nr++; @@ -168,19 +164,22 @@ mix_subscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) */ /* For the sake of people without 64 bit CPUs: */ fs->buf_size = 2 + /* Additional safety */ - (self->dev->buf_size * - (1 + (feed->conf.rate / self->dev->conf.rate))); -fprintf(stderr, " ---> %d/%d/%d/%d = %d\n", - self->dev->buf_size, - feed->conf.rate, - self->dev->conf.rate, - feed->frame_size, - fs->buf_size); + (self->dev->buf_size * + (1 + (feed->conf.rate / self->dev->conf.rate))); + fprintf(stderr, " ---> %d/%d/%d/%d = %d\n", + self->dev->buf_size, + feed->conf.rate, + self->dev->conf.rate, + feed->frame_size, + fs->buf_size); fs->buf = (byte*)sci_malloc(fs->buf_size * feed->frame_size); -fprintf(stderr, " ---> --> %d for %p at %p\n", fs->buf_size * feed->frame_size, (void *)fs, (void *)fs->buf); -{int i; for (i = 0; i < fs->buf_size * feed->frame_size; i++) -fs->buf[i] = 0xa5; } + fprintf(stderr, " ---> --> %d for %p at %p\n", fs->buf_size * feed->frame_size, (void *)fs, (void *)fs->buf); + { + int i; + for (i = 0; i < fs->buf_size * feed->frame_size; i++) + fs->buf[i] = 0xa5; + } fs->scount = urat(0, 1); fs->spd = urat(feed->conf.rate, self->dev->conf.rate); fs->scount.den = fs->spd.den; @@ -191,22 +190,21 @@ fs->buf[i] = 0xa5; } fs->mode = SFX_PCM_FEED_MODE_ALIVE; /* If the feed can't provide us with timestamps, we don't need to wait for it to do so */ - fs->pending_review = (feed->get_timestamp)? 1 : 0; + fs->pending_review = (feed->get_timestamp) ? 1 : 0; fs->frame_bufstart = 0; #ifdef DEBUG sciprintf("[soft-mixer] Subscribed %s-%x (%d Hz, %d/%x) at %d+%d/%d, buffer size %d\n", - feed->debug_name, feed->debug_nr, feed->conf.rate, feed->conf.stereo, feed->conf.format, - fs->spd.val, fs->spd.nom, fs->spd.den, fs->buf_size); + feed->debug_name, feed->debug_nr, feed->conf.rate, feed->conf.stereo, feed->conf.format, + fs->spd.val, fs->spd.nom, fs->spd.den, fs->buf_size); #endif RELEASE_LOCK(); } static void -_mix_unsubscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) -{ +_mix_unsubscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) { int i; #ifdef DEBUG sciprintf("[soft-mixer] Unsubscribing %s-%x\n", feed->debug_name, feed->debug_nr); @@ -230,29 +228,28 @@ _mix_unsubscribe(sfx_pcm_mixer_t *self, sfx_pcm_feed_t *feed) /* Limit memory waste */ self->feeds_allocd >>= 1; self->feeds - = (sfx_pcm_feed_state_t*)sci_realloc(self->feeds, - sizeof(sfx_pcm_feed_state_t) - * self->feeds_allocd); + = (sfx_pcm_feed_state_t*)sci_realloc(self->feeds, + sizeof(sfx_pcm_feed_state_t) + * self->feeds_allocd); } for (i = 0; i < self->feeds_nr; i++) fprintf(stderr, " Feed #%d: %s-%x\n", - i, self->feeds[i].feed->debug_name, - self->feeds[i].feed->debug_nr); + i, self->feeds[i].feed->debug_name, + self->feeds[i].feed->debug_nr); return; } } - fprintf(stderr, "[sfx-mixer] Assertion failed: Deleting invalid feed %p out of %d\n", - (void *)feed, self->feeds_nr); + fprintf(stderr, "[sfx-mixer] Assertion failed: Deleting invalid feed %p out of %d\n", + (void *)feed, self->feeds_nr); BREAKPOINT(); } static void -mix_exit(sfx_pcm_mixer_t *self) -{ +mix_exit(sfx_pcm_mixer_t *self) { ACQUIRE_LOCK(); while (self->feeds_nr) _mix_unsubscribe(self, self->feeds[0].feed); @@ -284,8 +281,7 @@ mix_exit(sfx_pcm_mixer_t *self) v = 32767 static inline void -mix_compute_output(sfx_pcm_mixer_t *self, int outplen) -{ +mix_compute_output(sfx_pcm_mixer_t *self, int outplen) { int frame_i; sfx_pcm_config_t conf = self->dev->conf; int use_16 = conf.format & SFX_PCM_FORMAT_16; @@ -303,11 +299,11 @@ mix_compute_output(sfx_pcm_mixer_t *self, int outplen) if (conf.stereo) { if (conf.stereo == SFX_PCM_STEREO_RL) { - lchan = P->writebuf + ((use_16)? 2 : 1); + lchan = P->writebuf + ((use_16) ? 2 : 1); rchan = P->writebuf; } else { lchan = P->writebuf; - rchan = P->writebuf + ((use_16)? 2 : 1); + rchan = P->writebuf + ((use_16) ? 2 : 1); } } else lchan = P->writebuf; @@ -380,8 +376,7 @@ mix_compute_output(sfx_pcm_mixer_t *self, int outplen) } static inline void -mix_swap_buffers(sfx_pcm_mixer_t *self) -{ /* Swap buffers */ +mix_swap_buffers(sfx_pcm_mixer_t *self) { /* Swap buffers */ byte *tmp = P->outbuf; P->outbuf = P->writebuf; P->writebuf = tmp; @@ -395,10 +390,10 @@ mix_swap_buffers(sfx_pcm_mixer_t *self) static inline int mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames) - /* Computes the number of frames we ought to write. It tries to minimise the number, - ** in order to reduce latency. */ - /* It sets 'skip_frames' to the number of frames to assume lost by latency, effectively - ** skipping them. */ +/* Computes the number of frames we ought to write. It tries to minimise the number, +** in order to reduce latency. */ +/* It sets 'skip_frames' to the number of frames to assume lost by latency, effectively +** skipping them. */ { int free_frames; int played_frames = 0; /* since the last call */ @@ -424,14 +419,13 @@ mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames) if (P->skew > usecs) { secs--; usecs += (1000000 - P->skew); - } - else + } else usecs -= P->skew; frame_pos = FRAME_OFFSET(usecs); played_frames = frame_pos - P->played_this_second - + ((secs - P->lsec) * self->dev->conf.rate); + + ((secs - P->lsec) * self->dev->conf.rate); /* fprintf(stderr, "%d:%d - %d:%d => %d\n", secs, frame_pos, P->lsec, P->played_this_second, played_frames); @@ -454,8 +448,8 @@ mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames) if (free_frames > self->dev->buf_size) { if (!diagnosed_too_slow) { sciprintf("[sfx-mixer] Your timer is too slow for your PCM output device (%d/%d), free=%d.\n" - "[sfx-mixer] You might want to try changing the device, timer, or mixer, if possible.\n", - played_frames, self->dev->buf_size, free_frames); + "[sfx-mixer] You might want to try changing the device, timer, or mixer, if possible.\n", + played_frames, self->dev->buf_size, free_frames); } diagnosed_too_slow = 1; @@ -468,20 +462,20 @@ mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames) if (P->delta_observations > MAX_DELTA_OBSERVATIONS) P->delta_observations = MAX_DELTA_OBSERVATIONS; -/* /\* Disabled, broken *\/ */ -/* if (0 && P->delta_observations > MIN_DELTA_OBSERVATIONS) { /\* Start improving after a while *\/ */ -/* int diff = self->dev->conf.rate - P->max_delta; */ + /* /\* Disabled, broken *\/ */ + /* if (0 && P->delta_observations > MIN_DELTA_OBSERVATIONS) { /\* Start improving after a while *\/ */ + /* int diff = self->dev->conf.rate - P->max_delta; */ -/* /\* log-approximate P->max_delta over time *\/ */ -/* recommended_frames = P->max_delta + */ -/* ((diff * MIN_DELTA_OBSERVATIONS) / P->delta_observations); */ -/* /\* WTF? *\/ */ -/* } else */ -/* recommended_frames = self->dev->buf_size; /\* Initially, keep the buffer full *\/ */ + /* /\* log-approximate P->max_delta over time *\/ */ + /* recommended_frames = P->max_delta + */ + /* ((diff * MIN_DELTA_OBSERVATIONS) / P->delta_observations); */ + /* /\* WTF? *\/ */ + /* } else */ + /* recommended_frames = self->dev->buf_size; /\* Initially, keep the buffer full *\/ */ #if (DEBUG >= 1) sciprintf("[soft-mixer] played since last time: %d, recommended: %d, free: %d\n", - played_frames, recommended_frames, free_frames); + played_frames, recommended_frames, free_frames); #endif result_frames = free_frames; @@ -498,7 +492,7 @@ mix_compute_buf_len(sfx_pcm_mixer_t *self, int *skip_frames) if (result_frames > self->dev->buf_size) { fprintf(stderr, "[soft-mixer] Internal assertion failed: frames-to-write %d > %d\n", - result_frames, self->dev->buf_size); + result_frames, self->dev->buf_size); } return result_frames; } @@ -551,9 +545,9 @@ static volatile int xx_size; static void mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, - int len, sfx_timestamp_t *ts, sfx_timestamp_t base_ts) - /* if add_result is non-zero, P->outbuf should be added to rather than overwritten. */ - /* base_ts is the timestamp for the first frame */ + int len, sfx_timestamp_t *ts, sfx_timestamp_t base_ts) +/* if add_result is non-zero, P->outbuf should be added to rather than overwritten. */ +/* base_ts is the timestamp for the first frame */ { sfx_pcm_feed_state_t *fs = self->feeds + add_result; sfx_pcm_feed_t *f = fs->feed; @@ -567,7 +561,7 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, byte *rsrc = fs->buf; /* Location to write to */ int frames_nr; - int bias = (conf.format & ~SFX_PCM_FORMAT_LMASK)? 0x8000 : 0; + int bias = (conf.format & ~SFX_PCM_FORMAT_LMASK) ? 0x8000 : 0; /* We use this only on a 16 bit level here */ /* The two most extreme source frames we consider for a @@ -584,18 +578,18 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, frames_nr = fs->spd.val * len; /* A little complicated since we must consider partial frames */ frames_nr += (fs->spd.nom * len - + (fs->scount.den - fs->scount.nom) /* remember that we may have leftovers */ - + (fs->spd.den - 1 /* round up */) - ) - / fs->spd.den; + + (fs->scount.den - fs->scount.nom) /* remember that we may have leftovers */ + + (fs->spd.den - 1 /* round up */) + ) + / fs->spd.den; ts->secs = -1; if (frames_nr > fs->buf_size) { fprintf(stderr, "%d (%d*%d + somethign) bytes, but only %d allowed!!!!!\n", - frames_nr * f->frame_size, - fs->spd.val, len, - fs->buf_size); + frames_nr * f->frame_size, + fs->spd.val, len, + fs->buf_size); BREAKPOINT(); } @@ -616,8 +610,8 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, case PCM_FEED_TIMESTAMP: { /* Compute the number of frames the returned timestamp is in the future: */ delay_frames = - sfx_timestamp_frame_diff(sfx_timestamp_renormalise(*ts, base_ts.frame_rate), - base_ts); + sfx_timestamp_frame_diff(sfx_timestamp_renormalise(*ts, base_ts.frame_rate), + base_ts); if (delay_frames <= 0) /* Start ASAP, even if it's too late */ @@ -627,7 +621,7 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, delay_frames = len; fs->pending_review = 0; } - break; + break; case PCM_FEED_EMPTY: fs->mode = SFX_PCM_FEED_MODE_DEAD; @@ -644,7 +638,7 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, default: fprintf(stderr, "[soft-mixer] Fatal: Invalid mode returned by PCM feed %s-%d's get_timestamp(): %d\n", - f->debug_name, f->debug_nr, newmode); + f->debug_name, f->debug_nr, newmode); exit(1); } } @@ -653,10 +647,10 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, /* Make sure we have sufficient information */ if (frames_nr > delay_frames + fs->frame_bufstart) frames_read = - f->poll(f, wr_dest, - frames_nr - - delay_frames - - fs->frame_bufstart); + f->poll(f, wr_dest, + frames_nr + - delay_frames + - fs->frame_bufstart); ACQUIRE_LOCK(); fs = self->feeds + add_result; @@ -681,15 +675,15 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, #if (DEBUG >= 2) sciprintf("[soft-mixer] Examining %s-%x (frame size %d); read %d/%d/%d, re-using %d frames\n", - f->debug_name, f->debug_nr, frame_size, frames_read, frames_nr, - fs->buf_size, fs->frame_bufstart); + f->debug_name, f->debug_nr, frame_size, frames_read, frames_nr, + fs->buf_size, fs->frame_bufstart); #endif if (conf.stereo == SFX_PCM_STEREO_LR) - rsrc += (use_16)? 2 : 1; + rsrc += (use_16) ? 2 : 1; else if (conf.stereo == SFX_PCM_STEREO_RL) - lsrc += (use_16)? 2 : 1; + lsrc += (use_16) ? 2 : 1; /* Otherwise, we let both point to the same place */ #if (DEBUG >= 2) @@ -723,7 +717,7 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, sciprintf("[soft-mixer] Initial read %d:%d\n", c_new.left, c_new.right); #endif c_old = c_new; - } + } #endif for (j = 0; j < frame_steps; j++) { @@ -737,16 +731,16 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, ** part analysis, so we add it to 'left' and 'right' ** later-- all others are added to (leftsum, rightsum). */ - if (j+1 < frame_steps) { + if (j + 1 < frame_steps) { leftsum += c_new.left; rightsum += c_new.right; } } left = c_new.left * fs->scount.nom - + c_old.left * (fs->scount.den - fs->scount.nom); + + c_old.left * (fs->scount.den - fs->scount.nom); right = c_new.right * fs->scount.nom - + c_old.right * (fs->scount.den - fs->scount.nom); + + c_old.right * (fs->scount.den - fs->scount.nom); /* Normalise */ left /= fs->spd.den; @@ -795,15 +789,15 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, xx_offset = ((frames_read - frames_left) * f->frame_size); xx_size = frames_left * f->frame_size; if (xx_offset + xx_size - >= fs->buf_size * f->frame_size) { + >= fs->buf_size * f->frame_size) { fprintf(stderr, "offset %d >= max %d!\n", - (xx_offset + xx_size), fs->buf_size * f->frame_size); + (xx_offset + xx_size), fs->buf_size * f->frame_size); BREAKPOINT(); } memmove(fs->buf, - fs->buf + ((frames_read - frames_left) * f->frame_size), - frames_left * f->frame_size); + fs->buf + ((frames_read - frames_left) * f->frame_size), + frames_left * f->frame_size); } #if (DEBUG >= 2) sciprintf("[soft-mixer] Leaving %d over\n", fs->frame_bufstart); @@ -818,144 +812,142 @@ mix_compute_input_linear(sfx_pcm_mixer_t *self, int add_result, } static int -mix_process_linear(sfx_pcm_mixer_t *self) -{ -ACQUIRE_LOCK(); -{ - int src_i; /* source feed index counter */ - int frames_skip; /* Number of frames to discard, rather than to emit */ - int buflen = mix_compute_buf_len(self, &frames_skip); /* Compute # of frames we must compute and write */ - int fake_buflen; - int timestamp_max_delta = 0; - int have_timestamp = 0; - sfx_timestamp_t start_timestamp; /* The timestamp at which the first frame will be played */ - sfx_timestamp_t min_timestamp; - min_timestamp.secs = 0; - sfx_timestamp_t timestamp; - - if (self->dev->get_output_timestamp) - start_timestamp = self->dev->get_output_timestamp(self->dev); - else { - long sec, usec; - sci_gettime(&sec, &usec); - start_timestamp = sfx_new_timestamp(sec, usec, self->dev->conf.rate); - } +mix_process_linear(sfx_pcm_mixer_t *self) { + ACQUIRE_LOCK(); + { + int src_i; /* source feed index counter */ + int frames_skip; /* Number of frames to discard, rather than to emit */ + int buflen = mix_compute_buf_len(self, &frames_skip); /* Compute # of frames we must compute and write */ + int fake_buflen; + int timestamp_max_delta = 0; + int have_timestamp = 0; + sfx_timestamp_t start_timestamp; /* The timestamp at which the first frame will be played */ + sfx_timestamp_t min_timestamp; + min_timestamp.secs = 0; + sfx_timestamp_t timestamp; + + if (self->dev->get_output_timestamp) + start_timestamp = self->dev->get_output_timestamp(self->dev); + else { + long sec, usec; + sci_gettime(&sec, &usec); + start_timestamp = sfx_new_timestamp(sec, usec, self->dev->conf.rate); + } - if ((P->outbuf) && (P->lastbuf_len)) { - sfx_timestamp_t ts; - int rv; + if ((P->outbuf) && (P->lastbuf_len)) { + sfx_timestamp_t ts; + int rv; - if (P->have_outbuf_timestamp) { - ts = sfx_timestamp_renormalise(P->outbuf_timestamp, self->dev->conf.rate); - } + if (P->have_outbuf_timestamp) { + ts = sfx_timestamp_renormalise(P->outbuf_timestamp, self->dev->conf.rate); + } - rv = self->dev->output(self->dev, P->outbuf, - P->lastbuf_len, - (P->have_outbuf_timestamp)? &ts : NULL); + rv = self->dev->output(self->dev, P->outbuf, + P->lastbuf_len, + (P->have_outbuf_timestamp) ? &ts : NULL); - if (rv == SFX_ERROR) { - RELEASE_LOCK(); - return rv; /* error */ + if (rv == SFX_ERROR) { + RELEASE_LOCK(); + return rv; /* error */ + } } - } #if (DEBUG >= 1) - if (self->feeds_nr) - sciprintf("[soft-mixer] Mixing %d output frames on %d input feeds\n", buflen, self->feeds_nr); + if (self->feeds_nr) + sciprintf("[soft-mixer] Mixing %d output frames on %d input feeds\n", buflen, self->feeds_nr); #endif - if (self->feeds_nr && !P->paused) { - /* Below, we read out all feeds in case we have to skip frames first, then get the - ** most current sound. 'fake_buflen' is either the actual buflen (for the last iteration) - ** or a fraction of the buf length to discard. */ - do { - if (frames_skip) { - if (frames_skip > self->dev->buf_size) - fake_buflen = self->dev->buf_size; - else - fake_buflen = frames_skip; - - frames_skip -= fake_buflen; - } else { - fake_buflen = buflen; - frames_skip = -1; /* Mark us as being completely done */ - } + if (self->feeds_nr && !P->paused) { + /* Below, we read out all feeds in case we have to skip frames first, then get the + ** most current sound. 'fake_buflen' is either the actual buflen (for the last iteration) + ** or a fraction of the buf length to discard. */ + do { + if (frames_skip) { + if (frames_skip > self->dev->buf_size) + fake_buflen = self->dev->buf_size; + else + fake_buflen = frames_skip; + + frames_skip -= fake_buflen; + } else { + fake_buflen = buflen; + frames_skip = -1; /* Mark us as being completely done */ + } - for (src_i = 0; src_i < self->feeds_nr; src_i++) { - mix_compute_input_linear(self, src_i, - fake_buflen, ×tamp, - start_timestamp); - - if (timestamp.secs >= 0) { - if (have_timestamp) { - int diff = sfx_timestamp_usecs_diff(min_timestamp, timestamp); - if (diff > 0) { - /* New earlier timestamp */ - timestamp = min_timestamp; - timestamp_max_delta += diff; - } else if (diff > timestamp_max_delta) - timestamp_max_delta = diff; - /* New max delta for timestamp */ - } else { - min_timestamp = timestamp; - have_timestamp = 1; + for (src_i = 0; src_i < self->feeds_nr; src_i++) { + mix_compute_input_linear(self, src_i, + fake_buflen, ×tamp, + start_timestamp); + + if (timestamp.secs >= 0) { + if (have_timestamp) { + int diff = sfx_timestamp_usecs_diff(min_timestamp, timestamp); + if (diff > 0) { + /* New earlier timestamp */ + timestamp = min_timestamp; + timestamp_max_delta += diff; + } else if (diff > timestamp_max_delta) + timestamp_max_delta = diff; + /* New max delta for timestamp */ + } else { + min_timestamp = timestamp; + have_timestamp = 1; + } } } - } - /* Destroy all feeds we finished */ - for (src_i = 0; src_i < self->feeds_nr; src_i++) - if (self->feeds[src_i].mode == SFX_PCM_FEED_MODE_DEAD) - _mix_unsubscribe(self, self->feeds[src_i].feed); - } while (frames_skip >= 0); - - } else { /* Zero it out */ - memset(P->compbuf_l, 0, sizeof(gint32) * buflen); - memset(P->compbuf_r, 0, sizeof(gint32) * buflen); - } + /* Destroy all feeds we finished */ + for (src_i = 0; src_i < self->feeds_nr; src_i++) + if (self->feeds[src_i].mode == SFX_PCM_FEED_MODE_DEAD) + _mix_unsubscribe(self, self->feeds[src_i].feed); + } while (frames_skip >= 0); + + } else { /* Zero it out */ + memset(P->compbuf_l, 0, sizeof(gint32) * buflen); + memset(P->compbuf_r, 0, sizeof(gint32) * buflen); + } #if (DEBUG >= 1) - if (self->feeds_nr) - sciprintf("[soft-mixer] Done mixing for this session, the result will be our next output buffer\n"); + if (self->feeds_nr) + sciprintf("[soft-mixer] Done mixing for this session, the result will be our next output buffer\n"); #endif #if (DEBUG >= 3) - if (self->feeds_nr) { - int i; - sciprintf("[soft-mixer] Intermediate representation:\n"); - for (i = 0; i < buflen; i++) - sciprintf("[soft-mixer] Offset %d:\t[%04x:%04x]\t%d:%d\n", i, - P->compbuf_l[i] & 0xffff, P->compbuf_r[i] & 0xffff, - P->compbuf_l[i], P->compbuf_r[i]); - } + if (self->feeds_nr) { + int i; + sciprintf("[soft-mixer] Intermediate representation:\n"); + for (i = 0; i < buflen; i++) + sciprintf("[soft-mixer] Offset %d:\t[%04x:%04x]\t%d:%d\n", i, + P->compbuf_l[i] & 0xffff, P->compbuf_r[i] & 0xffff, + P->compbuf_l[i], P->compbuf_r[i]); + } #endif - if (timestamp_max_delta > TIMESTAMP_MAX_ALLOWED_DELTA) - sciprintf("[soft-mixer] Warning: Difference in timestamps between audio feeds is %d us\n", timestamp_max_delta); + if (timestamp_max_delta > TIMESTAMP_MAX_ALLOWED_DELTA) + sciprintf("[soft-mixer] Warning: Difference in timestamps between audio feeds is %d us\n", timestamp_max_delta); - mix_compute_output(self, buflen); - P->lastbuf_len = buflen; + mix_compute_output(self, buflen); + P->lastbuf_len = buflen; - /* Finalize */ - mix_swap_buffers(self); - if (have_timestamp) - P->outbuf_timestamp = sfx_timestamp_add(min_timestamp, - timestamp_max_delta >> 1); - P->have_outbuf_timestamp = have_timestamp; + /* Finalize */ + mix_swap_buffers(self); + if (have_timestamp) + P->outbuf_timestamp = sfx_timestamp_add(min_timestamp, + timestamp_max_delta >> 1); + P->have_outbuf_timestamp = have_timestamp; -} RELEASE_LOCK(); + } + RELEASE_LOCK(); return SFX_OK; } static void -mix_pause(sfx_pcm_mixer_t *self) -{ +mix_pause(sfx_pcm_mixer_t *self) { ACQUIRE_LOCK(); P->paused = 1; RELEASE_LOCK(); } static void -mix_resume(sfx_pcm_mixer_t *self) -{ +mix_resume(sfx_pcm_mixer_t *self) { ACQUIRE_LOCK(); P->paused = 0; RELEASE_LOCK(); diff --git a/engines/sci/sfx/mixer/test.cpp b/engines/sci/sfx/mixer/test.cpp index 20b3e952e1..1119f0933c 100644 --- a/engines/sci/sfx/mixer/test.cpp +++ b/engines/sci/sfx/mixer/test.cpp @@ -45,10 +45,10 @@ int dev_output(sfx_pcm_device_t *self, byte *buf, int count); sfx_pcm_device_t devices[DEVICES_NR] = { { "test-1", "0", dev_init, dev_exit, dev_option, dev_output, - { 200, SFX_PCM_MONO, SFX_PCM_FORMAT_U8 }, 1024, NULL }, + { 200, SFX_PCM_MONO, SFX_PCM_FORMAT_U8 }, 1024, NULL }, #if (DEVICES_NR > 1) - { "test-2", "0", dev_init, dev_exit, dev_option, dev_output, - { 200, SFX_PCM_STEREO_LR, SFX_PCM_FORMAT_U8 }, 1024, NULL }, + { "test-2", "0", dev_init, dev_exit, dev_option, dev_output, { 200, SFX_PCM_STEREO_LR, SFX_PCM_FORMAT_U8 }, 1024, NULL + }, { "test-3", "0", dev_init, dev_exit, dev_option, dev_output, { 200, SFX_PCM_STEREO_RL, SFX_PCM_FORMAT_U8 }, 1024, NULL }, { "test-4", "0", dev_init, dev_exit, dev_option, dev_output, @@ -70,42 +70,38 @@ sfx_pcm_device_t devices[DEVICES_NR] = { int output_count; -int dev_init(sfx_pcm_device_t *self) -{ +int dev_init(sfx_pcm_device_t *self) { output_count = 0; fprintf(stderr, "[DEV] Initialised device %p as follows:\n" - "\trate = %d\n" - "\tstereo = %s\n" - "\tbias = %x\n" - "\tbytes/sample = %d\n" - "\tendianness = %s\n", - self, - self->conf.rate, - self->conf.stereo? ((self->conf.stereo == SFX_PCM_STEREO_LR)? "Left, Right" : "Right, Left") : "No", - self->conf.format & ~SFX_PCM_FORMAT_LMASK, - (self->conf.format & SFX_PCM_FORMAT_16)? 2 : 1, - ((self->conf.format & SFX_PCM_FORMAT_ENDIANNESS) == SFX_PCM_FORMAT_BE)? "big" : "little"); + "\trate = %d\n" + "\tstereo = %s\n" + "\tbias = %x\n" + "\tbytes/sample = %d\n" + "\tendianness = %s\n", + self, + self->conf.rate, + self->conf.stereo ? ((self->conf.stereo == SFX_PCM_STEREO_LR) ? "Left, Right" : "Right, Left") : "No", + self->conf.format & ~SFX_PCM_FORMAT_LMASK, + (self->conf.format & SFX_PCM_FORMAT_16) ? 2 : 1, + ((self->conf.format & SFX_PCM_FORMAT_ENDIANNESS) == SFX_PCM_FORMAT_BE) ? "big" : "little"); return 0; } -void dev_exit(sfx_pcm_device_t *self) -{ +void dev_exit(sfx_pcm_device_t *self) { fprintf(stderr, "[DEV] Uninitialising device\n"); } -int dev_option(sfx_pcm_device_t *self, char *name, char *value) -{ +int dev_option(sfx_pcm_device_t *self, char *name, char *value) { fprintf(stderr, "[DEV] Set option '%s' to '%s'\n", name, value); return 0; } int dev_output_enabled = 0; -int dev_output(sfx_pcm_device_t *self, byte *buf, int count) -{ - int mono_sample_size = ((self->conf.format & SFX_PCM_FORMAT_16)? 2 : 1); - int sample_size = (self->conf.stereo? 2 : 1) * mono_sample_size; +int dev_output(sfx_pcm_device_t *self, byte *buf, int count) { + int mono_sample_size = ((self->conf.format & SFX_PCM_FORMAT_16) ? 2 : 1); + int sample_size = (self->conf.stereo ? 2 : 1) * mono_sample_size; int bias = self->conf.format & ~SFX_PCM_FORMAT_LMASK; int is_bigendian = (self->conf.format & SFX_PCM_FORMAT_ENDIANNESS) == SFX_PCM_FORMAT_BE; byte *left_channel = buf; @@ -125,7 +121,7 @@ int dev_output(sfx_pcm_device_t *self, byte *buf, int count) while (count--) { int right = right_channel[0]; int left = left_channel[0]; - int second_byte = ((self->conf.format & SFX_PCM_FORMAT_16)? 1 : 0); + int second_byte = ((self->conf.format & SFX_PCM_FORMAT_16) ? 1 : 0); if (second_byte) { @@ -186,18 +182,18 @@ typedef struct { sfx_pcm_feed_t feeds[FEEDS_NR] = { { feed_poll, feed_destroy, &(private_bits[0]), - { 200, SFX_PCM_MONO, SFX_PCM_FORMAT_S8 }, "test-feed", 0, 0} + { 200, SFX_PCM_MONO, SFX_PCM_FORMAT_S8 }, "test-feed", 0, 0} #if FEEDS_NR > 1 - ,{ feed_poll, feed_destroy, &(private_bits[1]), - { 400, SFX_PCM_MONO, SFX_PCM_FORMAT_U8 }, "test-feed", 1, 0} + , { feed_poll, feed_destroy, &(private_bits[1]), + { 400, SFX_PCM_MONO, SFX_PCM_FORMAT_U8 }, "test-feed", 1, 0} #endif #if FEEDS_NR > 2 - ,{ feed_poll, feed_destroy, &(private_bits[2]), - { 20, SFX_PCM_MONO, SFX_PCM_FORMAT_S16_LE }, "test-feed", 2, 0} + , { feed_poll, feed_destroy, &(private_bits[2]), + { 20, SFX_PCM_MONO, SFX_PCM_FORMAT_S16_LE }, "test-feed", 2, 0} #endif #if FEEDS_NR > 3 - ,{ feed_poll, feed_destroy, &(private_bits[3]), - { 150, SFX_PCM_STEREO_LR, SFX_PCM_FORMAT_S8 }, "test-feed", 3, 0} + , { feed_poll, feed_destroy, &(private_bits[3]), + { 150, SFX_PCM_STEREO_LR, SFX_PCM_FORMAT_S8 }, "test-feed", 3, 0} #endif /* ,{ feed_poll, feed_destroy, &(private_bits[4]), @@ -208,46 +204,47 @@ sfx_pcm_feed_t feeds[FEEDS_NR] = { }; byte feed_data_0[] = {0xfd, 0xfe, 0xff, 0, 1, 2, 3, 4, 5, 6}; -byte feed_data_1[] = {0x80, 0x90, 0xA0, 0xB0, 0xC0, - 0xD0, 0xD0, 0xC0, 0xB0, 0xA0, 0x90, 0x80}; +byte feed_data_1[] = {0x80, 0x90, 0xA0, 0xB0, 0xC0, + 0xD0, 0xD0, 0xC0, 0xB0, 0xA0, 0x90, 0x80 + }; byte feed_data_2[] = {0x00, 0x00, - 0x00, 0x80, - 0xe8, 0x03}; + 0x00, 0x80, + 0xe8, 0x03 + }; byte feed_data_3[] = {0x00, 0x10, - 0x01, 0x20, - 0x02, 0x30}; + 0x01, 0x20, + 0x02, 0x30 + }; sample_feed_t sample_feeds[FEEDS_NR] = { { 1, 10, feed_data_0 } #if FEEDS_NR > 1 - ,{ 21, 12, feed_data_1 } + , { 21, 12, feed_data_1 } #endif #if FEEDS_NR > 2 - ,{ 0, 3, feed_data_2 } + , { 0, 3, feed_data_2 } #endif #if FEEDS_NR > 3 - ,{ 40, 3, feed_data_3 } + , { 40, 3, feed_data_3 } #endif }; void -feed_destroy(sfx_pcm_feed_t *self) -{ +feed_destroy(sfx_pcm_feed_t *self) { int_struct *s = (int_struct *) self->internal; s->i = 0; /* reset */ } int -feed_poll(sfx_pcm_feed_t *self, byte *dest, int size) -{ +feed_poll(sfx_pcm_feed_t *self, byte *dest, int size) { int_struct *s = (int_struct *) self->internal; int sample_size = self->sample_size; sample_feed_t *data = &(sample_feeds[self->debug_nr]); int bias = self->conf.format & ~SFX_PCM_FORMAT_LMASK; byte neutral[4] = {0, 0, 0, 0}; int i; -fprintf(stderr, "[feed] Asked for %d at %p, ss=%d\n", size, dest, sample_size); + fprintf(stderr, "[feed] Asked for %d at %p, ss=%d\n", size, dest, sample_size); if (bias) { byte first = bias >> 8; byte second = bias & 0xff; @@ -295,8 +292,7 @@ extern FILE *con_file; int -main(int argc, char **argv) -{ +main(int argc, char **argv) { int dev_nr; mix = sfx_pcm_find_mixer(NULL); @@ -306,7 +302,7 @@ main(int argc, char **argv) return 1; } else { fprintf(stderr, "Running %s, v%s\n", - mix->name, mix->version); + mix->name, mix->version); } con_file = stderr; @@ -332,7 +328,7 @@ main(int argc, char **argv) mix->subscribe(mix, &(feeds[j])); fprintf(stderr, "[test] Subscribed %d feeds.\n", - FEEDS_NR); + FEEDS_NR); while (output_count < MIN_OUTPUT) { DELAY; diff --git a/engines/sci/sfx/pcm-iterator.cpp b/engines/sci/sfx/pcm-iterator.cpp index cad4bd50f9..43d262c85e 100644 --- a/engines/sci/sfx/pcm-iterator.cpp +++ b/engines/sci/sfx/pcm-iterator.cpp @@ -50,7 +50,7 @@ static sfx_pcm_feed_t pcm_it_prototype = { pi_destroy, NULL, /* No timestamp getter */ NULL, /* Internal data goes here */ - {0,0,0}, /* Must fill in configuration */ + {0, 0, 0}, /* Must fill in configuration */ "song-iterator", 0, /* Ideally the resource number should go here */ 0 /* The mixer computes this for us */ @@ -59,10 +59,9 @@ static sfx_pcm_feed_t pcm_it_prototype = { sfx_pcm_feed_t * sfx_iterator_make_feed(byte *base_data, - int offset, - int size, - sfx_pcm_config_t conf) -{ + int offset, + int size, + sfx_pcm_config_t conf) { sfx_pcm_feed_t *feed; pcm_data_internal_t *idat; byte *data = base_data + offset; @@ -87,8 +86,7 @@ sfx_iterator_make_feed(byte *base_data, static int -pi_poll(sfx_pcm_feed_t *self, byte *dest, int size) -{ +pi_poll(sfx_pcm_feed_t *self, byte *dest, int size) { int data_len; if (size >= D->frames_left) @@ -100,7 +98,7 @@ pi_poll(sfx_pcm_feed_t *self, byte *dest, int size) memcpy(dest, D->data, data_len); #if 0 -memset(dest, 0xff, data_len); + memset(dest, 0xff, data_len); #endif D->data += data_len; @@ -109,8 +107,7 @@ memset(dest, 0xff, data_len); } static void -pi_destroy(sfx_pcm_feed_t *self) -{ +pi_destroy(sfx_pcm_feed_t *self) { sci_refcount_decref(D->base_data); sci_free(D); sci_free(self); diff --git a/engines/sci/sfx/pcm_device/alsa.cpp b/engines/sci/sfx/pcm_device/alsa.cpp index 26d4c35044..4698d66478 100644 --- a/engines/sci/sfx/pcm_device/alsa.cpp +++ b/engines/sci/sfx/pcm_device/alsa.cpp @@ -44,7 +44,7 @@ static snd_pcm_format_t format = SND_PCM_FORMAT_S16; static unsigned int rate = 44100; /* FIXME */ static unsigned int channels = 2; /* FIXME */ static unsigned int buffer_time = 100000; /* FIXME */ -static unsigned int period_time = 1000000/60; /* 60Hz */ /* FIXME */ +static unsigned int period_time = 1000000 / 60; /* 60Hz */ /* FIXME */ static snd_pcm_sframes_t buffer_size; static snd_pcm_sframes_t period_size; @@ -64,8 +64,7 @@ static volatile byte run_thread; static pthread_mutex_t mutex; static int -xrun_recovery(snd_pcm_t *handle, int err) -{ +xrun_recovery(snd_pcm_t *handle, int err) { if (err == -EPIPE) { /* under-run */ err = snd_pcm_prepare(handle); if (err < 0) @@ -85,8 +84,7 @@ xrun_recovery(snd_pcm_t *handle, int err) } static void * -alsa_thread(void *arg) -{ +alsa_thread(void *arg) { gint16 *ptr; int err, cptr; guint8 *buf; @@ -130,22 +128,20 @@ alsa_thread(void *arg) } static sfx_timestamp_t -pcmout_alsa_output_timestamp(sfx_pcm_device_t *self) -{ +pcmout_alsa_output_timestamp(sfx_pcm_device_t *self) { /* Number of frames enqueued in the output device: */ int delta = (buffer_size - period_size) / frame_size - /* Number of frames enqueued in the internal audio buffer: */ - + audio_buffer.frames_nr; + /* Number of frames enqueued in the internal audio buffer: */ + + audio_buffer.frames_nr; return sfx_timestamp_add(sfx_new_timestamp(last_callback_secs, - last_callback_usecs, - rate), - delta); + last_callback_usecs, + rate), + delta); } static int -pcmout_alsa_init(sfx_pcm_device_t *self) -{ +pcmout_alsa_init(sfx_pcm_device_t *self) { unsigned int rrate; int err, dir; snd_pcm_hw_params_t *hwparams; @@ -195,7 +191,7 @@ pcmout_alsa_init(sfx_pcm_device_t *self) sciprintf("[SND:ALSA] Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err)); return SFX_ERROR; } - err = snd_pcm_hw_params_get_buffer_size(hwparams, (snd_pcm_uframes_t*)&buffer_size); + err = snd_pcm_hw_params_get_buffer_size(hwparams, (snd_pcm_uframes_t*) & buffer_size); if (err < 0) { sciprintf("[SND:ALSA] Unable to get buffer size for playback: %s\n", snd_strerror(err)); return SFX_ERROR; @@ -205,7 +201,7 @@ pcmout_alsa_init(sfx_pcm_device_t *self) sciprintf("[SND:ALSA] Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err)); return SFX_ERROR; } - err = snd_pcm_hw_params_get_period_size(hwparams, (snd_pcm_uframes_t*)&period_size, &dir); + err = snd_pcm_hw_params_get_period_size(hwparams, (snd_pcm_uframes_t*) & period_size, &dir); if (err < 0) { sciprintf("[SND:ALSA] Unable to get period size for playback: %s\n", snd_strerror(err)); return SFX_ERROR; @@ -270,8 +266,7 @@ pcmout_alsa_init(sfx_pcm_device_t *self) static int pcmout_alsa_output(sfx_pcm_device_t *self, byte *buf, - int count, sfx_timestamp_t *ts) -{ + int count, sfx_timestamp_t *ts) { if (ts) sfx_audbuf_write_timestamp(&audio_buffer, *ts); @@ -280,14 +275,12 @@ pcmout_alsa_output(sfx_pcm_device_t *self, byte *buf, } static int -pcmout_alsa_set_option(sfx_pcm_device_t *self, char *name, char *value) -{ +pcmout_alsa_set_option(sfx_pcm_device_t *self, char *name, char *value) { return SFX_ERROR; } static void -pcmout_alsa_exit(sfx_pcm_device_t *self) -{ +pcmout_alsa_exit(sfx_pcm_device_t *self) { int err; run_thread = 0; @@ -310,15 +303,13 @@ pcmout_alsa_exit(sfx_pcm_device_t *self) } static int -timer_alsa_set_option(char *name, char *value) -{ +timer_alsa_set_option(char *name, char *value) { return SFX_ERROR; } static int -timer_alsa_init(void (*callback)(void *data), void *data) -{ +timer_alsa_init(void (*callback)(void *data), void *data) { alsa_sfx_timer_callback = callback; alsa_sfx_timer_data = data; @@ -326,16 +317,14 @@ timer_alsa_init(void (*callback)(void *data), void *data) } static int -timer_alsa_stop(void) -{ +timer_alsa_stop(void) { alsa_sfx_timer_callback = NULL; return SFX_OK; } static int -timer_alsa_block(void) -{ +timer_alsa_block(void) { if (pthread_mutex_lock(&mutex) != 0) { fprintf(stderr, "[SND:ALSA] Failed to lock mutex\n"); return SFX_ERROR; @@ -345,8 +334,7 @@ timer_alsa_block(void) } static int -timer_alsa_unblock(void) -{ +timer_alsa_unblock(void) { if (pthread_mutex_unlock(&mutex) != 0) { fprintf(stderr, "[SND:ALSA] Failed to unlock mutex\n"); return SFX_ERROR; diff --git a/engines/sci/sfx/pcm_device/audbuf_test.cpp b/engines/sci/sfx/pcm_device/audbuf_test.cpp index 216aa9079e..08e8b2ad5e 100644 --- a/engines/sci/sfx/pcm_device/audbuf_test.cpp +++ b/engines/sci/sfx/pcm_device/audbuf_test.cpp @@ -36,12 +36,11 @@ sfx_audio_buf_t buf; void -tester_write(unsigned char *data, int datalen, int framesize, int gran) -{ +tester_write(unsigned char *data, int datalen, int framesize, int gran) { int i; for (i = 0; i < datalen; i += gran) { - int size = (i + gran < datalen)? gran : datalen - i; + int size = (i + gran < datalen) ? gran : datalen - i; sfx_audbuf_write(&buf, data + (i * framesize), framesize, size); } @@ -49,22 +48,21 @@ tester_write(unsigned char *data, int datalen, int framesize, int gran) void -tester_read(unsigned char *data, int datalen, int framesize, int gran) -{ +tester_read(unsigned char *data, int datalen, int framesize, int gran) { unsigned char *readdata = malloc(datalen * framesize); int i; for (i = 0; i < datalen; i += gran) { - int size = (i + gran < datalen)? gran : datalen - i; + int size = (i + gran < datalen) ? gran : datalen - i; int j; sfx_audbuf_read(&buf, readdata + (i * framesize), framesize, size); for (j = 0; j < gran * framesize; j++) { - int offset = i*framesize + j; + int offset = i * framesize + j; if (data[i] != readdata[i]) { fprintf(stderr, "[ERROR] Mismatch at offset %08x (sample #%d): Expected %02x, got %02x\n", - offset, i, readdata[i], data[i]); + offset, i, readdata[i], data[i]); } } } @@ -75,7 +73,7 @@ tester_read(unsigned char *data, int datalen, int framesize, int gran) void test1(unsigned char *data, int len) - /* Test the 'regular' case */ +/* Test the 'regular' case */ { int framesize; int stepsize; @@ -102,7 +100,7 @@ test1(unsigned char *data, int len) void test2(unsigned char *data, int framesize) - /* Test whether buffer underrun repeats are handled correctly */ +/* Test whether buffer underrun repeats are handled correctly */ { int i; unsigned char *src; @@ -123,7 +121,7 @@ test2(unsigned char *data, int framesize) for (j = 0; j < framesize; j++) if (src[j + offset] != data[j]) { fprintf(stderr, "[ERROR] At copy sample %d, frame %d, offset %d: Expected %02x, got %02x\n", - i, inst, j, data[j], src[j+offset]); + i, inst, j, data[j], src[j+offset]); } } memset(src, 0xbf, framesize * TEST2_LEN); @@ -141,21 +139,20 @@ test2(unsigned char *data, int framesize) #define CHUNK_LEN_2 16 #define CHUNK_LEN_3 40 -unsigned char test_data_0[CHUNK_LEN_0] = - { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -unsigned char test_data_1[CHUNK_LEN_1] = - { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0xff, 0x00, 0xff, 0x00}; -unsigned char test_data_2[CHUNK_LEN_2] = - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -unsigned char test_data_3[CHUNK_LEN_3] = - { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88 }; +unsigned char test_data_0[CHUNK_LEN_0] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +unsigned char test_data_1[CHUNK_LEN_1] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, + 0xff, 0x00, 0xff, 0x00 + }; +unsigned char test_data_2[CHUNK_LEN_2] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; +unsigned char test_data_3[CHUNK_LEN_3] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88 + }; struct { int len; @@ -168,8 +165,7 @@ struct { }; int -main(int argc, char **argv) -{ +main(int argc, char **argv) { int i; sfx_audbuf_init(&buf); diff --git a/engines/sci/sfx/pcm_device/audiobuf.cpp b/engines/sci/sfx/pcm_device/audiobuf.cpp index fa23708ce4..15c5bb765b 100644 --- a/engines/sci/sfx/pcm_device/audiobuf.cpp +++ b/engines/sci/sfx/pcm_device/audiobuf.cpp @@ -36,8 +36,7 @@ buffer_underrun_status = NO_BUFFER_UNDERRUN; static sfx_audio_buf_chunk_t * -sfx_audbuf_alloc_chunk(void) -{ +sfx_audbuf_alloc_chunk(void) { sfx_audio_buf_chunk_t *ch = (sfx_audio_buf_chunk_t*)sci_malloc(sizeof(sfx_audio_buf_chunk_t)); ch->used = 0; ch->next = NULL; @@ -47,8 +46,7 @@ sfx_audbuf_alloc_chunk(void) } void -sfx_audbuf_init(sfx_audio_buf_t *buf, sfx_pcm_config_t pcm_conf) -{ +sfx_audbuf_init(sfx_audio_buf_t *buf, sfx_pcm_config_t pcm_conf) { int framesize = SFX_PCM_FRAME_SIZE(pcm_conf); byte silence[16]; int silencew = pcm_conf.format & ~SFX_PCM_FORMAT_LMASK; @@ -81,8 +79,7 @@ sfx_audbuf_init(sfx_audio_buf_t *buf, sfx_pcm_config_t pcm_conf) } static void -sfx_audbuf_free_chain(sfx_audio_buf_chunk_t *b) -{ +sfx_audbuf_free_chain(sfx_audio_buf_chunk_t *b) { while (b) { sfx_audio_buf_chunk_t *n = b->next; sci_free(b); @@ -91,8 +88,7 @@ sfx_audbuf_free_chain(sfx_audio_buf_chunk_t *b) } void -sfx_audbuf_free(sfx_audio_buf_t *buf) -{ +sfx_audbuf_free(sfx_audio_buf_t *buf) { sfx_audbuf_free_chain(buf->first); sfx_audbuf_free_chain(buf->unused); buf->first = buf->last = buf->unused = NULL; @@ -100,8 +96,7 @@ sfx_audbuf_free(sfx_audio_buf_t *buf) } void -sfx_audbuf_write(sfx_audio_buf_t *buf, unsigned char *src, int frames) -{ +sfx_audbuf_write(sfx_audio_buf_t *buf, unsigned char *src, int frames) { /* In here, we compute PER BYTE */ int data_left = buf->framesize * frames; @@ -147,7 +142,7 @@ sfx_audbuf_write(sfx_audio_buf_t *buf, unsigned char *src, int frames) buf->unused = buf_next_unused; } else /* Allocate */ buf->last->next = - sfx_audbuf_alloc_chunk(); + sfx_audbuf_alloc_chunk(); buf->last->prev = old; } @@ -174,13 +169,12 @@ sfx_audbuf_write(sfx_audio_buf_t *buf, unsigned char *src, int frames) #endif if (frames && (src - buf->framesize) != buf->last_frame) - /* Backup last frame, unless we're already filling from it */ + /* Backup last frame, unless we're already filling from it */ memcpy(buf->last_frame, src - buf->framesize, buf->framesize); } int -sfx_audbuf_read(sfx_audio_buf_t *buf, unsigned char *dest, int frames) -{ +sfx_audbuf_read(sfx_audio_buf_t *buf, unsigned char *dest, int frames) { int written = 0; if (frames <= 0) @@ -189,9 +183,9 @@ sfx_audbuf_read(sfx_audio_buf_t *buf, unsigned char *dest, int frames) if (buf->read_timestamp.secs >= 0) { /* Have a timestamp? Must update it! */ buf->read_timestamp = - sfx_timestamp_add(buf->read_timestamp, - frames); - + sfx_timestamp_add(buf->read_timestamp, + frames); + } buf->frames_nr -= frames; @@ -245,9 +239,9 @@ sfx_audbuf_read(sfx_audio_buf_t *buf, unsigned char *dest, int frames) written += rdframes; if (frames && - (!buf->first || buf->read_offset == buf->first->used)) { + (!buf->first || buf->read_offset == buf->first->used)) { fprintf(stderr, "Underrun by %d frames at %d\n", frames, - buf->read_timestamp.frame_rate); + buf->read_timestamp.frame_rate); /* Buffer underrun! */ if (!buffer_underrun_status == NO_BUFFER_UNDERRUN) { buffer_underrun_status = SAW_BUFFER_UNDERRUN; @@ -265,8 +259,7 @@ sfx_audbuf_read(sfx_audio_buf_t *buf, unsigned char *dest, int frames) #if 0 static void -_sfx_audbuf_rewind_stream(sfx_audio_buf_t *buf, int delta) -{ +_sfx_audbuf_rewind_stream(sfx_audio_buf_t *buf, int delta) { if (delta > buf->frames_nr) delta = buf->frames_nr; @@ -296,8 +289,7 @@ _sfx_audbuf_rewind_stream(sfx_audio_buf_t *buf, int delta) #endif void -sfx_audbuf_write_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t ts) -{ +sfx_audbuf_write_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t ts) { sfx_timestamp_t newstamp; newstamp = sfx_timestamp_add(ts, -buf->frames_nr); @@ -308,7 +300,7 @@ sfx_audbuf_write_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t ts) buf->read_timestamp = newstamp; else { int delta = sfx_timestamp_frame_diff(newstamp, buf->read_timestamp); - long s1,s2,s3,u1,u2,u3; + long s1, s2, s3, u1, u2, u3; sfx_timestamp_gettime(&(buf->read_timestamp), &s1, &u1); sfx_timestamp_gettime(&(newstamp), &s2, &u2); sfx_timestamp_gettime(&(ts), &s3, &u3); @@ -322,7 +314,7 @@ sfx_audbuf_write_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t ts) #endif } else if (delta > 0) { fprintf(stderr, "[SFX-BUF] audiobuf.c: Timestamp delta %d at %d: Filling in as silence frames\n", - delta, buf->read_timestamp.frame_rate); + delta, buf->read_timestamp.frame_rate); /* Fill up with silence */ while (delta--) { sfx_audbuf_write(buf, buf->last_frame, 1); @@ -333,8 +325,7 @@ sfx_audbuf_write_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t ts) } int -sfx_audbuf_read_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t *ts) -{ +sfx_audbuf_read_timestamp(sfx_audio_buf_t *buf, sfx_timestamp_t *ts) { if (buf->read_timestamp.secs > 0) { *ts = buf->read_timestamp; return 0; diff --git a/engines/sci/sfx/pcm_device/pcm_devices.cpp b/engines/sci/sfx/pcm_device/pcm_devices.cpp index 09e20bb07b..b8e5b51b39 100644 --- a/engines/sci/sfx/pcm_device/pcm_devices.cpp +++ b/engines/sci/sfx/pcm_device/pcm_devices.cpp @@ -39,16 +39,16 @@ extern sfx_pcm_device_t sfx_pcm_driver_dc; sfx_pcm_device_t *pcmout_drivers[] = { #ifndef NO_PCMOUT #ifdef SCUMMVM - &sfx_pcm_driver_scummvm, + &sfx_pcm_driver_scummvm, #else // SCUMMVM # ifdef HAVE_SDL - &sfx_pcm_driver_sdl, + &sfx_pcm_driver_sdl, # endif # ifdef HAVE_ALSA - &sfx_pcm_driver_alsa, + &sfx_pcm_driver_alsa, # endif # ifdef __DC__ - &sfx_pcm_driver_dc, + &sfx_pcm_driver_dc, # endif #endif // SCUMMVM #endif @@ -56,18 +56,17 @@ sfx_pcm_device_t *pcmout_drivers[] = { }; sfx_pcm_device_t * -sfx_pcm_find_device(char *name) -{ - int retval = 0; +sfx_pcm_find_device(char *name) { + int retval = 0; - if (!name) { /* Find default driver */ - return pcmout_drivers[0]; - } + if (!name) { /* Find default driver */ + return pcmout_drivers[0]; + } - while (pcmout_drivers[retval] && - strcasecmp(name, pcmout_drivers[retval]->name)) - retval++; + while (pcmout_drivers[retval] && + strcasecmp(name, pcmout_drivers[retval]->name)) + retval++; - return pcmout_drivers[retval]; + return pcmout_drivers[retval]; } diff --git a/engines/sci/sfx/pcm_device/scummvm.cpp b/engines/sci/sfx/pcm_device/scummvm.cpp index c66aa0706e..e6bb5f9c25 100644 --- a/engines/sci/sfx/pcm_device/scummvm.cpp +++ b/engines/sci/sfx/pcm_device/scummvm.cpp @@ -33,7 +33,7 @@ static void pcmout_scummvm_exit(sfx_pcm_device_t *self) { } static int pcmout_scummvm_output(sfx_pcm_device_t *self, byte *buf, int count, - sfx_timestamp_t *timestamp) { + sfx_timestamp_t *timestamp) { byte *__buf = new byte[count * pcmout_scummvm_framesize]; @@ -57,4 +57,4 @@ sfx_pcm_device_t sfx_pcm_driver_scummvm = { 0, NULL, NULL - }; +}; diff --git a/engines/sci/sfx/pcm_device/sdl.cpp b/engines/sci/sfx/pcm_device/sdl.cpp index bd125835cb..c4c47ed2a1 100644 --- a/engines/sci/sfx/pcm_device/sdl.cpp +++ b/engines/sci/sfx/pcm_device/sdl.cpp @@ -46,24 +46,22 @@ static long last_callback_secs, last_callback_usecs; static int last_callback_len; static sfx_timestamp_t -pcmout_sdl_output_timestamp(sfx_pcm_device_t *self) -{ +pcmout_sdl_output_timestamp(sfx_pcm_device_t *self) { /* Number of frames enqueued in the output device: */ int delta = (buf_size - last_callback_len) / frame_size - /* Number of frames enqueued in the internal audio buffer: */ - + audio_buffer.frames_nr; + /* Number of frames enqueued in the internal audio buffer: */ + + audio_buffer.frames_nr; return sfx_timestamp_add(sfx_new_timestamp(last_callback_secs, - last_callback_usecs, - rate), - delta); + last_callback_usecs, + rate), + delta); } FILE *fil = NULL; static void -timer_sdl_internal_callback(void *userdata, byte *dest, int len) -{ +timer_sdl_internal_callback(void *userdata, byte *dest, int len) { sci_gettime(&last_callback_secs, &last_callback_usecs); last_callback_len = len; @@ -83,12 +81,12 @@ timer_sdl_internal_callback(void *userdata, byte *dest, int len) deltatime = sfx_timestamp_usecs_diff(ts, real_ts); fprintf(stderr, "[SDL] Frames requested: %d Playing %ld too late. Needed %ldus for computations.\n", - len / frame_size, deltatime, - (usec2-usec) + (sec2-sec)*1000000); + len / frame_size, deltatime, + (usec2 - usec) + (sec2 - sec)*1000000); if (abs(deltatime) > DELTA_TIME_LIMIT) sciprintf("[SND:SDL] Very high delta time for PCM playback: %ld too late (%d frames in the future)\n", - deltatime, sfx_timestamp_frame_diff(sfx_new_timestamp(sec, usec, rate), ts)); + deltatime, sfx_timestamp_frame_diff(sfx_new_timestamp(sec, usec, rate), ts)); #if 0 if (deltatime < 0) { @@ -97,7 +95,7 @@ timer_sdl_internal_callback(void *userdata, byte *dest, int len) int frames_to_kill = sfx_timestamp_frame_diff(real_ts, ts); while (frames_to_kill) { - int d = frames_to_kill > max_read? max_read : frames_to_kill; + int d = frames_to_kill > max_read ? max_read : frames_to_kill; sfx_audbuf_read(&audio_buffer, dest, d); frames_to_kill -= d; } @@ -126,12 +124,11 @@ timer_sdl_internal_callback(void *userdata, byte *dest, int len) static int -pcmout_sdl_init(sfx_pcm_device_t *self) -{ +pcmout_sdl_init(sfx_pcm_device_t *self) { SDL_AudioSpec a; - if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE) != 0) { - fprintf (stderr, "[SND:SDL] Error while initialising: %s\n", SDL_GetError()); + if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE) != 0) { + fprintf(stderr, "[SND:SDL] Error while initialising: %s\n", SDL_GetError()); return -1; } @@ -146,8 +143,8 @@ pcmout_sdl_init(sfx_pcm_device_t *self) a.callback = timer_sdl_internal_callback; a.userdata = NULL; - if (SDL_OpenAudio (&a, NULL) < 0) { - fprintf (stderr, "[SND:SDL] Error while opening audio: %s\n", SDL_GetError()); + if (SDL_OpenAudio(&a, NULL) < 0) { + fprintf(stderr, "[SND:SDL] Error while opening audio: %s\n", SDL_GetError()); return SFX_ERROR; } @@ -162,15 +159,14 @@ pcmout_sdl_init(sfx_pcm_device_t *self) frame_size = SFX_PCM_FRAME_SIZE(self->conf); sfx_audbuf_init(&audio_buffer, self->conf); - SDL_PauseAudio (0); + SDL_PauseAudio(0); return SFX_OK; } int pcmout_sdl_output(sfx_pcm_device_t *self, byte *buf, - int count, sfx_timestamp_t *ts) -{ + int count, sfx_timestamp_t *ts) { if (ts) sfx_audbuf_write_timestamp(&audio_buffer, *ts); sfx_audbuf_write(&audio_buffer, buf, count); @@ -179,15 +175,13 @@ pcmout_sdl_output(sfx_pcm_device_t *self, byte *buf, static int -pcmout_sdl_set_option(sfx_pcm_device_t *self, char *name, char *value) -{ +pcmout_sdl_set_option(sfx_pcm_device_t *self, char *name, char *value) { return SFX_ERROR; /* Option not supported */ } static void -pcmout_sdl_exit(sfx_pcm_device_t *self) -{ - SDL_PauseAudio (1); +pcmout_sdl_exit(sfx_pcm_device_t *self) { + SDL_PauseAudio(1); SDL_CloseAudio(); sfx_audbuf_free(&audio_buffer); @@ -201,15 +195,13 @@ pcmout_sdl_exit(sfx_pcm_device_t *self) static int -timer_sdl_set_option(char *name, char *value) -{ +timer_sdl_set_option(char *name, char *value) { return SFX_ERROR; } static int -timer_sdl_init(void (*callback)(void *data), void *data) -{ +timer_sdl_init(void (*callback)(void *data), void *data) { sdl_sfx_timer_callback = callback; sdl_sfx_timer_data = data; @@ -218,24 +210,21 @@ timer_sdl_init(void (*callback)(void *data), void *data) } static int -timer_sdl_stop(void) -{ +timer_sdl_stop(void) { sdl_sfx_timer_callback = NULL; return SFX_OK; } static int -timer_sdl_block(void) -{ +timer_sdl_block(void) { SDL_LockAudio(); return SFX_OK; } static int -timer_sdl_unblock(void) -{ +timer_sdl_unblock(void) { SDL_UnlockAudio(); return SFX_OK; diff --git a/engines/sci/sfx/player/players.cpp b/engines/sci/sfx/player/players.cpp index eafff46bc3..e4d56c45f3 100644 --- a/engines/sci/sfx/player/players.cpp +++ b/engines/sci/sfx/player/players.cpp @@ -37,8 +37,7 @@ sfx_player_t *sfx_players[] = { }; sfx_player_t * -sfx_find_player(char *name) -{ +sfx_find_player(char *name) { if (!name) { /* Implement platform policy here */ @@ -46,7 +45,7 @@ sfx_find_player(char *name) } else { int n = 0; while (sfx_players[n] && - strcasecmp(sfx_players[n]->name, name)) + strcasecmp(sfx_players[n]->name, name)) ++n; return sfx_players[n]; diff --git a/engines/sci/sfx/player/polled.cpp b/engines/sci/sfx/player/polled.cpp index a5e85ca191..6eb659d494 100644 --- a/engines/sci/sfx/player/polled.cpp +++ b/engines/sci/sfx/player/polled.cpp @@ -47,9 +47,8 @@ static int new_song = 0; static int time_counter = 0; static void -pp_tell_synth(int buf_nr, byte *buf) -{ - seq->handle_command(seq, buf[0], buf_nr-1, buf+1); +pp_tell_synth(int buf_nr, byte *buf) { + seq->handle_command(seq, buf[0], buf_nr - 1, buf + 1); } @@ -57,8 +56,7 @@ pp_tell_synth(int buf_nr, byte *buf) /* Mixer implementation */ /*----------------------*/ int -ppf_poll(sfx_pcm_feed_t *self, byte *dest, int size) -{ +ppf_poll(sfx_pcm_feed_t *self, byte *dest, int size) { int written = 0; byte buf[4]; int buf_nr; @@ -75,10 +73,10 @@ ppf_poll(sfx_pcm_feed_t *self, byte *dest, int size) while (time_counter <= TIME_INC) { int next_stat = songit_next(&play_it, - &(buf[0]), &buf_nr, - IT_READER_MASK_ALL - | IT_READER_MAY_FREE - | IT_READER_MAY_CLEAN); + &(buf[0]), &buf_nr, + IT_READER_MASK_ALL + | IT_READER_MAY_FREE + | IT_READER_MAY_CLEAN); switch (next_stat) { case SI_PCM: @@ -97,8 +95,8 @@ ppf_poll(sfx_pcm_feed_t *self, byte *dest, int size) break; /* Boooring... .*/ case 0: /* MIDI command */ - - seq->handle_command(seq, buf[0], buf_nr - 1, buf+1); + + seq->handle_command(seq, buf[0], buf_nr - 1, buf + 1); break; default: @@ -107,7 +105,7 @@ ppf_poll(sfx_pcm_feed_t *self, byte *dest, int size) } can_play = time_counter / TIME_INC; - do_play = (can_play > (size - written))? (size - written) : can_play; + do_play = (can_play > (size - written)) ? (size - written) : can_play; time_counter -= do_play * TIME_INC; @@ -119,14 +117,12 @@ ppf_poll(sfx_pcm_feed_t *self, byte *dest, int size) } void -ppf_destroy(sfx_pcm_feed_t *self) -{ +ppf_destroy(sfx_pcm_feed_t *self) { /* no-op */ } int -ppf_get_timestamp(sfx_pcm_feed_t *self, sfx_timestamp_t *timestamp) -{ +ppf_get_timestamp(sfx_pcm_feed_t *self, sfx_timestamp_t *timestamp) { if (!new_song) return PCM_FEED_IDLE; @@ -160,20 +156,17 @@ sfx_pcm_feed_t pcmfeed = { /*--------------------*/ static void -pp_timer_callback(void) -{ +pp_timer_callback(void) { /* Hey, we're polled anyway ;-) */ } static int -pp_set_option(char *name, char *value) -{ +pp_set_option(char *name, char *value) { return SFX_ERROR; } static int -pp_init(resource_mgr_t *resmgr, int expected_latency) -{ +pp_init(resource_mgr_t *resmgr, int expected_latency) { resource_t *res = NULL, *res2 = NULL; int fd; @@ -204,12 +197,12 @@ pp_init(resource_mgr_t *resmgr, int expected_latency) } if (seq->init(seq, - (res)? res->data : NULL, - (res)? res->size : 0, - (res2)? res2->data : NULL, - (res2)? res2->size : 0)) { + (res) ? res->data : NULL, + (res) ? res->size : 0, + (res2) ? res2->data : NULL, + (res2) ? res2->size : 0)) { sciprintf("[sfx:seq:polled] Initialisation failed: Sequencer '%s', v%s failed to initialise\n", - seq->name, seq->version); + seq->name, seq->version); return SFX_ERROR; } @@ -223,8 +216,7 @@ pp_init(resource_mgr_t *resmgr, int expected_latency) } static int -pp_add_iterator(song_iterator_t *it, GTimeVal start_time) -{ +pp_add_iterator(song_iterator_t *it, GTimeVal start_time) { song_iterator_t *old = play_it; SIMSG_SEND(it, SIMSG_SET_PLAYMASK(seq->playmask)); @@ -241,8 +233,8 @@ pp_add_iterator(song_iterator_t *it, GTimeVal start_time) function, to avoid a race condition with the mixer. */ if (old == NULL) { new_timestamp = sfx_new_timestamp(start_time.tv_sec, - start_time.tv_usec, - seq->pcm_conf.rate); + start_time.tv_usec, + seq->pcm_conf.rate); /* ASAP otherwise */ time_counter = 0; new_song = 1; @@ -252,19 +244,17 @@ pp_add_iterator(song_iterator_t *it, GTimeVal start_time) } static int -pp_fade_out(void) -{ +pp_fade_out(void) { fprintf(stderr, __FILE__": Attempt to fade out- not implemented yet\n"); return SFX_ERROR; } static int -pp_stop(void) -{ +pp_stop(void) { song_iterator_t *it = play_it; play_it = NULL; -fprintf(stderr, "[play] Now stopping it %p\n", (void *)it); + fprintf(stderr, "[play] Now stopping it %p\n", (void *)it); if (it) songit_free(it); @@ -274,8 +264,7 @@ fprintf(stderr, "[play] Now stopping it %p\n", (void *)it); } static int -pp_send_iterator_message(song_iterator_message_t msg) -{ +pp_send_iterator_message(song_iterator_message_t msg) { if (!play_it) return SFX_ERROR; @@ -284,8 +273,7 @@ pp_send_iterator_message(song_iterator_message_t msg) } static int -pp_pause(void) -{ +pp_pause(void) { play_paused = 1; seq->set_volume(seq, 0); @@ -293,10 +281,8 @@ pp_pause(void) } static int -pp_resume(void) -{ - if (!play_it) - { +pp_resume(void) { + if (!play_it) { play_paused = 0; return SFX_OK; /* Nothing to resume */ } @@ -312,8 +298,7 @@ pp_resume(void) } static int -pp_exit(void) -{ +pp_exit(void) { seq->exit(seq); songit_free(play_it); play_it = NULL; diff --git a/engines/sci/sfx/player/realtime.cpp b/engines/sci/sfx/player/realtime.cpp index a88056162c..3819a56642 100644 --- a/engines/sci/sfx/player/realtime.cpp +++ b/engines/sci/sfx/player/realtime.cpp @@ -38,16 +38,14 @@ extern sfx_player_t sfx_player_realtime; /* Playing mechanism */ static inline GTimeVal -current_time(void) -{ +current_time(void) { GTimeVal tv; sci_get_current_time(&tv); return tv; } static inline GTimeVal -add_time_delta(GTimeVal tv, long delta) -{ +add_time_delta(GTimeVal tv, long delta) { int sec_d; tv.tv_usec += delta; @@ -60,12 +58,11 @@ add_time_delta(GTimeVal tv, long delta) } static inline long -delta_time(GTimeVal comp_tv, GTimeVal base) -{ +delta_time(GTimeVal comp_tv, GTimeVal base) { GTimeVal tv; sci_get_current_time(&tv); return (comp_tv.tv_sec - tv.tv_sec) * 1000000 - + (comp_tv.tv_usec - tv.tv_usec); + + (comp_tv.tv_usec - tv.tv_usec); } static song_iterator_t *play_it = NULL; @@ -79,8 +76,7 @@ static int play_writeahead = 0; static int play_moredelay = 0; static void -play_song(song_iterator_t *it, GTimeVal *wakeup_time, int writeahead_time) -{ +play_song(song_iterator_t *it, GTimeVal *wakeup_time, int writeahead_time) { unsigned char buf[8]; int result; @@ -89,57 +85,55 @@ play_song(song_iterator_t *it, GTimeVal *wakeup_time, int writeahead_time) sci_get_current_time(&ct); *wakeup_time = - add_time_delta(*wakeup_time, delta_time(play_pause_counter, ct)); + add_time_delta(*wakeup_time, delta_time(play_pause_counter, ct)); play_pause_counter = ct; } else - /* Not paused: */ - while (play_it && delta_time(*wakeup_time, current_time()) - < writeahead_time) { - int delay; - - switch ((delay = songit_next(&(play_it), - &(buf[0]), &result, - IT_READER_MASK_ALL - | IT_READER_MAY_FREE - | IT_READER_MAY_CLEAN))) { - - case SI_FINISHED: - play_it_done = 1; - return; - - case SI_IGNORE: - case SI_LOOP: - case SI_RELATIVE_CUE: - case SI_ABSOLUTE_CUE: - break; - - case SI_PCM: - sfx_play_iterator_pcm(play_it, 0); - break; - - case 0: - seq->event(buf[0], result-1, buf+1); - - break; - - default: - play_moredelay = delay - 1; - *wakeup_time = song_next_wakeup_time(wakeup_time, delay); - if (seq->delay) - seq->delay(delay); + /* Not paused: */ + while (play_it && delta_time(*wakeup_time, current_time()) + < writeahead_time) { + int delay; + + switch ((delay = songit_next(&(play_it), + &(buf[0]), &result, + IT_READER_MASK_ALL + | IT_READER_MAY_FREE + | IT_READER_MAY_CLEAN))) { + + case SI_FINISHED: + play_it_done = 1; + return; + + case SI_IGNORE: + case SI_LOOP: + case SI_RELATIVE_CUE: + case SI_ABSOLUTE_CUE: + break; + + case SI_PCM: + sfx_play_iterator_pcm(play_it, 0); + break; + + case 0: + seq->event(buf[0], result - 1, buf + 1); + + break; + + default: + play_moredelay = delay - 1; + *wakeup_time = song_next_wakeup_time(wakeup_time, delay); + if (seq->delay) + seq->delay(delay); + } } - } } static void -rt_tell_synth(int buf_nr, byte *buf) -{ - seq->event(buf[0], buf_nr-1, buf+1); +rt_tell_synth(int buf_nr, byte *buf) { + seq->event(buf[0], buf_nr - 1, buf + 1); } static void -rt_timer_callback(void) -{ +rt_timer_callback(void) { if (play_it && !play_it_done) { if (!play_moredelay) { long delta = delta_time(play_last_time, current_time()); @@ -159,15 +153,14 @@ rt_timer_callback(void) } static resource_t * -find_patch(resource_mgr_t *resmgr, const char *seq_name, int patchfile) -{ +find_patch(resource_mgr_t *resmgr, const char *seq_name, int patchfile) { resource_t *res = NULL; if (patchfile != SFX_SEQ_PATCHFILE_NONE) { res = scir_find_resource(resmgr, sci_patch, patchfile, 0); if (!res) { fprintf(stderr, "[SFX] " __FILE__": patch.%03d requested by sequencer (%s), but not found\n", - patchfile, seq_name); + patchfile, seq_name); } } @@ -177,17 +170,15 @@ find_patch(resource_mgr_t *resmgr, const char *seq_name, int patchfile) /* API implementation */ static int -rt_set_option(char *name, char *value) -{ +rt_set_option(char *name, char *value) { return SFX_ERROR; } static int -rt_init(resource_mgr_t *resmgr, int expected_latency) -{ +rt_init(resource_mgr_t *resmgr, int expected_latency) { resource_t *res = NULL, *res2 = NULL; void *seq_dev = NULL; - GTimeVal foo = {0,0}; + GTimeVal foo = {0, 0}; seq = sfx_find_sequencer(NULL); @@ -204,11 +195,11 @@ rt_init(resource_mgr_t *resmgr, int expected_latency) if (seq->device) seq_dev = sfx_find_device(seq->device, NULL); - if (seq->open(res? res->size : 0, - res? res->data : NULL, - res2? res2->size : 0, - res2? res2->data : NULL, - seq_dev)) { + if (seq->open(res ? res->size : 0, + res ? res->data : NULL, + res2 ? res2->size : 0, + res2 ? res2->data : NULL, + seq_dev)) { fprintf(stderr, "[SFX] " __FILE__": Sequencer failed to initialize\n"); return SFX_ERROR; } @@ -226,8 +217,7 @@ rt_init(resource_mgr_t *resmgr, int expected_latency) } static int -rt_add_iterator(song_iterator_t *it, GTimeVal start_time) -{ +rt_add_iterator(song_iterator_t *it, GTimeVal start_time) { if (seq->reset_timer) /* Restart timer counting if possible */ seq->reset_timer(start_time); @@ -243,15 +233,13 @@ rt_add_iterator(song_iterator_t *it, GTimeVal start_time) } static int -rt_fade_out(void) -{ +rt_fade_out(void) { fprintf(stderr, __FILE__": Attempt to fade out- not implemented yet\n"); return SFX_ERROR; } static int -rt_stop(void) -{ +rt_stop(void) { song_iterator_t *it = play_it; play_it = NULL; @@ -265,8 +253,7 @@ rt_stop(void) } static int -rt_send_iterator_message(song_iterator_message_t msg) -{ +rt_send_iterator_message(song_iterator_message_t msg) { if (!play_it) return SFX_ERROR; @@ -275,8 +262,7 @@ rt_send_iterator_message(song_iterator_message_t msg) } static int -rt_pause(void) -{ +rt_pause(void) { sci_get_current_time(&play_pause_started); /* Also, indicate that we haven't modified the time counter ** yet */ @@ -291,18 +277,16 @@ rt_pause(void) } static int -rt_resume(void) -{ +rt_resume(void) { play_paused = 0; return SFX_OK; } static int -rt_exit(void) -{ +rt_exit(void) { int retval = SFX_OK; - if(seq->close()) { + if (seq->close()) { fprintf(stderr, "[SFX] Sequencer reported error on close\n"); retval = SFX_ERROR; } diff --git a/engines/sci/sfx/seq/gm.cpp b/engines/sci/sfx/seq/gm.cpp index 4889e76ea8..ecd459236d 100644 --- a/engines/sci/sfx/seq/gm.cpp +++ b/engines/sci/sfx/seq/gm.cpp @@ -40,8 +40,7 @@ static midi_writer_t *writer = NULL; static int -midi_gm_open(int patch_len, byte *data, int patch2_len, byte *data2, void *device) -{ +midi_gm_open(int patch_len, byte *data, int patch2_len, byte *data2, void *device) { sfx_instrument_map_t *instrument_map = sfx_instrument_map_load_sci(data, patch_len); if (!instrument_map) { @@ -61,17 +60,15 @@ midi_gm_open(int patch_len, byte *data, int patch2_len, byte *data2, void *devic } static int -midi_gm_close(void) -{ +midi_gm_close(void) { return SFX_OK; } static int -midi_gm_event(byte command, int argc, byte *argv) -{ +midi_gm_event(byte command, int argc, byte *argv) { byte data[4]; - assert (argc < 4); + assert(argc < 4); data[0] = command; memcpy(data + 1, argv, argc); @@ -81,16 +78,14 @@ midi_gm_event(byte command, int argc, byte *argv) } static int -midi_gm_delay(int ticks) -{ +midi_gm_delay(int ticks) { writer->delay(writer, ticks); return SFX_OK; } static int -midi_gm_reset_timer(GTimeVal ts) -{ +midi_gm_reset_timer(GTimeVal ts) { writer->reset_timer(writer); return SFX_OK; @@ -99,8 +94,7 @@ midi_gm_reset_timer(GTimeVal ts) #define MIDI_MASTER_VOLUME_LEN 8 static int -midi_gm_volume(guint8 volume) -{ +midi_gm_volume(guint8 volume) { byte data[MIDI_MASTER_VOLUME_LEN] = { 0xf0, 0x7f, @@ -109,7 +103,8 @@ midi_gm_volume(guint8 volume) 0x01, volume, volume, - 0xf7}; + 0xf7 + }; writer->write(writer, data, MIDI_MASTER_VOLUME_LEN); if (writer->flush) @@ -119,11 +114,11 @@ midi_gm_volume(guint8 volume) } static int -midi_gm_allstop(void) -{ +midi_gm_allstop(void) { byte data[3] = { 0xb0, - 0x78, /* all sound off */ - 0 }; + 0x78, /* all sound off */ + 0 + }; int i; /* All sound off on all channels */ @@ -138,11 +133,11 @@ midi_gm_allstop(void) } static int -midi_gm_reverb(int reverb) -{ +midi_gm_reverb(int reverb) { byte data[3] = { 0xb0, - 91, /* set reverb */ - reverb }; + 91, /* set reverb */ + reverb + }; int i; /* Set reverb on all channels */ @@ -158,8 +153,7 @@ midi_gm_reverb(int reverb) } static int -midi_gm_set_option(char *x, char *y) -{ +midi_gm_set_option(char *x, char *y) { return SFX_ERROR; } diff --git a/engines/sci/sfx/seq/instrument-map.cpp b/engines/sci/sfx/seq/instrument-map.cpp index 204ecfdc34..65bab7a32f 100644 --- a/engines/sci/sfx/seq/instrument-map.cpp +++ b/engines/sci/sfx/seq/instrument-map.cpp @@ -32,9 +32,8 @@ #include "sfx_engine.h" sfx_instrument_map_t * -sfx_instrument_map_new(int velocity_maps_nr) -{ - sfx_instrument_map_t *map = (sfx_instrument_map_t *)sci_malloc(sizeof (sfx_instrument_map_t)); +sfx_instrument_map_new(int velocity_maps_nr) { + sfx_instrument_map_t *map = (sfx_instrument_map_t *)sci_malloc(sizeof(sfx_instrument_map_t)); int i; map->initialisation_block_size = 0; @@ -47,7 +46,7 @@ sfx_instrument_map_new(int velocity_maps_nr) map->velocity_map = NULL; /* Yes, this complicates control flow needlessly, but it avoids some of the pointless ** warnings that certain memory tools seem to find appropriate. */ else { - map->velocity_map = (byte **)sci_malloc(sizeof (byte *) * velocity_maps_nr); + map->velocity_map = (byte **)sci_malloc(sizeof(byte *) * velocity_maps_nr); for (i = 0; i < velocity_maps_nr; ++i) map->velocity_map[i] = (byte *)sci_malloc(SFX_VELOCITIES_NR); } @@ -56,7 +55,7 @@ sfx_instrument_map_new(int velocity_maps_nr) map->percussion_volume_adjust = 0; for (i = 0; i < SFX_RHYTHM_NR; ++i) - map->percussion_map[i] = i; + map->percussion_map[i] = i; for (i = 0; i < SFX_INSTRUMENTS_NR; ++i) { @@ -69,8 +68,7 @@ sfx_instrument_map_new(int velocity_maps_nr) } void -sfx_instrument_map_free(sfx_instrument_map_t *map) -{ +sfx_instrument_map_free(sfx_instrument_map_t *map) { if (!map) return; @@ -106,21 +104,20 @@ sfx_instrument_map_free(sfx_instrument_map_t *map) static int -patch001_type0_length(byte *data, size_t length) -{ +patch001_type0_length(byte *data, size_t length) { unsigned int pos = 492 + 246 * data[491]; -/* printf("timbres %d (post = %04x)\n",data[491], pos);*/ + /* printf("timbres %d (post = %04x)\n",data[491], pos);*/ if ((length >= (pos + 386)) && (data[pos] == 0xAB) && (data[pos + 1] == 0xCD)) pos += 386; -/* printf("pos = %04x (%02x %02x)\n", pos, data[pos], data[pos + 1]); */ + /* printf("pos = %04x (%02x %02x)\n", pos, data[pos], data[pos + 1]); */ if ((length >= (pos + 267)) && (data[pos] == 0xDC) && (data[pos + 1] == 0xBA)) pos += 267; -/* printf("pos = %04x %04x (%d)\n", pos, length, pos-length); */ + /* printf("pos = %04x %04x (%d)\n", pos, length, pos-length); */ if (pos == length) @@ -129,34 +126,31 @@ patch001_type0_length(byte *data, size_t length) } static int -patch001_type1_length(byte *data, size_t length) -{ +patch001_type1_length(byte *data, size_t length) { if ((length >= 1155) && (((data[1154] << 8) + data[1153] + 1155) == length)) return 1; return 0; } int -sfx_instrument_map_detect(byte *data, size_t length) -{ +sfx_instrument_map_detect(byte *data, size_t length) { /* length test */ if (length < 1155) return SFX_MAP_MT32; if (length > 16889) return SFX_MAP_MT32_GM; if (patch001_type0_length(data, length) && - !patch001_type1_length(data, length)) + !patch001_type1_length(data, length)) return SFX_MAP_MT32; if (patch001_type1_length(data, length) && - !patch001_type0_length(data, length)) + !patch001_type0_length(data, length)) return SFX_MAP_MT32_GM; return SFX_MAP_UNKNOWN; } sfx_instrument_map_t * -sfx_instrument_map_load_sci(byte *data, size_t size) -{ +sfx_instrument_map_load_sci(byte *data, size_t size) { sfx_instrument_map_t * map; int i, m; @@ -230,45 +224,39 @@ typedef struct decorated_midi_writer { static void -init_decorated(struct _midi_writer *self_) -{ +init_decorated(struct _midi_writer *self_) { decorated_midi_writer_t *self = (decorated_midi_writer_t *) self_; self->writer->init(self->writer); } static void -set_option_decorated(struct _midi_writer *self_, char *name, char *value) -{ +set_option_decorated(struct _midi_writer *self_, char *name, char *value) { decorated_midi_writer_t *self = (decorated_midi_writer_t *) self_; self->writer->set_option(self->writer, name, value); } static void -delay_decorated(struct _midi_writer *self_, int ticks) -{ +delay_decorated(struct _midi_writer *self_, int ticks) { decorated_midi_writer_t *self = (decorated_midi_writer_t *) self_; self->writer->delay(self->writer, ticks); } static void -flush_decorated(struct _midi_writer *self_) -{ +flush_decorated(struct _midi_writer *self_) { decorated_midi_writer_t *self = (decorated_midi_writer_t *) self_; if (self->writer->flush) self->writer->flush(self->writer); } static void -reset_timer_decorated(struct _midi_writer *self_) -{ +reset_timer_decorated(struct _midi_writer *self_) { decorated_midi_writer_t *self = (decorated_midi_writer_t *) self_; self->writer->reset_timer(self->writer); } static void -close_decorated(decorated_midi_writer_t *self) -{ +close_decorated(decorated_midi_writer_t *self) { sfx_instrument_map_free(self->map); self->map = NULL; self->writer->close(self->writer); @@ -280,8 +268,7 @@ close_decorated(decorated_midi_writer_t *self) #define BOUND_127(x) (((x) < 0)? 0 : (((x) > 0x7f)? 0x7f : (x))) static int -bound_hard_127(int i, const char *descr) -{ +bound_hard_127(int i, const char *descr) { int r = BOUND_127(i); if (r != i) fprintf(stderr, "[instrument-map] Hard-clipping %02x to %02x in %s\n", i, r, descr); @@ -289,8 +276,7 @@ bound_hard_127(int i, const char *descr) } static int -set_bend_range(midi_writer_t *writer, int channel, int range) -{ +set_bend_range(midi_writer_t *writer, int channel, int range) { byte buf[3] = {0xb0, 0x65, 0x00}; buf[0] |= channel & 0xf; @@ -315,18 +301,18 @@ set_bend_range(midi_writer_t *writer, int channel, int range) } static int -write_decorated(decorated_midi_writer_t *self, byte *buf, int len) -{ +write_decorated(decorated_midi_writer_t *self, byte *buf, int len) { sfx_instrument_map_t *map = self->map; int op = *buf & 0xf0; int chan = *buf & 0x0f; int patch = self->patches[chan].patch; int rhythm = self->patches[chan].rhythm; - assert (len >= 1); + assert(len >= 1); if (op == 0xC0 && chan != MIDI_RHYTHM_CHANNEL) { /* Program change */ - /*int*/ patch = bound_hard_127(buf[1], "program change"); + /*int*/ + patch = bound_hard_127(buf[1], "program change"); int instrument = map->patch_map[patch].patch; int bend_range = map->patch_bend_range[patch]; @@ -335,7 +321,7 @@ write_decorated(decorated_midi_writer_t *self, byte *buf, int len) if (instrument == SFX_UNMAPPED || instrument == SFX_MAPPED_TO_RHYTHM) return SFX_OK; - assert (len >= 2); + assert(len >= 2); buf[1] = bound_hard_127(instrument, "patch lookup"); if (self->writer->write(self->writer, buf, len) != SFX_OK) @@ -367,7 +353,7 @@ write_decorated(decorated_midi_writer_t *self, byte *buf, int len) if (instrument == SFX_UNMAPPED) return SFX_OK; - assert (len >= 3); + assert(len >= 3); velocity = bound_hard_127(buf[2], "rhythm velocity"); velocity_map_index = map->percussion_velocity_map_index; @@ -384,13 +370,14 @@ write_decorated(decorated_midi_writer_t *self, byte *buf, int len) } case 0xB0: { /* Controller change */ - assert (len >= 3); + assert(len >= 3); if (buf[1] == 0x7) /* Volume change */ buf[2] = BOUND_127(buf[2] + map->percussion_volume_adjust); break; } - default: break; + default: + break; } } else { @@ -405,7 +392,7 @@ write_decorated(decorated_midi_writer_t *self, byte *buf, int len) int note = bound_hard_127(buf[1], "note"); int velocity = bound_hard_127(buf[2], "velocity"); int velocity_map_index = map->velocity_map_index[patch]; - assert (len >= 3); + assert(len >= 3); note += map->patch_key_shift[patch]; /* Not the most efficient solutions, but the least error-prone */ @@ -423,12 +410,13 @@ write_decorated(decorated_midi_writer_t *self, byte *buf, int len) } case 0xB0: /* Controller change */ - assert (len >= 3); + assert(len >= 3); if (buf[1] == 0x7) /* Volume change */ buf[2] = BOUND_127(buf[2] + map->patch_volume_adjust[patch]); break; - default: break; + default: + break; } } @@ -439,8 +427,7 @@ write_decorated(decorated_midi_writer_t *self, byte *buf, int len) #define MAX_PER_TICK (MIDI_BYTES_PER_SECOND / 60) /* After this, we ought to issue one tick of pause */ static void -init(midi_writer_t *writer, byte *data, size_t len) -{ +init(midi_writer_t *writer, byte *data, size_t len) { int offset = 0; byte status = 0; @@ -479,13 +466,13 @@ init(midi_writer_t *writer, byte *data, size_t len) msg[0] = op; switch (op & 0xf0) { - case 0xc0: - case 0xd0: - args = 1; - break; - default: - args = 2; - } + case 0xc0: + case 0xd0: + args = 1; + break; + default: + args = 2; + } if (args > len - offset) { fprintf(stderr, "[instrument-map] Insufficient bytes remaining for MIDI command %02x\n", op); @@ -506,8 +493,7 @@ init(midi_writer_t *writer, byte *data, size_t len) #define NAME_SUFFIX "+instruments" midi_writer_t * -sfx_mapped_writer(midi_writer_t *writer, sfx_instrument_map_t *map) -{ +sfx_mapped_writer(midi_writer_t *writer, sfx_instrument_map_t *map) { int i; decorated_midi_writer_t *retval; diff --git a/engines/sci/sfx/seq/map-mt32-to-gm.cpp b/engines/sci/sfx/seq/map-mt32-to-gm.cpp index b4c56f2602..d51e2a3391 100644 --- a/engines/sci/sfx/seq/map-mt32-to-gm.cpp +++ b/engines/sci/sfx/seq/map-mt32-to-gm.cpp @@ -176,7 +176,7 @@ static const char /*10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*30*/ 0, 0, 0, 0, -/* The preceeding percussions are not covered by the GM standard */ + /* The preceeding percussions are not covered by the GM standard */ /*34*/ "Acoustic Bass Drum", /*35*/ "Bass Drum 1", /*36*/ "Side Stick", @@ -566,8 +566,7 @@ static struct { }; static gint8 -lookup_instrument(const char *iname) -{ +lookup_instrument(const char *iname) { int i = 0; while (MT32_MemoryTimbreMaps[i].name) { @@ -579,8 +578,7 @@ lookup_instrument(const char *iname) } static gint8 -lookup_rhythm_key(const char *iname) -{ +lookup_rhythm_key(const char *iname) { int i = 0; while (MT32_MemoryTimbreMaps[i].name) { @@ -592,31 +590,29 @@ lookup_rhythm_key(const char *iname) } static void -print_map(int sci, int ins, int rhythm, int mt32) -{ +print_map(int sci, int ins, int rhythm, int mt32) { #ifdef DEBUG_MT32_TO_GM if (ins == SFX_UNMAPPED || (ins == SFX_MAPPED_TO_RHYTHM && rhythm == SFX_UNMAPPED)) { sciprintf("[MT32-to-GM] No mapping available for [%i] `%s' (%i)\n", - sci, MT32_PresetTimbreMaps[mt32].name, mt32); + sci, MT32_PresetTimbreMaps[mt32].name, mt32); return; } if (ins == SFX_MAPPED_TO_RHYTHM) { sciprintf("[MT32-to-GM] Mapping [%i] `%s' (%i) to `%s' [R] (%i)\n", - sci, MT32_PresetTimbreMaps[mt32].name, mt32, - GM_Percussion_Names[rhythm], rhythm); + sci, MT32_PresetTimbreMaps[mt32].name, mt32, + GM_Percussion_Names[rhythm], rhythm); return; } sciprintf("[MT32-to-GM] Mapping [%i] `%s' (%i) to `%s' (%i)\n", - sci, MT32_PresetTimbreMaps[mt32].name, mt32, - GM_Instrument_Names[ins], ins); + sci, MT32_PresetTimbreMaps[mt32].name, mt32, + GM_Instrument_Names[ins], ins); #endif } static void -print_map_mem(int sci, int ins, int rhythm, char *mt32) -{ +print_map_mem(int sci, int ins, int rhythm, char *mt32) { #ifdef DEBUG_MT32_TO_GM char name[11]; @@ -625,47 +621,45 @@ print_map_mem(int sci, int ins, int rhythm, char *mt32) if (ins == SFX_UNMAPPED || (ins == SFX_MAPPED_TO_RHYTHM && rhythm == SFX_UNMAPPED)) { sciprintf("[MT32-to-GM] No mapping available for [%i] `%s'\n", - sci, name); + sci, name); return; } if (ins == SFX_MAPPED_TO_RHYTHM) { sciprintf("[MT32-to-GM] Mapping [%i] `%s' to `%s' [R] (%i)\n", - sci, name, GM_Percussion_Names[rhythm], rhythm); + sci, name, GM_Percussion_Names[rhythm], rhythm); return; } sciprintf("[MT32-to-GM] Mapping [%i] `%s' to `%s' (%i)\n", - sci, name, GM_Instrument_Names[ins], ins); + sci, name, GM_Instrument_Names[ins], ins); #endif } static void -print_map_rhythm(int sci, int ins, int rhythm, int mt32) -{ +print_map_rhythm(int sci, int ins, int rhythm, int mt32) { #ifdef DEBUG_MT32_TO_GM if (ins == SFX_UNMAPPED || (ins == SFX_MAPPED_TO_RHYTHM && rhythm == SFX_UNMAPPED)) { sciprintf("[MT32-to-GM] No mapping available for [%i] `%s' [R] (%i)\n", - sci, MT32_RhythmTimbreMaps[mt32].name, mt32); + sci, MT32_RhythmTimbreMaps[mt32].name, mt32); return; } if (ins == SFX_MAPPED_TO_RHYTHM) { sciprintf("[MT32-to-GM] Mapping [%i] `%s' [R] (%i) to `%s' [R] (%i)\n", - sci, MT32_RhythmTimbreMaps[mt32].name, mt32, - GM_Percussion_Names[rhythm], rhythm); + sci, MT32_RhythmTimbreMaps[mt32].name, mt32, + GM_Percussion_Names[rhythm], rhythm); return; } sciprintf("[MT32-to-GM] Mapping [%i] `%s' [R] (%i) to `%s' (%i)\n", - sci, MT32_RhythmTimbreMaps[mt32].name, mt32, - GM_Instrument_Names[ins], ins); + sci, MT32_RhythmTimbreMaps[mt32].name, mt32, + GM_Instrument_Names[ins], ins); #endif } static void -print_map_rhythm_mem(int sci, int rhythm, char *mt32) -{ +print_map_rhythm_mem(int sci, int rhythm, char *mt32) { #ifdef DEBUG_MT32_TO_GM char name[11]; @@ -674,18 +668,17 @@ print_map_rhythm_mem(int sci, int rhythm, char *mt32) if (rhythm == SFX_UNMAPPED) { sciprintf("[MT32-to-GM] No mapping available for [%i] `%s'\n", - sci, name); + sci, name); return; } sciprintf("[MT32-to-GM] Mapping [%i] `%s' to `%s' (%i)\n", - sci, name, GM_Percussion_Names[rhythm], rhythm); + sci, name, GM_Percussion_Names[rhythm], rhythm); #endif } sfx_instrument_map_t * -sfx_instrument_map_mt32_to_gm(byte *data, size_t size) -{ +sfx_instrument_map_mt32_to_gm(byte *data, size_t size) { int memtimbres, patches; guint8 group, number, keyshift, finetune, bender_range; guint8 *patchpointer; @@ -731,7 +724,7 @@ sfx_instrument_map_mt32_to_gm(byte *data, size_t size) memtimbres = *(data + 0x1EB); pos = 0x1EC + memtimbres * 0xF6; - if (size > pos && ((0x100 * *(data + pos) + *(data +pos + 1)) == 0xABCD)) { + if (size > pos && ((0x100 * *(data + pos) + *(data + pos + 1)) == 0xABCD)) { patches = 96; pos += 2 + 8 * 48; } else diff --git a/engines/sci/sfx/seq/mt32.cpp b/engines/sci/sfx/seq/mt32.cpp index de478cf4f6..0633d8b66b 100644 --- a/engines/sci/sfx/seq/mt32.cpp +++ b/engines/sci/sfx/seq/mt32.cpp @@ -40,7 +40,7 @@ static midi_writer_t *midi_writer = NULL; static int midi_mt32_poke(guint32 address, guint8 *data, unsigned int n); static int midi_mt32_poke_gather(guint32 address, guint8 *data1, unsigned int count1, - guint8 *data2, unsigned int count2); + guint8 *data2, unsigned int count2); static int midi_mt32_write_block(guint8 *data, unsigned int count); static int midi_mt32_sysex_delay(void); static int midi_mt32_volume(guint8 volume); @@ -59,26 +59,27 @@ static int mt32_init_delay = 0; /* Used to count the number of ticks (1/60s of a /* timbre, volume, panpot, reverb. keys 24-87 (64 keys)*/ static guint8 default_rhythm_keymap[256] = { /* MT-32 default */ - 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, /* 24-27 */ - 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, - 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x40,0x64,7,1, - 0x40,0x64,7,1, 0x4a,0x64,6,1, 0x41,0x64,7,1, 0x4b,0x64,8,1, - 0x45,0x64,6,1, 0x44,0x64,11,1, 0x46,0x64,6,1, 0x44,0x64,11,1, - 0x5d,0x64,6,1, 0x43,0x64,8,1, 0x47,0x64,6,1, 0x43,0x64,8,1, - 0x42,0x64,3,1, 0x48,0x64,6,1, 0x42,0x64,3,1, 0x49,0x64,8,1, - 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x56,0x64,9,1, 0x7f,0x64,7,1, - 0x4c,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, - 0x52,0x64,2,1, 0x53,0x64,4,1, 0x4d,0x64,8,1, 0x4e,0x64,9,1, - 0x4f,0x64,10,1, 0x50,0x64,7,1, 0x51,0x64,5,1, 0x54,0x64,2,1, - 0x55,0x64,2,1, 0x5b,0x64,9,1, 0x58,0x64,4,1, 0x5a,0x64,9,1, - 0x59,0x64,9,1, 0x5c,0x64,10,1, 0x7f,0x64,7,1, 0x57,0x64,12,1, - 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, - 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, - 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1, 0x7f,0x64,7,1 /* 84-87 */ + 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, /* 24-27 */ + 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, + 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x40, 0x64, 7, 1, + 0x40, 0x64, 7, 1, 0x4a, 0x64, 6, 1, 0x41, 0x64, 7, 1, 0x4b, 0x64, 8, 1, + 0x45, 0x64, 6, 1, 0x44, 0x64, 11, 1, 0x46, 0x64, 6, 1, 0x44, 0x64, 11, 1, + 0x5d, 0x64, 6, 1, 0x43, 0x64, 8, 1, 0x47, 0x64, 6, 1, 0x43, 0x64, 8, 1, + 0x42, 0x64, 3, 1, 0x48, 0x64, 6, 1, 0x42, 0x64, 3, 1, 0x49, 0x64, 8, 1, + 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x56, 0x64, 9, 1, 0x7f, 0x64, 7, 1, + 0x4c, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, + 0x52, 0x64, 2, 1, 0x53, 0x64, 4, 1, 0x4d, 0x64, 8, 1, 0x4e, 0x64, 9, 1, + 0x4f, 0x64, 10, 1, 0x50, 0x64, 7, 1, 0x51, 0x64, 5, 1, 0x54, 0x64, 2, 1, + 0x55, 0x64, 2, 1, 0x5b, 0x64, 9, 1, 0x58, 0x64, 4, 1, 0x5a, 0x64, 9, 1, + 0x59, 0x64, 9, 1, 0x5c, 0x64, 10, 1, 0x7f, 0x64, 7, 1, 0x57, 0x64, 12, 1, + 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, + 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, + 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1, 0x7f, 0x64, 7, 1 /* 84-87 */ }; static guint8 default_partial_reserve[9] = { /* MT-32 DEFAULT */ - 3, 10, 6, 4, 3, 0, 0, 0, 6 }; + 3, 10, 6, 4, 3, 0, 0, 0, 6 +}; static struct { guint8 mode; @@ -88,8 +89,7 @@ static struct { static int -midiout_write_block(byte *buf, int len, int delta) -{ +midiout_write_block(byte *buf, int len, int delta) { if (delta) midi_writer->delay(midi_writer, delta); @@ -101,7 +101,7 @@ midiout_write_block(byte *buf, int len, int delta) static int midiout_write_delayed_block(byte *buf, int len) - /* Only used for initial programming */ +/* Only used for initial programming */ { int rv = midiout_write_block(buf, len, 0); int delay = 1 + (len / MAGIC_MIDIOUT_DELAY); @@ -139,8 +139,7 @@ int midi_mt32_defaults(guint8 volume, guint8 reverb) { return SFX_OK; } -int midi_mt32_open(int length, byte *data, int length2, byte *data2, void *dev) -{ +int midi_mt32_open(int length, byte *data, int length2, byte *data2, void *dev) { guint8 unknown_sysex[6] = {0x16, 0x16, 0x16, 0x16, 0x16, 0x16}; guint8 i, memtimbres; unsigned int block2, block3; @@ -181,8 +180,8 @@ int midi_mt32_open(int length, byte *data, int length2, byte *data2, void *dev) printf("MT-32: Writing Patches #01 - #32\n"); midi_mt32_poke(0x050000, data + 107, 256); if ((length > block2) && - data[block2] == 0xAB && - data[block2 + 1] == 0xCD) { + data[block2] == 0xAB && + data[block2 + 1] == 0xCD) { printf("MT-32: Writing Patches #33 - #64\n"); midi_mt32_poke_gather(0x050200, data + 363, 128, data + block2 + 2, 128); printf("MT-32: Writing Patches #65 - #96\n"); @@ -201,14 +200,14 @@ int midi_mt32_open(int length, byte *data, int length2, byte *data2, void *dev) } /* Write Rhythm key map and Partial Reserve */ if ((length > block3) && - data[block3] == 0xDC && - data[block3 + 1] == 0xBA) { + data[block3] == 0xDC && + data[block3 + 1] == 0xBA) { printf("MT-32: Writing Rhythm key map\n"); midi_mt32_poke(0x030110, data + block3 + 2, 256); printf("MT-32: Writing Partial Reserve\n"); midi_mt32_poke(0x100004, data + block3 + 258, 9); } else { - midi_mt32_defaults(0,0); /* send default keymap/reserve */ + midi_mt32_defaults(0, 0); /* send default keymap/reserve */ } /* Display MT-32 initialization done message */ printf("MT-32: Displaying Text: \"%.20s\"\n", data); @@ -218,7 +217,7 @@ int midi_mt32_open(int length, byte *data, int length2, byte *data2, void *dev) midi_mt32_poke(0x52000A, unknown_sysex, 6); printf("MT-32: Setting up reverb levels\n"); default_reverb = data[0x3e]; - memcpy(mt32_reverb,data+ 0x4a, 3 * 11); + memcpy(mt32_reverb, data + 0x4a, 3 * 11); midi_mt32_reverb(default_reverb); printf("MT-32: Setting default volume (%d)\n", data[0x3c]); midi_mt32_volume(data[0x3c]); @@ -229,13 +228,12 @@ int midi_mt32_open(int length, byte *data, int length2, byte *data2, void *dev) return 0; } else { midi_mt32_poke(0x200000, (guint8 *)" FreeSCI Rocks! ", 20); - return midi_mt32_defaults(0x0c,1); /* send defaults in absence of patch data */ + return midi_mt32_defaults(0x0c, 1); /* send defaults in absence of patch data */ } return -1; } -int midi_mt32_close(void) -{ +int midi_mt32_close(void) { midi_mt32_allstop(); if (type == 0) { printf("MT-32: Displaying Text: \"%.20s\"\n", shutdown_msg); @@ -245,8 +243,7 @@ int midi_mt32_close(void) return SFX_OK; } -int midi_mt32_volume(guint8 volume) -{ +int midi_mt32_volume(guint8 volume) { volume &= 0x7f; /* (make sure it's not over 127) */ if (midi_mt32_poke(0x100016, &volume, 1) < 0) return -1; @@ -254,8 +251,7 @@ int midi_mt32_volume(guint8 volume) return 0; } -int midi_mt32_allstop(void) -{ +int midi_mt32_allstop(void) { byte buf[4]; int i; @@ -270,14 +266,13 @@ int midi_mt32_allstop(void) return 0; } -int midi_mt32_reverb(int param) -{ +int midi_mt32_reverb(int param) { guint8 buffer[3]; if (param == -1) param = default_reverb; - printf("MT-32: Sending reverb # %d (%d, %d, %d)\n",param, mt32_reverb[param].mode, + printf("MT-32: Sending reverb # %d (%d, %d, %d)\n", param, mt32_reverb[param].mode, mt32_reverb[param].time, mt32_reverb[param].level); @@ -291,8 +286,7 @@ int midi_mt32_reverb(int param) static int -midi_mt32_poke(guint32 address, guint8 *data, unsigned int count) -{ +midi_mt32_poke(guint32 address, guint8 *data, unsigned int count) { guint8 checksum = 0; unsigned int i; @@ -319,8 +313,7 @@ midi_mt32_poke(guint32 address, guint8 *data, unsigned int count) static int midi_mt32_poke_gather(guint32 address, guint8 *data1, unsigned int count1, - guint8 *data2, unsigned int count2) -{ + guint8 *data2, unsigned int count2) { guint8 checksum = 0; unsigned int i; @@ -347,8 +340,7 @@ midi_mt32_poke_gather(guint32 address, guint8 *data1, unsigned int count1, static int -midi_mt32_write_block(guint8 *data, unsigned int count) -{ +midi_mt32_write_block(guint8 *data, unsigned int count) { unsigned int block_start = 0; unsigned int i = 0; @@ -366,7 +358,7 @@ midi_mt32_write_block(guint8 *data, unsigned int count) } if (count >= block_start) { if (midiout_write_delayed_block(data + block_start, count - block_start - ) != (count - block_start)) { + ) != (count - block_start)) { fprintf(stderr, "midi_mt32_write_block(): midiout_write_block failed!\n"); return 1; } @@ -376,9 +368,8 @@ midi_mt32_write_block(guint8 *data, unsigned int count) } static int -midi_mt32_sysex_delay(void) -{ - /* Under Win32, we won't get any sound, in any case... */ +midi_mt32_sysex_delay(void) { + /* Under Win32, we won't get any sound, in any case... */ #ifdef HAVE_USLEEP usleep(320 * 63); /* One MIDI byte is 320us, 320us * 63 > 20ms */ #elif defined (WIN32) @@ -392,8 +383,7 @@ midi_mt32_sysex_delay(void) } static int -midi_mt32_event(byte command, int argc, byte *argv) -{ +midi_mt32_event(byte command, int argc, byte *argv) { byte buf[8]; buf[0] = command; @@ -407,8 +397,7 @@ midi_mt32_event(byte command, int argc, byte *argv) static void -delay_init(void) -{/* Wait for MT-32 initialisation to complete */ +delay_init(void) {/* Wait for MT-32 initialisation to complete */ long endsec = mt32_init_sec, uendsec = mt32_init_usec; long sec, usec; int loopcount = 0; @@ -430,8 +419,7 @@ delay_init(void) } static int -midi_mt32_reset_timer(GTimeVal ts) -{ +midi_mt32_reset_timer(GTimeVal ts) { if (mt32_init_delay) { /* We might still have to wait for initialisation to complete */ delay_init(); mt32_init_delay = 0; @@ -444,15 +432,13 @@ midi_mt32_reset_timer(GTimeVal ts) static int -midi_mt32_delay(int ticks) -{ +midi_mt32_delay(int ticks) { delta += ticks; /* Accumulate, write before next command */ return SFX_OK; } static int -midi_mt32_set_option(char *name, char *value) -{ +midi_mt32_set_option(char *name, char *value) { return SFX_ERROR; /* No options are supported at this time */ } diff --git a/engines/sci/sfx/seq/oss-adlib.cpp b/engines/sci/sfx/seq/oss-adlib.cpp index 0406556f56..d2275fb9b5 100644 --- a/engines/sci/sfx/seq/oss-adlib.cpp +++ b/engines/sci/sfx/seq/oss-adlib.cpp @@ -50,8 +50,7 @@ static unsigned char oper_note[ADLIB_VOICES]; static unsigned char oper_chn[ADLIB_VOICES]; #if 1 -void seqbuf_dump(void) /* OSS upcall */ -{ +void seqbuf_dump(void) { /* OSS upcall */ if (_seqbufptr) if (write(seqfd, _seqbuf, _seqbufptr) == -1) { perror("ADLIB write "); @@ -62,10 +61,9 @@ void seqbuf_dump(void) /* OSS upcall */ #endif /* initialise note/operator lists, etc. */ -void adlib_init_lists(void) -{ +void adlib_init_lists(void) { int i; - for(i = 0 ; i < ADLIB_VOICES ; i++) { + for (i = 0 ; i < ADLIB_VOICES ; i++) { oper_note[i] = 255; oper_chn[i] = 255; note_time[i] = 0; @@ -73,40 +71,38 @@ void adlib_init_lists(void) free_voices = ADLIB_VOICES; } -int adlib_stop_note(int chn, int note, int velocity) -{ - int i, op=255; - - for (i=0;i<ADLIB_VOICES && op==255;i++) { +int adlib_stop_note(int chn, int note, int velocity) { + int i, op = 255; + + for (i = 0;i < ADLIB_VOICES && op == 255;i++) { if (oper_chn[i] == chn) if (oper_note[i] == note) - op=i; + op = i; } - if (op==255) { - printf ("can't stop.. chn %d %d %d\n", chn, note, velocity); + if (op == 255) { + printf("can't stop.. chn %d %d %d\n", chn, note, velocity); return 255; /* not playing */ } - + SEQ_STOP_NOTE(dev, op, note, velocity); SEQ_DUMPBUF(); oper_chn[op] = 255; oper_note[op] = 255; note_time[op] = 0; - + free_voices++; return op; } -int adlib_kill_one_note(int chn) -{ +int adlib_kill_one_note(int chn) { int oldest = 255, i = 255; long time = 0; - + if (free_voices >= ADLIB_VOICES) { - printf("Free list empty but no notes playing\n"); + printf("Free list empty but no notes playing\n"); return 255; } /* No notes playing */ @@ -128,7 +124,7 @@ int adlib_kill_one_note(int chn) /* printf("Killing chn %d, oper %d\n", chn, oldest); */ - if (oldest == 255) + if (oldest == 255) return 255; /* Was already stopped. Why? */ SEQ_STOP_NOTE(dev, oldest, oper_note[oldest], 0); @@ -143,9 +139,8 @@ int adlib_kill_one_note(int chn) } static void -adlib_start_note(int chn, int note, int velocity) -{ - int free; +adlib_start_note(int chn, int note, int velocity) { + int free; struct timeval now; if (velocity == 0) { @@ -153,11 +148,11 @@ adlib_start_note(int chn, int note, int velocity) return; } - gettimeofday(&now, NULL); + gettimeofday(&now, NULL); if (free_voices <= 0) free = adlib_kill_one_note(chn); - else + else for (free = 0; free < ADLIB_VOICES ; free++) if (oper_chn[free] == 255) break; @@ -176,27 +171,26 @@ adlib_start_note(int chn, int note, int velocity) static int midi_adlib_open(int data_length, byte *data_ptr, int data2_length, - byte *data2_ptr, void *seq) -{ + byte *data2_ptr, void *seq) { int nrdevs, i, n; struct synth_info info; struct sbi_instrument sbi; if (data_length < 1344) { - printf ("invalid patch.003"); + printf("invalid patch.003"); return -1; } - for (i = 0; i < 48; i++) - make_sbi((adlib_def *)(data_ptr+(28 * i)), adlib_sbi[i]); + for (i = 0; i < 48; i++) + make_sbi((adlib_def *)(data_ptr + (28 * i)), adlib_sbi[i]); if (data_length > 1344) - for (i = 48; i < 96; i++) - make_sbi((adlib_def *)(data_ptr+2+(28 * i)), adlib_sbi[i]); + for (i = 48; i < 96; i++) + make_sbi((adlib_def *)(data_ptr + 2 + (28 * i)), adlib_sbi[i]); memset(instr, 0, sizeof(instr)); - - if (!IS_VALID_FD(seqfd=open("/dev/sequencer", O_WRONLY, 0))) { + + if (!IS_VALID_FD(seqfd = open("/dev/sequencer", O_WRONLY, 0))) { perror("/dev/sequencer"); return(-1); } @@ -204,9 +198,9 @@ midi_adlib_open(int data_length, byte *data_ptr, int data2_length, perror("/dev/sequencer"); return(-1); } - for (i=0;i<nrdevs && dev==-1;i++) { + for (i = 0;i < nrdevs && dev == -1;i++) { info.device = i; - if (ioctl(seqfd, SNDCTL_SYNTH_INFO, &info)==-1) { + if (ioctl(seqfd, SNDCTL_SYNTH_INFO, &info) == -1) { perror("info: /dev/sequencer"); return(-1); } @@ -227,7 +221,7 @@ midi_adlib_open(int data_length, byte *data_ptr, int data2_length, for (i = 0; i < 96; i++) { for (n = 0; n < 32; n++) memcpy(sbi.operators, &adlib_sbi[i], sizeof(sbi_instr_data)); - sbi.channel=i; + sbi.channel = i; SEQ_WRPATCH(&sbi, sizeof(sbi)); SEQ_DUMPBUF(); } @@ -239,16 +233,14 @@ midi_adlib_open(int data_length, byte *data_ptr, int data2_length, static int -midi_adlib_close(void) -{ +midi_adlib_close(void) { SEQ_DUMPBUF(); return close(seqfd); } static int -midi_adlib_allstop(void) -{ +midi_adlib_allstop(void) { int i; for (i = 0; i < ADLIB_VOICES ; i++) { if (oper_chn[i] == 255) @@ -261,26 +253,24 @@ midi_adlib_allstop(void) } static int -midi_adlib_reverb(int param) -{ +midi_adlib_reverb(int param) { printf("reverb NYI %04x \n", param); return 0; } static inline int -midi_adlib_event1(guint8 command, guint8 note, guint8 velocity) -{ +midi_adlib_event1(guint8 command, guint8 note, guint8 velocity) { guint8 channel, oper; channel = command & 0x0f; oper = command & 0xf0; - switch (oper) { + switch (oper) { case 0x80: adlib_stop_note(channel, note, velocity); return 0; - case 0x90: - adlib_start_note(channel,note,velocity); + case 0x90: + adlib_start_note(channel, note, velocity); return 0; case 0xe0: /* Pitch bend needs scaling? */ SEQ_BENDER(dev, channel, ((note << 8) & velocity)); @@ -291,23 +281,22 @@ midi_adlib_event1(guint8 command, guint8 note, guint8 velocity) return 0; case 0xd0: /* aftertouch */ SEQ_CHN_PRESSURE(dev, channel, note); - SEQ_DUMPBUF(); + SEQ_DUMPBUF(); return 0; default: printf("ADLIB: Unknown event %02x\n", command); return 0; } - + SEQ_DUMPBUF(); return 0; } static inline int -midi_adlib_event2(guint8 command, guint8 param) -{ +midi_adlib_event2(guint8 command, guint8 param) { guint8 channel; guint8 oper; - + channel = command & 0x0f; oper = command & 0xf0; switch (oper) { @@ -327,8 +316,7 @@ midi_adlib_event2(guint8 command, guint8 param) } static int -midi_adlib_event(byte command, int argc, byte *argv) -{ +midi_adlib_event(byte command, int argc, byte *argv) { if (argc > 1) return midi_adlib_event1(command, argv[0], argv[1]); else @@ -336,15 +324,13 @@ midi_adlib_event(byte command, int argc, byte *argv) } static int -midi_adlib_delay(int ticks) -{ +midi_adlib_delay(int ticks) { SEQ_DELTA_TIME(ticks); return SFX_OK; } static int -midi_adlib_set_option(char *name, char *value) -{ +midi_adlib_set_option(char *name, char *value) { return SFX_ERROR; /* No options are supported at this time */ } diff --git a/engines/sci/sfx/seq/sequencers.cpp b/engines/sci/sfx/seq/sequencers.cpp index 3ba7f25a46..60752f624b 100644 --- a/engines/sci/sfx/seq/sequencers.cpp +++ b/engines/sci/sfx/seq/sequencers.cpp @@ -49,8 +49,7 @@ sfx_sequencer_t *sfx_sequencers[] = { sfx_sequencer_t * -sfx_find_sequencer(char *name) -{ +sfx_find_sequencer(char *name) { if (!name) { /* Implement default policy for your platform (if any) here, or in a function ** called from here (if it's non-trivial). Try to use midi_devices[0], if @@ -60,8 +59,8 @@ sfx_find_sequencer(char *name) } else { int n = 0; while (sfx_sequencers[n] - && strcasecmp(sfx_sequencers[n]->name, name)) - ++n; + && strcasecmp(sfx_sequencers[n]->name, name)) + ++n; return sfx_sequencers[n]; } diff --git a/engines/sci/sfx/sequencer.h b/engines/sci/sfx/sequencer.h index bafb6716aa..606bd657f1 100644 --- a/engines/sci/sfx/sequencer.h +++ b/engines/sci/sfx/sequencer.h @@ -98,7 +98,7 @@ typedef struct _sfx_sequencer { ** Returns : SFX_OK on success, SFX_ERROR otherwise */ - int (*volume)(guint8 volume); /* OPTIONAL -- can be NULL */ + int (*volume)(guint8 volume); /* OPTIONAL -- can be NULL */ /* Sets the sequencer volume ** Parameters; (byte) volume: The volume to set, with 0 being mute and 127 full volume ** Returns : SFX_OK on success, SFX_ERROR otherwise diff --git a/engines/sci/sfx/softseq.h b/engines/sci/sfx/softseq.h index d790f87229..8de5295a86 100644 --- a/engines/sci/sfx/softseq.h +++ b/engines/sci/sfx/softseq.h @@ -52,7 +52,7 @@ typedef struct sfx_softseq { int (*init)(struct sfx_softseq *self, byte *res_data, int res_size, - byte *res2_data, int res2_size); + byte *res2_data, int res2_size); /* Initialises the sequencer ** Parameters: (sfx_softseq_t *) self: Self reference ** (byte *) res_data: Resource data for 'patch_nr' (see below) @@ -128,7 +128,7 @@ sfx_softseq_t * sfx_find_softseq(const char *name); /* Finds a given or default software sequencer ** Parameters: (const char *) name: Name of the sequencer to look up, or NULL for default -** Returns : (sfx_softseq_t *) The requested sequencer, or NULL if not found +** Returns : (sfx_softseq_t *) The requested sequencer, or NULL if not found */ #endif /* !defined(SFX_SOFTSEQ_H_) */ diff --git a/engines/sci/sfx/softseq/SN76496.cpp b/engines/sci/sfx/softseq/SN76496.cpp index 0bacc295ea..3843902195 100644 --- a/engines/sci/sfx/softseq/SN76496.cpp +++ b/engines/sci/sfx/softseq/SN76496.cpp @@ -38,40 +38,36 @@ static int global_volume = 100; /* Base volume */ static int volumes[CHANNELS_NR] = { 100, 100, 100 }; static int notes[CHANNELS_NR] = {0, 0, 0}; /* Current halftone, or 0 if off */ -static int freq_count[CHANNELS_NR] = {0, 0, 0}; +static int freq_count[CHANNELS_NR] = {0, 0, 0}; static int channel_assigner = 0; static int channels_assigned = 0; -static int chan_nrs[CHANNELS_NR] = {-1, -1, -1}; +static int chan_nrs[CHANNELS_NR] = { -1, -1, -1}; extern sfx_softseq_t sfx_softseq_pcspeaker; /* Forward-declare the sequencer we are defining here */ static int -SN76496_set_option(sfx_softseq_t *self, const char *name, const char *value) -{ +SN76496_set_option(sfx_softseq_t *self, const char *name, const char *value) { return SFX_ERROR; } static int SN76496_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch2, - int patch2_len) -{ + int patch2_len) { return SFX_OK; } static void -SN76496_exit(sfx_softseq_t *self) -{ +SN76496_exit(sfx_softseq_t *self) { } static void -SN76496_event(sfx_softseq_t *self, byte command, int argc, byte *argv) -{ +SN76496_event(sfx_softseq_t *self, byte command, int argc, byte *argv) { int i; int chan = -1; #if 0 - fprintf(stderr, "Note [%02x : %02x %02x]\n", command, argc?argv[0] : 0, (argc > 1)? argv[1] : 0); + fprintf(stderr, "Note [%02x : %02x %02x]\n", command, argc ? argv[0] : 0, (argc > 1) ? argv[1] : 0); #endif if ((command & 0xe0) == 0x80) { int chan_nr = command & 0xf; @@ -104,7 +100,7 @@ SN76496_event(sfx_softseq_t *self, byte command, int argc, byte *argv) } #if 0 fprintf(stderr, " --> %d [%04x], {%d,%d,%d}@%d\n", chan, - channels_assigned, chan_nrs[0],chan_nrs[1],chan_nrs[2],channel_assigner); + channels_assigned, chan_nrs[0], chan_nrs[1], chan_nrs[2], channel_assigner); #endif switch (command & 0xf0) { @@ -132,7 +128,7 @@ SN76496_event(sfx_softseq_t *self, byte command, int argc, byte *argv) default: #if DEBUG - fprintf(stderr, "[SFX:PCM-PC] Unused MIDI command %02x %02x %02x\n", command, argc?argv[0] : 0, (argc > 1)? argv[1] : 0); + fprintf(stderr, "[SFX:PCM-PC] Unused MIDI command %02x %02x %02x\n", command, argc ? argv[0] : 0, (argc > 1) ? argv[1] : 0); #endif break; /* ignore */ } @@ -158,20 +154,18 @@ freq_table[12] = { /* A4 is 440Hz, halftone map is x |-> ** 2^(x/12) */ }; static inline int -get_freq(int note) -{ +get_freq(int note) { int halftone_delta = note - BASE_NOTE; int oct_diff = ((halftone_delta + BASE_OCTAVE * 12) / 12) - BASE_OCTAVE; - int halftone_index = (halftone_delta + (12*100)) % 12 ; - int freq = (!note)? 0 : freq_table[halftone_index] / (1 << (-oct_diff)); + int halftone_index = (halftone_delta + (12 * 100)) % 12 ; + int freq = (!note) ? 0 : freq_table[halftone_index] / (1 << (-oct_diff)); return freq; } void -SN76496_poll(sfx_softseq_t *self, byte *dest, int len) -{ +SN76496_poll(sfx_softseq_t *self, byte *dest, int len) { gint16 *buf = (gint16 *) dest; int i; int chan; @@ -186,7 +180,7 @@ SN76496_poll(sfx_softseq_t *self, byte *dest, int len) for (chan = 0; chan < CHANNELS_NR; chan++) if (notes[chan]) { int volume = (global_volume * volumes[chan]) - >> VOLUME_SHIFT; + >> VOLUME_SHIFT; freq_count[chan] += freq[chan]; while (freq_count[chan] >= (FREQUENCY << 1)) @@ -195,12 +189,12 @@ SN76496_poll(sfx_softseq_t *self, byte *dest, int len) if (freq_count[chan] - freq[chan] < 0) { /* Unclean rising edge */ int l = volume << 1; - result += -volume + (l*freq_count[chan])/freq[chan]; + result += -volume + (l * freq_count[chan]) / freq[chan]; } else if (freq_count[chan] >= FREQUENCY - && freq_count[chan] - freq[chan] < FREQUENCY) { + && freq_count[chan] - freq[chan] < FREQUENCY) { /* Unclean falling edge */ int l = volume << 1; - result += volume - (l*(freq_count[chan] - FREQUENCY))/freq[chan]; + result += volume - (l * (freq_count[chan] - FREQUENCY)) / freq[chan]; } else { if (freq_count[chan] < FREQUENCY) result += volume; @@ -214,16 +208,14 @@ SN76496_poll(sfx_softseq_t *self, byte *dest, int len) } void -SN76496_allstop(sfx_softseq_t *self) -{ +SN76496_allstop(sfx_softseq_t *self) { int i; for (i = 0; i < CHANNELS_NR; i++) notes[i] = 0; } void -SN76496_volume(sfx_softseq_t *self, int new_volume) -{ +SN76496_volume(sfx_softseq_t *self, int new_volume) { global_volume = new_volume; } diff --git a/engines/sci/sfx/softseq/amiga.cpp b/engines/sci/sfx/softseq/amiga.cpp index 280f22fa5e..111ffdf5cf 100644 --- a/engines/sci/sfx/softseq/amiga.cpp +++ b/engines/sci/sfx/softseq/amiga.cpp @@ -132,8 +132,7 @@ static int freq_table[] = { }; static void -set_envelope(channel_t *channel, envelope_t *envelope, int phase) -{ +set_envelope(channel_t *channel, envelope_t *envelope, int phase) { channel->envelope = phase; channel->envelope_samples = envelope[phase].length; @@ -144,8 +143,7 @@ set_envelope(channel_t *channel, envelope_t *envelope, int phase) } static inline int -interpolate(sbyte *samples, frac_t offset) -{ +interpolate(sbyte *samples, frac_t offset) { int x = frac_to_int(offset); int diff = (samples[x + 1] - samples[x]) << 8; @@ -153,8 +151,7 @@ interpolate(sbyte *samples, frac_t offset) } static void -play_instrument(gint16 *dest, channel_t *channel, int count) -{ +play_instrument(gint16 *dest, channel_t *channel, int count) { int index = 0; int vol = hw_channels[channel->hw_channel].volume; instrument_t *instrument = bank.instruments[channel->instrument]; @@ -168,8 +165,7 @@ play_instrument(gint16 *dest, channel_t *channel, int count) if (channel->looping) { samples = instrument->loop; seg_end = instrument->loop_size; - } - else { + } else { samples = instrument->samples; seg_end = instrument->size; } @@ -258,8 +254,7 @@ play_instrument(gint16 *dest, channel_t *channel, int count) } static void -change_instrument(int channel, int instrument) -{ +change_instrument(int channel, int instrument) { #ifdef DEBUG if (bank.instruments[instrument]) sciprintf("[sfx:seq:amiga] Setting channel %i to \"%s\" (%i)\n", channel, bank.instruments[instrument]->name, instrument); @@ -270,8 +265,7 @@ change_instrument(int channel, int instrument) } static void -stop_channel(int ch) -{ +stop_channel(int ch) { int i; /* Start decay phase for note on this hw channel, if any */ @@ -285,8 +279,7 @@ stop_channel(int ch) } static void -stop_note(int ch, int note) -{ +stop_note(int ch, int note) { int channel; instrument_t *instrument; @@ -309,8 +302,7 @@ stop_note(int ch, int note) } static void -start_note(int ch, int note, int velocity) -{ +start_note(int ch, int note, int velocity) { instrument_t *instrument; int channel; @@ -347,8 +339,7 @@ start_note(int ch, int note, int velocity) /* Compute rate for note */ channels[channel].rate = double_to_frac(freq_table[fnote] / (double) FREQUENCY); - } - else + } else channels[channel].rate = double_to_frac(BASE_FREQ / (double) FREQUENCY); channels[channel].instrument = hw_channels[ch].instrument; @@ -368,18 +359,15 @@ start_note(int ch, int note, int velocity) channels[channel].looping = 0; } -static gint16 read_int16(byte *data) -{ +static gint16 read_int16(byte *data) { return (data[0] << 8) | data[1]; } -static gint32 read_int32(byte *data) -{ +static gint32 read_int32(byte *data) { return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; } -static instrument_t *read_instrument(FILE *file, int *id) -{ +static instrument_t *read_instrument(FILE *file, int *id) { instrument_t *instrument; byte header[61]; int size; @@ -422,7 +410,7 @@ static instrument_t *read_instrument(FILE *file, int *id) instrument->name[29] = 0; #ifdef DEBUG sciprintf("[sfx:seq:amiga] Reading instrument %i: \"%s\" (%i bytes)\n", - *id, instrument->name, size); + *id, instrument->name, size); sciprintf(" Mode: %02x\n", instrument->mode); sciprintf(" Looping: %s\n", instrument->mode & MODE_LOOP ? "on" : "off"); sciprintf(" Pitch changes: %s\n", instrument->mode & MODE_PITCH ? "on" : "off"); @@ -439,7 +427,7 @@ static instrument_t *read_instrument(FILE *file, int *id) if (loop_offset + seg_size[1] > size) { #ifdef DEBUG sciprintf("[sfx:seq:amiga] Warning: looping samples extend %i bytes past end of sample block\n", - loop_offset + seg_size[1] - size); + loop_offset + seg_size[1] - size); #endif seg_size[1] = size - loop_offset; } @@ -466,14 +454,12 @@ static instrument_t *read_instrument(FILE *file, int *id) } static int -ami_set_option(sfx_softseq_t *self, const char *name, const char *value) -{ +ami_set_option(sfx_softseq_t *self, const char *name, const char *value) { return SFX_ERROR; } static int -ami_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch2, int patch2_len) -{ +ami_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch2, int patch2_len) { FILE *file; byte header[40]; int i; @@ -535,8 +521,7 @@ ami_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch2, int patc } static void -ami_exit(sfx_softseq_t *self) -{ +ami_exit(sfx_softseq_t *self) { int i; for (i = 0; i < bank.size; i++) { @@ -548,8 +533,7 @@ ami_exit(sfx_softseq_t *self) } static void -ami_event(sfx_softseq_t *self, byte command, int argc, byte *argv) -{ +ami_event(sfx_softseq_t *self, byte command, int argc, byte *argv) { int channel, oper; channel = command & 0x0f; @@ -562,7 +546,7 @@ ami_event(sfx_softseq_t *self, byte command, int argc, byte *argv) return; } - switch(oper) { + switch (oper) { case 0x90: if (argv[1] > 0) start_note(channel, argv[0], argv[1]); @@ -595,8 +579,7 @@ ami_event(sfx_softseq_t *self, byte command, int argc, byte *argv) } void -ami_poll(sfx_softseq_t *self, byte *dest, int len) -{ +ami_poll(sfx_softseq_t *self, byte *dest, int len) { int i, j; gint16 *buf = (gint16 *) dest; gint16 *buffers = (gint16*)malloc(len * 2 * CHANNELS_NR); @@ -620,19 +603,17 @@ ami_poll(sfx_softseq_t *self, byte *dest, int len) /* Adjust volume */ buf[2 * j] = mixedl * volume >> 16; - buf[2 * j + 1] = mixedr *volume >> 16; + buf[2 * j + 1] = mixedr * volume >> 16; } } void -ami_volume(sfx_softseq_t *self, int new_volume) -{ +ami_volume(sfx_softseq_t *self, int new_volume) { volume = new_volume; } void -ami_allstop(sfx_softseq_t *self) -{ +ami_allstop(sfx_softseq_t *self) { int i; for (i = 0; i < HW_CHANNELS_NR; i++) stop_channel(i); diff --git a/engines/sci/sfx/softseq/fluidsynth.cpp b/engines/sci/sfx/softseq/fluidsynth.cpp index 750891d60c..c0b64d24ec 100644 --- a/engines/sci/sfx/softseq/fluidsynth.cpp +++ b/engines/sci/sfx/softseq/fluidsynth.cpp @@ -50,20 +50,17 @@ static int rpn[16]; /* MIDI writer */ static int -fluidsynth_midi_init(struct _midi_writer *self) -{ +fluidsynth_midi_init(struct _midi_writer *self) { return SFX_OK; } static int -fluidsynth_midi_set_option(struct _midi_writer *self, char *name, char *value) -{ +fluidsynth_midi_set_option(struct _midi_writer *self, char *name, char *value) { return SFX_ERROR; } static int -fluidsynth_midi_write(struct _midi_writer *self, unsigned char *buf, int len) -{ +fluidsynth_midi_write(struct _midi_writer *self, unsigned char *buf, int len) { if (buf[0] == 0xf0) sciprintf("FluidSynth: Skipping sysex message.\n"); else if (len == 2) { @@ -72,21 +69,20 @@ fluidsynth_midi_write(struct _midi_writer *self, unsigned char *buf, int len) command = buf[0] & 0xf0; channel = buf[0] & 0x0f; - switch(command) { + switch (command) { case 0xc0: fluid_synth_program_change(synth, channel, buf[1]); break; default: printf("FluidSynth: MIDI command [%02x %02x] not supported\n", buf[0], buf[1]); } - } - else if (len == 3) { + } else if (len == 3) { guint8 command, channel; command = buf[0] & 0xf0; channel = buf[0] & 0x0f; - switch(command) { + switch (command) { case 0x80: fluid_synth_noteoff(synth, channel, buf[1]); break; @@ -121,26 +117,22 @@ fluidsynth_midi_write(struct _midi_writer *self, unsigned char *buf, int len) default: sciprintf("FluidSynth: MIDI command [%02x %02x %02x] not supported\n", buf[0], buf[1], buf[2]); } - } - else + } else sciprintf("FluidSynth: Skipping invalid message of %i bytes.\n", len); return SFX_OK; } static void -fluidsynth_midi_delay(struct _midi_writer *self, int ticks) -{ +fluidsynth_midi_delay(struct _midi_writer *self, int ticks) { } static void -fluidsynth_midi_reset_timer(struct _midi_writer *self) -{ +fluidsynth_midi_reset_timer(struct _midi_writer *self) { } static void -fluidsynth_midi_close(struct _midi_writer *self) -{ +fluidsynth_midi_close(struct _midi_writer *self) { } static midi_writer_t midi_writer_fluidsynth = { @@ -157,15 +149,13 @@ static midi_writer_t midi_writer_fluidsynth = { /* Software sequencer */ static void -fluidsynth_poll(sfx_softseq_t *self, byte *dest, int count) -{ +fluidsynth_poll(sfx_softseq_t *self, byte *dest, int count) { fluid_synth_write_s16(synth, count, dest, 0, 2, dest + 2, 0, 2); } static int fluidsynth_init(sfx_softseq_t *self, byte *data_ptr, int data_length, - byte *data2_ptr, int data2_length) -{ + byte *data2_ptr, int data2_length) { int sfont_id; double min, max; @@ -185,7 +175,7 @@ fluidsynth_init(sfx_softseq_t *self, byte *data_ptr, int data_length, fluid_settings_getnum_range(settings, "synth.sample-rate", &min, &max); if (SAMPLE_RATE < min || SAMPLE_RATE > max) { sciprintf("FluidSynth ERROR: Sample rate '%i' not supported. Valid " - "range is (%i-%i).\n", SAMPLE_RATE, (int) min, (int) max); + "range is (%i-%i).\n", SAMPLE_RATE, (int) min, (int) max); delete_fluid_settings(settings); return SFX_ERROR; } @@ -202,41 +192,36 @@ fluidsynth_init(sfx_softseq_t *self, byte *data_ptr, int data_length, } gmseq->open(data_length, data_ptr, data2_length, data2_ptr, - &midi_writer_fluidsynth); + &midi_writer_fluidsynth); return SFX_OK; } static void -fluidsynth_exit(sfx_softseq_t *self) -{ +fluidsynth_exit(sfx_softseq_t *self) { delete_fluid_synth(synth); delete_fluid_settings(settings); } static void -fluidsynth_allstop(sfx_softseq_t *self) -{ +fluidsynth_allstop(sfx_softseq_t *self) { if (gmseq->allstop) gmseq->allstop(); } static void -fluidsynth_volume(sfx_softseq_t *self, int volume) -{ +fluidsynth_volume(sfx_softseq_t *self, int volume) { if (gmseq->volume) gmseq->volume(volume); } static int -fluidsynth_set_option(sfx_softseq_t *self, const char *name, const char *value) -{ +fluidsynth_set_option(sfx_softseq_t *self, const char *name, const char *value) { return SFX_ERROR; } static void -fluidsynth_event(sfx_softseq_t *self, byte cmd, int argc, byte *argv) -{ +fluidsynth_event(sfx_softseq_t *self, byte cmd, int argc, byte *argv) { gmseq->event(cmd, argc, argv); } diff --git a/engines/sci/sfx/softseq/fmopl.h b/engines/sci/sfx/softseq/fmopl.h index 0250c23a5a..c8ec230515 100644 --- a/engines/sci/sfx/softseq/fmopl.h +++ b/engines/sci/sfx/softseq/fmopl.h @@ -43,9 +43,9 @@ enum { }; -typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec); -typedef void (*OPL_IRQHANDLER)(int param,int irq); -typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us); +typedef void (*OPL_TIMERHANDLER)(int channel, double interval_Sec); +typedef void (*OPL_IRQHANDLER)(int param, int irq); +typedef void (*OPL_UPDATEHANDLER)(int param, int min_interval_us); #define OPL_TYPE_WAVESEL 0x01 /* waveform select */ @@ -64,7 +64,7 @@ typedef struct fm_opl_slot { guint32 mul; /* multiple :ML_TABLE[ML] */ guint32 Cnt; /* frequency count */ guint32 Incr; /* frequency step */ - + /* envelope generator state */ guint8 eg_typ;/* envelope type flag */ guint8 evm; /* envelope phase */ @@ -121,7 +121,7 @@ typedef struct fm_opl_f { /* Rythm sention */ guint8 rythm; /* Rythm mode , key flag */ - + /* time tables */ int AR_TABLE[75]; /* atttack rate tables */ int DR_TABLE[75]; /* decay rate tables */ diff --git a/engines/sci/sfx/softseq/mt32.cpp b/engines/sci/sfx/softseq/mt32.cpp index 3389a286e5..7e1ca27aa9 100644 --- a/engines/sci/sfx/softseq/mt32.cpp +++ b/engines/sci/sfx/softseq/mt32.cpp @@ -49,20 +49,17 @@ static int initializing; /* MIDI writer */ static int -mt32_midi_init(struct _midi_writer *self) -{ +mt32_midi_init(struct _midi_writer *self) { return SFX_OK; } static int -mt32_midi_set_option(struct _midi_writer *self, char *name, char *value) -{ +mt32_midi_set_option(struct _midi_writer *self, char *name, char *value) { return SFX_ERROR; } static int -mt32_midi_write(struct _midi_writer *self, unsigned char *buf, int len) -{ +mt32_midi_write(struct _midi_writer *self, unsigned char *buf, int len) { if (buf[0] == 0xf0) synth->playSysex(buf, len); else if (len < 4) { @@ -73,26 +70,22 @@ mt32_midi_write(struct _midi_writer *self, unsigned char *buf, int len) if (len > 1) msg |= buf[2] << 16; synth->playMsg(msg); - } - else + } else sciprintf("MT32EMU: Skipping non-sysex message of more than 3 bytes.\n"); return SFX_OK; } static void -mt32_midi_delay(struct _midi_writer *self, int ticks) -{ +mt32_midi_delay(struct _midi_writer *self, int ticks) { } static void -mt32_midi_reset_timer(struct _midi_writer *self) -{ +mt32_midi_reset_timer(struct _midi_writer *self) { } static void -mt32_midi_close(struct _midi_writer *self) -{ +mt32_midi_close(struct _midi_writer *self) { } static midi_writer_t midi_writer_mt32 = { @@ -108,8 +101,7 @@ static midi_writer_t midi_writer_mt32 = { /* Software sequencer */ -static void printDebug(void *userData, const char *fmt, va_list list) -{ +static void printDebug(void *userData, const char *fmt, va_list list) { if (initializing) { vprintf(fmt, list); printf("\n"); @@ -117,15 +109,13 @@ static void printDebug(void *userData, const char *fmt, va_list list) } static void -mt32_poll(sfx_softseq_t *self, byte *dest, int count) -{ +mt32_poll(sfx_softseq_t *self, byte *dest, int count) { synth->render((MT32Emu::Bit16s *) dest, count); } static int mt32_init(sfx_softseq_t *self, byte *data_ptr, int data_length, byte *data2_ptr, - int data2_length) -{ + int data2_length) { MT32Emu::SynthProperties prop; char *home = sci_get_homedir(); char *romdir; @@ -136,7 +126,7 @@ mt32_init(sfx_softseq_t *self, byte *data_ptr, int data_length, byte *data2_ptr, } romdir = (char *) sci_malloc(sizeof(home) + 2 * sizeof(G_DIR_SEPARATOR_S) - + sizeof(FREESCI_GAMEDIR) + 1); + + sizeof(FREESCI_GAMEDIR) + 1); strcpy(romdir, home); strcat(romdir, G_DIR_SEPARATOR_S); @@ -166,7 +156,7 @@ mt32_init(sfx_softseq_t *self, byte *data_ptr, int data_length, byte *data2_ptr, initializing = 0; mt32seq->open(data_length, data_ptr, data2_length, data2_ptr, - &midi_writer_mt32); + &midi_writer_mt32); free(romdir); @@ -174,8 +164,7 @@ mt32_init(sfx_softseq_t *self, byte *data_ptr, int data_length, byte *data2_ptr, } static void -mt32_exit(sfx_softseq_t *self) -{ +mt32_exit(sfx_softseq_t *self) { synth->close(); delete synth; @@ -183,28 +172,24 @@ mt32_exit(sfx_softseq_t *self) } static void -mt32_allstop(sfx_softseq_t *self) -{ +mt32_allstop(sfx_softseq_t *self) { if (mt32seq->allstop) mt32seq->allstop(); } static void -mt32_volume(sfx_softseq_t *self, int volume) -{ +mt32_volume(sfx_softseq_t *self, int volume) { if (mt32seq->volume) mt32seq->volume(volume / 2); /* High volume causes clipping. */ } static int -mt32_set_option(sfx_softseq_t *self, const char *name, const char *value) -{ +mt32_set_option(sfx_softseq_t *self, const char *name, const char *value) { return SFX_ERROR; } static void -mt32_event(sfx_softseq_t *self, byte cmd, int argc, byte *argv) -{ +mt32_event(sfx_softseq_t *self, byte cmd, int argc, byte *argv) { mt32seq->event(cmd, argc, argv); } diff --git a/engines/sci/sfx/softseq/opl2.cpp b/engines/sci/sfx/softseq/opl2.cpp index 80b6adf162..50f0318a10 100644 --- a/engines/sci/sfx/softseq/opl2.cpp +++ b/engines/sci/sfx/softseq/opl2.cpp @@ -55,26 +55,26 @@ static int ready = 0; static int pcmout_stereo = STEREO; static int register_base[11] = { - 0x20, 0x23, 0x40, 0x43, - 0x60, 0x63, 0x80, 0x83, - 0xe0, 0xe3, 0xc0 + 0x20, 0x23, 0x40, 0x43, + 0x60, 0x63, 0x80, 0x83, + 0xe0, 0xe3, 0xc0 }; static int register_offset[12] = { - /* Channel 1 2 3 4 5 6 7 8 9 */ - /* Operator 1 */ 0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12, 0x18, 0x19, 0x1A + /* Channel 1 2 3 4 5 6 7 8 9 */ + /* Operator 1 */ 0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12, 0x18, 0x19, 0x1A }; static int ym3812_note[13] = { - 0x157, 0x16b, 0x181, 0x198, 0x1b0, 0x1ca, - 0x1e5, 0x202, 0x220, 0x241, 0x263, 0x287, - 0x2ae + 0x157, 0x16b, 0x181, 0x198, 0x1b0, 0x1ca, + 0x1e5, 0x202, 0x220, 0x241, 0x263, 0x287, + 0x2ae }; static guint8 sci_adlib_vol_base[16] = { - 0x00, 0x11, 0x15, 0x19, 0x1D, 0x22, 0x26, 0x2A, - 0x2E, 0x23, 0x37, 0x3B, 0x3F, 0x3F, 0x3F, 0x3F + 0x00, 0x11, 0x15, 0x19, 0x1D, 0x22, 0x26, 0x2A, + 0x2E, 0x23, 0x37, 0x3B, 0x3F, 0x3F, 0x3F, 0x3F }; static guint8 sci_adlib_vol_tables[16][64]; @@ -97,8 +97,7 @@ static guint8 adlib_master; /* initialise note/operator lists, etc. */ -void adlibemu_init_lists(void) -{ +void adlibemu_init_lists(void) { int i; int j; @@ -122,29 +121,26 @@ void adlibemu_init_lists(void) memset(adlib_reg_R, 0, sizeof(adlib_reg_R)); memset(oper_chn, 0xff, sizeof(oper_chn)); memset(oper_note, 0xff, sizeof(oper_note)); - adlib_master=12; + adlib_master = 12; } /* more shamelessly lifted from xmp and adplug. And altered. :) */ -static inline int opl_write_L (int a, int v) -{ +static inline int opl_write_L(int a, int v) { adlib_reg_L[a] = v; - OPLWrite (ym3812_L, 0x388, a); - return OPLWrite (ym3812_L, 0x389, v); + OPLWrite(ym3812_L, 0x388, a); + return OPLWrite(ym3812_L, 0x389, v); } -static inline int opl_write_R (int a, int v) -{ +static inline int opl_write_R(int a, int v) { adlib_reg_R[a] = v; - OPLWrite (ym3812_R, 0x388, a); - return OPLWrite (ym3812_R, 0x389, v); + OPLWrite(ym3812_R, 0x388, a); + return OPLWrite(ym3812_R, 0x389, v); } -static inline int opl_write(int a, int v) -{ - opl_write_L(a,v); - return opl_write_R(a,v); +static inline int opl_write(int a, int v) { + opl_write_L(a, v); + return opl_write_R(a, v); } /* @@ -155,105 +151,101 @@ static inline guint8 opl_read (int a) } */ -void synth_setpatch (int voice, guint8 *data) -{ - int i; +void synth_setpatch(int voice, guint8 *data) { + int i; - opl_write(0xBD, 0); + opl_write(0xBD, 0); - for (i = 0; i < 10; i++) - opl_write(register_base[i] + register_offset[voice], data[i]); + for (i = 0; i < 10; i++) + opl_write(register_base[i] + register_offset[voice], data[i]); - opl_write(register_base[10] + voice, data[10]); + opl_write(register_base[10] + voice, data[10]); - /* mute voice after patch change */ - opl_write_L(0xb0 + voice, adlib_reg_L[0xb0+voice] & 0xdf); - opl_write_R(0xb0 + voice, adlib_reg_R[0xb0+voice] & 0xdf); + /* mute voice after patch change */ + opl_write_L(0xb0 + voice, adlib_reg_L[0xb0+voice] & 0xdf); + opl_write_R(0xb0 + voice, adlib_reg_R[0xb0+voice] & 0xdf); #ifdef DEBUG_ADLIB - for (i = 0; i < 10; i++) - printf("%02x ", adlib_reg_L[register_base[i]+register_offset[voice]]); - printf("%02x ", adlib_reg_L[register_base[10]+voice]); + for (i = 0; i < 10; i++) + printf("%02x ", adlib_reg_L[register_base[i] + register_offset[voice]]); + printf("%02x ", adlib_reg_L[register_base[10] + voice]); #endif } -void synth_setvolume_L (int voice, int volume) -{ - gint8 level1, level2; - - level1 = ~adlib_reg_L[register_base[2]+register_offset[voice]] & 0x3f; - level2 = ~adlib_reg_L[register_base[3]+register_offset[voice]] & 0x3f; - - if (level1) { - level1 += sci_adlib_vol_tables[adlib_master][volume>>1]; - } - - if (level2) { - level2 += sci_adlib_vol_tables[adlib_master][volume>>1]; - } - - if (level1 > 0x3f) - level1 = 0x3f; - if (level1 < 0) - level1 = 0; - - if (level2 > 0x3f) - level2 = 0x3f; - if (level2 < 0) - level2 = 0; - - /* algorithm-dependent; we may need to set both operators. */ - if (adlib_reg_L[register_base[10]+voice] & 1) - opl_write_L(register_base[2]+register_offset[voice], - (guint8)((~level1 &0x3f) | - (adlib_reg_L[register_base[2]+register_offset[voice]]&0xc0))); - - opl_write_L(register_base[3]+register_offset[voice], - (guint8)((~level2 &0x3f) | - (adlib_reg_L[register_base[3]+register_offset[voice]]&0xc0))); +void synth_setvolume_L(int voice, int volume) { + gint8 level1, level2; + + level1 = ~adlib_reg_L[register_base[2] + register_offset[voice]] & 0x3f; + level2 = ~adlib_reg_L[register_base[3] + register_offset[voice]] & 0x3f; + + if (level1) { + level1 += sci_adlib_vol_tables[adlib_master][volume>>1]; + } + + if (level2) { + level2 += sci_adlib_vol_tables[adlib_master][volume>>1]; + } + + if (level1 > 0x3f) + level1 = 0x3f; + if (level1 < 0) + level1 = 0; + + if (level2 > 0x3f) + level2 = 0x3f; + if (level2 < 0) + level2 = 0; + + /* algorithm-dependent; we may need to set both operators. */ + if (adlib_reg_L[register_base[10] + voice] & 1) + opl_write_L(register_base[2] + register_offset[voice], + (guint8)((~level1 &0x3f) | + (adlib_reg_L[register_base[2] + register_offset[voice]]&0xc0))); + + opl_write_L(register_base[3] + register_offset[voice], + (guint8)((~level2 &0x3f) | + (adlib_reg_L[register_base[3] + register_offset[voice]]&0xc0))); } -void synth_setvolume_R (int voice, int volume) -{ - gint8 level1, level2; - - level1 = ~adlib_reg_R[register_base[2]+register_offset[voice]] & 0x3f; - level2 = ~adlib_reg_R[register_base[3]+register_offset[voice]] & 0x3f; - - if (level1) { - level1 += sci_adlib_vol_tables[adlib_master][volume>>1]; - } - - if (level2) { - level2 += sci_adlib_vol_tables[adlib_master][volume>>1]; - } - - if (level1 > 0x3f) - level1 = 0x3f; - if (level1 < 0) - level1 = 0; - - if (level2 > 0x3f) - level2 = 0x3f; - if (level2 < 0) - level2 = 0; - - /* now for the other side. */ - if (adlib_reg_R[register_base[10]+voice] & 1) - opl_write_R(register_base[2]+register_offset[voice], - (guint8)((~level1 &0x3f) | - (adlib_reg_R[register_base[2]+register_offset[voice]]&0xc0))); - - opl_write_R(register_base[3]+register_offset[voice], - (guint8)((~level2 &0x3f) | - (adlib_reg_R[register_base[3]+register_offset[voice]]&0xc0))); +void synth_setvolume_R(int voice, int volume) { + gint8 level1, level2; + + level1 = ~adlib_reg_R[register_base[2] + register_offset[voice]] & 0x3f; + level2 = ~adlib_reg_R[register_base[3] + register_offset[voice]] & 0x3f; + + if (level1) { + level1 += sci_adlib_vol_tables[adlib_master][volume>>1]; + } + + if (level2) { + level2 += sci_adlib_vol_tables[adlib_master][volume>>1]; + } + + if (level1 > 0x3f) + level1 = 0x3f; + if (level1 < 0) + level1 = 0; + + if (level2 > 0x3f) + level2 = 0x3f; + if (level2 < 0) + level2 = 0; + + /* now for the other side. */ + if (adlib_reg_R[register_base[10] + voice] & 1) + opl_write_R(register_base[2] + register_offset[voice], + (guint8)((~level1 &0x3f) | + (adlib_reg_R[register_base[2] + register_offset[voice]]&0xc0))); + + opl_write_R(register_base[3] + register_offset[voice], + (guint8)((~level2 &0x3f) | + (adlib_reg_R[register_base[3] + register_offset[voice]]&0xc0))); } -void synth_setnote (int voice, int note, int bend) -{ +void synth_setnote(int voice, int note, int bend) { int n, fre, oct; float delta; @@ -262,22 +254,22 @@ void synth_setnote (int voice, int note, int bend) n = note % 12; if (bend < 8192) - bend = 8192-bend; - delta = pow(2, (float) (bend%8192)/8192.0); + bend = 8192 - bend; + delta = pow(2, (float)(bend % 8192) / 8192.0); if (bend > 8192) - fre = (int)(ym3812_note[n]*delta); + fre = (int)(ym3812_note[n] * delta); else - fre = (int)(ym3812_note[n]/delta); + fre = (int)(ym3812_note[n] / delta); oct = note / 12 - 1; if (oct < 0) - oct = 0; + oct = 0; opl_write(0xa0 + voice, fre & 0xff); opl_write(0xb0 + voice, - 0x20 | ((oct << 2) & 0x1c) | ((fre >> 8) & 0x03)); + 0x20 | ((oct << 2) & 0x1c) | ((fre >> 8) & 0x03)); #ifdef DEBUG_ADLIB printf("-- %02x %02x\n", adlib_reg_L[0xa0+voice], adlib_reg_L[0xb0+voice]); #endif @@ -287,167 +279,163 @@ void synth_setnote (int voice, int note, int bend) /* back to your regularly scheduled driver */ -int adlibemu_stop_note(int chn, int note, int velocity) -{ - int i, op=255; +int adlibemu_stop_note(int chn, int note, int velocity) { + int i, op = 255; - // sciprintf("Note off %d %d %d\n", chn, note, velocity); + // sciprintf("Note off %d %d %d\n", chn, note, velocity); - for (i=0;i<ADLIB_VOICES && op==255;i++) { - if (oper_chn[i] == chn) - if (oper_note[i] == note) - op=i; - } + for (i = 0;i < ADLIB_VOICES && op == 255;i++) { + if (oper_chn[i] == chn) + if (oper_note[i] == note) + op = i; + } - if (op==255) { + if (op == 255) { #ifdef DEBUG_ADLIB - printf ("ADLIB: can't stop note: C%02x N%02x V%02x\n", chn, note, velocity); - printf ("C "); - for (i = 0; i < ADLIB_VOICES ; i++ ) { - printf ("%02x ", oper_chn[i]); - } - printf ("\n"); - printf ("N "); - for (i = 0; i < ADLIB_VOICES ; i++ ) { - printf ("%02x ", oper_note[i]); - } - printf ("\n"); + printf("ADLIB: can't stop note: C%02x N%02x V%02x\n", chn, note, velocity); + printf("C "); + for (i = 0; i < ADLIB_VOICES ; i++) { + printf("%02x ", oper_chn[i]); + } + printf("\n"); + printf("N "); + for (i = 0; i < ADLIB_VOICES ; i++) { + printf("%02x ", oper_note[i]); + } + printf("\n"); #endif - return -1; /* that note isn't playing.. */ - } + return -1; /* that note isn't playing.. */ + } - opl_write_L(0xb0+op,(adlib_reg_L[0xb0+op] & 0xdf)); - opl_write_R(0xb0+op,(adlib_reg_R[0xb0+op] & 0xdf)); + opl_write_L(0xb0 + op, (adlib_reg_L[0xb0+op] & 0xdf)); + opl_write_R(0xb0 + op, (adlib_reg_R[0xb0+op] & 0xdf)); - oper_chn[op] = 255; - oper_note[op] = 255; + oper_chn[op] = 255; + oper_note[op] = 255; - free_voices++; + free_voices++; #ifdef DEBUG_ADLIB - printf("stop voice %d (%d rem): C%02x N%02x V%02x\n", op, free_voices, chn, note, velocity); + printf("stop voice %d (%d rem): C%02x N%02x V%02x\n", op, free_voices, chn, note, velocity); #endif - return 0; + return 0; } -int adlibemu_start_note(int chn, int note, int velocity) -{ - int op, volume_L, volume_R, inst = 0; - - // sciprintf("Note on %d %d %d\n", chn, note, velocity); - - if (velocity == 0) { - return adlibemu_stop_note(chn, note, velocity); - } - - if (free_voices <= 0) { - printf("ADLIB: All voices full\n"); /* XXX implement overflow code */ - return -1; - } - - for (op = 0; op < ADLIB_VOICES ; op++) - if (oper_chn[op] == 255) - break; - - if (op == ADLIB_VOICES) { - printf("ADLIB: WTF? We couldn't find a voice yet it we have %d left.\n", free_voices); - return -1; - } - - /* Scale channel volume */ - volume_L = velocity * vol[chn] / 127; - volume_R = velocity * vol[chn] / 127; - - /* Apply a pan */ - if (pcmout_stereo) { - if (pan[chn] > 0x3f) /* pan right; so we scale the left down. */ - volume_L = volume_L / 0x3f * (0x3f - (pan[chn] - 0x3f)); - else if (pan[chn] < 0x3f) /* pan left; so we scale the right down.*/ - volume_R = volume_R / 0x3f * (0x3f - (0x3f-pan[chn])); - } - inst = instr[chn]; - - synth_setpatch(op, adlib_sbi[inst]); - synth_setvolume_L(op, volume_L); - synth_setvolume_R(op, volume_R); - synth_setnote(op, note, pitch[chn]); - - oper_chn[op] = chn; - oper_note[op] = note; - free_voices--; +int adlibemu_start_note(int chn, int note, int velocity) { + int op, volume_L, volume_R, inst = 0; + + // sciprintf("Note on %d %d %d\n", chn, note, velocity); + + if (velocity == 0) { + return adlibemu_stop_note(chn, note, velocity); + } + + if (free_voices <= 0) { + printf("ADLIB: All voices full\n"); /* XXX implement overflow code */ + return -1; + } + + for (op = 0; op < ADLIB_VOICES ; op++) + if (oper_chn[op] == 255) + break; + + if (op == ADLIB_VOICES) { + printf("ADLIB: WTF? We couldn't find a voice yet it we have %d left.\n", free_voices); + return -1; + } + + /* Scale channel volume */ + volume_L = velocity * vol[chn] / 127; + volume_R = velocity * vol[chn] / 127; + + /* Apply a pan */ + if (pcmout_stereo) { + if (pan[chn] > 0x3f) /* pan right; so we scale the left down. */ + volume_L = volume_L / 0x3f * (0x3f - (pan[chn] - 0x3f)); + else if (pan[chn] < 0x3f) /* pan left; so we scale the right down.*/ + volume_R = volume_R / 0x3f * (0x3f - (0x3f - pan[chn])); + } + inst = instr[chn]; + + synth_setpatch(op, adlib_sbi[inst]); + synth_setvolume_L(op, volume_L); + synth_setvolume_R(op, volume_R); + synth_setnote(op, note, pitch[chn]); + + oper_chn[op] = chn; + oper_note[op] = note; + free_voices--; #ifdef DEBUG_ADLIB - printf("play voice %d (%d rem): C%02x N%02x V%02x/%02x-%02x P%02x (%02x/%02x)\n", op, free_voices, chn, note, velocity, volume_L, volume_R, inst, - adlib_reg_L[register_base[2]+register_offset[op]] & 0x3f, - adlib_reg_L[register_base[3]+register_offset[op]] & 0x3f); + printf("play voice %d (%d rem): C%02x N%02x V%02x/%02x-%02x P%02x (%02x/%02x)\n", op, free_voices, chn, note, velocity, volume_L, volume_R, inst, + adlib_reg_L[register_base[2] + register_offset[op]] & 0x3f, + adlib_reg_L[register_base[3] + register_offset[op]] & 0x3f); #endif - return 0; + return 0; } static -void adlibemu_update_pitch(int chn, int note, int newpitch) -{ - int i; - int matched = 0; +void adlibemu_update_pitch(int chn, int note, int newpitch) { + int i; + int matched = 0; - pitch[chn] = newpitch; + pitch[chn] = newpitch; - for (i=0;i<ADLIB_VOICES;i++) { - if (oper_chn[i] == chn) - { - matched++; - synth_setnote(i, oper_note[i], newpitch); - } - } + for (i = 0;i < ADLIB_VOICES;i++) { + if (oper_chn[i] == chn) { + matched++; + synth_setnote(i, oper_note[i], newpitch); + } + } // printf("Matched %d notes on channel %d.\n", matched, chn); } -void test_adlib (void) { +void test_adlib(void) { - int voice = 0; + int voice = 0; #if 0 - guint8 data[] = { 0x25, 0x21, 0x48, 0x48, 0xf0, 0xf2, 0xf0, 0xa5, 0x00, 0x00, 0x06 }; + guint8 data[] = { 0x25, 0x21, 0x48, 0x48, 0xf0, 0xf2, 0xf0, 0xa5, 0x00, 0x00, 0x06 }; #else - guint8 *data = adlib_sbi[0x0a]; + guint8 *data = adlib_sbi[0x0a]; #endif #if 1 - opl_write(register_base[0]+register_offset[voice], data[0]); - opl_write(register_base[1]+register_offset[voice], data[1]); - opl_write(register_base[2]+register_offset[voice], data[2]); - opl_write(register_base[3]+register_offset[voice], data[3]); - opl_write(register_base[4]+register_offset[voice], data[4]); - opl_write(register_base[5]+register_offset[voice], data[5]); - opl_write(register_base[6]+register_offset[voice], data[6]); - opl_write(register_base[7]+register_offset[voice], data[7]); - opl_write(register_base[8]+register_offset[voice], data[8]); - opl_write(register_base[9]+register_offset[voice], data[9]); - opl_write(register_base[10]+register_offset[voice], data[10]); + opl_write(register_base[0] + register_offset[voice], data[0]); + opl_write(register_base[1] + register_offset[voice], data[1]); + opl_write(register_base[2] + register_offset[voice], data[2]); + opl_write(register_base[3] + register_offset[voice], data[3]); + opl_write(register_base[4] + register_offset[voice], data[4]); + opl_write(register_base[5] + register_offset[voice], data[5]); + opl_write(register_base[6] + register_offset[voice], data[6]); + opl_write(register_base[7] + register_offset[voice], data[7]); + opl_write(register_base[8] + register_offset[voice], data[8]); + opl_write(register_base[9] + register_offset[voice], data[9]); + opl_write(register_base[10] + register_offset[voice], data[10]); #else - synth_setpatch(voice, data); + synth_setpatch(voice, data); #endif #if 0 - opl_write(0xA0 + voice, 0x57); - opl_write(0xB0 + voice, 0x2d); + opl_write(0xA0 + voice, 0x57); + opl_write(0xB0 + voice, 0x2d); #else - synth_setvolume_L(voice, 0x50); - synth_setvolume_R(voice, 0x50); - synth_setnote(voice, 0x30, 0); + synth_setvolume_L(voice, 0x50); + synth_setvolume_R(voice, 0x50); + synth_setnote(voice, 0x30, 0); #endif - /* - instr[0x0e] = 0x0a; - instr[0x03] = 0x26; + /* + instr[0x0e] = 0x0a; + instr[0x03] = 0x26; - adlibemu_start_note(0x0e, 0x30, 0x40); - sleep(1); - adlibemu_start_note(0x03, 0x48, 0x40); - sleep(1); - */ + adlibemu_start_note(0x0e, 0x30, 0x40); + sleep(1); + adlibemu_start_note(0x03, 0x48, 0x40); + sleep(1); + */ } @@ -455,8 +443,7 @@ void test_adlib (void) { We assume 16-bit stereo frames (ie 4 bytes) */ static void -opl2_poll (sfx_softseq_t *self, byte *dest, int count) -{ +opl2_poll(sfx_softseq_t *self, byte *dest, int count) { gint16 *buffer = (gint16 *) dest; gint16 *ptr = buffer; @@ -481,7 +468,7 @@ opl2_poll (sfx_softseq_t *self, byte *dest, int count) samples = sci_min(samples, remaining); if (samples) { YM3812UpdateOne(ADLIB_LEFT, ptr, samples, 1); - YM3812UpdateOne(ADLIB_RIGHT, ptr+1, samples, 1); + YM3812UpdateOne(ADLIB_RIGHT, ptr + 1, samples, 1); } if (remaining > samples) { remaining_delta = (remaining - samples) * 1000000 / pcmout_sample_rate; @@ -496,37 +483,36 @@ opl2_poll (sfx_softseq_t *self, byte *dest, int count) #endif if (pcmout_stereo) { - YM3812UpdateOne (ym3812_L, ptr, count, 1); - YM3812UpdateOne (ym3812_R, ptr+1, count, 1); + YM3812UpdateOne(ym3812_L, ptr, count, 1); + YM3812UpdateOne(ym3812_R, ptr + 1, count, 1); } else { - YM3812UpdateOne (ym3812_L, ptr, count, 0); + YM3812UpdateOne(ym3812_L, ptr, count, 0); } } static int opl2_init(sfx_softseq_t *self, byte *data_ptr, int data_length, byte *data2_ptr, - int data2_length) -{ + int data2_length) { int i; /* load up the patch.003 file, parse out the instruments */ if (data_length < 1344) { - sciprintf ("[sfx:seq:opl2] Invalid patch.003: Expected %d, got %d\n", 1344, data_length); + sciprintf("[sfx:seq:opl2] Invalid patch.003: Expected %d, got %d\n", 1344, data_length); return -1; } for (i = 0; i < 48; i++) - make_sbi((adlib_def *)(data_ptr+(28 * i)), adlib_sbi[i]); + make_sbi((adlib_def *)(data_ptr + (28 * i)), adlib_sbi[i]); if (data_length > 1344) for (i = 48; i < 96; i++) - make_sbi((adlib_def *)(data_ptr+2+(28 * i)), adlib_sbi[i]); + make_sbi((adlib_def *)(data_ptr + 2 + (28 * i)), adlib_sbi[i]); OPLBuildTables(FMOPL_ENV_BITS_HQ, FMOPL_EG_ENT_HQ); - if (!(ym3812_L = OPLCreate (OPL_TYPE_YM3812, OPL_INTERNAL_FREQ, SAMPLE_RATE)) || - !(ym3812_R = OPLCreate (OPL_TYPE_YM3812, OPL_INTERNAL_FREQ, SAMPLE_RATE))) { - sciprintf ("[sfx:seq:opl2] Failure: Emulator init failed!\n"); + if (!(ym3812_L = OPLCreate(OPL_TYPE_YM3812, OPL_INTERNAL_FREQ, SAMPLE_RATE)) || + !(ym3812_R = OPLCreate(OPL_TYPE_YM3812, OPL_INTERNAL_FREQ, SAMPLE_RATE))) { + sciprintf("[sfx:seq:opl2] Failure: Emulator init failed!\n"); return SFX_ERROR; } @@ -538,8 +524,7 @@ opl2_init(sfx_softseq_t *self, byte *data_ptr, int data_length, byte *data2_ptr, static void -opl2_exit(sfx_softseq_t *self) -{ +opl2_exit(sfx_softseq_t *self) { FM_OPL *opl = ym3812_L; ym3812_L = NULL; OPLDestroy(opl); @@ -551,16 +536,15 @@ opl2_exit(sfx_softseq_t *self) } static void -opl2_allstop(sfx_softseq_t *self) -{ +opl2_allstop(sfx_softseq_t *self) { // printf("AdlibEmu: Reset\n"); if (! ready) return; adlibemu_init_lists(); - OPLResetChip (ym3812_L); - OPLResetChip (ym3812_R); + OPLResetChip(ym3812_L); + OPLResetChip(ym3812_R); opl_write(0x01, 0x20); opl_write(0xBD, 0xc0); @@ -571,106 +555,99 @@ opl2_allstop(sfx_softseq_t *self) // test_adlib(); } -int midi_adlibemu_reverb(short param) -{ - printf("ADLIB: reverb NYI %04x \n", param); - return 0; +int midi_adlibemu_reverb(short param) { + printf("ADLIB: reverb NYI %04x \n", param); + return 0; } -int midi_adlibemu_event(guint8 command, guint8 note, guint8 velocity, guint32 delta) -{ - guint8 channel, oper; - - channel = command & 0x0f; - oper = command & 0xf0; - - switch (oper) { - case 0x80: - return adlibemu_stop_note(channel, note, velocity); - case 0x90: /* noteon and noteoff */ - return adlibemu_start_note(channel, note, velocity); - case 0xe0: /* Pitch bend */ - { - int bend = (note & 0x7f) | ((velocity & 0x7f) << 7); +int midi_adlibemu_event(guint8 command, guint8 note, guint8 velocity, guint32 delta) { + guint8 channel, oper; + + channel = command & 0x0f; + oper = command & 0xf0; + + switch (oper) { + case 0x80: + return adlibemu_stop_note(channel, note, velocity); + case 0x90: /* noteon and noteoff */ + return adlibemu_start_note(channel, note, velocity); + case 0xe0: { /* Pitch bend */ + int bend = (note & 0x7f) | ((velocity & 0x7f) << 7); // printf("Bend to %d\n", bend); - adlibemu_update_pitch(channel, note, bend); - } - case 0xb0: /* CC changes. */ - switch (note) { - case 0x07: - vol[channel] = velocity; - break; - case 0x0a: - pan[channel] = velocity; - break; - case 0x4b: - break; - case 0x7b: { /* all notes off */ - int i = 0; - for (i=0;i<ADLIB_VOICES;i++) - if (oper_chn[i] == channel) - adlibemu_stop_note(channel, oper_note[i], 0); - break; - } - default: - ; /* XXXX ignore everything else for now */ - } - return 0; - case 0xd0: /* aftertouch */ - /* XXX Aftertouch in the OPL thing? */ - return 0; - default: - printf("ADLIB: Unknown event %02x\n", command); - return 0; - } - - return 0; + adlibemu_update_pitch(channel, note, bend); + } + case 0xb0: /* CC changes. */ + switch (note) { + case 0x07: + vol[channel] = velocity; + break; + case 0x0a: + pan[channel] = velocity; + break; + case 0x4b: + break; + case 0x7b: { /* all notes off */ + int i = 0; + for (i = 0;i < ADLIB_VOICES;i++) + if (oper_chn[i] == channel) + adlibemu_stop_note(channel, oper_note[i], 0); + break; + } + default: + ; /* XXXX ignore everything else for now */ + } + return 0; + case 0xd0: /* aftertouch */ + /* XXX Aftertouch in the OPL thing? */ + return 0; + default: + printf("ADLIB: Unknown event %02x\n", command); + return 0; + } + + return 0; } -int midi_adlibemu_event2(guint8 command, guint8 param, guint32 delta) -{ - guint8 channel; - guint8 oper; +int midi_adlibemu_event2(guint8 command, guint8 param, guint32 delta) { + guint8 channel; + guint8 oper; - channel = command & 0x0f; - oper = command & 0xf0; - switch (oper) { - case 0xc0: /* change instrument */ + channel = command & 0x0f; + oper = command & 0xf0; + switch (oper) { + case 0xc0: /* change instrument */ #ifdef DEBUG_ADLIB - printf("ADLIB: Selecting instrument %d on channel %d\n", param, channel); + printf("ADLIB: Selecting instrument %d on channel %d\n", param, channel); #endif - instr[channel] = param; - return 0; - default: - printf("ADLIB: Unknown event %02x\n", command); - } + instr[channel] = param; + return 0; + default: + printf("ADLIB: Unknown event %02x\n", command); + } - return 0; + return 0; } static void -opl2_volume(sfx_softseq_t *self, int volume) -{ - guint8 i; +opl2_volume(sfx_softseq_t *self, int volume) { + guint8 i; - i = (guint8)volume * 15 / 100; + i = (guint8)volume * 15 / 100; - adlib_master=i; + adlib_master = i; #ifdef DEBUG_ADLIB - printf("ADLIB: master volume set to %d\n", adlib_master); + printf("ADLIB: master volume set to %d\n", adlib_master); #endif } int -opl2_set_option(sfx_softseq_t *self, const char *name, const char *value) -{ +opl2_set_option(sfx_softseq_t *self, const char *name, const char *value) { return SFX_ERROR; } void -opl2_event(sfx_softseq_t *self, byte cmd, int argc, byte *argv) -{ +opl2_event(sfx_softseq_t *self, byte cmd, int argc, byte *argv) { if (argc == 1) midi_adlibemu_event2(cmd, argv[0], 0); else if (argc == 2) diff --git a/engines/sci/sfx/softseq/pcspeaker.cpp b/engines/sci/sfx/softseq/pcspeaker.cpp index cde71ae62e..99a95913ff 100644 --- a/engines/sci/sfx/softseq/pcspeaker.cpp +++ b/engines/sci/sfx/softseq/pcspeaker.cpp @@ -35,35 +35,31 @@ static int volume = 0x0600; static int note = 0; /* Current halftone, or 0 if off */ -static int freq_count = 0; +static int freq_count = 0; extern sfx_softseq_t sfx_softseq_pcspeaker; /* Forward-declare the sequencer we are defining here */ static int -sps_set_option(sfx_softseq_t *self, const char *name, const char *value) -{ +sps_set_option(sfx_softseq_t *self, const char *name, const char *value) { return SFX_ERROR; } static int sps_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch2, - int patch2_len) -{ + int patch2_len) { return SFX_OK; } static void -sps_exit(sfx_softseq_t *self) -{ +sps_exit(sfx_softseq_t *self) { } static void -sps_event(sfx_softseq_t *self, byte command, int argc, byte *argv) -{ +sps_event(sfx_softseq_t *self, byte command, int argc, byte *argv) { #if 0 - fprintf(stderr, "Note [%02x : %02x %02x]\n", command, argc?argv[0] : 0, (argc > 1)? argv[1] : 0); + fprintf(stderr, "Note [%02x : %02x %02x]\n", command, argc ? argv[0] : 0, (argc > 1) ? argv[1] : 0); #endif switch (command & 0xf0) { @@ -89,7 +85,7 @@ sps_event(sfx_softseq_t *self, byte command, int argc, byte *argv) default: #if DEBUG - fprintf(stderr, "[SFX:PCM-PC] Unused MIDI command %02x %02x %02x\n", command, argc?argv[0] : 0, (argc > 1)? argv[1] : 0); + fprintf(stderr, "[SFX:PCM-PC] Unused MIDI command %02x %02x %02x\n", command, argc ? argv[0] : 0, (argc > 1) ? argv[1] : 0); #endif break; /* ignore */ } @@ -116,12 +112,11 @@ freq_table[12] = { /* A4 is 440Hz, halftone map is x |-> ** 2^(x/12) */ void -sps_poll(sfx_softseq_t *self, byte *dest, int len) -{ +sps_poll(sfx_softseq_t *self, byte *dest, int len) { int halftone_delta = note - BASE_NOTE; int oct_diff = ((halftone_delta + BASE_OCTAVE * 12) / 12) - BASE_OCTAVE; - int halftone_index = (halftone_delta + (12*100)) % 12 ; - int freq = (!note)? 0 : freq_table[halftone_index] / (1 << (-oct_diff)); + int halftone_index = (halftone_delta + (12 * 100)) % 12 ; + int freq = (!note) ? 0 : freq_table[halftone_index] / (1 << (-oct_diff)); gint16 *buf = (gint16 *) dest; int i; @@ -134,12 +129,12 @@ sps_poll(sfx_softseq_t *self, byte *dest, int len) if (freq_count - freq < 0) { /* Unclean rising edge */ int l = volume << 1; - buf[i] = -volume + (l*freq_count)/freq; + buf[i] = -volume + (l * freq_count) / freq; } else if (freq_count >= FREQUENCY - && freq_count - freq < FREQUENCY) { + && freq_count - freq < FREQUENCY) { /* Unclean falling edge */ int l = volume << 1; - buf[i] = volume - (l*(freq_count - FREQUENCY))/freq; + buf[i] = volume - (l * (freq_count - FREQUENCY)) / freq; } else { if (freq_count < FREQUENCY) buf[i] = volume; @@ -153,14 +148,12 @@ sps_poll(sfx_softseq_t *self, byte *dest, int len) } void -sps_volume(sfx_softseq_t *self, int new_volume) -{ +sps_volume(sfx_softseq_t *self, int new_volume) { volume = new_volume << 4; } void -sps_allstop(sfx_softseq_t *self) -{ +sps_allstop(sfx_softseq_t *self) { note = 0; } diff --git a/engines/sci/sfx/softseq/softsequencers.cpp b/engines/sci/sfx/softseq/softsequencers.cpp index a63500ebd5..115d9bfdf9 100644 --- a/engines/sci/sfx/softseq/softsequencers.cpp +++ b/engines/sci/sfx/softseq/softsequencers.cpp @@ -42,7 +42,7 @@ extern sfx_softseq_t sfx_softseq_fluidsynth; static sfx_softseq_t *sw_sequencers[] = { &sfx_softseq_opl2, -/* &sfx_softseq_mt32, */ + /* &sfx_softseq_mt32, */ &sfx_softseq_SN76496, &sfx_softseq_pcspeaker, &sfx_softseq_amiga, @@ -54,8 +54,7 @@ static sfx_softseq_t *sw_sequencers[] = { sfx_softseq_t * -sfx_find_softseq(const char *name) -{ +sfx_find_softseq(const char *name) { if (!name) return sw_sequencers[0]; else { diff --git a/engines/sci/sfx/songlib.cpp b/engines/sci/sfx/songlib.cpp index 57475e82db..abfe293627 100644 --- a/engines/sci/sfx/songlib.cpp +++ b/engines/sci/sfx/songlib.cpp @@ -31,8 +31,7 @@ #define debug_stream stderr GTimeVal -song_sleep_time(GTimeVal *lastslept, long ticks) -{ +song_sleep_time(GTimeVal *lastslept, long ticks) { GTimeVal tv; long timetosleep; long timeslept; /* Time already slept */ @@ -40,7 +39,7 @@ song_sleep_time(GTimeVal *lastslept, long ticks) sci_get_current_time(&tv); timeslept = 1000000 * (tv.tv_sec - lastslept->tv_sec) + - tv.tv_usec - lastslept->tv_usec; + tv.tv_usec - lastslept->tv_usec; timetosleep -= timeslept; @@ -55,8 +54,7 @@ song_sleep_time(GTimeVal *lastslept, long ticks) GTimeVal -song_next_wakeup_time(GTimeVal *lastslept, long ticks) -{ +song_next_wakeup_time(GTimeVal *lastslept, long ticks) { GTimeVal retval; retval.tv_sec = lastslept->tv_sec + (ticks / 60); @@ -72,8 +70,7 @@ song_next_wakeup_time(GTimeVal *lastslept, long ticks) song_t * -song_new(song_handle_t handle, song_iterator_t *it, int priority) -{ +song_new(song_handle_t handle, song_iterator_t *it, int priority) { song_t *retval; retval = (song_t*) sci_malloc(sizeof(song_t)); @@ -97,14 +94,13 @@ song_new(song_handle_t handle, song_iterator_t *it, int priority) void -song_lib_add(songlib_t songlib, song_t *song) -{ +song_lib_add(songlib_t songlib, song_t *song) { song_t **seeker = NULL; int pri = song->priority; if (NULL == song) { - sciprintf("song_lib_add(): NULL passed for song\n"); - return; + sciprintf("song_lib_add(): NULL passed for song\n"); + return; } if (*(songlib.lib) == NULL) { @@ -123,8 +119,7 @@ song_lib_add(songlib_t songlib, song_t *song) } static void /* Recursively free a chain of songs */ -_songfree_chain(song_t *song) -{ +_songfree_chain(song_t *song) { if (song) { _songfree_chain(song->next); songit_free(song->it); @@ -135,23 +130,20 @@ _songfree_chain(song_t *song) void -song_lib_init(songlib_t *songlib) -{ +song_lib_init(songlib_t *songlib) { songlib->lib = &(songlib->_s); songlib->_s = NULL; } void -song_lib_free(songlib_t songlib) -{ +song_lib_free(songlib_t songlib) { _songfree_chain(*(songlib.lib)); *(songlib.lib) = NULL; } song_t * -song_lib_find(songlib_t songlib, song_handle_t handle) -{ +song_lib_find(songlib_t songlib, song_handle_t handle) { song_t *seeker = *(songlib.lib); while (seeker) { @@ -165,13 +157,12 @@ song_lib_find(songlib_t songlib, song_handle_t handle) song_t * -song_lib_find_next_active(songlib_t songlib, song_t *other) -{ - song_t *seeker = other? other->next : *(songlib.lib); +song_lib_find_next_active(songlib_t songlib, song_t *other) { + song_t *seeker = other ? other->next : *(songlib.lib); while (seeker) { if ((seeker->status == SOUND_STATUS_WAITING) || - (seeker->status == SOUND_STATUS_PLAYING)) + (seeker->status == SOUND_STATUS_PLAYING)) break; seeker = seeker->next; } @@ -184,14 +175,12 @@ song_lib_find_next_active(songlib_t songlib, song_t *other) } song_t * -song_lib_find_active(songlib_t songlib) -{ +song_lib_find_active(songlib_t songlib) { return song_lib_find_next_active(songlib, NULL); } int -song_lib_remove(songlib_t songlib, song_handle_t handle) -{ +song_lib_remove(songlib_t songlib, song_handle_t handle) { int retval; song_t *goner = *(songlib.lib); @@ -222,8 +211,7 @@ song_lib_remove(songlib_t songlib, song_handle_t handle) } void -song_lib_resort(songlib_t songlib, song_t *song) -{ +song_lib_resort(songlib_t songlib, song_t *song) { if (*(songlib.lib) == song) *(songlib.lib) = song->next; else { @@ -240,8 +228,7 @@ song_lib_resort(songlib_t songlib, song_t *song) } int -song_lib_count(songlib_t songlib) -{ +song_lib_count(songlib_t songlib) { song_t *seeker = *(songlib.lib); int retval = 0; @@ -254,29 +241,27 @@ song_lib_count(songlib_t songlib) } void -song_lib_set_restore_behavior(songlib_t songlib, song_handle_t handle, RESTORE_BEHAVIOR action) -{ +song_lib_set_restore_behavior(songlib_t songlib, song_handle_t handle, RESTORE_BEHAVIOR action) { song_t *seeker = song_lib_find(songlib, handle); seeker->restore_behavior = action; } void -song_lib_dump(songlib_t songlib, int line) -{ +song_lib_dump(songlib_t songlib, int line) { song_t *seeker = *(songlib.lib); - fprintf(debug_stream,"L%d:", line); + fprintf(debug_stream, "L%d:", line); do { - fprintf(debug_stream," %p", (void *)seeker); + fprintf(debug_stream, " %p", (void *)seeker); if (seeker) { - fprintf(debug_stream,"[%04lx,p=%d,s=%d]->", seeker->handle, seeker->priority,seeker->status); + fprintf(debug_stream, "[%04lx,p=%d,s=%d]->", seeker->handle, seeker->priority, seeker->status); seeker = seeker->next; } - fprintf(debug_stream,"\n"); + fprintf(debug_stream, "\n"); } while (seeker); - fprintf(debug_stream,"\n"); + fprintf(debug_stream, "\n"); } diff --git a/engines/sci/sfx/test-iterator.cpp b/engines/sci/sfx/test-iterator.cpp index 1ecce673f9..6d5374065a 100644 --- a/engines/sci/sfx/test-iterator.cpp +++ b/engines/sci/sfx/test-iterator.cpp @@ -38,8 +38,7 @@ int errors = 0; void -error(char *fmt, ...) -{ +error(char *fmt, ...) { va_list ap; fprintf(stderr, "[ERROR] "); @@ -63,8 +62,7 @@ struct simple_it_struct { } simple_iterator; int -simple_it_next(song_iterator_t *_self, unsigned char *buf, int *result) -{ +simple_it_next(song_iterator_t *_self, unsigned char *buf, int *result) { struct simple_it_struct *self = (struct simple_it_struct *) _self; if (self->lifetime_remaining == -1) { @@ -109,26 +107,22 @@ simple_it_next(song_iterator_t *_self, unsigned char *buf, int *result) } sfx_pcm_feed_t * -simple_it_pcm_feed(song_iterator_t *_self) -{ +simple_it_pcm_feed(song_iterator_t *_self) { error("No PCM feed!\n"); return NULL; } void -simple_it_init(song_iterator_t *_self) -{ +simple_it_init(song_iterator_t *_self) { } song_iterator_t * -simple_it_handle_message(song_iterator_t *_self, song_iterator_message_t msg) -{ +simple_it_handle_message(song_iterator_t *_self, song_iterator_message_t msg) { return NULL; } void -simple_it_cleanup(song_iterator_t *_self) -{ +simple_it_cleanup(song_iterator_t *_self) { } /* Initialises the simple iterator. @@ -138,8 +132,7 @@ simple_it_cleanup(song_iterator_t *_self) ** The first cue is emitted after cues[0] ticks, and it is 1. After cues[1] additional ticks ** the next cue is emitted, and so on. */ song_iterator_t * -setup_simple_iterator(int delay, char *cues, int cues_nr) -{ +setup_simple_iterator(int delay, char *cues, int cues_nr) { simple_iterator.lifetime_remaining = delay; simple_iterator.cues = cues; simple_iterator.cue_counter = 0; @@ -169,16 +162,15 @@ setup_simple_iterator(int delay, char *cues, int cues_nr) #define ASSERT_CUE(n) ASSERT_NEXT(SI_ABSOLUTE_CUE); ASSERT_RESULT(n) void -test_simple_it() -{ +test_simple_it() { song_iterator_t *it; - song_iterator_t *simple_it = (song_iterator_t *) &simple_iterator; + song_iterator_t *simple_it = (song_iterator_t *) & simple_iterator; unsigned char data[4]; int result; puts("[TEST] simple iterator (test artifact)"); it = setup_simple_iterator(42, NULL, 0); - + ASSERT_SIT; ASSERT_NEXT(42); ASSERT_SIT; @@ -202,10 +194,9 @@ test_simple_it() } void -test_fastforward() -{ +test_fastforward() { song_iterator_t *it; - song_iterator_t *simple_it = (song_iterator_t *) &simple_iterator; + song_iterator_t *simple_it = (song_iterator_t *) & simple_iterator; song_iterator_t *ff_it; unsigned char data[4]; int result; @@ -287,18 +278,18 @@ test_fastforward() #define SIMPLE_SONG_SIZE 50 static unsigned char simple_song[SIMPLE_SONG_SIZE] = { - 0x00, /* Regular song */ - /* Only use channel 0 for all devices */ - 0x02, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - /* Song begins here */ - 42, 0x90, 60, 0x7f, /* Play C after 42 ticks */ - 02, 64, 0x42, /* Play E after 2 more ticks, using running status mode */ - 0xf8, 10, 0x80, 60, 0x02, /* Stop C after 250 ticks */ - 0, 64, 0x00, /* Stop E immediately */ - 00, 0xfc /* Stop song */ + 0x00, /* Regular song */ + /* Only use channel 0 for all devices */ + 0x02, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* Song begins here */ + 42, 0x90, 60, 0x7f, /* Play C after 42 ticks */ + 02, 64, 0x42, /* Play E after 2 more ticks, using running status mode */ + 0xf8, 10, 0x80, 60, 0x02, /* Stop C after 250 ticks */ + 0, 64, 0x00, /* Stop E immediately */ + 00, 0xfc /* Stop song */ }; #define ASSERT_MIDI3(cmd, arg0, arg1) \ @@ -307,9 +298,8 @@ static unsigned char simple_song[SIMPLE_SONG_SIZE] = { ASSERT(data[2] == arg1); void -test_iterator_sci0() -{ - song_iterator_t *it = songit_new (simple_song, SIMPLE_SONG_SIZE, SCI_SONG_ITERATOR_TYPE_SCI0, 0l); +test_iterator_sci0() { + song_iterator_t *it = songit_new(simple_song, SIMPLE_SONG_SIZE, SCI_SONG_ITERATOR_TYPE_SCI0, 0l); unsigned char data[4]; int result; SIMSG_SEND(it, SIMSG_SET_PLAYMASK(0x0001)); /* Initialise song, enabling channel 0 */ @@ -333,9 +323,8 @@ test_iterator_sci0() void -test_iterator_sci0_loop() -{ - song_iterator_t *it = songit_new (simple_song, SIMPLE_SONG_SIZE, SCI_SONG_ITERATOR_TYPE_SCI0, 0l); +test_iterator_sci0_loop() { + song_iterator_t *it = songit_new(simple_song, SIMPLE_SONG_SIZE, SCI_SONG_ITERATOR_TYPE_SCI0, 0l); unsigned char data[4]; int result; SIMSG_SEND(it, SIMSG_SET_PLAYMASK(0x0001)); /* Initialise song, enabling channel 0 */ @@ -374,26 +363,25 @@ test_iterator_sci0_loop() #define LOOP_SONG_SIZE 54 unsigned char loop_song[LOOP_SONG_SIZE] = { - 0x00, /* Regular song song */ - /* Only use channel 0 for all devices */ - 0x02, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - /* Song begins here */ - 42, 0x90, 60, 0x7f, /* Play C after 42 ticks */ - 13, 0x80, 60, 0x00, /* Stop C after 13 ticks */ - 00, 0xCF, 0x7f, /* Set loop point */ - 02, 0x90, 64, 0x42, /* Play E after 2 more ticks, using running status mode */ - 03, 0x80, 64, 0x00, /* Stop E after 3 ticks */ - 00, 0xfc /* Stop song/loop */ + 0x00, /* Regular song song */ + /* Only use channel 0 for all devices */ + 0x02, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* Song begins here */ + 42, 0x90, 60, 0x7f, /* Play C after 42 ticks */ + 13, 0x80, 60, 0x00, /* Stop C after 13 ticks */ + 00, 0xCF, 0x7f, /* Set loop point */ + 02, 0x90, 64, 0x42, /* Play E after 2 more ticks, using running status mode */ + 03, 0x80, 64, 0x00, /* Stop E after 3 ticks */ + 00, 0xfc /* Stop song/loop */ }; void -test_iterator_sci0_mark_loop() -{ - song_iterator_t *it = songit_new (loop_song, LOOP_SONG_SIZE, SCI_SONG_ITERATOR_TYPE_SCI0, 0l); +test_iterator_sci0_mark_loop() { + song_iterator_t *it = songit_new(loop_song, LOOP_SONG_SIZE, SCI_SONG_ITERATOR_TYPE_SCI0, 0l); unsigned char data[4]; int result; SIMSG_SEND(it, SIMSG_SET_PLAYMASK(0x0001)); /* Initialise song, enabling channel 0 */ @@ -437,8 +425,7 @@ test_iterator_sci0_mark_loop() int -main(int argc, char **argv) -{ +main(int argc, char **argv) { test_simple_it(); test_fastforward(); test_iterator_sci0(); diff --git a/engines/sci/sfx/tests/tests.cpp b/engines/sci/sfx/tests/tests.cpp index 10eacc0de2..0999d3615f 100644 --- a/engines/sci/sfx/tests/tests.cpp +++ b/engines/sci/sfx/tests/tests.cpp @@ -7,24 +7,25 @@ static char calledDeathListenerCallback; static unsigned char song[] = { // PCM not present -0, + 0, // channel defs -0, 0x20, 0, 0x21, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0, + 0, 0x20, 0, 0x21, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, // note on, wait, note off -0xAA, -0x90, 0xAA, 0xAA, -0xAA, -0x80, 0xAA, 0xAA, -0xAA, -0x91, 0xAA, 0xAA, -0xAA, -0x81, 0xAA, 0xAA, -0xAA, + 0xAA, + 0x90, 0xAA, 0xAA, + 0xAA, + 0x80, 0xAA, 0xAA, + 0xAA, + 0x91, 0xAA, 0xAA, + 0xAA, + 0x81, 0xAA, 0xAA, + 0xAA, // end track -0xFC}; + 0xFC +}; #define SONG_CMD_COUNT 10 @@ -43,8 +44,7 @@ static unsigned char song[] = { songit_free(it); -void testFinishSong() -{ +void testFinishSong() { TEST_SETUP(); message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); TESTEQUAL(0xAA, message); @@ -53,8 +53,7 @@ void testFinishSong() TESTEQUAL(0, message); TESTEQUAL(3, result); - for (i=0; i < SONG_CMD_COUNT - 2; i++) - { + for (i = 0; i < SONG_CMD_COUNT - 2; i++) { message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); } @@ -64,23 +63,20 @@ void testFinishSong() } -void DeathListenerCallback(void *v1, void *v2) -{ +void DeathListenerCallback(void *v1, void *v2) { calledDeathListenerCallback++; return; } -void testDeathListener() -{ +void testDeathListener() { TEST_SETUP(); song_iterator_add_death_listener( - it, - it, - (void (*)(void *, void*))DeathListenerCallback); + it, + it, + (void(*)(void *, void*))DeathListenerCallback); - for (i=0; i < SONG_CMD_COUNT; i++) - { + for (i = 0; i < SONG_CMD_COUNT; i++) { message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); } @@ -91,22 +87,20 @@ void testDeathListener() TESTEQUAL(1, calledDeathListenerCallback); } -void testMultipleDeathListeners() -{ +void testMultipleDeathListeners() { TEST_SETUP(); song_iterator_add_death_listener( - it, - it, - (void (*)(void *, void*))DeathListenerCallback); + it, + it, + (void(*)(void *, void*))DeathListenerCallback); song_iterator_add_death_listener( - it, - it, - (void (*)(void *, void*))DeathListenerCallback); + it, + it, + (void(*)(void *, void*))DeathListenerCallback); - for (i=0; i < SONG_CMD_COUNT; i++) - { + for (i = 0; i < SONG_CMD_COUNT; i++) { message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); } @@ -117,19 +111,17 @@ void testMultipleDeathListeners() TESTEQUAL(2, calledDeathListenerCallback); } -void testStopSong() -{ +void testStopSong() { TEST_SETUP(); SIMSG_SEND(it, SIMSG_STOP); - + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); TESTEQUAL(SI_FINISHED, message); TEST_TEARDOWN(); } -void testStopLoopedSong() -{ +void testStopLoopedSong() { TEST_SETUP(); SIMSG_SEND(it, SIMSG_SET_LOOPS(3)); @@ -143,8 +135,7 @@ void testStopLoopedSong() TEST_TEARDOWN(); } -void testChangeSongMask() -{ +void testChangeSongMask() { TEST_SETUP(); message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); @@ -159,8 +150,7 @@ void testChangeSongMask() } -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { testFinishSong(); testDeathListener(); testMultipleDeathListeners(); diff --git a/engines/sci/sfx/time.cpp b/engines/sci/sfx/time.cpp index 0063b8ef65..6bcafd015c 100644 --- a/engines/sci/sfx/time.cpp +++ b/engines/sci/sfx/time.cpp @@ -31,8 +31,7 @@ #include "sci/include/resource.h" sfx_timestamp_t -sfx_new_timestamp(long secs, long usecs, int frame_rate) -{ +sfx_new_timestamp(long secs, long usecs, int frame_rate) { sfx_timestamp_t r; r.secs = secs; r.usecs = usecs; @@ -44,8 +43,7 @@ sfx_new_timestamp(long secs, long usecs, int frame_rate) sfx_timestamp_t -sfx_timestamp_add(sfx_timestamp_t timestamp, int frames) -{ +sfx_timestamp_add(sfx_timestamp_t timestamp, int frames) { timestamp.frame_offset += frames; if (timestamp.frame_offset < 0) { @@ -62,8 +60,7 @@ sfx_timestamp_add(sfx_timestamp_t timestamp, int frames) } int -sfx_timestamp_frame_diff(sfx_timestamp_t a, sfx_timestamp_t b) -{ +sfx_timestamp_frame_diff(sfx_timestamp_t a, sfx_timestamp_t b) { long usecdelta = 0; if (a.frame_rate != b.frame_rate) { @@ -74,21 +71,20 @@ sfx_timestamp_frame_diff(sfx_timestamp_t a, sfx_timestamp_t b) if (a.usecs != b.usecs) { #if (SIZEOF_LONG >= 8) usecdelta = (a.usecs * a.frame_rate) / 1000000 - - (b.usecs * b.frame_rate) / 1000000; + - (b.usecs * b.frame_rate) / 1000000; #else - usecdelta = ((a.usecs/1000) * a.frame_rate) / 1000 - - ((b.usecs/1000) * b.frame_rate) / 1000; + usecdelta = ((a.usecs / 1000) * a.frame_rate) / 1000 + - ((b.usecs / 1000) * b.frame_rate) / 1000; #endif } return usecdelta - + (a.secs - b.secs) * a.frame_rate - + a.frame_offset - b.frame_offset; + + (a.secs - b.secs) * a.frame_rate + + a.frame_offset - b.frame_offset; } long -sfx_timestamp_usecs_diff(sfx_timestamp_t t1, sfx_timestamp_t t2) -{ +sfx_timestamp_usecs_diff(sfx_timestamp_t t1, sfx_timestamp_t t2) { long secs1, secs2; long usecs1, usecs2; @@ -96,11 +92,10 @@ sfx_timestamp_usecs_diff(sfx_timestamp_t t1, sfx_timestamp_t t2) sfx_timestamp_gettime(&t2, &secs2, &usecs2); return (usecs1 - usecs2) + ((secs1 - secs2) * 1000000); -} +} sfx_timestamp_t -sfx_timestamp_renormalise(sfx_timestamp_t timestamp, int new_freq) -{ +sfx_timestamp_renormalise(sfx_timestamp_t timestamp, int new_freq) { sfx_timestamp_t r; sfx_timestamp_gettime(×tamp, &r.secs, &r.usecs); r.frame_rate = new_freq; @@ -110,8 +105,7 @@ sfx_timestamp_renormalise(sfx_timestamp_t timestamp, int new_freq) } void -sfx_timestamp_gettime(sfx_timestamp_t *timestamp, long *secs, long *usecs) -{ +sfx_timestamp_gettime(sfx_timestamp_t *timestamp, long *secs, long *usecs) { long ust = timestamp->usecs; /* On 64 bit machines, we can do an accurate computation */ #if (SIZEOF_LONG >= 8) diff --git a/engines/sci/sfx/timer/pthread.cpp b/engines/sci/sfx/timer/pthread.cpp index 074adbe08f..bcef9639c4 100644 --- a/engines/sci/sfx/timer/pthread.cpp +++ b/engines/sci/sfx/timer/pthread.cpp @@ -41,8 +41,7 @@ pthread_t thread; volatile static int thread_run; static void * -timer_thread(void *arg) -{ +timer_thread(void *arg) { while (thread_run) { if (callback) callback(callback_data); @@ -54,14 +53,12 @@ timer_thread(void *arg) } static int -set_option(char *name, char *value) -{ +set_option(char *name, char *value) { return SFX_ERROR; } static int -init(void (*func)(void *), void *data) -{ +init(void (*func)(void *), void *data) { if (callback) { fprintf(stderr, "Error: Attempt to initialize pthread timer more than once\n"); return SFX_ERROR; @@ -85,8 +82,7 @@ init(void (*func)(void *), void *data) } static int -stop(void) -{ +stop(void) { thread_run = 0; pthread_join(thread, NULL); diff --git a/engines/sci/sfx/timer/sigalrm.cpp b/engines/sci/sfx/timer/sigalrm.cpp index 40cc2872e1..2bab402d14 100644 --- a/engines/sci/sfx/timer/sigalrm.cpp +++ b/engines/sci/sfx/timer/sigalrm.cpp @@ -43,26 +43,23 @@ static void *sig_callback_data = NULL; static sigset_t current_sigset; static void -timer_handler(int i) -{ +timer_handler(int i) { if (sig_callback) sig_callback(sig_callback_data); } static int -sigalrm_set_option(char *name, char *value) -{ +sigalrm_set_option(char *name, char *value) { return SFX_ERROR; } static int -sigalrm_start(void) -{ +sigalrm_start(void) { struct itimerval itimer; itimer.it_value.tv_sec = 0; - itimer.it_value.tv_usec = 1000000/60; + itimer.it_value.tv_usec = 1000000 / 60; itimer.it_interval = itimer.it_value; signal(SIGALRM, timer_handler); /* Re-instate timer handler, to make sure */ @@ -73,8 +70,7 @@ sigalrm_start(void) static int -sigalrm_init(void (*callback)(void *), void *data) -{ +sigalrm_init(void (*callback)(void *), void *data) { if (sig_callback) { fprintf(stderr, "Error: Attempt to initialize sigalrm timer more than once\n"); return SFX_ERROR; @@ -98,8 +94,7 @@ sigalrm_init(void (*callback)(void *), void *data) static int -sigalrm_stop(void) -{ +sigalrm_stop(void) { struct itimerval itimer; if (!sig_callback) { @@ -119,8 +114,7 @@ sigalrm_stop(void) static int -sigalrm_block(void) -{ +sigalrm_block(void) { if (sigprocmask(SIG_BLOCK, ¤t_sigset, NULL) != 0) { fprintf(stderr, "Error: Failed to block sigalrm\n"); return SFX_ERROR; @@ -131,8 +125,7 @@ sigalrm_block(void) static int -sigalrm_unblock(void) -{ +sigalrm_unblock(void) { if (sigprocmask(SIG_UNBLOCK, ¤t_sigset, NULL) != 0) { fprintf(stderr, "Error: Failed to unblock sigalrm\n"); return SFX_ERROR; diff --git a/engines/sci/sfx/timer/timer_scummvm.cpp b/engines/sci/sfx/timer/timer_scummvm.cpp index 80fc309d1d..beb57aef6b 100644 --- a/engines/sci/sfx/timer/timer_scummvm.cpp +++ b/engines/sci/sfx/timer/timer_scummvm.cpp @@ -19,13 +19,13 @@ void scummvm_timer_update_internal(void *ptr) { int scummvm_timer_start(void (*func)(void *), void *data) { if (scummvm_timer_callback) { fprintf(stderr, - "Error: Attempt to initialize gametick timer more than once\n"); + "Error: Attempt to initialize gametick timer more than once\n"); return SFX_ERROR; } if (!func) { fprintf(stderr, - "Error: Attempt to initialize gametick timer w/o callback\n"); + "Error: Attempt to initialize gametick timer w/o callback\n"); return SFX_ERROR; } @@ -45,10 +45,10 @@ int scummvm_timer_stop() { sfx_timer_t sfx_timer_scummvm = { "ScummVM", "0.1", - DELAY/1000, 0, + DELAY / 1000, 0, NULL, &scummvm_timer_start, &scummvm_timer_stop, 0, 0 - }; +}; diff --git a/engines/sci/sfx/timer/timers.cpp b/engines/sci/sfx/timer/timers.cpp index 71e6e75c96..bdcd9dad34 100644 --- a/engines/sci/sfx/timer/timers.cpp +++ b/engines/sci/sfx/timer/timers.cpp @@ -57,15 +57,14 @@ sfx_timer_t *sfx_timers[] = { sfx_timer_t * -sfx_find_timer(char *name) -{ +sfx_find_timer(char *name) { if (!name) { /* Policies go here */ return sfx_timers[0]; } else { int n = 0; while (sfx_timers[n] - && strcasecmp(sfx_timers[n]->name, name)) + && strcasecmp(sfx_timers[n]->name, name)) ++n; return sfx_timers[n]; diff --git a/engines/sci/sfx/timetest.cpp b/engines/sci/sfx/timetest.cpp index 80d9ad1b78..fed6ef9f75 100644 --- a/engines/sci/sfx/timetest.cpp +++ b/engines/sci/sfx/timetest.cpp @@ -31,11 +31,10 @@ #include <sfx_time.h> #include <assert.h> -sfx_timestamp_t a,b,c; +sfx_timestamp_t a, b, c; int -main(int argc, char **argv) -{ +main(int argc, char **argv) { int i; a = sfx_new_timestamp(10, 0, 1000); b = sfx_new_timestamp(10, 1000, 1000); |