Skip to content

Commit 43cbddf

Browse files
author
rdeioris
authored
Merge pull request #166 from Jay2645/add-streaming-audio-function
Created a 'write_audio_to_buffer' function.
2 parents edd27fb + 85de0dd commit 43cbddf

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Source/UnrealEnginePython/Private/UEPyAudio.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
#include "UnrealEnginePythonPrivatePCH.h"
2+
#include "Sound/SoundWaveProcedural.h"
23

4+
PyObject *py_queue_procedural_audio(ue_PyUObject *self, PyObject * args) {
5+
// Writes from a Python buffer object to a USoundWaveProcedural class
6+
ue_py_check(self);
7+
8+
if (!self->ue_object->IsA<USoundWaveProcedural>())
9+
return PyErr_Format(PyExc_Exception, "UObject is not a USoundWaveProcedural.");
10+
11+
USoundWaveProcedural *sound_wave_procedural = (USoundWaveProcedural *)self->ue_object;
12+
Py_buffer sound_buffer;
13+
14+
if(!PyArg_ParseTuple(args, "y*:write_audio_to_buffer", &sound_buffer)) {
15+
return NULL;
16+
}
17+
18+
// Convert the buffer
19+
uint8 *buffer = (uint8 *)sound_buffer.buf;
20+
if(buffer == nullptr)
21+
return PyErr_Format(PyExc_Exception, "Invalid sound buffer.");
22+
23+
// Add the audio to the Sound Wave's audio buffer
24+
sound_wave_procedural->QueueAudio(buffer, sound_buffer.len);
25+
26+
// Clean up
27+
PyBuffer_Release(&sound_buffer);
28+
29+
Py_INCREF(Py_None);
30+
return Py_None;
31+
}
332

433
PyObject *py_ue_play_sound_at_location(ue_PyUObject *self, PyObject * args) {
534

Source/UnrealEnginePython/Private/UEPyAudio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
#include "UnrealEnginePython.h"
66

7+
PyObject *py_queue_procedural_audio(ue_PyUObject *self, PyObject * args);
78
PyObject *py_ue_play_sound_at_location(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
528528
{ "get_actor_velocity", (PyCFunction)py_ue_get_actor_velocity, METH_VARARGS, "" },
529529

530530
{ "play_sound_at_location", (PyCFunction)py_ue_play_sound_at_location, METH_VARARGS, "" },
531+
{ "queue_audio", (PyCFunction)py_queue_procedural_audio, METH_VARARGS, "" },
531532

532533
{ "world_tick", (PyCFunction)py_ue_world_tick, METH_VARARGS, "" },
533534

0 commit comments

Comments
 (0)