Browse Source

Add Tracy to VocalGame

Hot-reloading is not yet working due to problems with multiple
instances of Tracy.
pitch-detection
Macoy Madson 10 months ago
parent
commit
3c722a36be
  1. 2
      src/Tracy.cake
  2. 10
      test/src/Loader.cake
  3. 73
      test/src/VocalGame.cake

2
src/Tracy.cake

@ -3,7 +3,7 @@
(import &comptime-only "Macros.cake")
(c-import "Tracy.hpp")
(c-import &with-decls "Tracy.hpp" "TracyC.h")
;; TODO: Linux only
(c-import "unistd.h")

10
test/src/Loader.cake

@ -9,6 +9,12 @@
(set-cakelisp-option executable-output "test/Loader")
;; TODO: Tracy gets confused when the reloaded lib has its own version of Tracy
(ignore
(add-cakelisp-search-directory "src")
(import "Tracy.cake")
(module-use-tracy-build-options))
;; We only want the shared libraries these use
;; (import "src/Ogre.cake"
;; "src/SDL.cake")
@ -57,4 +63,6 @@
"OgreOverlay_d"
"SDL2")
;; TODO: Relative path is going to break for sure
(add-library-runtime-search-directory "../Dependencies/ogre-next/build/Debug/lib" "." "../Dependencies/SDL/buildSDLBuild/lib")
(add-library-runtime-search-directory "."
"../Dependencies/ogre-next/build/Debug/lib"
"../Dependencies/SDL/buildSDLBuild/lib")

73
test/src/VocalGame.cake

