Skip to content

Commit

Permalink
apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
svenpaulsen committed Apr 4, 2023
1 parent c6420d2 commit 4b02bce
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 70 deletions.
4 changes: 2 additions & 2 deletions Source/Odin/Private/OdinAudioCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void UOdinAudioCapture::AsyncChangeCaptureDeviceById(FString
ChangeCaptureDeviceById(NewDeviceId, bSuccess);

AsyncTask(ENamedThreads::GameThread, [OnChangeCompleted, bSuccess]() {
// We execute the delegate along with the param
// We execute the delegate along with the param.
OnChangeCompleted.Execute(bSuccess);
});
});
Expand Down Expand Up @@ -253,7 +253,7 @@ void UOdinAudioCapture::RestartStream()
// OpenCaptureStream automatically closes the capture stream, if it's already active.
if (AudioCapture.OpenCaptureStream(Params, MoveTemp(OnCapture), 1024)) {
// If we opened the capture stream successfully, get the capture device info and initialize
// the UAudioGenerator
// the UAudioGenerator.
Audio::FCaptureDeviceInfo Info;
if (AudioCapture.GetCaptureDeviceInfo(Info)) {
Init(Info.PreferredSampleRate, Info.InputChannels);
Expand Down
2 changes: 1 addition & 1 deletion Source/Odin/Private/OdinCaptureMedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ void UOdinCaptureMedia::BeginDestroy()
{
Reset();
Super::BeginDestroy();
}
}
2 changes: 1 addition & 1 deletion Source/Odin/Private/OdinJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,4 @@ void UOdinJsonObject::SetObjectArrayField(const FString &Field
}

JsonObj->SetArrayField(FieldName, EntriesArray);
}
}
2 changes: 1 addition & 1 deletion Source/Odin/Private/OdinJsonValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,4 @@ UOdinJsonObject *UOdinJsonValue::AsObject()
return JsonObj;
}

void UOdinJsonValue::ErrorMessage(const FString &InType) const {}
void UOdinJsonValue::ErrorMessage(const FString &InType) const {}
2 changes: 1 addition & 1 deletion Source/Odin/Private/OdinMediaBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
UOdinMediaBase::UOdinMediaBase(const class FObjectInitializer &PCIP)
: Super(PCIP)
{
}
}
2 changes: 1 addition & 1 deletion Source/Odin/Private/OdinMediaSoundGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ void OdinMediaSoundGenerator::SetOdinStream(OdinMediaStreamHandle streamHandle)

void OdinMediaSoundGenerator::OnBeginGenerate() {}

void OdinMediaSoundGenerator::OnEndGenerate() {}
void OdinMediaSoundGenerator::OnEndGenerate() {}
2 changes: 1 addition & 1 deletion Source/Odin/Private/OdinMediaSoundGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OdinMediaSoundGenerator : public ISoundGenerator
// Called when a new buffer is required.
int32 OnGenerateAudio(float *OutAudio, int32 NumSamples) override final;

// Returns the number of samples to render per callback
// Returns the number of samples to render per callback.
int32 GetDesiredNumSamplesToRenderPerCallback() const override final
{
return 1920; // 20ms 48kHz stereo
Expand Down
2 changes: 1 addition & 1 deletion Source/Odin/Private/OdinRoom.AsyncNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ void UOdinRoomSendMessage::Activate()
this->OnResponse, this->OnError, this->OnSuccess))
->StartBackgroundTask();
this->SetReadyToDestroy();
}
}
2 changes: 1 addition & 1 deletion Source/Odin/Private/OdinRoom.AsyncTasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class RemoveMediaTask : public FNonAbandonableTask

