The reference to singing comes a few verses later:
4 Where wast thou when I laid the foundations of the earth? Declare, if thou hast the understanding.
5 Who determined the measures thereof, if thou knowest? Or who stretched the line upon it?
6 Whereupon were the foundations thereof fastened? Or who laid the corner-stone thereof,
7 When the morning stars sang together, and all the sons of God shouted for joy?
We know that God preceded creation, of course, and there is reason to believe that a "heavenly court" (ministering angels) also preceded the completion of creation, for God uses the plural in Genesis 1. That could just be the "royal we" but it probably refers to the existence of other beings. This statement occurs after the creation of the earth but before the creation of man.
If other beings existed then, could those beings not be capable of singing?
I don't think Job 38 is saying that music is somehow foundational, but just that singers existed at the time of creation. God is chastising Job and saying he doesn't have the complete picture; he's not asserting that music is somehow special, only describing events that predated the creation of man.
As for a distinction between the creation of matter and the creation of the earth specifically, the text does not seem to draw a distinction. The first line of Genesis is "When God began to create the heavens and the earth" (ha-aretz). The text doesn't seem to consider matter in the abstract.
Please note: This answer was written for a neutral, academic audience
and is not intended to be interpreted in the context of a religious
belief or doctrine.