“The idea came to us, why not try masking music hallucination?” said Sukhbinder Kumar, a staff scientist at Newcastle University and one of the study’s co-authors.

It turned out that Sylvia found that music by Bach sometimes eased her hallucinations. When Dr. Kumar and his colleagues measured the effect in their lab, they found a consistent pattern: once the Bach stopped, Sylvia had several seconds of total relief from the hallucinations. Then the hallucinatory piano gradually returned, reaching full strength about a minute and a half after the Bach ended.

Dr. Kumar and his colleagues wondered what they would see if they measured her brain activity as her hallucinations rebounded. Brain scans in the past have only yielded murky clues about musical hallucinations, for a variety of reasons.

One problem has to do with how the studies have been designed. Scientists compare a group of people with normal hearing with another group of people who experience musical hallucinations to see if there are any significant differences in their brain activity. All the variations in each group may blur the evidence for how the hallucinations arise. Sylvia, by contrast, offered Dr. Kumar and his colleagues an opportunity to essentially switch hallucinations on and off in a single brain.

For their experiment, Sylvia put on earphones and sat with her head in a scanner that detects the magnetic field produced by the brain. On the day of the study, she was hearing selections from Gilbert and Sullivan’s “H.M.S. Pinafore.”

Every few minutes the scientists would switch to Bach for 30 seconds, to tamp down the hallucination. When the real music stopped, Sylvia pressed numbers on a keyboard to rate the strength of her hallucinations while the scanner recorded her brain activity.

Dr. Kumar and his colleagues later pored over the data. They compared Sylvia’s brain activity when the hallucinations were strongest with when they were at their weakest. They found that a few regions consistently produced stronger brain waves when the hallucinations were louder.