⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paqa_errs.c

📁 mediastreamer2是开源的网络传输媒体流的库
💻 C
📖 第 1 页 / 共 2 页
字号:
/** @file paqa_errs.c	@brief Self Testing Quality Assurance app for PortAudio	Do lots of bad things to test error reporting.	@author Phil Burk  http://www.softsynth.com    Pieter Suurmond adapted to V19 API.*//* * $Id: paqa_errs.c 791 2004-05-07 20:56:30Z aknudsen $ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com * Copyright (c) 1999-2000 Ross Bencina and Phil Burk * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files * (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * Any person wishing to distribute modifications to the Software is * requested to send the modifications to the original developer so that * they can be incorporated into the canonical version. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include <stdio.h>#include <math.h>#include "portaudio.h"/*--------- Definitions ---------*/#define MODE_INPUT        (0)#define MODE_OUTPUT       (1)#define FRAMES_PER_BUFFER (64)#define SAMPLE_RATE       (44100.0)typedef struct PaQaData{    unsigned long  framesLeft;    int            numChannels;    int            bytesPerSample;    int            mode;}PaQaData;static int gNumPassed = 0; /* Two globals */static int gNumFailed = 0;/*------------------- Macros ------------------------------*//* Print ERROR if it fails. Tally success or failure. Odd  *//* do-while wrapper seems to be needed for some compilers. */#define EXPECT(_exp) \    do \    { \        if ((_exp)) {\            gNumPassed++; \        } \        else { \            printf("\nERROR - 0x%x - %s for %s\n", result, Pa_GetErrorText(result), #_exp ); \            gNumFailed++; \            goto error; \        } \    } while(0)#define HOPEFOR(_exp) \    do \    { \        if ((_exp)) {\            gNumPassed++; \        } \        else { \            printf("\nERROR - 0x%x - %s for %s\n", result, Pa_GetErrorText(result), #_exp ); \            gNumFailed++; \        } \    } while(0)/*-------------------------------------------------------------------------*//* This routine will be called by the PortAudio engine when audio is needed.   It may be called at interrupt level on some machines so don't do anything   that could mess up the system like calling malloc() or free().*/static int QaCallback( const void*                      inputBuffer,                       void*                            outputBuffer,                       unsigned long                    framesPerBuffer,			           const PaStreamCallbackTimeInfo*  timeInfo,			           PaStreamCallbackFlags            statusFlags,                       void*                            userData ){    unsigned long   i;    unsigned char*  out = (unsigned char *) outputBuffer;    PaQaData*       data = (PaQaData *) userData;        (void)inputBuffer; /* Prevent "unused variable" warnings. */    /* Zero out buffer so we don't hear terrible noise. */    if( data->mode == MODE_OUTPUT )    {        unsigned long numBytes = framesPerBuffer * data->numChannels * data->bytesPerSample;        for( i=0; i<numBytes; i++ )        {            *out++ = 0;        }    }    /* Are we through yet? */    if( data->framesLeft > framesPerBuffer )    {        data->framesLeft -= framesPerBuffer;        return 0;    }    else    {        data->framesLeft = 0;        return 1;    }}static PaDeviceIndex FindInputOnlyDevice(void){    PaDeviceIndex result = Pa_GetDefaultInputDevice();    if( result != paNoDevice && Pa_GetDeviceInfo(result)->maxOutputChannels == 0 )        return result;    for( result = 0; result < Pa_GetDeviceCount(); ++result )    {        if( Pa_GetDeviceInfo(result)->maxOutputChannels == 0 )            return result;    }    return paNoDevice;}static PaDeviceIndex FindOutputOnlyDevice(void){    PaDeviceIndex result = Pa_GetDefaultOutputDevice();    if( result != paNoDevice && Pa_GetDeviceInfo(result)->maxInputChannels == 0 )        return result;    for( result = 0; result < Pa_GetDeviceCount(); ++result )    {        if( Pa_GetDeviceInfo(result)->maxInputChannels == 0 )            return result;    }    return paNoDevice;}/*-------------------------------------------------------------------------------------------------*/static int TestBadOpens( void ){    PaStream*           stream = NULL;    PaError             result;    PaQaData            myData;    PaStreamParameters  ipp, opp;        /* Setup data for synthesis thread. */    myData.framesLeft = (unsigned long) (SAMPLE_RATE * 100); /* 100 seconds */    myData.numChannels = 1;    myData.mode = MODE_OUTPUT;    /*----------------------------- No devices specified: */    ipp.device                    = opp.device                    = paNoDevice;    ipp.channelCount              = opp.channelCount              = 0; /* Also no channels. */    ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;    ipp.sampleFormat              = opp.sampleFormat              = paFloat32;    /* Take the low latency of the default device for all subsequent tests. */    ipp.suggestedLatency          = Pa_GetDeviceInfo(Pa_GetDefaultInputDevice())->defaultLowInputLatency;    opp.suggestedLatency          = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice())->defaultLowOutputLatency;    HOPEFOR(((result = Pa_OpenStream(&stream, &ipp, &opp,                                     SAMPLE_RATE, FRAMES_PER_BUFFER,                                     paClipOff, QaCallback, &myData )) == paInvalidDevice));    /*----------------------------- No devices specified #2: */    HOPEFOR(((result = Pa_OpenStream(&stream, NULL, NULL,                                     SAMPLE_RATE, FRAMES_PER_BUFFER,                                     paClipOff, QaCallback, &myData )) == paInvalidDevice));    /*----------------------------- Out of range input device specified: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -