<commit_before>/**
 * OpenAL cross platform audio library
 * Copyright (C) 2011-2013 by authors.
 * This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA  02111-1307, USA.
 * Or go to http://www.gnu.org/copyleft/lgpl.html
 */

#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
#include <errno.h>
#include <memory.h>
#include <sys/select.h>
#include <sys/asoundlib.h>
#include <sys/neutrino.h>

#include "alMain.h"
#include "alu.h"

typedef struct
{
    snd_pcm_t* pcmHandle;
    int audio_fd;

    ALvoid* buffer;
    ALsizei size;

    volatile int killNow;
    ALvoid* thread;

    snd_pcm_channel_setup_t  csetup;
    snd_pcm_channel_params_t cparams;
} qsa_data;

typedef struct
{
    ALCchar* name;
    int card;
    int dev;
} DevMap;

static const ALCchar qsaDevice[]="QSA Default";
static DevMap* allDevNameMap;
static ALuint numDevNames;
static DevMap* allCaptureDevNameMap;
static ALuint numCaptureDevNames;

static const struct
{
    int32_t format;
} formatlist[]=
{
    {SND_PCM_SFMT_FLOAT_LE},
    {SND_PCM_SFMT_S32_LE},
    {SND_PCM_SFMT_U32_LE},
    {SND_PCM_SFMT_S16_LE},
    {SND_PCM_SFMT_U16_LE},
    {SND_PCM_SFMT_S8},
    {SND_PCM_SFMT_U8},
    {0},
};

static const struct
{
    int32_t rate;
} ratelist[]=
{
    {192000},
    {176400},
    {96000},
    {88200},
    {48000},
    {44100},
    {32000},
    {24000},
    {22050},
    {16000},
    {12000},
    {11025},
    {8000},
    {0},
};

static const struct
{
    int32_t channels;
} channellist[]=
{
    {8},
    {7},
    {6},
    {4},
    {2},
    {1},
    {0},
};

static DevMap* deviceList(int type, ALuint* count)
{
    snd_ctl_t* handle;
    snd_pcm_info_t pcminfo;
    int max_cards, card, err, dev, num_devices, idx;
    DevMap* dev_list;
    char name[1024];
    struct snd_ctl_hw_info info;
    void* temp;

    idx=0;
    num_devices=0;
    max_cards=snd_cards();

    if (max_cards<=0)
    {
        return 0;
    }

    dev_list=malloc(sizeof(DevMap)*1);
    dev_list[0].name=strdup(qsaDevice);
    num_devices=1;

    for (card=0; card<max_cards; card++)
    {
        if ((err=snd_ctl_open(&handle, card))<0)
        {
            continue;
        }
        if ((err=snd_ctl_hw_info(handle, &info))<0)
        {
            snd_ctl_close(handle);
            continue;
        }

        for (dev=0; dev<(int)info.pcmdevs; dev++)
        {
            if ((err=snd_ctl_pcm_info(handle, dev, &pcminfo)) < 0)
            {
                continue;
            }

            if ((type==SND_PCM_CHANNEL_PLAYBACK && (pcminfo.flags&SND_PCM_INFO_PLAYBACK)) ||
                (type==SND_PCM_CHANNEL_CAPTURE && (pcminfo.flags&SND_PCM_INFO_CAPTURE)))
            {
                temp=realloc(dev_list, sizeof(DevMap)*(num_devices+1));
                if (temp)
                {
                    dev_list=temp;
                    snprintf(name, sizeof(name), "%s [%s] (hw:%d,%d)", info.name, pcminfo.name, card, dev);
                    dev_list[num_devices].name=strdup(name);
                    dev_list[num_devices].card=card;
                    dev_list[num_devices].dev=dev;
                    num_devices++;
                }
            }
        }
        snd_ctl_close (handle);
    }

    *count=num_devices;

    return dev_list;
}

