How do we use the information in g(t) to determine the composition of the medium that the wave is traveling through? Moreover, knowing that the earth is heterogeneous, how can we isolate any one single substance or rock type? How accurate is this kind of measurement?
In short: we can't, and it's not.
Taking the example of oceanic lithosphere, we can take a pretty good stab: we know (approximately) what a cross-section through the oceanic crust and mantle looks like because of the existence of ophiolites. They're pretty consistent in terms of thicknesses of units represented (see the cross-section at that link), so when in oceanic lithosphere we see 2km at a certain velocity underlain by 4km at a different velocity, with a sharp transition between the two, it's a fair bet that the former corresponds to sheeted dykes and the latter to layered gabbros, and so on down.
Some laboratory measurements of the speed of sound waves in various lithologies can be made (including measurements of both synthetic substances and of mantle xenoliths that have, for whatever reason, been brought up to the surface), but they aren't definitive. Seismic anisotropy - different "speeds" to different components of wave phases (e.g. P versus S waves) depending on the angle the wave being measured took through the rock in question - can be linked to e.g. alignment of olivine crystals. As another example we know that the core is of a different composition to the mantle because of the difference in the speed of sound and through mass-balance arguments, but seismic velocity through the core doesn't tell us anything about what it's made of.
To add further complications, variations in seismic speed can always be explained by a trade-off between compositional and thermal variations, as with LLSVPs.
Mostly what we're working with here is a bunch of best guesses. That's not to say they're useless - in a field where you get to run a single experiment that lasts 4.5Ga and you've no control over any of the parameters, best guesses are often the best we have to work with - but they're also very definitely not definitive.