As a kid, something similar happened to me sort of regularly (maybe a few times a year?). As I was falling asleep, some noises that initially might have been normal ambient noises started looping, acquiring some rhythmic pattern and becoming progressively louder, until suddenly there was a loud bang followed by a sense of complete void and silence.
After a while I learned to notice the "looping sound" pattern and just raise my head from the pillow to interrupt it. Then, at some point, it never returned again.