View Full Version : Where to start?
Well I am eager to try out all the new stuff here in Machine Code.
I am lost as where to start?
CO2, ok I understand will allow us run C code in thinBasic, that is really cool!
But ASMosphere and Oxygen, which do I start with?
My experience with Machine Code to date, very little.
I read and worked with this book on my HP100LX.
The book is available now online in pdf :)
I read the 16bit version for dos which this links to.
http://webster.cs.ucr.edu/AoA/DOS/pdf/0_AoAPDF.html
All the versions for different os's are available here:
http://webster.cs.ucr.edu/AoA/index.html
Charles Pegge
28-05-2008, 13:04
Hi Kent,
I see machine code as being very close to electronics - think registers, memory cells, addressing modes, stacks and queues. Programming languages are pure artifice - but they are useful for handling large quantities of the stuff.
But where to start? I would try assembler. and play with some of the examples. If you morph the examples one instruction at a time. You can't go far wrong. Trying to write a whole program from scratch is too difficult because there are too many possibilities for error. But once you have some stable pieces of code, you can really pick up speed.
Apart from data structures for Asmosphere, there will be macros with parameters and a small set of runtimes for allocating static memory and making it easier to bind to DLLs. Once this is done, I hope to develop some more substantial examples - and a manual with Petr's CHM kit. :)
Charles, I think I came up with a very good use already to use your module. I will need your help on this one.
I know in powebasic you did something similar, but I would like to do it with your module if possible in thinbasic as trying to do stricly thinbasic project.
I need to generate sounds or music dynamically from code only. I will have an example app if a few days and you can see where I want to use it then.
Thought I would give you a heads up so you can think about it and come up with ideas :)
Charles Pegge
28-05-2008, 22:25
Yes, I did some real-time audio synth in PB, feeding data directly into a wav audio buffer. This is a project that starts out in a simple enough way, then the realization dawns that audio is almost as complex and rich as video. I could not see an end point to such a project that could be reached in a matter of months so I held off taking it any further, well certainly in PB.
But this stuff is well worth revisiting - it demands both very low level coding and layers of high level coding to which thinBasic is well suited. Let's see how far we can take it :)
Charles, as you might know... thinBasic can use the FMOD dll. I have not read up on it, but perhaps it provides things we could tap into. I will read up on stuff, fmod and others, while taking a break from coding. Should be interesting!
My memory, just realized it wasn't fmod, but bass.dll. Sorry about any cofusion it might have caused.
Charles Pegge
31-05-2008, 00:38
I used low-level MCI and set up a looping buffer which was kept topped up with chunks of sound generated by a series of oscillator, filter and envelope functions. When a sound was triggered the parameters were set and it would drop a chunk of sound into the buffer ahead of the reading position, every time a frame was rendered.
With this technique long sounds and reverberations can be produced with very little latency, using small buffers.
The code got very dense as I added more and more stuff - and it (& I) started to buckle under the complexity. The pieces need to be rescued and reconstructed with a much stronger framework.
I am sure we could make a sound effects module out of this. - and make the tanks thunder!
Charles, I did some research in bass.dll. It appears we can use it to do what we need.
When you download bass from here, they give many examples in various languages.
There is a synth demo in c and in visual basic.
http://www.un4seen.com/
Charles Pegge
31-05-2008, 08:16
Thanks Kent, downloaded BASS. I dont have VB but had a brief look at the C synth example source. Bass provides all the infrastructure but nothing to support creation of the original sound - uses a sine wave in the example. Building sounds will be the main task before us.
I don't know if I ever sent you this, unfortunately the source is not in it, but steve gibson really came up with something that really offers that wonderful rich sound.
http://www.grc.com/smgassembly.htm
It is the section The new ASPI_ME Title Page App:
I have been doing searches to see how you create sound sources, nothing so far, but run into fun things along the way so a fun item to search for :)
I am glad we have the infrastructure with bass, so that is very good !
Charles Pegge
31-05-2008, 11:42
Just to give a flavour, here are two specimin sounds generated in real time using my software. They sound polyphonic but its done mostly with harmonics, frequency modulation and envelopes.
Charles thanks, very cool sounds!
In searching so far, I don't understand where the sounds are being generated. Is there deep down a windows api call that is made that takes the code and sends it to the sound hardware? I run across directsound which is part of directx and BASS even uses it, so I assume that is how it is done. Is this right direction for me to study up on?
http://msdn.microsoft.com/en-us/library/bb206044%28VS.85%29.aspx
Petr Schreiber
31-05-2008, 18:19
Hi Charles,
those are some very cool sounds!
w12.wav reminds me of some sound FX from original "Prince of Persia"
Petr
Charles Pegge
31-05-2008, 20:48
Kent,
DirectSound has a COM interface. My software went in at a lowerlevel feeding the sound buffer directly, controlling all aspects of the audio data. I think all the active buffers are mixed, volume controlled then fed to the sound hardware drivers.
All the functions I used are part of MCI and can be found in PB's win32API.inc and are called waveout??something.
Used these notes by Jeff Glatt below:
ErosOlmi
31-05-2008, 21:19
http://www.bervini.net/raffaello/
Into the above link you will find a lot of very interesting Power Basic sources.
Some of the works with sounds. On in particular generates very nice sound using MIDI interface. Search for "Suona file midi (PBWIN)".
Some other works with FMOD lib, that is very interesting too and free if used inside free software (like thinBasic project)
Eros
Thanks for the links guys.
Petr Schreiber
31-05-2008, 22:00
Very nice website,
some really nice stuff like that software 3D engine, hmm :)
Regarding MIDI, I used it in RobotDuel already, here is some minimal example with lot of scary sounds:
uses "Console"
' This API is needed for the sound
DECLARE FUNCTION midiOutClose LIB "WINMM.DLL" ALIAS "midiOutClose" (BYVAL hMidiOut AS DWORD) AS LONG
DECLARE FUNCTION midiOutOpen LIB "WINMM.DLL" ALIAS "midiOutOpen" (lphMidiOut AS DWORD, BYVAL uDeviceID AS DWORD, BYVAL dwCallback AS DWORD, BYVAL dwInstance AS DWORD, BYVAL dwFlags AS DWORD) AS LONG
DECLARE FUNCTION midiOutShortMsg LIB "WINMM.DLL" ALIAS "midiOutShortMsg" (BYVAL hMidiOut AS DWORD, BYVAL dwMsg AS DWORD) AS LONG
dim hMidiOut as dword
dim midierror as long = midiOutOpen(hMidiOut, 0, 0, 0, 0)
if midierror then msgbox 0, "Cannot init MIDI, program will not have sound"
dim i, n as long
for i = 1 to 255
console_PrintLine("Instrument"+STR$(i))
midi_SelectInstrument(i,0)
midi_PlayNote(40, 100,0)
sleep 1000
next
console_PrintLine("End of sounds :)")
midiOutClose(hMidiOut)
console_WaitKey
FUNCTION midi_PlayNote(note AS LONG, volume AS LONG, channel AS LONG) AS LONG
LOCAL midimsg AS LONG, result AS LONG
midimsg = &H90 + note*&h100 + volume*&h10000 + channel
IF midiOutShortMsg(hMidiOut, midimsg) <> 0 THEN MSGBOX 0, "Error occured while trying to play note"+STR$(note)+" at volume"+STR$(volume)+" on channel"+STR$(channel)
END FUNCTION
FUNCTION midi_SelectInstrument( instrument AS LONG, channel AS LONG) AS LONG
LOCAL midimsg AS LONG
instrument -= 1
midimsg = &HC0 + instrument*&h100 + 0*&h10000 + channel
IF midiOutShortMsg(hMidiOut, midimsg) <> 0 THEN MSGBOX 0, "Error occured while setting up instrument"
END FUNCTION
Petr
Charles Pegge
31-05-2008, 23:00
Thank you Eros.
Bervini Raffaello's music is good too.
Here are some notes on the mci low level midi interface -
Thanks Petr for reminding of music without media via midi, good idea too.
At least we can use that as a place holder till hardcore version is ready. I will tinker with it for tanks.
Thanks for the link to Charles, the other one was neat. Will check this one out now.
The site Eros linked to is very cool too!!
Using Petr's example code and a little bit of tinkering came up with a first possible tank sound candidate.
uses "Console"
' This API is needed for the sound
DECLARE FUNCTION midiOutClose LIB "WINMM.DLL" ALIAS "midiOutClose" (BYVAL hMidiOut AS DWORD) AS LONG
DECLARE FUNCTION midiOutOpen LIB "WINMM.DLL" ALIAS "midiOutOpen" (lphMidiOut AS DWORD, BYVAL uDeviceID AS DWORD, BYVAL dwCallback AS DWORD, BYVAL dwInstance AS DWORD, BYVAL dwFlags AS DWORD) AS LONG
DECLARE FUNCTION midiOutShortMsg LIB "WINMM.DLL" ALIAS "midiOutShortMsg" (BYVAL hMidiOut AS DWORD, BYVAL dwMsg AS DWORD) AS LONG
dim hMidiOut as dword
dim midierror as long = midiOutOpen(hMidiOut, 0, 0, 0, 0)
if midierror then msgbox 0, "Cannot init MIDI, program will not have sound"
dim i,c, n,x,y as long
i = 40 'idle?
for y = 1 to 10
for x = 12 to 20
console_PrintLine("Instrument"+STR$(i)+" note"+Str$(x))
midi_SelectInstrument(i,0)
midi_PlayNote(x, rnd(75,125),0)
sleep 25
next
next
i=32 'moving
for y = 1 to 20
for x = 12 to 20
console_PrintLine("Instrument"+STR$(i)+" note"+Str$(x))
midi_SelectInstrument(i,0)
midi_PlayNote(x, rnd(75,125),0)
sleep 25
next
next
midi_PlayNote(x, 0,0)
console_PrintLine("End of sounds :)")
console_WaitKey
midiOutClose(hMidiOut)
FUNCTION midi_PlayNote(note AS LONG, volume AS LONG, channel AS LONG) AS LONG
LOCAL midimsg AS LONG, result AS LONG
midimsg = &H90 + note*&h100 + volume*&h10000 + channel
IF midiOutShortMsg(hMidiOut, midimsg) <> 0 THEN MSGBOX 0, "Error occured while trying to play note"+STR$(note)+" at volume"+STR$(volume)+" on channel"+STR$(channel)
END FUNCTION
FUNCTION midi_SelectInstrument( instrument AS LONG, channel AS LONG) AS LONG
LOCAL midimsg AS LONG
instrument -= 1
midimsg = &HC0 + instrument*&h100 + 0*&h10000 + channel
IF midiOutShortMsg(hMidiOut, midimsg) <> 0 THEN MSGBOX 0, "Error occured while setting up instrument"
END FUNCTION
Charles Pegge
01-06-2008, 08:43
Kent,Petr
This will give you just about everything you need to know about programming MIDI
MIDI Technical Fanatic's Brainwashing Center
Lesser life forms communicate in more primitive, less artistic manners such as barks, chirps, roars, or any of the many human verbal languages in use throughout the globe. But, gods communicate using MIDI messages. Even a picture, whose value is often equated to a thousand words, cannot match the scope of emotional and intellectual power unleashed by a stream of MIDI messages. But, try to tell that to the visual-and-print-fixated, tone-deaf heathen who infest this planet...
http://www.borg.com/~jglatt/
I love that quote Charles! Definitely will be on that site today assimilating!