Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Convert Sound Into String Data? (for media-less sound/music)

Author
Message
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 21st Jun 2012 21:18
I was really impressed with Jukuma's "Pac Man":
http://forum.thegamecreators.com/?m=forum_view&t=174784&b=6

Especially the way he created music from strings of data!
(Looks like Hexadecimal to me...??)

Does DBPro have the ability to reverse-engineer sound in this way?
In other words, to load a WAV file and then dump it all into a string file..???

Thanks in advance.

D.D.
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 21st Jun 2012 22:09
There's a MAKE MEMBLOCK FROM SOUND command, so with that you have access to all the bytes of data and can manipulate it in anyway you wish. You could change each byte into two hexadecimal characters if you wanted to.

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 22nd Jun 2012 00:29
by going byte by byte you can get whatever you want

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 22nd Jun 2012 00:34
honestly, his project is really good.

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Jun 2012 02:21 Edited at: 22nd Jun 2012 02:22
@Derek Darkly

Quote: "Does DBPro have the ability to reverse-engineer sound in this way?
In other words, to load a WAV file and then dump it all into a string file..???

Thanks in advance."


This isn't really whats going on in the pac man example. The data statements are actually a HEX dump of a midi file. The midi file can be prepared ahead of time by what ever means, then one can use just about any hex editor and dump the file to text. I think it's very clever that Jukuma did that.

You then save your data statements (in this case stings) converted back to binary in a file thus recreating the midi file.

Here's a small dump of the "Close Encounters" communication:


Each byte in the actual midi file is 2 string bytes. The first byte to convert is 4d = 77 .

When you convert all of the string bytes and save them to a file, you rebuild the midi file. Since midi files are very small (much smaller than wav or mp3 or ogg) you can feasibly have a decent sized song stored as data statements.

Enjoy your day.
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Jun 2012 05:08 Edited at: 22nd Jun 2012 05:16
Quote: "The data statements are actually a HEX dump of a midi file. "


Ah, so midi music is the way to go for self-contained tunes...
(And perhaps short WAVs?) I'm really digging the whole concept.

D.D.
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Jun 2012 06:56 Edited at: 22nd Jun 2012 19:34
I think I've got the hang of it, check me out...



D.D.
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 22nd Jun 2012 10:59
Thanks guys but how to get the notes such as: do re me ........

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Jun 2012 11:37
Quote: "I think I've got the hang of it, check me out..."

Hey, pretty cool! What's interesting about using a single string of hex values, is the size it saves in the data statements. 4 byte entries look like

data "4d546864"

as opposed to the decimal equivalent of

data 77,84,104,100

So with a larger file, you can really squeeze in more data by using the hex dump. You just have to convert the bytes at run time so it might be a slight trade off between data statement style and saving/loading time.

@basjak
Quote: "Thanks guys but how to get the notes such as: do re me ........"

With what we've been talking about, you have to make the midi file ahead of time. That means your file is already built with the notes in it. You can use a lot of different tools to do it. Anvil Studio is pretty good and I think there's a free limited version. Once you have a midi file, you use a hex editor or some other tool to convert the midi file to raw data to be used in your data statements.

If you are talking about creating the notes from scratch, then you'd have to know the midi specification/format if you wanted to use midi. If you wanted to create general "sound" then you need a little knowledge about wave forms and such. You could build your own sound generator by using a memblock and converting that data to a DB sound.

Enjoy your day.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Jun 2012 13:06
Weird... After reading this over the last few days and thinking about the days on the Atari ST and converting files to data statements I thought I'd do that for you...

Here's a code snippet that converts an input file to a DBP include file of data statements:



Fingers crossed that it's correct...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 22nd Jun 2012 15:34
amazing. sometimes things are in our hands but we don't see it.

Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Jun 2012 19:39
@Latch
Quote: "Hey, pretty cool! What's interesting about using a single string of hex values, is the size it saves in the data statements. 4 byte entries look like

data "4d546864"

as opposed to the decimal equivalent of

data 77,84,104,100"


Great point!
I'll try it that way in the little mini-game I'm working on.

D.D.
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Jun 2012 19:43
@basjak
Quote: "Thanks guys but how to get the notes such as: do re me ........"


What I did was open a pre-made MIDI file and then when each byte was read, I re-wrote it as a string like str$(i) to another file with commas like str$(i)+","

Then I just copied and pasted all that into DATA lines.

D.D.
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Jun 2012 19:48
@WLGfx
Quote: "Here's a code snippet that converts an input file to a DBP include file of data statements:"



Nice!
That could turn into a whole extractor/editor app.

I'm always torn between making stuff that's practical and stuff that's just fun, but one usually begets the other.

D.D.

Login to post a reply

Server time is: 2026-07-07 19:09:13
Your offset time is: 2026-07-07 19:09:13