From investors. At the current market price; i.e. closer to $20/share than $40/share. Keep in mind two things: the person who sold the share doesn't get any further income from that share, unlike a dividend, and the company won't buy back shares if they believe the shares are fairly- or over-valued. They only buy back shares if they think the stock prices is too low.
The buy-back only acts as a "dividend" to those who sell after the buy-back has raised the stock price, not to those who sold into the buy-back.
"Moreover, your shares in the company increased. If you had 1 share to start with, after the buyback you have the equivalent of 2 shares. Your "dividend" is the extra share, which the company bought for you using the cash they would have otherwise paid out."
Uh, are you confusing buy-backs with stock splits? Before the buy-back, you have one stock share. After the buy-back, you have one stock share, which represents a larger share of the corporation's earnings and book value. Bought-back shares disappear. Your "dividend" is the difference in price of that one share before and after the buy-back.
And the price of that share is free floating, moving according to market forces.
 In theory. Ideally. They can also do so to manipulate the stock price, the strike price of management options, and other things that are generally bad for investors. Stock buy-backs have a legitimate purpose, to signal to investors that management considers the stock price to be too low. They're not a substitute for dividends.
 They go into the company's treasury, where they can be re-sold later to raise money without affecting dilution, IIUC.