diff --git a/runtime/onnxruntime/include/audio.h b/runtime/onnxruntime/include/audio.h index b14d3b85d..7e889cfbc 100644 --- a/runtime/onnxruntime/include/audio.h +++ b/runtime/onnxruntime/include/audio.h @@ -24,6 +24,7 @@ class AudioFrame { AudioFrame(); AudioFrame(int len); AudioFrame(const AudioFrame &other); + AudioFrame& operator=(const AudioFrame &other); AudioFrame(int start, int end, bool is_final); ~AudioFrame(); diff --git a/runtime/onnxruntime/src/audio.cpp b/runtime/onnxruntime/src/audio.cpp index ba6045f8a..20db14b26 100644 --- a/runtime/onnxruntime/src/audio.cpp +++ b/runtime/onnxruntime/src/audio.cpp @@ -151,11 +151,40 @@ AudioFrame::AudioFrame(int len) : len(len) start = 0; } AudioFrame::AudioFrame(const AudioFrame &other) + : start(other.start), end(other.end), is_final(other.is_final), len(other.len), + global_start(other.global_start), global_end(other.global_end) { + if (other.data != nullptr && len > 0) { + data = static_cast(malloc(sizeof(float) * len)); + if (data != nullptr) { + memcpy(data, other.data, sizeof(float) * len); + } + } +} +AudioFrame& AudioFrame::operator=(const AudioFrame &other) +{ + if (this == &other) { + return *this; + } + + float* copied_data = nullptr; + if (other.data != nullptr && other.len > 0) { + copied_data = static_cast(malloc(sizeof(float) * other.len)); + if (copied_data == nullptr) { + return *this; + } + memcpy(copied_data, other.data, sizeof(float) * other.len); + } + + free(data); start = other.start; end = other.end; - len = other.len; is_final = other.is_final; + data = copied_data; + len = other.len; + global_start = other.global_start; + global_end = other.global_end; + return *this; } AudioFrame::AudioFrame(int start, int end, bool is_final):start(start),end(end),is_final(is_final){ len = end - start;