facet icon indicating copy to clipboard operation
facet copied to clipboard

error loading custom samples

Open kindohm opened this issue 2 years ago • 4 comments

Copied some of my own samples in, and received this error when loading one by name:

new $('x').sample('by2 - Marker #1.wav');

image

I'm guessing that Facet requires a specific sample rate; I haven't tried to confirm this yet.

kindohm avatar May 21 '22 12:05 kindohm

Looks like my samples are the same format as most of the samples that are included with Facet, which is 32-bit at 44,100.

kindohm avatar May 21 '22 12:05 kindohm

Here's an example sample that produces the error: https://www.dropbox.com/s/qfol86lqzzkiw61/by2%20-%20Marker%20%232.wav?dl=0

kindohm avatar May 21 '22 12:05 kindohm

Great catch, thanks! This is a compatibility issue with stereo wav files. Right now Facet expects mono wav files. The node-wav library that I'm using to decode the wav data should work with stereo files.. but I designed the system kinda expecting mono :) I think a good path forward for now is to update the try/catch so that if Facet fails to decode the wav, the error message indicates to use mono files.

nnirror avatar May 24 '22 16:05 nnirror

Ahhh of course, mono makes sense because of what Facet is doing. Another idea would be to default to only the left channel if a stereo wav file is supplied.

kindohm avatar May 24 '22 16:05 kindohm

I spent some time deep diving on this and pinpointed the problem (hex editors FTW)!

The error message is coming the node-wav package which is for decoding wav files into floating-point data. The decoding package expects all wav files to have a number of bytes that is evenly divisible by 4. The sample file above "by2 - Marker #2.wav" is 123774 bytes, which is not evenly divisible by 4.

I fixed this by removing the last 4 trailing 0s in the hex editor file (pictured), making the resulting file 123772 bytes, which is evenly divisible by 4. Then loading this sample worked for me.

I'm going to keep this issue open because I want to add better error handling for this situation before closing it out. Screen Shot 2022-12-16 at 11 28 16 AM

nnirror avatar Dec 16 '22 16:12 nnirror

This commit should fix this issue: https://github.com/mjcella/facet/commit/b4d6366fc6e44241469df6fa98b731922a1c04d0

Now whenever a sample is encountered with a byte length that is not 4, the Facet code will just pad the buffer with 0s until it is evenly divisible, so that it will work with the node-wav decoding package. Nice to have a commit with a negative number of lines 😄

nnirror avatar Dec 16 '22 17:12 nnirror