Internal Speaker Music

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Internal Speaker Music

Post by Patz QuickBASIC Creations »

I've developed a SOUND format (no pun intended) to handle Internal Speaker Music. However, it's impractical to make music files to use...

Code: Select all

'ISM Audio Interpreter v0.0.1- Patrick Connor
MusicFile = FREEFILE
OPEN "C:\SOUND.ISM" FOR BINARY ACCESS READ AS #MusicFile
FOR A = 1 TO LOF(MusicFile)/2    'Each SOUND statement requires 2 bytes
 GET #MusicFile, , Chirp%
 SOUND Chirp%, 0.05
NEXT A
CLOSE #MusicFile
I'm eventually going to add more to the file, like tags and stuff. But... Does anyone know how to create a program that can convert PLAY codes into a suitable format for that code? If you're feeling really nice, you could also tell how to convert simple WAV files into the ISM format, too :P. I don't need to know how to create tagging and stuff. I already have an idea on how I'm going to do it.

By the way: Don't try and convince me not to use this format. I made it to run on any computer with an internal speaker, and it's a really small format. So, yeah...
Zoasterboy
Coder
Posts: 12
Joined: Thu Nov 02, 2006 3:51 pm
Location: Washington
Contact:

Post by Zoasterboy »

This sounds like a good idea, ill work on somthing and post it up when im done.
-yah
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

I've implemented tags now. The tags are appended to the start of the music file. The structure of them allows for tags to be excluded at anytime.

Code: Select all

First 7 bytes: "PQBCISM"
Eighth byte: Version identifier
CHR$(201)+Title$+CHR$(202)
CHR$(203)+Artist$+CHR$(204)
CHR$(253)+Comment$+CHR$(254)
CHR$(255) = Stop parsing comments, start music file
(all others above 200 are reserved for any possible future use.)
So, anything else that users may find useful I'll implement into the ISM standard. So, as of now, all of the ones not listed above (excluding 253-254) act as comments. Nobody in their right mind would use ASCII characters above 200 in tags, so that's why I did it. It also makes the file smaller.

I'll post code with this in days to come.
Meanwhile, here is some code to make some "music" that will work with the interpreter I made above (excluding tags)

Code: Select all

RANDOMIZE TIMER
MusicFile = FREEFILE
OPEN "C:\MUSIC.ISM" FOR BINARY ACCESS WRITE AS #MusicFile
FOR A = 1 TO 5000
 Temp% = INT(RND*32000)+38
 PUT #MusicFile, , Temp%
NEXT A
CLOSE #MusicFile
It doesn't sound pretty, but it demonstrates what I'm doing.
Zoasterboy
Coder
Posts: 12
Joined: Thu Nov 02, 2006 3:51 pm
Location: Washington
Contact:

Post by Zoasterboy »

How do you alter the first 8 bytes of a file with Qbasic? Calling assembly commands?
-yah
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

Pretty much, use GET on a file with a STRING*1. Ex:

Code: Select all

DIM Byte AS STRING*1
OPEN "YOURFILE.TXT" FOR BINARY ACCESS READ WRITE AS #1
'some
'code
'goes
'here
GET #1, ,Byte
Then if you need numeric values you can use ASC.

But that's the easy way out. There's probably better (read: more efficient) ways of doing it.
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

If anyone else is interested, please give some feedback...

BTW: Here are what the different versions are going to have implemented. Note: By the standard I listed above, there can only be a maximum of 256 versions (not that I'll need that many)

Code: Select all

00: Basic support, one in my first post
01: Tag support
02: Repeat based compression
any more are open for suggestion.
This is how repeat based compression will work. The first byte will be a marker to signal a repeat (I'm going to use C8h). The next 2 bytes will be what sound to repeat (ex 1234h). Then the last byte in this compression will be how many times to repeat it. Thus if a note is repeated more that 4 times then this compression will reduce file size.

Example: Something like

Code: Select all

341Ah, 341Ah, 341Ah, 341Ah, 341Ah, 341Ah, 341Ah, 341Ah
(which is 16 bytes) will end up compressed as

Code: Select all

C8h, 341Ah, 08h
(which is 4 bytes). I got the idea from something known to the TI community as Lite8x.
Post Reply