#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA429_A20ED_A20E_A20F_A21E_A31E
#ifdef MEDIA428_A20ED_A20E_A20F_A21E
extern int16_t G0744_i_Period;
extern long G0745_SwooshSoundDataByteCount;
extern unsigned char G0746_auc_SwooshSoundData[9078];

void F0908_InitSound(
)
{
        G0734_ps_AmigaData->SwooshSoundData = AllocMem(G0745_SwooshSoundDataByteCount, MEMF_CHIP);
        if (G0734_ps_AmigaData->SwooshSoundData == NULL) {
                Alert(0x80444D13, 0L);
        }
        G0734_ps_AmigaData->Sound1LeftChannel->ioa_Data = G0734_ps_AmigaData->SwooshSoundData;
        G0734_ps_AmigaData->Sound1LeftChannel->ioa_Length = G0745_SwooshSoundDataByteCount;
        G0734_ps_AmigaData->Sound1LeftChannel->ioa_Period = G0744_i_Period;
        G0734_ps_AmigaData->Sound1RightChannel->ioa_Data = G0734_ps_AmigaData->SwooshSoundData;
        G0734_ps_AmigaData->Sound1RightChannel->ioa_Length = G0745_SwooshSoundDataByteCount;
        G0734_ps_AmigaData->Sound1RightChannel->ioa_Period = G0744_i_Period;
        CopyMem(&G0746_auc_SwooshSoundData, G0734_ps_AmigaData->SwooshSoundData, G0745_SwooshSoundDataByteCount);
}

void F0909_PlaySwooshSound(
)
{
        BeginIO(G0734_ps_AmigaData->Sound1LeftChannel);
        BeginIO(G0734_ps_AmigaData->Sound1RightChannel);
        G0734_ps_AmigaData->Sound1Control->ioa_Request.io_Command = CMD_START;
        DoIO(G0734_ps_AmigaData->Sound1Control);
}

