To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at https://github.com/sonic-visualiser/sv-dependency-builds .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / src / portaudio_20161030_catalina_patch / bindings / cpp / source / portaudiocpp / BlockingStream.cxx @ 162:d43aab368df9

History | View | Annotate | Download (2 KB)

1
#include "portaudiocpp/BlockingStream.hxx"
2

    
3
#include "portaudio.h"
4

    
5
#include "portaudiocpp/StreamParameters.hxx"
6
#include "portaudiocpp/Exception.hxx"
7

    
8
namespace portaudio
9
{
10

    
11
        // --------------------------------------------------------------------------------------
12

    
13
        BlockingStream::BlockingStream()
14
        {
15
        }
16

    
17
        BlockingStream::BlockingStream(const StreamParameters &parameters)
18
        {
19
                open(parameters);
20
        }
21

    
22
        BlockingStream::~BlockingStream()
23
        {
24
                try
25
                {
26
                        close();
27
                }
28
                catch (...)
29
                {
30
                        // ignore all errors
31
                }
32
        }
33

    
34
        // --------------------------------------------------------------------------------------
35

    
36
        void BlockingStream::open(const StreamParameters &parameters)
37
        {
38
                PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(), 
39
                        parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), NULL, NULL);
40

    
41
                if (err != paNoError)
42
                {
43
                        throw PaException(err);
44
                }
45
        }
46

    
47
        // --------------------------------------------------------------------------------------
48

    
49
        void BlockingStream::read(void *buffer, unsigned long numFrames)
50
        {
51
                PaError err = Pa_ReadStream(stream_, buffer, numFrames);
52

    
53
                if (err != paNoError)
54
                {
55
                        throw PaException(err);
56
                }
57
        }
58

    
59
        void BlockingStream::write(const void *buffer, unsigned long numFrames)
60
        {
61
                PaError err = Pa_WriteStream(stream_, buffer, numFrames);
62

    
63
                if (err != paNoError)
64
                {
65
                        throw PaException(err);
66
                }
67
        }
68

    
69
        // --------------------------------------------------------------------------------------
70

    
71
        signed long BlockingStream::availableReadSize() const
72
        {
73
                signed long avail = Pa_GetStreamReadAvailable(stream_);
74

    
75
                if (avail < 0)
76
                {
77
                        throw PaException(avail);
78
                }
79

    
80
                return avail;
81
        }
82

    
83
        signed long BlockingStream::availableWriteSize() const
84
        {
85
                signed long avail = Pa_GetStreamWriteAvailable(stream_);
86

    
87
                if (avail < 0)
88
                {
89
                        throw PaException(avail);
90
                }
91

    
92
                return avail;
93
        }
94

    
95
        // --------------------------------------------------------------------------------------
96

    
97
} // portaudio
98

    
99

    
100