read 'clm ' block from wav file?

Pixilang programming language
Post Reply
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

read 'clm ' block from wav file?

Post by AutumnCheney »

i'm trying to use pixilang to read serum wavetable files. i know that these files use 'clm ' blocks to store cue points, but i don't know how i could read these. i don't see support for them in the riff library, and i'm wondering how support for these could be added

i've attached an example wavetable to this post
Attachments
08-Roughmath I.wav.zip
(15.78 KiB) Downloaded 127 times
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: read 'clm ' block from wav file?

Post by AutumnCheney »

oh wait, looking through the riff.pixi, i don't see an implementation of reading riff files

well then, how would i get started with something like this?
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: read 'clm ' block from wav file?

Post by AutumnCheney »

this may be helpful; putting it here for future reference

https://onestepcode.com/read-wav-header/
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: read 'clm ' block from wav file?

Post by AutumnCheney »

also this kvr thread about the serum wavetable format

https://www.kvraudio.com/forum/viewtopic.php?t=517146
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: read 'clm ' block from wav file?

Post by AutumnCheney »

i suppose what i should be asking is how do i read a wav file byte by byte, including the headers?

i'm trying this code to at least get the length but it only returns 8192 (the file has 8192 samples); it should be more than that i think

Code: Select all

filename = "wavetable.wav"

stream = load(filename, "rb")

xsize = get_xsize(stream)
ysize = get_ysize(stream)

logf("%d", xsize)
logf("\n")
logf("%d", ysize)
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: read 'clm ' block from wav file?

Post by AutumnCheney »

alright, i learned about the fopen() function; now i'm trying to output a specified number of bytes from the file to the console

Code: Select all

filename = "wavetable.wav"

stream = fopen(filename, "rb")

data = new()
clean(data)
length = fread(data, 2, stream)

rotate(data, 2)

for (i = length; i >= 0; i - 1) {
	logf("%x ", data[i])
}

fclose(stream)
remove(data)
remove(stream)
the problem with this is that it outputs the bytes backwards, and i can't get it to output them forward (you can see my attempt here at doing it by both rotating the container and by reversing the loop). also, there are zeroes in the output? idk, would like some help with this

edit: obviously rotation and reversing the loop would cancel out the direction, but doing only one of them doesn't help either
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: read 'clm ' block from wav file?

Post by AutumnCheney »

alright, i've solved the zeroes issue by subtracting a variable readlen from length in the "i = length" statement and using said variable as my fread length

but, looking into the other problem, i think this may have to do with endianness. the wav file by nature is little-endian, and my system is also little-endian, but i'm wondering if pixilang uses little-endian or big-endian? that could explain why the bits were reversed
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: read 'clm ' block from wav file?

Post by NightRadio »

You are right, the 'clm ' blocks are not supported yet. If you are interested in where and how the WAV loading is implemented, see lib_pixilang/pixilang_vm_load_save.cpp : pix_vm_load

The easiest way to load the raw data (any binary data without parsing) is:

Code: Select all

...wrong code...
Pixilang uses little-endian which is the standard in today's software and hardware.
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: read 'clm ' block from wav file?

Post by AutumnCheney »

NightRadio wrote: Fri Jul 29, 2022 12:39 pm The easiest way to load the raw data (any binary data without parsing) is:

Code: Select all

...wrong code...
thank you for the code! though when i run this (with len in the for loop replaced with "4"), it only outputs four zeroes; i want it to output the first four bytes of my wav file in hex (which in my case are 54, 49, 46, and 46)
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: read 'clm ' block from wav file?

Post by NightRadio »

Sorry, I forgot that this method is not yet implemented in Pixilang :)
So here is the correct code:

Code: Select all

f = fopen(filename,"rb")
if f
{
    len = get_file_size(filename)
    data = new(len,1,INT8)
    fread(data,len,f)
    for( i = 0; i < len; i + 1 )
    {
        logf( "%x ", data[i] )
    }
    fclose(f)
    remove(data)
}
Post Reply