summaryrefslogtreecommitdiff
path: root/src/c_portadao.c
blob: d664b69c510e1bc4f4beb043d3780e0b47f4f927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129


//  Programmed by Jedidiah Barber
//  Released into the public domain


#include <stdio.h>
#include <unistd.h>
#include <portaudio.h>
#include "c_portadao.h"



const int pa_no_error = paNoError;
const int pa_not_initialized = paNotInitialized;
const int pa_unanticipated_host_error = paUnanticipatedHostError;
const int pa_invalid_channel_count = paInvalidChannelCount;
const int pa_invalid_sample_rate = paInvalidSampleRate;
const int pa_invalid_device = paInvalidDevice;
const int pa_invalid_flag = paInvalidFlag;
const int pa_sample_format_not_supported = paSampleFormatNotSupported;
const int pa_bad_io_device_combination = paBadIODeviceCombination;
const int pa_insufficient_memory = paInsufficientMemory;
const int pa_buffer_too_big = paBufferTooBig;
const int pa_buffer_too_small = paBufferTooSmall;
const int pa_null_callback = paNullCallback;
const int pa_bad_stream_ptr = paBadStreamPtr;
const int pa_timed_out = paTimedOut;
const int pa_internal_error = paInternalError;
const int pa_device_unavailable = paDeviceUnavailable;
const int pa_incompatible_host_api_specific_stream_info = paIncompatibleHostApiSpecificStreamInfo;
const int pa_stream_is_stopped = paStreamIsStopped;
const int pa_stream_is_not_stopped = paStreamIsNotStopped;
const int pa_input_overflowed = paInputOverflowed;
const int pa_output_underflowed = paOutputUnderflowed;
const int pa_host_api_not_found = paHostApiNotFound;
const int pa_invalid_host_api = paInvalidHostApi;
const int pa_cannot_read_from_a_callback_stream = paCanNotReadFromACallbackStream;
const int pa_cannot_write_to_a_callback_stream = paCanNotWriteToACallbackStream;
const int pa_cannot_read_from_an_output_only_stream = paCanNotReadFromAnOutputOnlyStream;
const int pa_cannot_write_to_an_input_only_stream = paCanNotWriteToAnInputOnlyStream;
const int pa_incompatible_stream_host_api = paIncompatibleStreamHostApi;
const int pa_bad_buffer_ptr = paBadBufferPtr;

const int pa_in_development = paInDevelopment;
const int pa_direct_sound = paDirectSound;
const int pa_mme = paMME;
const int pa_asio = paASIO;
const int pa_sound_manager = paSoundManager;
const int pa_core_audio = paCoreAudio;
const int pa_oss = paOSS;
const int pa_alsa = paALSA;
const int pa_al = paAL;
const int pa_beos = paBeOS;
const int pa_wdmks = paWDMKS;
const int pa_jack = paJACK;
const int pa_wasapi = paWASAPI;
const int pa_audio_science_hpi = paAudioScienceHPI;
const int pa_sndio = paSndio;

const int pa_no_device = paNoDevice;

const unsigned long pa_float_32 = paFloat32;
const unsigned long pa_int_32 = paInt32;
const unsigned long pa_int_24 = paInt24;
const unsigned long pa_int_16 = paInt16;
const unsigned long pa_int_8 = paInt8;
const unsigned long pa_uint_8 = paUInt8;

const int pa_format_is_supported = paFormatIsSupported;

const unsigned long pa_no_flag = paNoFlag;
const unsigned long pa_clip_off = paClipOff;
const unsigned long pa_dither_off = paDitherOff;
const unsigned long pa_never_drop_input = paNeverDropInput;
const unsigned long pa_prime_output_buffers_using_stream_callback =
    paPrimeOutputBuffersUsingStreamCallback;

const int pa_continue = paContinue;
const int pa_complete = paComplete;
const int pa_abort = paAbort;

const unsigned long pa_input_underflow = paInputUnderflow;
const unsigned long pa_input_overflow = paInputOverflow;
const unsigned long pa_output_underflow = paOutputUnderflow;
const unsigned long pa_output_overflow = paOutputOverflow;
const unsigned long pa_priming_output = paPrimingOutput;



int fd_backup;
int suppressed = 0;

void suppress_stderr() {
    fflush(stderr);
    fd_backup = dup(STDERR_FILENO);
    //if (freopen("/dev/null", "w", stderr) == NULL) {
    //    freopen("nul", "w", stderr);
    //}
    close(STDERR_FILENO);
    suppressed = 1;
}

void restore_stderr() {
    fflush(stderr);
    dup2(fd_backup, fileno(stderr));
    close(fd_backup);
    suppressed = 0;
}

int apa_init(int stop_msg) {
    if (stop_msg) {
        suppress_stderr();
    }
    int result = Pa_Initialize();
    if (suppressed) {
        restore_stderr();
    }
    return result;
}

int apa_term() {
    if (suppressed) {
        restore_stderr();
    }
    return Pa_Terminate();
}