MCPcopy Create free account
hub / github.com/demoth/jake2 / LoadSound

Method LoadSound

client/src/main/java/jake2/client/sound/WaveLoader.java:51–118  ·  view source on GitHub ↗

Loads a sound from a wav file.

(sfx_t s)

Source from the content-addressed store, hash-verified

49 * Loads a sound from a wav file.
50 */
51 public static sfxcache_t LoadSound(sfx_t s) {
52 if (s.name.charAt(0) == '*')
53 return null;
54
55 // see if still in memory
56 sfxcache_t sc = s.cache;
57 if (sc != null)
58 return sc;
59
60 String name;
61 // load it in
62 if (s.truename != null)
63 name = s.truename;
64 else
65 name = s.name;
66
67 String namebuffer;
68 if (name.charAt(0) == '#')
69 namebuffer = name.substring(1);
70 else
71 namebuffer = "sound/" + name;
72
73 byte[] data = FS.LoadFile(namebuffer);
74
75 if (data == null) {
76 Com.DPrintf("Couldn't load " + namebuffer + "\n");
77 return null;
78 }
79
80 int size = data.length;
81
82 wavinfo_t info = GetWavinfo(s.name, data, size);
83
84 if (info.channels != 1)
85 {
86 Com.Printf(s.name + " is a stereo sample - ignoring\n");
87 return null;
88 }
89
90 float stepscale;
91 if (DONT_DO_A_RESAMPLING_FOR_JOAL_AND_LWJGL)
92 stepscale = 1;
93 else
94 stepscale = (float)info.rate / S.getDefaultSampleRate();
95
96 int len = (int) (info.samples / stepscale);
97 len = len * info.width * info.channels;
98
99 // TODO: handle max sample bytes with a cvar
100 if (len >= maxsamplebytes)
101 {
102 Com.Printf(s.name + " is too long: " + len + " bytes?! ignoring.\n");
103 return null;
104 }
105
106 sc = s.cache = new sfxcache_t(len);
107
108 sc.length = info.samples;

Callers 1

LoadSoundMethod · 0.95

Calls 6

LoadFileMethod · 0.95
DPrintfMethod · 0.95
GetWavinfoMethod · 0.95
PrintfMethod · 0.95
getDefaultSampleRateMethod · 0.95
ResampleSfxMethod · 0.95

Tested by

no test coverage detected