Advertisement
AloXado320

volume options n64

Jan 16th, 2022
751
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // in src/audio/external.c (above play_music in my case)
  2.  
  3. void set_sequence_player_volume(s32 player, f32 volume) {
  4.     gSequencePlayers[player].volumeScale = volume;
  5. }
  6.  
  7. // in src/game/sound_init.c (above thread4_sound)
  8.  
  9. #define MAX_VOLUME 127
  10. unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME
  11. unsigned int configMusicVolume = MAX_VOLUME;
  12. unsigned int configSfxVolume = MAX_VOLUME;
  13. unsigned int configEnvVolume = MAX_VOLUME;
  14.  
  15. void change_audio_volumes(void) {
  16.     const f32 master_mod = (f32)configMasterVolume / 127.0f;
  17.     set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * master_mod);
  18.     set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * master_mod);
  19.     set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * master_mod);
  20. }
  21.  
  22. // in thread4_sound, change_audio_volumes() is called at the bottom of while (TRUE) like this
  23.  
  24. void thread4_sound(UNUSED void *arg) {
  25.     audio_init();
  26.     sound_init();
  27.  
  28.     // Zero-out unused vector
  29.     vec3f_copy(unused80339DC0, gVec3fZero);
  30.  
  31.     osCreateMesgQueue(&sSoundMesgQueue, sSoundMesgBuf, ARRAY_COUNT(sSoundMesgBuf));
  32.     set_vblank_handler(1, &sSoundVblankHandler, &sSoundMesgQueue, (OSMesg) 512);
  33.  
  34.     while (TRUE) {
  35.         OSMesg msg;
  36.  
  37.         osRecvMesg(&sSoundMesgQueue, &msg, OS_MESG_BLOCK);
  38.         if (gResetTimer < 25) {
  39.             struct SPTask *spTask;
  40.             profiler_log_thread4_time();
  41.             spTask = create_next_audio_frame_task();
  42.             if (spTask != NULL) {
  43.                 dispatch_audio_sptask(spTask);
  44.             }
  45.             profiler_log_thread4_time();
  46.         }
  47.        
  48. #ifdef TARGET_N64 // TODO: save to EEPROM
  49.         change_audio_volumes();
  50. #endif
  51.     }
  52. }
  53.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement