sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

spawn_sound.c (3984B)


      1 #include <PR/ultratypes.h>
      2 
      3 #include "audio/external.h"
      4 #include "behavior_data.h"
      5 #include "engine/behavior_script.h"
      6 #include "engine/graph_node.h"
      7 #include "object_helpers.h"
      8 #include "object_list_processor.h"
      9 #include "sm64.h"
     10 #include "spawn_sound.h"
     11 #include "rumble_init.h"
     12 
     13 /*
     14  * execute an object's current sound state with a provided array
     15  * of sound states. Used for the stepping sounds of various
     16  * objects. (King Bobomb, Bowser, King Whomp)
     17  */
     18 void exec_anim_sound_state(struct SoundState *soundStates) {
     19     s32 stateIdx = gCurrentObject->oSoundStateID;
     20 
     21     switch (soundStates[stateIdx].playSound) {
     22         // since we have an array of sound states corresponding to
     23         // various behaviors, not all entries intend to play sounds. the
     24         // boolean being 0 for unused entries skips these states.
     25         case FALSE:
     26             break;
     27         case TRUE: {
     28             s32 animFrame;
     29 
     30             // in the sound state information, -1 (0xFF) is for empty
     31             // animFrame entries. These checks skips them.
     32             if ((animFrame = soundStates[stateIdx].animFrame1) >= 0) {
     33                 if (cur_obj_check_anim_frame(animFrame)) {
     34                     cur_obj_play_sound_2(soundStates[stateIdx].soundMagic);
     35                 }
     36             }
     37 
     38             if ((animFrame = soundStates[stateIdx].animFrame2) >= 0) {
     39                 if (cur_obj_check_anim_frame(animFrame)) {
     40                     cur_obj_play_sound_2(soundStates[stateIdx].soundMagic);
     41                 }
     42             }
     43         } break;
     44     }
     45 }
     46 
     47 /*
     48  * Create a sound spawner for objects that need a sound play once.
     49  * (Breakable walls, King Bobomb exploding, etc)
     50  */
     51 void create_sound_spawner(s32 soundMagic) {
     52     struct Object *obj = spawn_object(gCurrentObject, 0, bhvSoundSpawner);
     53 
     54     obj->oSoundEffectUnkF4 = soundMagic;
     55 }
     56 
     57 /*
     58  * The following 2 functions are relevant to the sound state function
     59  * above. While only cur_obj_play_sound_2 is used, they may have been intended as
     60  * separate left/right leg functions that went unused.
     61  */
     62 void cur_obj_play_sound_1(s32 soundMagic) {
     63     if (gCurrentObject->header.gfx.node.flags & GRAPH_RENDER_ACTIVE) {
     64         play_sound(soundMagic, gCurrentObject->header.gfx.cameraToObject);
     65     }
     66 }
     67 
     68 void cur_obj_play_sound_2(s32 soundMagic) {
     69     if (gCurrentObject->header.gfx.node.flags & GRAPH_RENDER_ACTIVE) {
     70         play_sound(soundMagic, gCurrentObject->header.gfx.cameraToObject);
     71 #if ENABLE_RUMBLE
     72         if (soundMagic == SOUND_OBJ_BOWSER_WALK) {
     73             queue_rumble_data(3, 60);
     74         }
     75         if (soundMagic == SOUND_OBJ_POUNDING_LOUD) {
     76             queue_rumble_data(3, 60);
     77         }
     78         if (soundMagic == SOUND_OBJ_WHOMP) {
     79             queue_rumble_data(5, 80);
     80         }
     81 #endif
     82     }
     83 }
     84 
     85 /*
     86  * These 2 functions below are completely unreferenced in all versions
     87  * of Super Mario 64. They are likely functions which facilitated
     88  * calculation of distance of an object to volume, since these are
     89  * common implementations of such a concept, and the fact they are
     90  * adjacent to other sound functions. The fact there are 2 functions
     91  * might show that the developers were testing several ranges, or certain
     92  * objects had different ranges, or had these for other unknown purposes.
     93  * Technically, these functions are only educated guesses. Trust these
     94  * interpretations at your own discretion.
     95  */
     96 s32 calc_dist_to_volume_range_1(f32 distance) { // range from 60-124
     97     s32 volume;
     98 
     99     if (distance < 500.0f) {
    100         volume = 127;
    101     } else if (1500.0f < distance) {
    102         volume = 0;
    103     } else {
    104         volume = (((distance - 500.0f) / 1000.0f) * 64.0f) + 60.0f;
    105     }
    106 
    107     return volume;
    108 }
    109 
    110 s32 calc_dist_to_volume_range_2(f32 distance) { // range from 79.2-143.2
    111     s32 volume;
    112 
    113     if (distance < 1300.0f) {
    114         volume = 127;
    115     } else if (2300.0f < distance) {
    116         volume = 0;
    117     } else {
    118         volume = (((distance - 1000.0f) / 1000.0f) * 64.0f) + 60.0f;
    119     }
    120 
    121     return volume;
    122 }