aboutsummaryrefslogtreecommitdiff
path: root/pd/portaudio/pa_linux_alsa/blocking_calls.c
blob: 6304b117ce894ed783d3c5f6175875aa5baf1623 (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

#include "pa_stream.h"

#include "pa_linux_alsa.h"

PaError ReadStream( PaStream* s,
                           void *buffer,
                           unsigned long frames )
{
    PaAlsaStream *stream = (PaAlsaStream*)s;

    /* TODO: handle failure, xruns */

    if( stream->capture_interleaved )
    {
        snd_pcm_mmap_readi( stream->pcm_capture, buffer, frames );
    }
    else
    {
        snd_pcm_mmap_readn( stream->pcm_capture, (void**)buffer, frames );
    }

    return paNoError;
}


PaError WriteStream( PaStream* s,
                            void *buffer,
                            unsigned long frames )
{
    PaAlsaStream *stream = (PaAlsaStream*)s;

    if( stream->playback_interleaved )
    {
        snd_pcm_mmap_writei( stream->pcm_playback, buffer, frames );
    }
    else
    {
        snd_pcm_mmap_writen( stream->pcm_playback, (void**)buffer, frames );
    }

    return paNoError;
}


unsigned long GetStreamReadAvailable( PaStream* s )
{
    PaAlsaStream *stream = (PaAlsaStream*)s;

    return snd_pcm_avail_update( stream->pcm_capture );
}


unsigned long GetStreamWriteAvailable( PaStream* s )
{
    PaAlsaStream *stream = (PaAlsaStream*)s;

    return snd_pcm_avail_update( stream->pcm_playback );
}