static ALuint qsa_proc_playback(ALvoid* ptr)
{
    ALCdevice* device=(ALCdevice*)ptr;
    qsa_data* data=(qsa_data*)device->ExtraData;
    char* write_ptr;
    int avail;
    snd_pcm_channel_status_t status;
    struct sched_param param;
    fd_set wfds;
    int selectret;
    struct timeval timeout;

    SetRTPriority();

    /* Increase default 10 priority to 11 to avoid jerky sound */
    SchedGet(0, 0, &param);
    param.sched_priority=param.sched_curpriority+1;
    SchedSet(0, 0, SCHED_NOCHANGE, &param);<commit_msg>Use force_align_arg_pointer for QSA<commit_after>/**
 * OpenAL cross platform audio library
 * Copyright (C) 2011-2013 by authors.
 * This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA  02111-1307, USA.
 * Or go to http://www.gnu.org/copyleft/lgpl.html
 */

#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
#include <errno.h>
#include <memory.h>
#include <sys/select.h>
#include <sys/asoundlib.h>
#include <sys/neutrino.h>

#include "alMain.h"
#include "alu.h"

typedef struct
{
    snd_pcm_t* pcmHandle;
    int audio_fd;

    ALvoid* buffer;
    ALsizei size;

    volatile int killNow;
    ALvoid* thread;

    snd_pcm_channel_setup_t  csetup;
    snd_pcm_channel_params_t cparams;
} qsa_data;

typedef struct
{
    ALCchar* name;
    int card;
    int dev;
} DevMap;

static const ALCchar qsaDevice[]="QSA Default";
static DevMap* allDevNameMap;
static ALuint numDevNames;
static DevMap* allCaptureDevNameMap;
static ALuint numCaptureDevNames;

static const struct
{
    int32_t format;
} formatlist[]=
{
    {SND_PCM_SFMT_FLOAT_LE},
    {SND_PCM_SFMT_S32_LE},
    {SND_PCM_SFMT_U32_LE},
    {SND_PCM_SFMT_S16_LE},
    {SND_PCM_SFMT_U16_LE},
    {SND_PCM_SFMT_S8},
    {SND_PCM_SFMT_U8},
    {0},
};

static const struct
{
    int32_t rate;
} ratelist[]=
{
    {192000},
    {176400},
    {96000},
    {88200},
    {48000},
    {44100},
    {32000},
    {24000},
    {22050},
    {16000},
    {12000},
    {11025},
    {8000},
    {0},
};

static const struct
{
    int32_t channels;
} channellist[]=
{
    {8},
    {7},
    {6},
    {4},
    {2},
    {1},
    {0},
};

static DevMap* deviceList(int type, ALuint* count)
{
    snd_ctl_t* handle;
    snd_pcm_info_t pcminfo;
    int max_cards, card, err, dev, num_devices, idx;
    DevMap* dev_list;
    char name[1024];
    struct snd_ctl_hw_info info;
    void* temp;

    idx=0;
    num_devices=0;
    max_cards=snd_cards();

    if (max_cards<=0)
    {
        return 0;
    }

    dev_list=malloc(sizeof(DevMap)*1);
    dev_list[0].name=strdup(qsaDevice);
    num_devices=1;

    for (card=0; card<max_cards; card++)
    {
        if ((err=snd_ctl_open(&handle, card))<0)
        {
            continue;
        }
        if ((err=snd_ctl_hw_info(handle, &info))<0)
        {
            snd_ctl_close(handle);
            continue;
        }

        for (dev=0; dev<(int)info.pcmdevs; dev++)
        {
            if ((err=snd_ctl_pcm_info(handle, dev, &pcminfo)) < 0)
            {
                continue;
            }

            if ((type==SND_PCM_CHANNEL_PLAYBACK && (pcminfo.flags&SND_PCM_INFO_PLAYBACK)) ||
                (type==SND_PCM_CHANNEL_CAPTURE && (pcminfo.flags&SND_PCM_INFO_CAPTURE)))
            {
                temp=realloc(dev_list, sizeof(DevMap)*(num_devices+1));
                if (temp)
                {
                    dev_list=temp;
                    snprintf(name, sizeof(name), "%s [%s] (hw:%d,%d)", info.name, pcminfo.name, card, dev);
                    dev_list[num_devices].name=strdup(name);
                    dev_list[num_devices].card=card;
                    dev_list[num_devices].dev=dev;
                    num_devices++;
                }
            }
        }
        snd_ctl_close (handle);
    }

    *count=num_devices;

    return dev_list;
}

/* force_align_arg_pointer is required for proper function arguments */
/* aligning, when SSE mixer is used. QNX has a bug in pthread_create */
/* function regarding thread stack alignment, it uses 64 bit align   */
/* instead of 128 bit, like main thread.                             */
#if defined(__GNUC__) && (_NTO_VERSION <= 650) && \
    defined(__i386__) && defined(HAVE_SSE)
__attribute__((force_align_arg_pointer))
#endif /* __GNUC__ && QNX version < 6.5.0 on x86 platform with SSE support */
static ALuint qsa_proc_playback(ALvoid* ptr)
{
    ALCdevice* device=(ALCdevice*)ptr;
    qsa_data* data=(qsa_data*)device->ExtraData;
    char* write_ptr;
    int avail;
    snd_pcm_channel_status_t status;
    struct sched_param param;
    fd_set wfds;
    int selectret;
    struct timeval timeout;

    SetRTPriority();

    /* Increase default 10 priority to 11 to avoid jerky sound */
    SchedGet(0, 0, &param);
    param.sched_priority=param.sched_curpriority+1;
    SchedSet(0, 0, SCHED_NOCHANGE, &param);
{'fraction_non_alphanumeric': 0.11549027895181742, 'fraction_numerical': 0.03127641589180051, 'mean_word_length': 2.579803328290469, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7274996', 'n_tokens_mistral': 3519, 'n_tokens_neox': 3278, 'n_words': 808}