Author Topic: 4 bit sound samples request  (Read 6172 times)

0 Members and 1 Guest are viewing this topic.

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
4 bit sound samples request
« 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?
If you like my work: why not give me an internet?








Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: 4 bit sound samples request
« Reply #1 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.
If you like my work: why not give me an internet?








Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: 4 bit sound samples request
« Reply #2 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.
I'm not a nerd but I pretend:

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: 4 bit sound samples request
« Reply #3 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...

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: 4 bit sound samples request
« Reply #4 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
If you like my work: why not give me an internet?








Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: 4 bit sound samples request
« Reply #5 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.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: 4 bit sound samples request
« Reply #6 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

« Last Edit: June 29, 2012, 04:14:20 pm by jimbauwens »

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: 4 bit sound samples request
« Reply #7 on: June 29, 2012, 05:55:18 pm »
The data is probably signed.
If you like my work: why not give me an internet?








Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: 4 bit sound samples request
« Reply #8 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.