void F0910_ReleaseSwooshSound(
)
{
        G0734_ps_AmigaData->Sound1Control->ioa_Request.io_Command = ADCMD_FINISH;
        M008_SET(G0734_ps_AmigaData->Sound1Control->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
        BeginIO(G0734_ps_AmigaData->Sound1Control);
        WaitIO(G0734_ps_AmigaData->Sound1LeftChannel);
        WaitIO(G0734_ps_AmigaData->Sound1RightChannel);
        M009_CLEAR(G0734_ps_AmigaData->Sound1Control->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
        G0734_ps_AmigaData->Sound1Control->ioa_Request.io_Command = CMD_STOP;
        DoIO(G0734_ps_AmigaData->Sound1Control);
        FreeMem(G0734_ps_AmigaData->SwooshSoundData, G0745_SwooshSoundDataByteCount);
        G0734_ps_AmigaData->SwooshSoundData = NULL;
}
#endif
#ifdef MEDIA618_A31E
extern int16_t G0744_i_Period;
extern long G0745_SwooshSoundDataByteCount;
extern unsigned char G0746_auc_SwooshSoundData[9078];


unsigned char* G3299_puc_SwooshSoundData;
UBYTE G0730_uc_AudioChannelsAllocation = 0x0F;
char G3238_AllocatedUnits;
struct Device* G3231_ps_AudioDevice;
struct IOAudio* G3227_ps_Sound1Control = NULL;
struct IOAudio* G3225_ps_Sound1LeftChannel = NULL;
struct IOAudio* G3226_ps_Sound1RightChannel = NULL;
struct IOAudio* G3230_ps_Sound2Control = NULL;
struct IOAudio* G3228_ps_Sound2LeftChannel = NULL;
struct IOAudio* G3229_ps_Sound2RightChannel = NULL;
struct MsgPort* G3234_ps_IOAudio3ReplyPort = NULL;
struct MsgPort* G3232_ps_IOAudio1ReplyPort = NULL;
struct MsgPort* G3233_ps_IOAudio2ReplyPort = NULL;
struct MsgPort* G3237_ps_IOAudio6ReplyPort = NULL;
struct MsgPort* G3235_ps_IOAudio4ReplyPort = NULL;
struct MsgPort* G3236_ps_IOAudio5ReplyPort = NULL;


void F0908_InitSound(
)
{
        G3225_ps_Sound1LeftChannel = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3226_ps_Sound1RightChannel = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3227_ps_Sound1Control = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3228_ps_Sound2LeftChannel = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3229_ps_Sound2RightChannel = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3230_ps_Sound2Control = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        if ((G3225_ps_Sound1LeftChannel == NULL) || (G3226_ps_Sound1RightChannel == NULL) || (G3227_ps_Sound1Control == NULL)) {
                F9073_DisplayError(14L);
        }
        if ((G3228_ps_Sound2LeftChannel == NULL) || (G3229_ps_Sound2RightChannel == NULL) || (G3230_ps_Sound2Control == NULL)) {
                F9073_DisplayError(14L);
        }
        if (OpenDevice("audio.device", 0L, G3227_ps_Sound1Control, 0L) != 0) {
                F9073_DisplayError(15L);
        }
        G3231_ps_AudioDevice = G3227_ps_Sound1Control->ioa_Request.io_Device;
        G3232_ps_IOAudio1ReplyPort = CreatePort(NULL, 0L);
        G3233_ps_IOAudio2ReplyPort = CreatePort(NULL, 0L);
        G3234_ps_IOAudio3ReplyPort = CreatePort(NULL, 0L);
        G3235_ps_IOAudio4ReplyPort = CreatePort(NULL, 0L);
        G3236_ps_IOAudio5ReplyPort = CreatePort(NULL, 0L);
        G3237_ps_IOAudio6ReplyPort = CreatePort(NULL, 0L);
        if ((G3232_ps_IOAudio1ReplyPort == NULL) || (G3233_ps_IOAudio2ReplyPort == NULL) || (G3234_ps_IOAudio3ReplyPort == NULL)) {
                F9073_DisplayError(16L);
        }
        if ((G3235_ps_IOAudio4ReplyPort == NULL) || (G3236_ps_IOAudio5ReplyPort == NULL) || (G3237_ps_IOAudio6ReplyPort == NULL)) {
                F9073_DisplayError(16L);
        }
        G3227_ps_Sound1Control->ioa_Request.io_Message.mn_ReplyPort = G3234_ps_IOAudio3ReplyPort;
        G3227_ps_Sound1Control->ioa_Request.io_Message.mn_Node.ln_Pri = ADALLOC_MAXPREC;
        G3227_ps_Sound1Control->ioa_Request.io_Command = ADCMD_ALLOCATE;
        G3227_ps_Sound1Control->ioa_Data = &G0730_uc_AudioChannelsAllocation; /* Value 0x0F = allocate all 4 channels (one bit per channel) */
        G3227_ps_Sound1Control->ioa_Length = sizeof(G0730_uc_AudioChannelsAllocation);
        if (DoIO(G3227_ps_Sound1Control) != 0) {
                F9073_DisplayError(17L);
        }
        G3238_AllocatedUnits = (long)G3227_ps_Sound1Control->ioa_Request.io_Unit & 255;
        *G3225_ps_Sound1LeftChannel = *G3227_ps_Sound1Control;
        G3227_ps_Sound1Control->ioa_Request.io_Command = ADCMD_FINISH;
        G3227_ps_Sound1Control->ioa_Request.io_Flags = IOF_QUICK;
        G3227_ps_Sound1Control->ioa_Request.io_Unit = (struct Unit*)(4 | 8); /* Channel 2 & 3 */
        G3225_ps_Sound1LeftChannel->ioa_Request.io_Command = CMD_WRITE;
        G3225_ps_Sound1LeftChannel->ioa_Request.io_Flags = IOF_QUICK | ADIOF_PERVOL;
        G3225_ps_Sound1LeftChannel->ioa_Volume = 64;
        G3225_ps_Sound1LeftChannel->ioa_Cycles = 1;
        G3225_ps_Sound1LeftChannel->ioa_Request.io_Unit = (struct Unit*)8; /* Channel 3 produce sound on left side */
        *G3226_ps_Sound1RightChannel = *G3225_ps_Sound1LeftChannel;
        G3226_ps_Sound1RightChannel->ioa_Request.io_Message.mn_ReplyPort = G3233_ps_IOAudio2ReplyPort;
        G3226_ps_Sound1RightChannel->ioa_Request.io_Unit = (struct Unit*)4; /* Channel 2 produce sound on right side */
        *G3230_ps_Sound2Control = *G3227_ps_Sound1Control;
        G3230_ps_Sound2Control->ioa_Request.io_Unit = (struct Unit*)(1 | 2); /* Channel 0 & 1 */
        *G3228_ps_Sound2LeftChannel = *G3225_ps_Sound1LeftChannel;
        G3228_ps_Sound2LeftChannel->ioa_Request.io_Message.mn_ReplyPort = G3235_ps_IOAudio4ReplyPort;
        G3228_ps_Sound2LeftChannel->ioa_Request.io_Unit = (struct Unit*)1; /* Channel 0 produce sound on left side */
        *G3229_ps_Sound2RightChannel = *G3226_ps_Sound1RightChannel;
        G3229_ps_Sound2RightChannel->ioa_Request.io_Message.mn_ReplyPort = G3236_ps_IOAudio5ReplyPort;
        G3229_ps_Sound2RightChannel->ioa_Request.io_Unit = (struct Unit*)2; /* Channel 1 produce sound on right side */
        if ((G3299_puc_SwooshSoundData = AllocMem(G0745_SwooshSoundDataByteCount, MEMF_CHIP)) == 0) {
                F9073_DisplayError(0xFFFFFFFF);
        }
        G3225_ps_Sound1LeftChannel->ioa_Data = G3299_puc_SwooshSoundData;
        G3225_ps_Sound1LeftChannel->ioa_Length = G0745_SwooshSoundDataByteCount;
        G3225_ps_Sound1LeftChannel->ioa_Period = G0744_i_Period;
        G3226_ps_Sound1RightChannel->ioa_Data = G3299_puc_SwooshSoundData;
        G3226_ps_Sound1RightChannel->ioa_Length = G0745_SwooshSoundDataByteCount;
        G3226_ps_Sound1RightChannel->ioa_Period = G0744_i_Period;
        F0007_MAIN_CopyBytes(G0746_auc_SwooshSoundData, G3299_puc_SwooshSoundData, G0745_SwooshSoundDataByteCount);
}

void F1230_CleanupSound(
)
{
        if (G3299_puc_SwooshSoundData) {
                FreeMem(G3299_puc_SwooshSoundData, G0745_SwooshSoundDataByteCount);
        }
        G3299_puc_SwooshSoundData = NULL;
        if (G3231_ps_AudioDevice) {
                CloseDevice(G3227_ps_Sound1Control);
        }
        G3231_ps_AudioDevice = NULL;
        if (G3225_ps_Sound1LeftChannel) {
                FreeMem(G3225_ps_Sound1LeftChannel, (long)sizeof(struct IOAudio));
        }
        G3225_ps_Sound1LeftChannel = NULL;
        if (G3226_ps_Sound1RightChannel) {
                FreeMem(G3226_ps_Sound1RightChannel, (long)sizeof(struct IOAudio));
        }
        G3226_ps_Sound1RightChannel = NULL;
        if (G3227_ps_Sound1Control) {
                FreeMem(G3227_ps_Sound1Control, (long)sizeof(struct IOAudio));
        }
        G3227_ps_Sound1Control = NULL;
        if (G3228_ps_Sound2LeftChannel) {
                FreeMem(G3228_ps_Sound2LeftChannel, (long)sizeof(struct IOAudio));
        }
        G3228_ps_Sound2LeftChannel = NULL;
        if (G3229_ps_Sound2RightChannel) {
                FreeMem(G3229_ps_Sound2RightChannel, (long)sizeof(struct IOAudio));
        }
        G3229_ps_Sound2RightChannel = NULL;
        if (G3230_ps_Sound2Control) {
                FreeMem(G3230_ps_Sound2Control, (long)sizeof(struct IOAudio));
        }
        G3230_ps_Sound2Control = NULL;
        if (G3232_ps_IOAudio1ReplyPort) {
                DeletePort(G3232_ps_IOAudio1ReplyPort);
        }
        G3232_ps_IOAudio1ReplyPort = NULL;
        if (G3233_ps_IOAudio2ReplyPort) {
                DeletePort(G3233_ps_IOAudio2ReplyPort);
        }
        G3233_ps_IOAudio2ReplyPort = NULL;
        if (G3234_ps_IOAudio3ReplyPort) {
                DeletePort(G3234_ps_IOAudio3ReplyPort);
        }
        G3234_ps_IOAudio3ReplyPort = NULL;
        if (G3235_ps_IOAudio4ReplyPort) {
                DeletePort(G3235_ps_IOAudio4ReplyPort);
        }
        G3235_ps_IOAudio4ReplyPort = NULL;
        if (G3236_ps_IOAudio5ReplyPort) {
                DeletePort(G3236_ps_IOAudio5ReplyPort);
        }
        G3236_ps_IOAudio5ReplyPort = NULL;
        if (G3237_ps_IOAudio6ReplyPort) {
                DeletePort(G3237_ps_IOAudio6ReplyPort);
        }
        G3237_ps_IOAudio6ReplyPort = NULL;
}

void F0909_PlaySwooshSound(
)
{
        BeginIO(G3225_ps_Sound1LeftChannel);
        BeginIO(G3226_ps_Sound1RightChannel);
        G3227_ps_Sound1Control->ioa_Request.io_Command = CMD_START;
        DoIO(G3227_ps_Sound1Control);
}

void F0910_ReleaseSwooshSound(
)
{
        G3227_ps_Sound1Control->ioa_Request.io_Command = ADCMD_FINISH;
        M008_SET(G3227_ps_Sound1Control->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
        BeginIO(G3227_ps_Sound1Control);
        WaitIO(G3225_ps_Sound1LeftChannel);
        WaitIO(G3226_ps_Sound1RightChannel);
        M009_CLEAR(G3227_ps_Sound1Control->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
        G3227_ps_Sound1Control->ioa_Request.io_Command = CMD_STOP;
        DoIO(G3227_ps_Sound1Control);
}
#endif
#endif
