I think Renfe has a cooperative agreement with Spanair which gives travellers the flexibility of using the train or flying.
Madrid-Barcelona used to be the busiest air route in the world in terms of the number of flights but recently traffic has fallen, though it's not clear the extent to which this is due to the arrival of AVE trains or to the severe economic downturn that has hit Spain.
If you can't secure one of the better deals, by Spanish standards high speed trains are expensive.