void DoWork()
{
// TODO(Nico) refactor error check this tmp to prevent audio_generator errors
// TODO: refactor to prevent potential sound generator errors
OdinReturnCode result = -1;
if (Room && Media) {
Room->UnbindCaptureMedia(Media);
Expand Down
93 changes: 47 additions & 46 deletions Source/Odin/Public/OdinAudioCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
#endif // ENGINE_MAJOR_VERSION >= 5
#include "OdinAudioCapture.generated.h"


USTRUCT(BlueprintType)
struct ODIN_API FOdinCaptureDeviceInfo
{
struct ODIN_API FOdinCaptureDeviceInfo {
GENERATED_BODY()

/**
Expand All @@ -28,73 +26,76 @@ struct ODIN_API FOdinCaptureDeviceInfo
FAudioCaptureDeviceInfo AudioCaptureInfo;
};


DECLARE_DYNAMIC_DELEGATE_TwoParams(FGetCaptureDeviceDelegate, const TArray<FOdinCaptureDeviceInfo>&,
OutDevices, const FOdinCaptureDeviceInfo&, CurrentDevice);

DECLARE_DYNAMIC_DELEGATE_OneParam(FChangeCaptureDeviceDelegate, bool,
bSuccess);
DECLARE_DYNAMIC_DELEGATE_OneParam(FChangeCaptureDeviceDelegate, bool, bSuccess);

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCaptureDeviceChange);

UCLASS(ClassGroup=(Odin), meta=(BlueprintSpawnableComponent))
UCLASS(ClassGroup = (Odin), meta = (BlueprintSpawnableComponent))
class ODIN_API UOdinAudioCapture : public UAudioCapture, public FTickableGameObject
{
GENERATED_BODY()

public:
public:
/**
* @brief IMPORTANT! Use the Async version, in case you experience stuttering. Returns all available capture devices with the device id.
* @brief IMPORTANT! Use the Async version, in case you experience stuttering. Returns all
* available capture devices with the device id.
* @param OutDevices All available capture devices
*/
UFUNCTION(BlueprintPure, Category="AudioCapture")
UFUNCTION(BlueprintPure, Category = "AudioCapture")
void GetCaptureDevicesAvailable(TArray<FOdinCaptureDeviceInfo>& OutDevices);

/**
* @brief Returns all available capture devices with the device id. Runs async.
* @param OnResult Callback for when the result is available.
*/
UFUNCTION(BlueprintCallable, Category="AudioCapture")
UFUNCTION(BlueprintCallable, Category = "AudioCapture")
void AsyncGetCaptureDevicesAvailable(FGetCaptureDeviceDelegate OnResult);

/**
* @brief Returns info on the current capture device.
* @param CurrentDevice Info on the current capture device
*/
UFUNCTION(BlueprintPure, Category="AudioCapture")
UFUNCTION(BlueprintPure, Category = "AudioCapture")
void GetCurrentAudioCaptureDevice(FOdinCaptureDeviceInfo& CurrentDevice);

/**
* @brief IMPORTANT! Use the Async version, in case you experience stuttering. Updates the capture device and restarts the capture stream of the Audio Capture component.
* @brief IMPORTANT! Use the Async version, in case you experience stuttering. Updates the
* capture device and restarts the capture stream of the Audio Capture component.
* @param NewDeviceId The id of the targeted capture device.
* @param bSuccess Whether or not the capture device was successfully changed
*/
UFUNCTION(BlueprintCallable, Category="AudioCapture")
UFUNCTION(BlueprintCallable, Category = "AudioCapture")
void ChangeCaptureDeviceById(FString NewDeviceId, bool& bSuccess);

/**
* @brief Updates the capture device and restarts the capture stream of the Audio Capture component. Runs async, therefore not blocking the main thread.
* @brief Updates the capture device and restarts the capture stream of the Audio Capture
* component. Runs async, therefore not blocking the main thread.
* @param NewDeviceId The id of the targeted capture device.
* @param OnChangeCompleted Callback for when the change result is available.
*/
UFUNCTION(BlueprintCallable, Category="AudioCapture")
UFUNCTION(BlueprintCallable, Category = "AudioCapture")
void AsyncChangeCaptureDeviceById(FString NewDeviceId,
FChangeCaptureDeviceDelegate OnChangeCompleted);

/**
* @brief IMPORTANT! Use the Async version, in case you experience stuttering. Updates the capture device and restarts the capture stream of the Audio Capture component.
* @brief IMPORTANT! Use the Async version, in case you experience stuttering. Updates the
* capture device and restarts the capture stream of the Audio Capture component.
* @param DeviceName The name of the targeted capture device. Needs to be an exact match.
* @param bSuccess Whether or not the capture device was successfully changed
*/
UFUNCTION(BlueprintCallable, Category="AudioCapture")
UFUNCTION(BlueprintCallable, Category = "AudioCapture")
void ChangeCaptureDeviceByName(FName DeviceName, bool& bSuccess);

/**
* @brief Updates the capture device and restarts the capture stream of the Audio Capture component. Runs async, therefore not blocking the main thread.
* @brief Updates the capture device and restarts the capture stream of the Audio Capture
* component. Runs async, therefore not blocking the main thread.
* @param DeviceName The name of the targeted capture device. Needs to be an exact match.
* @param OnChangeCompleted Callback for when the change result is available.
*/
UFUNCTION(BlueprintCallable, Category="AudioCapture")
UFUNCTION(BlueprintCallable, Category = "AudioCapture")
void AsyncChangeCaptureDeviceByName(FName DeviceName,
FChangeCaptureDeviceDelegate OnChangeCompleted);

Expand All @@ -114,17 +115,17 @@ class ODIN_API UOdinAudioCapture : public UAudioCapture, public FTickableGameObj

/**
* @brief Will be called, if Odin recognizes that the selected capture device does not supply
* data anymore, i.e. if a microphone was unplugged. Odin will wait for AllowedTimeWithoutStreamUpdate
* seconds, before trying a stream restart.
* data anymore, i.e. if a microphone was unplugged. Odin will wait for
* AllowedTimeWithoutStreamUpdate seconds, before trying a stream restart.
*/
UPROPERTY(BlueprintAssignable, Category="AudioCapture")
UPROPERTY(BlueprintAssignable, Category = "AudioCapture")
FCaptureDeviceChange OnCaptureDeviceReset;

/**
* @brief Will be called, if the Default Device is the currently selected and if the Default Device
* was switched by the system.
* @brief Will be called, if the Default Device is the currently selected and if the Default
* Device was switched by the system.
*/
UPROPERTY(BlueprintAssignable, Category="AudioCapture")
UPROPERTY(BlueprintAssignable, Category = "AudioCapture")
FCaptureDeviceChange OnDefaultDeviceChanged;

#pragma region FTickableGameObject
Expand All @@ -151,25 +152,27 @@ class ODIN_API UOdinAudioCapture : public UAudioCapture, public FTickableGameObj
}
#pragma endregion

protected:
protected:
virtual void PostInitProperties() override;
#if ENGINE_MAJOR_VERSION >= 5
void HandleDefaultDeviceChanged(EAudioDeviceChangedRole AudioDeviceChangedRole, FString DeviceId);
#else // ENGINE_MAJOR_VERSION >= 5
void HandleDefaultDeviceChanged(EAudioDeviceChangedRole AudioDeviceChangedRole,
FString DeviceId);
#else // ENGINE_MAJOR_VERSION >= 5
void HandleDefaultDeviceChanged(FString DeviceId);
#endif // ENGINE_MAJOR_VERSION >= 5
/**
* @brief Actual capture device implementation. Will take a device check function as input.
* This function should take a FOdinCaptureDeviceInfo as input and return a bool. It should
* return true, if the input is the device we'd like to change to.
*
* @tparam DeviceCheck Function taking a FOdinCaptureDeviceInfo as input and returning bool.
* @param DeviceCheckFunction This is used to check, whether the currently looked at device is the device we'd like to change to.
*
* @tparam DeviceCheck Function taking a FOdinCaptureDeviceInfo as input and returning bool.
* @param DeviceCheckFunction This is used to check, whether the currently looked at device is
* the device we'd like to change to.
* @return True, if the device was changed successfully
*/
template <typename DeviceCheck>
bool ChangeCaptureDevice(const DeviceCheck& DeviceCheckFunction);

/**
* @brief Restart the stream, using CurrentSelectedDeviceIndex as the new input.
*/
Expand All @@ -178,33 +181,31 @@ class ODIN_API UOdinAudioCapture : public UAudioCapture, public FTickableGameObj
/**
* @brief The index of the currently selected device. -1 and 0 both refer to the Default Device.
*/
UPROPERTY(BlueprintReadOnly, Category="AudioCapture")
UPROPERTY(BlueprintReadOnly, Category = "AudioCapture")
int32 CurrentSelectedDeviceIndex = INDEX_NONE;

/**
* @brief The amount of time in seconds the capture object waits for a stream to resume, before restarting with default device.
* @brief The amount of time in seconds the capture object waits for a stream to resume, before
* restarting with default device.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="AudioCapture")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AudioCapture")
float AllowedTimeWithoutStreamUpdate = 0.25f;

/**
* @brief The amount of time in seconds a capture device is allowed to try and set up the stream.
* This is especially helpful for i.e. Bluetooth-Connected Headsets.
* @brief The amount of time in seconds a capture device is allowed to try and set up the
* stream. This is especially helpful for i.e. Bluetooth-Connected Headsets.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="AudioCapture")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AudioCapture")
float AllowedTimeForStreamSetup = 3.0f;



/**
* @brief Will be filled in, once a device was selected by the user.
* We can't have access to this before the custom selection, because - at least the Windows RtAudio
* implementation - AudioDeviceInterface does not provide us with a Device Id or Url of the
* Default Device.
* We can't have access to this before the custom selection, because - at least the Windows
* RtAudio implementation - AudioDeviceInterface does not provide us with a Device Id or Url of
* the Default Device.
*/
FOdinCaptureDeviceInfo CustomSelectedDevice;

double LastStreamTime = -1.0f;
double LastStreamTime = -1.0f;
double TimeWithoutStreamUpdate = 0.0f;

};
2 changes: 1 addition & 1 deletion Source/Odin/Public/OdinCaptureMedia.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ class ODIN_API UOdinCaptureMedia : public UOdinMediaBase
UAudioCapture *audio_capture_ = nullptr;

FAudioGeneratorHandle audio_generator_handle_;
};
};
5 changes: 2 additions & 3 deletions Source/Odin/Public/OdinFunctionLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ UOdinAudioCapture* UOdinFunctionLibrary::CreateOdinAudioCapture(UObject* WorldCo
World = WorldContextObject->GetWorld();
} else {
UE_LOG(Odin, Warning,
TEXT(
"No World Context provided when creating Odin Audio Capture. Audio Capture will not be able to react to capture devices being removed."
));
TEXT("No World Context provided when creating Odin Audio Capture. Audio Capture "
"will not be able to react to capture devices being removed."));
}
UOdinAudioCapture* OdinAudioCapture = NewObject<UOdinAudioCapture>(World);
if (OdinAudioCapture->OpenDefaultAudioStream()) {
Expand Down
8 changes: 4 additions & 4 deletions Source/Odin/Public/OdinFunctionLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ODIN_API UOdinFunctionLibrary : public UBlueprintFunctionLibrary
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Odin|Custom Data")
static FString BytesToString(const TArray<uint8> &data);

UFUNCTION(BlueprintCallable, Category = "Odin|Audio Capture", meta=(WorldContext = "WorldContextObject"))
static class UOdinAudioCapture* CreateOdinAudioCapture(UObject *WorldContextObject);

};
UFUNCTION(BlueprintCallable, Category = "Odin|Audio Capture",
meta = (WorldContext = "WorldContextObject"))
static class UOdinAudioCapture *CreateOdinAudioCapture(UObject *WorldContextObject);
};
2 changes: 1 addition & 1 deletion Source/Odin/Public/OdinJsonValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ class ODIN_API UOdinJsonValue : public UObject
protected:
/** Simple error logger */
void ErrorMessage(const FString &InType) const;
};
};
2 changes: 1 addition & 1 deletion Source/Odin/Public/OdinMediaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ class ODIN_API UOdinMediaBase : public UObject

