Several things have contributed to the decline, but it's not just
digital downloads (legal or illegal). A number of
studies have been done on that issue.
Many music store chains are no longer in existance. Online sales have taken over. CD sales have also changed from a specialized store to combination book and music store. The advent of Amazon found bookstores fighting to compete for book sales and adding music to supplement sales. However, the lower costs that large providers like Amazon can provide, combined with free shipping, still force smaller outfits to struggle to compete.
Another factor is that at the advent of CDs, many people began to replace thier vinyl, cassette and other format libraries over roughly a twenty year period. Those libraries are now updated, providing another contribution to the dropoff. Add in people spending part of their entertainment budget on gaming and DVD and sales drop further.
"...In 1999 38,900 individual titles were released in the US. The number of releases fell by 30% by 2001 when only 27,000 titles were released. With fewer titles on the market the number of units sold is bound to decrease as well." [BBC News]
If you add all this in with the tough economy of the last few years, it is quickly evident that there is more than one reason CD sales are declining.
CDs are still at the forefront of all music sales and will be for some time. The only thing occuring is the RIAA whining, like a child about a paper cut, instead of making internal changes to match the outside ones. Other industries and companies have taken the worldly changes, the proverbial "bull by the horns", and turned it into a profitable enterprise. Why can't the music industry?