@ -1,6 +1,9 @@
(import &comptime-only "Options.cake" "Macros.cake" "GamelibMacros.cake")
(import "Ogre.cake" "OgreInitialize.cake" "SDL.cake" "Math.cake")
(import "Ogre.cake" "OgreInitialize.cake" "SDL.cake" "Math.cake" "Tracy.cake")
(module-use-tracy-build-options)
;; TODO: Should this happen automatically, because import automatically adds current working dir?
;; Should it add working dir?
(add-c-search-directory-module ".")
@ -22,6 +25,7 @@
;; gnuplot> plot 'out.dat' with lines
(defun-local audio-dump-recorded-buffer (output-filename (* (const char))
buffer (* Uint8) buffer-size int)
(ZoneScopedN "Audio dump recording")
(var dest-file (* FILE) (fopen output-filename "w"))
(unless dest-file
(printf "Could not open file to write data\n")
@ -48,6 +52,7 @@
(set audio-input-buffer null))
(defun-local audio-output-callback (userdata (* void) stream (* Uint8) stream-length int)
(ZoneScopedN "Audio output")
;; (printf "Audio len %d\n" stream-length)
(static-var up bool false)
(set up (not up))
@ -92,6 +97,7 @@
;; Note: If input is sampled at a different rate, playback will be at a lower pitch. Use SDL's
;; audio conversion functions to handle that properly
(defun-local audio-input-callback (userdata (* void) stream (* Uint8) stream-length int)
(ZoneScopedN "Audio input")
(unless audio-is-recording
(return))
;; (printf "received audio %d %d %d\n"
@ -110,6 +116,7 @@
;; Returns number of devices in device-names-out
(defun-local sdl-audio-get-devices (device-names-out (* (* (* (const char))))
is-capture bool &return int)
(ZoneScopedN "Audio get devices")
(var num-devices int (SDL_GetNumAudioDevices is-capture))
(set (deref device-names-out) (type-cast
(calloc (sizeof (type (* (const char)))) num-devices)
@ -142,8 +149,10 @@
output-device-spec-out (* SDL_AudioSpec)
input-device-spec-out (* SDL_AudioSpec)
&return bool)
(ZoneScopedN "Audio intialization")
(var audio-driver (* (const char)) (SDL_GetCurrentAudioDriver))
(scope ;; Drivers
(ZoneScopedN "Audio drivers")
(printf "Available drivers:\n")
(var num-drivers int (SDL_GetNumAudioDrivers))
(var i int 0)
@ -176,6 +185,7 @@
(var output-device-id SDL_AudioDeviceID 0)
(var obtained-output-spec SDL_AudioSpec (array 0))
(scope ;; Output device
(ZoneScopedN "Audio output device")
(var desired-spec SDL_AudioSpec (array 0))
(set (field desired-spec freq) 44100)
(set (field desired-spec format) AUDIO_U8)
@ -208,6 +218,7 @@
(var obtained-input-spec SDL_AudioSpec (array 0))
(var input-device-id SDL_AudioDeviceID 0)
(scope ;; input device
(ZoneScopedN "Audio input device")
(var desired-spec SDL_AudioSpec (array 0))
(set (field desired-spec freq) 44100)
(set (field desired-spec format) AUDIO_U8)
@ -295,30 +306,39 @@
scene-manager (* (in Ogre SceneManager))))
(defun-local app-main (&return int)
(TracyCZoneN startup-zone "Startup" 1)
(unless initialized
;; (defun main (&return int)
(unless (sdl-initialize-for-3d (addr g-window))
(return 1))
(ZoneScopedN "Intialization")
(scope
(ZoneScopedN "SDL initialization")
;; (defun main (&return int)
(unless (sdl-initialize-for-3d (addr g-window))
(return 1)))
(audio-input-buffer-initialize)
;; Ogre uses exceptions for error handling, so we can't gracefully close without getting all that
;; stuff set up (which I don't really want to do; it belongs in Gamelib)
(unless (ogre-initialize-sdl)
(return 1))
(scope
(ZoneScopedN "Ogre initialization")
;; Ogre uses exceptions for error handling, so we can't gracefully close without getting all that
;; stuff set up (which I don't really want to do; it belongs in Gamelib)
(unless (ogre-initialize-sdl)
(return 1)))
(set monkey-mesh (ogre-load-mesh "Monkey_Mesh.mesh"))
(set monkey-node (ogre-node-from-item monkey-mesh))
;; TODO: How to change this animation's name?
(set monkey-anim-handle
(ogre-attach-animation monkey-mesh "Monkey_Mesh.skeleton" "Monkey_AngleChin"))
(scope
(ZoneScopedN "Scene setup/load meshes")
(set monkey-mesh (ogre-load-mesh "Monkey_Mesh.mesh"))
(set monkey-node (ogre-node-from-item monkey-mesh))
;; TODO: How to change this animation's name?
(set monkey-anim-handle
(ogre-attach-animation monkey-mesh "Monkey_Mesh.skeleton" "Monkey_AngleChin"))
(set g-light-node (ogre-create-light))
(set g-light-node (ogre-create-light))
(when g-ogre-root
(printf "Creating PBS spheres\n")
(ogreCreatePbsSpheres g-ogre-root (ogre-get-scene-manager))
(printf "Creating PBS spheres done\n"))
(when g-ogre-root
(printf "Creating PBS spheres\n")
(ogreCreatePbsSpheres g-ogre-root (ogre-get-scene-manager))
(printf "Creating PBS spheres done\n")))
(set initialized true))
@ -343,8 +363,13 @@
;; "Debounce" via only reloading on key release
(var was-reload-pressed bool false)
(TracyCZoneEnd startup-zone)
;; Main loop
(while (not exit-reason)
(FrameMarkNamed "Frame")
(ZoneScopedN "Frame")
(var event SDL_Event)
(while (SDL_PollEvent (addr event))
(when (= (field event type) SDL_QUIT)
@ -382,6 +407,7 @@
(set audio-is-recording (at SDL_SCANCODE_SPACE currentKeyStates))
(when (and (!= prev-recording-value audio-is-recording)
(not audio-is-recording))
(ZoneScopedN "Audio conversion")
(scope ;; Convert audio to playback format.
;; This was necessary in my case because my microphone records at 48kHz, but my sound card
;; expects 44.1kHz output
@ -485,19 +511,22 @@
127.f)))
(var audio-pos vec3 (array audio-read-head-to-world 0.f audio-volume-to-world))
(var final-pos vec3 (vec3-scale-add-vec3 delta-position delta-time tracker-position))
;; (var final-pos vec3 (vec3-scale-add-vec3 delta-position delta-time
;; (vec3-add tracker-position audio-pos)))
;; (var final-pos vec3 (vec3-scale-add-vec3 delta-position delta-time tracker-position))
(var final-pos vec3 (vec3-scale-add-vec3 delta-position delta-time
(vec3-add tracker-position audio-pos)))
(ogre-node-set-position (addr monkey-node) (vec-xyz final-pos))
(ogre-animation-add-time monkey-anim-handle delta-time)
(set last-frame-perf-count (SDL_GetPerformanceCounter))
(scope
(ZoneScopedN "Ogre render + vsync")
(unless (ogre-render-frame)
(set exit-reason "Failed to render frame")
(break)))
(break))))
(ZoneScopedN "Shutdown")
(audio-dump-recorded-buffer "out.dat"
audio-input-buffer audio-input-buffer-size)

Loading…
Cancel
Save