friend class UOdinPlaybackMedia;
friend class UOdinCaptureMedia;
};
};
2 changes: 1 addition & 1 deletion Source/Odin/Public/OdinPlaybackMedia.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ class ODIN_API UOdinPlaybackMedia : public UOdinMediaBase

UPROPERTY(BlueprintReadOnly, Category = "Room")
UOdinRoom *Room;
};
};
2 changes: 1 addition & 1 deletion Source/Odin/Public/OdinSubmixListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class ODIN_API UOdinSubmixListener : public UObject, public ISubmixBufferListene

void OnNewSubmixBuffer(const USoundSubmix* OwningSubmix, float* AudioData, int32 InNumSamples,
int32 InNumChannels, const int32 InSampleRate, double) override;
};
};
2 changes: 1 addition & 1 deletion Source/Odin/Public/OdinSynthComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class ODIN_API UOdinSynthComponent : public USynthComponent
UOdinPlaybackMedia *playback_media_ = nullptr;

TSharedPtr<OdinMediaSoundGenerator, ESPMode::ThreadSafe> sound_generator_;
};
};
2 changes: 1 addition & 1 deletion Source/Odin/Public/OdinTokenGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class ODIN_API UOdinTokenGenerator : public UObject

private:
struct OdinTokenGenerator *TokenGenerator = nullptr;
};
};

0 comments on commit 4b02bce

Please sign in to comment.