Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Keoni29 on June 26, 2012, 02:31:27 am

Title: 4 bit sound samples request
Post by: Keoni29 on June 26, 2012, 02:31:27 am
Heya, I built a digital to analog converter for my TI84+
I can write values to it easily using a subroutine I wrote. WA(nibble) writes a 4 bit value to the DAC
Now I need some 4 bit samples which I can use with it. Preferably compressed (two nibbles in a byte) and stored in an appvar.
Does anyone know how to accomplish this?
Title: Re: 4 bit sound samples request
Post by: Keoni29 on June 26, 2012, 06:20:29 am
Ok here's what I'm gonna do:
I'm load audio samples in audacity and I convert them as 8 bit raw. I copy the raw hex values and I paste them in sourcecoder. Then I copy the values divided by 16 to an appvar.
Title: Re: 4 bit sound samples request
Post by: aeTIos on June 26, 2012, 07:11:16 am
Double-post tho I think it's not too big problem.
Yeah I think that's what you should do.
Title: Re: 4 bit sound samples request
Post by: TIfanx1999 on June 26, 2012, 10:57:07 am
Ok here's what I'm gonna do:
I'm load audio samples in audacity and I convert them as 8 bit raw. I copy the raw hex values and I paste them in sourcecoder. Then I copy the values divided by 16 to an appvar.
Will that work properly? O.O I guess there isn't a 4bit downsampling in Audacity...
Title: Re: 4 bit sound samples request
Post by: Keoni29 on June 28, 2012, 10:39:22 am
Ok here's what I'm gonna do:
I'm load audio samples in audacity and I convert them as 8 bit raw. I copy the raw hex values and I paste them in sourcecoder. Then I copy the values divided by 16 to an appvar.
Will that work properly? O.O I guess there isn't a 4bit downsampling in Audacity...
Jimbauwen's converter still glitches, so: no it does not work properly :P
Title: Re: 4 bit sound samples request
Post by: thepenguin77 on June 28, 2012, 01:25:27 pm
Ok here's what I'm gonna do:
I'm load audio samples in audacity and I convert them as 8 bit raw. I copy the raw hex values and I paste them in sourcecoder. Then I copy the values divided by 16 to an appvar.
Will that work properly? O.O I guess there isn't a 4bit downsampling in Audacity...
Jimbauwen's converter still glitches, so: no it does not work properly :P

If you know any computer programming languages, you could probably do the conversion yourself. The .wav file format is not that complicated and I've written 3 programs already that take its data.

If that computer programming language happens to be C++, you can borrow the source to my TruSound and TruVid.
Title: Re: 4 bit sound samples request
Post by: Jim Bauwens on June 29, 2012, 04:06:24 pm
Hey, it doesn't glitch :P
It does exactly what you ask ;)

Here is the code:
Code: [Select]
#!/usr/bin/env python
# This program converts 8 bit DEC files to 4 bit
import sys

def fixHex(h):
res = h.replace("0x","").upper()
if len(res) == 1:
res = "0"+res
return res

if len(sys.argv) < 2:
print("python convert.py <filename>")
exit(-1)

try:
file = open(sys.argv[1], "rb")
except:
print(sys.argv[1] + " can not be opened!")
exit(-1)

data = file.read()

out = ""

try:
for i in range(len(data)):
if i%4 == 0:
part1 = (ord(data[i])>>4)<<4
part2 = ord(data[i+3])>>4
out += fixHex(hex(part1+part2))
except:
print("Warning, file size odd! Last byte ignored.")

print(out[:-1])

Example input data:
A1 A1 B2 B2 3C 3C 4D 4D (but in binary form)
Output:
AB34 (in string)

So, what is does is loop 4 bytes a time over all the data.
The first byte and the third byte is what I need as the second and fourth are just the same.
Then I do there operations each loop:
a = (ord(byte1)>>4)<<4
b = (ord(byte3)>>4)
output = a + b

Title: Re: 4 bit sound samples request
Post by: Keoni29 on June 29, 2012, 05:55:18 pm
The data is probably signed.
Title: Re: 4 bit sound samples request
Post by: Jim Bauwens on June 30, 2012, 03:51:18 pm
What would that change ?
I assume the first bit indicates the sign, and that bit doesn't get lost.