how do I derive the system equation for a simple delay with feedback? I am a software engineer, and just learning digital signal processing formally, though I've hacked around before a fair amount.

I'm implementing a delay audio VST and I'm trying to wrap my head around how one creates equations of the output given a system diagram. I'm not used to circuit diagrams (they're weirdly parallel to me), so I'm trying to figure out how one goes from this system diagram:



to an equation. As best I can tell, the equation for this is:

y[t] = x[t] + y[t - T] * gain


where x[t] is the input on the far left, y[t] is the output on the far right, and the delay time in samples is T. 

Is this correct? 

I don't fully see how the system diagram implies the second term is y[t - T] rather than x[t - T], but intuitively, I know it must be, because an audio delay unit can't really incorporate feedback if the original signal delay only happens once (feedback must enable the ever-decaying ringing with time). Otherwise we'd get just a shifted version of the original, added to the original. This would be boring.
In such cases it helps to define an additional signal $w[n]$ at the input of the delay. Now you can write down two equations describing the system:

$$\begin{align}w[n]&amp;=x[n]+g\cdot w[n-N]\\y[n]&amp;=x[n]+w[n-N]\end{align}\tag{1}$$

where $N$ denotes the delay (in samples) and $g$ is the feedback gain. From the second equation you can express $w[n-N]$ in terms of $x[n]$ and $y[n]$:

$$w[n-N]=y[n]-x[n]\tag{2}$$

Plugging this into the first equation gives

$$y[n+N]-x[n+N]=x[n]+g\cdot \left(y[n]-x[n]\right)\tag{3}$$

Rearranging and subtracting $N$ from all indices results in

$$y[n]=x[n]+(1-g)x[n-N]+g\cdot y[n-N]\tag{4}$$

Eq. $(4)$ is the (single) difference equation describing the system. However, it's more efficient to implement the system using the two equations given in $(1)$.