read 'clm ' block from wav file?
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
read 'clm ' block from wav file?
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
i've attached an example wavetable to this post
- Attachments
-
- 08-Roughmath I.wav.zip
- (15.78 KiB) Downloaded 149 times
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
Re: read 'clm ' block from wav file?
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?
well then, how would i get started with something like this?
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
Re: read 'clm ' block from wav file?
also this kvr thread about the serum wavetable format
https://www.kvraudio.com/forum/viewtopic.php?t=517146
https://www.kvraudio.com/forum/viewtopic.php?t=517146
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
Re: read 'clm ' block from wav file?
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
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)
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
Re: read 'clm ' block from wav file?
alright, i learned about the fopen() function; now i'm trying to output a specified number of bytes from the file to the console
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
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)
edit: obviously rotation and reversing the loop would cancel out the direction, but doing only one of them doesn't help either
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
Re: read 'clm ' block from wav file?
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
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
- NightRadio
- Site Admin
- Posts: 3955
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: read 'clm ' block from wav file?
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:
Pixilang uses little-endian which is the standard in today's software and hardware.
The easiest way to load the raw data (any binary data without parsing) is:
Code: Select all
...wrong code...
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
Re: read 'clm ' block from wav file?
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)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...
- NightRadio
- Site Admin
- Posts: 3955
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: read 'clm ' block from wav file?
Sorry, I forgot that this method is not yet implemented in Pixilang :)
So here is the correct code:
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)
}