import message
import mixer
import channel
import receiver
from plots import plot_before_after, plot_before_after_amqam, show

# message
orig1 = message.sin()
orig2 = message.square()
m1 = message.sin()
m2 = message.square()

# mixer
m = mixer.AMQAM(m1, m2)

# channel
m = channel.attenuation(m)
m = channel.fading(m)
m = channel.gauss_noise(m)

# receiver
m = receiver.unattenuate(m)
m1, m2 = receiver.demuxAMQAM(m)
m1 = receiver.lpf(m1)
m2 = receiver.lpf(m2)

plot_before_after_amqam(orig1, orig2, m1, m2)
show()
        function_name = str(fn).split()[1]
        original_message = msg()
        original_message_aud = msg(length=2)
        m = fn(original_message)
        m_aud = fn(original_message_aud)
        m_aud.write(filename='audio/'+message_name+'_'+function_name+'.wav')
        plot_both(m, filename='plots/'+message_name+'_'+function_name+'.png')

#am-qam
for ind1 in range(len(types)):
    msg1 = types[ind1]
    name1 = str(msg1).split()[1]
    orig1 = msg1()
    orig1aud = msg1(length=2)
    orig1aud.write(filename='audio/qam/'+name1+'_orig.wav')
    plot_both(orig1, filename='plots/qam/'+name1+'_orig.png')
    for msg2 in types[ind1:]:
        name2 = str(msg2).split()[1]
        orig2 = msg2()
        orig2aud = msg2(length=2)
        m = mixer.AMQAM(msg1(), msg2())
        maud = mixer.AMQAM(msg1(length=2), msg2(length=2))
        m1, m2 = receiver.demuxAMQAM(m)
        m1aud, m2aud = receiver.demuxAMQAM(maud)
        m1 = receiver.lpf(m1)
        m2 = receiver.lpf(m2)
        m1aud = receiver.lpf(m1aud)
        m2aud = receiver.lpf(m2aud)
        m1aud.write(filename='audio/qam/'+name1+'_'+name2+'_msg1.wav')
        m2aud.write(filename='audio/qam/'+name1+'_'+name2+'_msg2.wav')
        plot_before_after_amqam(orig1, orig2, m1, m2, filename='plots/qam/'+name1+'_'+name2+'.png')