// File: /workspace/github_c_makefile_star2_O0/pipde[P]deos-songlib/lib/songlib.c
// Function: dplay
void
dplay(double beats,int *data,int length, int bps)
    {
    static double beatSlop = 0.0;

    double where;
    double front;
    double middle;

    int skip;
    register double samples = beatsToSamples(beats);
    register int noteSamples = (int) samples;
    register int dataLen;
    register int len;
    register double diminishedAmplitude,increasedAmplitude;
    register int i;
    register double fadeLimit;
    register double bpsFactor;
    double startOfFade;
    double emphasis;

    dTrace("entering\n");
    //printf("playing note at %f\n",location - spaces);

    if (beats == 0) 
        {
        oneshot(data,length,bps);
        return;
        }

    samples = beatsToSamples(beats);
    noteSamples = (int) samples;
    where = samplesToMeasures(location - spaces);

    front = (int) (where + 0.011);

    if (beatsPerMeasure % 2 == 0)
        middle = 0.5;
    else
        middle = (beatsPerMeasure + 1.0) / (2 * beatsPerMeasure);

    //printf("where: %f, front: %f, middle: %f, front + middle: %f\n",
        //where,front,middle,front+middle);
    //getchar();

    if (where > front - 0.01 && where < front + 0.01)
        {
        emphasis = primaryEmphasis;
        //printf("primary emphasis at measure %f\n",where);
        }
    else if (where > front + middle - 0.01 && where < front + middle + 0.01)
        {
        emphasis = secondaryEmphasis;
        //printf("secondary emphasis at measure %f\n",where);
        }
    else
        {
        emphasis = 1.0;
        }

    beatSlop += samples - noteSamples;
    while (beatSlop > 1.0)
        {
        //printf("dplay: adding extra sample\n");
        ++noteSamples;
        beatSlop -= 1.0;
        }

    bpsFactor = pow(2,bitsPerSample) / pow(2,bps);

    skip = beatsToSamples(skipAttack);

    len = MIN(length, noteSamples - skip);
    dataLen = length;

    while (location + noteSamples >= output->samples)
        growOutput();

    /* write out all the data we have up to len (len <= noteSamples) */

    increasedAmplitude = 0;
    for (i = 0; i < len; ++i)
        {
        output->data[0][(int)location] +=
            data[i+skip] * amplitude * bpsFactor * emphasis * increasedAmplitude;
        location += 1;
        if (increasedAmplitude >= 1)
            increasedAmplitude = 1;
        else
            increasedAmplitude += attack;
        }

    /* if we run out of data, replicate the last sample to make up */
    /* the shortfall */
    
    if (len < noteSamples)
        {
        register const int lastSample = data[length-1] * amplitude * emphasis;

        diminishedAmplitude = amplitude * emphasis;
        for (; i < noteSamples; ++i)
            {
            output->data[0][(int)location] += lastSample
                * bpsFactor *diminishedAmplitude;
            location += 1;
            diminishedAmplitude *= sustain;
            }
        }

    /* write out fade/sustained portion */

    startOfFade = location;
    diminishedAmplitude = amplitude * emphasis;
    fadeLimit = FADE_LIMIT / MAX(crescendoFactor,1.0);

    for (; i < dataLen && diminishedAmplitude > fadeLimit; ++i)
        {
        //added the next line (probably should compute the
        //number of samples needed in advance)
        if (location >= output->samples) growOutput();
        output->data[0][(int)location] += 
            data[i] * diminishedAmplitude * bpsFactor;
        location += 1;
        diminishedAmplitude *= sustain;
        }

    if (location > maxLocation) maxLocation = location;

    sustainedLocation = location;
    location = startOfFade;
    //printf("ending note at %f\n",location - spaces);
    //printf("    %f samples\n",samples);

    if (TempoChange) setTempo(getTempo() + beats * TempoDelta);
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movsd %xmm0, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movsd -0x8(%rbp), %xmm0
callq 0x3980
movsd %xmm0, -0x40(%rbp)
cvttsd2si -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
movsd -0x8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x3215
jp 0x3215
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x3a00
jmp 0x37ad
movsd -0x8(%rbp), %xmm0
callq 0x3980
movsd %xmm0, -0x40(%rbp)
cvttsd2si -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
movsd 0x1eaa4(%rip), %xmm0    # 0x21cd8
subsd 0x1edec(%rip), %xmm0    # 0x22028
callq 0x3b30
movsd %xmm0, -0x20(%rbp)
movsd 0xa102(%rip), %xmm0     # 0xd350
addsd -0x20(%rbp), %xmm0
cvttsd2si %xmm0, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x28(%rbp)
movl 0xf1ba(%rip), %eax      # 0x12420
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x3282
movsd 0xa0dd(%rip), %xmm0     # 0xd358
movsd %xmm0, -0x30(%rbp)
jmp 0x32ab
cvtsi2sdl 0xf196(%rip), %xmm0 # 0x12420
movsd 0xa096(%rip), %xmm1     # 0xd328
addsd %xmm1, %xmm0
movl 0xf184(%rip), %eax      # 0x12420
shll %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movsd 0xa0a3(%rip), %xmm2     # 0xd360
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x32f1
movsd -0x20(%rbp), %xmm1
movsd 0xa08c(%rip), %xmm0     # 0xd360
addsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x32f1
movsd 0xf141(%rip), %xmm0     # 0x12428
movsd %xmm0, -0x88(%rbp)
jmp 0x3357
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
addsd -0x30(%rbp), %xmm1
movsd 0xa058(%rip), %xmm2     # 0xd360
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3345
movsd -0x20(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd 0xa037(%rip), %xmm2     # 0xd360
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3345
movsd 0xf0f5(%rip), %xmm0     # 0x12430
movsd %xmm0, -0x88(%rbp)
jmp 0x3355
movsd 0x9fdb(%rip), %xmm0     # 0xd328
movsd %xmm0, -0x88(%rbp)
jmp 0x3357
movsd -0x40(%rbp), %xmm0
cvtsi2sdl -0x44(%rbp), %xmm1
subsd %xmm1, %xmm0
addsd 0x1ecb3(%rip), %xmm0    # 0x22020
movsd %xmm0, 0x1ecab(%rip)    # 0x22020
movsd 0x1eca3(%rip), %xmm0    # 0x22020
movsd 0x9fa3(%rip), %xmm1     # 0xd328
ucomisd %xmm1, %xmm0
jbe 0x33b2
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movsd 0x1ec84(%rip), %xmm0    # 0x22020
movsd 0x9f84(%rip), %xmm1     # 0xd328
subsd %xmm1, %xmm0
movsd %xmm0, 0x1ec70(%rip)    # 0x22020
jmp 0x3375
cvtsi2sdl 0xf04e(%rip), %xmm1 # 0x12408
movsd 0x9f6e(%rip), %xmm0     # 0xd330
callq 0x2080
movsd %xmm0, -0x98(%rbp)
cvtsi2sdl -0x18(%rbp), %xmm1
movsd 0x9f54(%rip), %xmm0     # 0xd330
callq 0x2080
movaps %xmm0, %xmm1
movsd -0x98(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd 0x1ec33(%rip), %xmm0    # 0x22030
callq 0x3980
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
movl -0x14(%rbp), %eax
movl -0x44(%rbp), %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3421
movl -0x14(%rbp), %eax
movl %eax, -0x9c(%rbp)
jmp 0x342d
movl -0x44(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x48(%rbp)
movsd 0x1e894(%rip), %xmm0    # 0x21cd8
cvtsi2sdl -0x44(%rbp), %xmm1
addsd %xmm1, %xmm0
movq 0x1e87c(%rip), %rax     # 0x21cd0
cvtsi2sdl 0xc(%rax), %xmm1
ucomisd %xmm1, %xmm0
jb 0x3466
callq 0x3b60
jmp 0x343c
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x3536
movq -0x10(%rbp), %rax
movl -0x64(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
mulsd 0xef9d(%rip), %xmm0     # 0x12438
mulsd -0x78(%rbp), %xmm0
mulsd -0x88(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
movq 0x1e81c(%rip), %rax     # 0x21cd0
movq 0x18(%rax), %rax
movq (%rax), %rax
cvttsd2si 0x1e815(%rip), %ecx # 0x21cd8
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movl %edx, (%rax,%rcx,4)
movsd 0x9e46(%rip), %xmm0     # 0xd328
addsd 0x1e7ee(%rip), %xmm0    # 0x21cd8
movsd %xmm0, 0x1e7e6(%rip)    # 0x21cd8
movsd -0x60(%rbp), %xmm0
movsd 0x9e29(%rip), %xmm1     # 0xd328
ucomisd %xmm1, %xmm0
jb 0x3514
movsd 0x9e1b(%rip), %xmm0     # 0xd328
movsd %xmm0, -0x60(%rbp)
jmp 0x3526
movsd 0xef24(%rip), %xmm0     # 0x12440
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x3528
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x3475
movl -0x4c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x3601
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
mulsd 0xeedc(%rip), %xmm0     # 0x12438
mulsd -0x88(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x8c(%rbp)
movsd 0xeec2(%rip), %xmm0     # 0x12438
mulsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x35ff
cvtsi2sdl -0x8c(%rbp), %xmm0
mulsd -0x78(%rbp), %xmm0
movsd -0x58(%rbp), %xmm2
movq 0x1e72c(%rip), %rax     # 0x21cd0
movq 0x18(%rax), %rax
movq (%rax), %rax
cvttsd2si 0x1e725(%rip), %ecx # 0x21cd8
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movl %edx, (%rax,%rcx,4)
movsd 0x9d56(%rip), %xmm0     # 0xd328
addsd 0x1e6fe(%rip), %xmm0    # 0x21cd8
movsd %xmm0, 0x1e6f6(%rip)    # 0x21cd8
movsd 0xee5e(%rip), %xmm0     # 0x12448
mulsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x3583
jmp 0x3601
movsd 0x1e6cf(%rip), %xmm0    # 0x21cd8
movsd %xmm0, -0x80(%rbp)
movsd 0xee22(%rip), %xmm0     # 0x12438
mulsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0xee25(%rip), %xmm0     # 0x12450
movsd 0x9cf5(%rip), %xmm1     # 0xd328
ucomisd %xmm1, %xmm0
jbe 0x364b
movsd 0xee0f(%rip), %xmm0     # 0x12450
movsd %xmm0, -0xa8(%rbp)
jmp 0x365d
movsd 0x9cd5(%rip), %xmm0     # 0xd328
movsd %xmm0, -0xa8(%rbp)
jmp 0x365d
movsd -0xa8(%rbp), %xmm1
movsd 0x9cfb(%rip), %xmm0     # 0xd368
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x64(%rbp), %ecx
xorl %eax, %eax
cmpl -0x48(%rbp), %ecx
movb %al, -0xa9(%rbp)
jge 0x3699
movsd -0x58(%rbp), %xmm0
ucomisd -0x70(%rbp), %xmm0
seta %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x36a8
jmp 0x3743
movsd 0x1e628(%rip), %xmm0    # 0x21cd8
movq 0x1e619(%rip), %rax     # 0x21cd0
cvtsi2sdl 0xc(%rax), %xmm1
ucomisd %xmm1, %xmm0
jb 0x36c7
callq 0x3b60
movq -0x10(%rbp), %rax
movslq -0x64(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
mulsd -0x58(%rbp), %xmm0
movsd -0x78(%rbp), %xmm2
movq 0x1e5eb(%rip), %rax     # 0x21cd0
movq 0x18(%rax), %rax
movq (%rax), %rax
cvttsd2si 0x1e5e4(%rip), %ecx # 0x21cd8
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movl %edx, (%rax,%rcx,4)
movsd 0x9c15(%rip), %xmm0     # 0xd328
addsd 0x1e5bd(%rip), %xmm0    # 0x21cd8
movsd %xmm0, 0x1e5b5(%rip)    # 0x21cd8
movsd 0xed1d(%rip), %xmm0     # 0x12448
mulsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x3676
movsd 0x1e58d(%rip), %xmm0    # 0x21cd8
cvtsi2sdl 0x1e58d(%rip), %xmm1 # 0x21ce0
ucomisd %xmm1, %xmm0
jbe 0x3767
cvttsd2si 0x1e577(%rip), %eax # 0x21cd8
movl %eax, 0x1e579(%rip)     # 0x21ce0
cvttsd2si 0x1e569(%rip), %eax # 0x21cd8
movl %eax, 0x1e8c3(%rip)     # 0x22038
movsd -0x80(%rbp), %xmm0
movsd %xmm0, 0x1e556(%rip)    # 0x21cd8
cmpl $0x0, 0xed8f(%rip)      # 0x12518
je 0x37ad
callq 0x3bf0
movaps %xmm0, %xmm1
movsd -0x8(%rbp), %xmm0
movsd 0xed80(%rip), %xmm2     # 0x12520
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x3bc0
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)