11#include " UnrealEnginePythonPrivatePCH.h"
22#include " Sound/SoundWaveProcedural.h"
33
4- PyObject *py_queue_procedural_audio (ue_PyUObject *self, PyObject * args) {
4+ PyObject *py_ue_queue_audio (ue_PyUObject *self, PyObject * args) {
55 // Writes from a Python buffer object to a USoundWaveProcedural class
66 ue_py_check (self);
77
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 ;
128 Py_buffer sound_buffer;
139
14- if (!PyArg_ParseTuple (args, " y*:write_audio_to_buffer " , &sound_buffer)) {
10+ if (!PyArg_ParseTuple (args, " y*:queue_audio " , &sound_buffer)) {
1511 return NULL ;
1612 }
1713
14+ USoundWaveProcedural *sound_wave_procedural = ue_py_check_type<USoundWaveProcedural>(self);
15+ if (!sound_wave_procedural)
16+ return PyErr_Format (PyExc_Exception, " UObject is not a USoundWaveProcedural." );
17+
1818 // Convert the buffer
1919 uint8 *buffer = (uint8 *)sound_buffer.buf ;
20- if (buffer == nullptr )
20+ if (buffer == nullptr )
2121 return PyErr_Format (PyExc_Exception, " Invalid sound buffer." );
2222
2323 // Add the audio to the Sound Wave's audio buffer
2424 sound_wave_procedural->QueueAudio (buffer, sound_buffer.len );
25-
25+
2626 // Clean up
2727 PyBuffer_Release (&sound_buffer);
2828
2929 Py_INCREF (Py_None);
3030 return Py_None;
3131}
3232
33+ PyObject *py_ue_sound_get_data (ue_PyUObject *self, PyObject * args) {
34+ ue_py_check (self);
35+
36+ USoundWave *sound = ue_py_check_type<USoundWave>(self);
37+ if (!sound)
38+ return PyErr_Format (PyExc_Exception, " UObject is not a USoundWave." );
39+
40+ FByteBulkData raw_data = sound->RawData ;
41+
42+ char *data = (char *)raw_data.Lock (LOCK_READ_ONLY);
43+ int32 data_size = raw_data.GetBulkDataSize ();
44+ PyObject *py_data = PyBytes_FromStringAndSize (data, data_size);
45+ raw_data.Unlock ();
46+ return py_data;
47+ }
48+
3349PyObject *py_ue_play_sound_at_location (ue_PyUObject *self, PyObject * args) {
3450
3551 ue_py_check (self);
@@ -44,13 +60,9 @@ PyObject *py_ue_play_sound_at_location(ue_PyUObject *self, PyObject * args) {
4460 return NULL ;
4561 }
4662
47-
4863 USoundBase *sound_object = nullptr ;
4964 if (ue_is_pyuobject (sound)) {
50- ue_PyUObject *py_sound = (ue_PyUObject *)sound;
51- if (py_sound->ue_object ->IsA <USoundBase>()) {
52- sound_object = (USoundBase *)py_sound->ue_object ;
53- }
65+ sound_object = ue_py_check_type<USoundBase>(sound);
5466 }
5567 else if (PyUnicodeOrString_Check (sound)) {
5668 sound_object = FindObject<USoundBase>(ANY_PACKAGE, UTF8_TO_TCHAR (PyUnicode_AsUTF8 (sound)));
0 commit comments