~ubuntu-branches/ubuntu/trusty/python-sfml/trusty

« back to all changes in this revision

Viewing changes to src/sfml/DerivableSoundRecorder.cpp

  • Committer: Package Import Robot
  • Author(s): James Cowgill
  • Date: 2013-12-09 17:50:52 UTC
  • mfrom: (1.1.3) (8.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20131209175052-11v6drpb6g3yksst
Tags: 1.5.1.is.1.3+dfsg-1
* New upstream version 1.3 (from python-sfml.org)
  - This is a complete rewrite of the Python bindings for SFML2, and
    the new maintainer is using a different version numbering scheme.
* Added myself to the list of uploaders
* Change package priority from extra to optional
* Bumped standards version (to 3.9.5) and debhelper compat (to 9)
* Added Python 3 and documentation packages
* Improve package description for debug packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pySFML - Python bindings for SFML
 
4
// Copyright 2012-2013, Jonathan De Wachter <dewachter.jonathan@gmail.com>
 
5
//
 
6
// This software is released under the LGPLv3 license.
 
7
// You should have received a copy of the GNU Lesser General Public License
 
8
// along with this program. If not, see <http://www.gnu.org/licenses/>.
 
9
//
 
10
////////////////////////////////////////////////////////////////////////////////
 
11
 
 
12
 
 
13
#include "DerivableSoundRecorder.hpp"
 
14
#include <iostream>
 
15
 
 
16
DerivableSoundRecorder::DerivableSoundRecorder(void* pyobj):
 
17
sf::SoundRecorder (),
 
18
m_pyobj           (static_cast<PyObject*>(pyobj))
 
19
{
 
20
        import_sfml__audio(); // make sure the audio module is imported
 
21
};
 
22
 
 
23
bool DerivableSoundRecorder::onStart()
 
24
{
 
25
    PyEval_InitThreads();
 
26
 
 
27
        static char method[] = "on_start";
 
28
    PyObject* r = PyObject_CallMethod(m_pyobj, method, NULL);
 
29
 
 
30
    return PyObject_IsTrue(r);
 
31
}
 
32
 
 
33
bool DerivableSoundRecorder::onProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
 
34
{
 
35
        static char method[] = "on_process_samples";
 
36
    static char format[] = "O";
 
37
 
 
38
    PyGILState_STATE gstate;
 
39
    gstate = PyGILState_Ensure();
 
40
 
 
41
    PyObject* pyChunk = (PyObject*)(wrap_chunk((sf::Int16*)samples, sampleCount, false));
 
42
    PyObject* r = PyObject_CallMethod(m_pyobj, method, format, pyChunk);
 
43
 
 
44
        Py_DECREF(pyChunk);
 
45
        PyGILState_Release(gstate);
 
46
 
 
47
    return PyObject_IsTrue(r);
 
48
}
 
49
 
 
50
void DerivableSoundRecorder::onStop()
 
51
{
 
52
    PyGILState_STATE gstate;
 
53
    gstate = PyGILState_Ensure();
 
54
 
 
55
        static char method[] = "on_stop";
 
56
    PyObject_CallMethod(m_pyobj, method, NULL);
 
57
 
 
58
        PyGILState_Release(gstate);
 
59
}