#include "util/demo_utils.hpp"
#include "util/client_license.h"
#include <fstream>
#include <iostream>
#include <vector>
constexpr auto ENV_VAR_LICENSE = "YOBE_LICENSE";
std::vector<double> YobeProcessing(const std::string& license, std::vector<double> input_buffer);
std::ofstream log_stream;
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cout << "cpp demo requires a .wav file as input.\n";
} else {
std::cout << "Just checking to see if the Yobe parameters match the audio file.\n";
const std::string file_path(argv[1]);
const auto input_buffer = DemoUtil::ReadAudioFile(file_path);
std::cout << '\n';
std::vector<double> processed_audio;
try {
processed_audio = YobeProcessing(getLicense(ENV_VAR_LICENSE), input_buffer);
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
DemoUtil::WriteAudioFile(file_path, processed_audio);
}
return 0;
}
std::vector<double> YobeProcessing(const std::string& license, std::vector<double> input_buffer) {
log_stream.open("yobe_bio_listener_demo.log");
#if NEAR_VOICE
#else
#endif
throw std::runtime_error("Initialization error");
}
std::vector<double> output_buffer;
std::vector<double> scratch_buffer(output_size);
uint32_t out_buffer_size = 0;
const auto total_input_samples = input_buffer.size();
std::cout << "Yobe engine has started processing.\n";
for (size_t input_index = 0; input_index < total_input_samples; input_index += input_size) {
if (input_index + input_size > total_input_samples) {
std::vector<double> pad_buffer(input_index + input_size - total_input_samples, 0.0);
input_buffer.insert(input_buffer.end(), pad_buffer.begin(), pad_buffer.end());
}
out_buffer_size = output_size;
status = bio_listener->ProcessBuffer(&input_buffer[input_index], scratch_buffer.data(), input_size,
&out_buffer_size);
} else if (out_buffer_size != 0) {
output_buffer.insert(output_buffer.end(), scratch_buffer.begin(), scratch_buffer.end());
}
}
auto deinit_status = bio_listener->Deinit();
std::cout << "There was an error when deinitializing the Yobe engine.\n";
throw std::runtime_error("Deinit error");
}
std::cout << "Yobe engine has finished processing.\n";
log_stream.close();
return output_buffer;
}
YOBE_SDK_API std::shared_ptr< BioListener > NewBioListener()
Creates a new instance of BioListener.
YOBE_SDK_API int32_t InputChannels()
Returns the number of input channels required for processing.
YOBE_SDK_API double AudioBufferTime()
Returns the processing audio buffer length in seconds.
YOBE_SDK_API void RegisterCallback(std::function< void(const char *)> log_callback)
Registers a callback function to receive Yobe logging information.
YOBE_SDK_API uint32_t OutputBufferSize()
Returns the output buffer size in samples.
YOBE_SDK_API uint32_t InputBufferSize()
Returns the input buffer size in samples.
YOBE_SDK_API uint32_t SamplingRate(bool output_sampling_rate=true)
Returns the expected sampling rate of the input/output buffers.
YOBE_SDK_API const char * StdError(Status status)
Translates a Yobe Status code into a more readable string.
YOBE_SDK_API int32_t OutputChannels()
Returns the number of processing output channels.
@ YOBE_STOPPED
This means that the engine successfully stopped.
@ YOBE_UNKNOWN
An unknown error has occurred.
@ YOBE_OK
The function executed successfully.
@ NEEDS_MORE_DATA
The algorithm needs more data before it can start processing the audio.
@ BROAD_SIDE
This orientation has the target voice perpendicular to the line connecting the two microphones.
@ NEAR_FIELD
The target voice is near field (less than 2 feet).
@ FAR_FIELD
The target voice is far field (3 feet or more).