When I plug the optical out of my TV into my DAC it makes the sound louder and it clips. It only works properly when the optical out goes directly from the Apple TV to the DAC. Why is this happening? I like to use the optical out of the TV so I can have multiple devices plugged in through the HDMI that I can play sound from.
Digital outputs like optical generally are not controlled by the outputting device's volume control - for example the AppleTV remote's volume control does not actually control the AppleTV's internal volume (in fact, I don't think the AppleTV even
has internally changeable audio volume) - instead, it can be configured to control the TV's (or AVR's, or whatever's) volume. Similarly, a TV's optical audio output just sends out the original digital data, with no volume attenuation applied or (in most cases) even possible, unless or until you adjust the volume on the receiving device (DAC, or perhaps an AVR or amp downstream from the DAC).
With that in mind, my first suspicion would be the output
format each device is using.TV optical outputs are notorious for being poorly documented and not officially supported, and often their default optical output format will be Dolby Digital 5.1 multichannel, which will be downmixed for stereo. So it is possible that when the TV is in your digital audio signal chain, it's mixing 6 channels into 2 and if it's doing that in a "dumb"way that could result in digital clipping.
I'm by no means an expert on this - but given that all of the AppleTV's and TV's digital audio outputs should be outputting the audio with no volume changes, my suspicion would be that it's something to do with different digital audio formats and how the TV is handling that.