When a cat is trying to bring up a hairball, it sounds like a heaving, vomiting, gagging type sound. Dry heaves might be a description. That's because the cat is actually trying to vomit up the hair stuck in his/her stomach. I guess you could also call it a retching type sound. When trying to vomit up a hairball, you can see the cat's sides heave in and out, as the abdominal muscles expand and contract. It can look rather dramatic. The cat will be sitting more upright, as opposed to be hunkered down close to the floor while doing it if it is due to hairballs.
The cat might be making those sounds due to trying to vomit for a reason other than hairballs, but hairball vomiting (called a hairball cough but it is really a vomiting) is common enough.
One of my cats has asthma, and at first we thought it was hairball "coughing" that he was doing more and more and more. No cat should be trying to hack up a hairball several times a day for weeks and weeks, without ever throwing one up, so he was finally diagnosed as having asthma. When he coughs from the asthma, he does hunker down to the floor and stretches his neck far out, like a goose. The sounds he makes then is reminiscent of a goose too. A honking kind of coughing noise. So, if it looks and sounds like that, it could be asthma.
Long haired cats need frequent combing to get out the loose hair. Try to do bit each day. If your cat has straight, fine hair, a flea comb gets more loose hair out than a brush will.