Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SVG creation logic for new waveman #7

Closed
zoomoid opened this issue Jul 17, 2020 · 1 comment
Closed

Add SVG creation logic for new waveman #7

zoomoid opened this issue Jul 17, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@zoomoid
Copy link
Owner

zoomoid commented Jul 17, 2020

SVG rectangles are largely templatable and also require configuration files to be present.
As we mount the config files into the container using Kubernetes, we provide default configurations for usage outside of Kubernetes or without a proper ConfigMap.

The config files are JSON data which nodeJS can read directly using require / import, hence we do not need to emply JSON readers.

A example config map looks like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: demo-wave-man-config
  namespace: web
  labels:
    app: demo-man
    svc: wave-man
data:
  small.json: |
    {
      "step_width": 16,
      "height": 200,
      "color": "{{.color}}",
      "rounded": 8,
      "steps": 32,
      "gap": 7,
      "mode": "rounded_avg",
      "align": "center",
      "sr": 48000,
      "mono": true,
      "scale": 1,
      "dpi": 600,
      "preserveAspectRatio": "none" 
    }
  full.json: |
    {
      "step_width": 20,
      "height": 200,
      "color": "{{.color}}",
      "rounded": 10,
      "steps": 64,
      "gap": 4,
      "mode": "rounded_avg",
      "align": "center",
      "sr": 48000,
      "mono": true,
      "scale": 1,
      "dpi": 600,
      "preserveAspectRatio": "none"
    }

Note that the color property is used to template the color such that the API server can replace the escape string with whatever color the user requests.

Most information for the actual rectangles can be derived from the config map.

The rendering logic for the SVG rectangles should look roughly like this:

  1. Take an already transformed chunk from the queue of chunks. The chunks carry both the chunks value as well as the index, such that we can derive the X position
  2. Calculate the X position using the index:x := i * config.step_width
    3 Calculate the Y position of the rectangle: This depends on the mode we are in: For bottom mode, the Y position is
    y := (1 - chunk) * config.height, while for center mode, the Y position is y := (0.5 * config.height) - (0.5 * chunk * config.height), as we need to center the rectangle in the canvas.
  3. Calculate the width of the rectangle: width := config.step_width - config.gap
  4. Calculate the height of the rectangle: height := config.height * chunk

After this, append the rectangle to the SVG string already constructed.

@zoomoid zoomoid added the enhancement New feature or request label Jul 17, 2020
@zoomoid
Copy link
Owner Author

zoomoid commented Jul 23, 2020

Rewrote the waveman new in Python again, this time with assumptions made about the supported mode.
Also made significant improvements in speed of the waveman by reading the file directly and only sampling small regions instead of the entire file each time. This speeds up the waveman into a mere 3 seconds for a 6 minute audio file while also reducing RAM and CPU requirements significantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant