mini sound programming

PM development, programming, hacking and all that fun stuff.
Post Reply
pxtr
Posts: 4
Joined: May 7th, 2010, 09:00

mini sound programming

Post by pxtr » May 7th, 2010, 09:00

Hi all,

I'm new here and with Pokemon Mini, I would be interested of programming Mini's one-channel sound but don't know well ASM (PASM). If someone could put an example code here, for instance starting one sound for a second and stopping it, that would be wonderful. Also, has anyone thought to write a simple Basic (or similar) language for Mini, that should widen the amount of programmers (and games etc), there are many Basic built (which output ASM) for instance for Atari 2600, 5200, Gameboy Advance etc.

Thanks for advance !


-J

pxtr
Posts: 4
Joined: May 7th, 2010, 09:00

Re: mini sound programming

Post by pxtr » May 8th, 2010, 22:30

OK, I will explain what I've found so far, I'm not sure if this forum is active anymore although the site seems new (or renewed). I'm not able to write ASM, but have programmed otherwise and able to read it a bit. I've used two emulators PokeMini 0.3 and minimon. I also found Lupin's PokeMusic tracker with which I was able to do first experiments. Pokemini didn't play the .min files at all but minimon did, that's good, I really like the sound (and yes, of course PokeMusic played its own stuff :)). Anyway I'm doing such experiments, mostly algorithmic compositions, and I'm using several 8-bit sources although PM interest me, I would make some stuff using it (realtime) as an only sound source. Still I need help: I've tried two things,
to generate PokeMusic file format, and Pokemusic's sound.asm. In first case I'm not sure of the file format, especially how first two bytes, REG_TIMER3_PRESET and REG_TIMER3_PIVOT are calculated (would need some examples), but good thing is that I understand at least one byte (the first storing length and volume !). With second case (sound.asm) I've no clue of .bin file format, anyway have tried this and that and heard quite odd "music". Need help, that's sure, can't find these by myself.

Thanks !

Lupin
Team Pokémé
Posts: 94
Joined: January 10th, 2005, 13:06

Re: mini sound programming

Post by Lupin » May 12th, 2010, 02:11

Hi pxtr,

the PM generates sound using a PWM output. It's a simple ON/OFF modulation using the TIMER3.

For understanding the sound generation it might be helpful to read this:
http://wiki.sublab.net/index.php/PM_Audio
http://wiki.sublab.net/index.php/Timers

Playing notes:
PokeMusic uses TIMER2 to load a new Note into TIMER3 (which generates the sound frequency and outputs it to the speaker). For this TIMER2 PRESET register is loaded with the correct divider (depending on song speed). Timer 2 will loads the counter with PRESET-Value, counts the counter down with 62500 Hz and generate an interrupt (dosound) when the counter reaches zero.

File format
The first two bytes of the BIN-File are the song speed (the value loaded into TIMER2 PRESET register).
After these two bytes the file contains:
- 1 Byte with Volume and duration of that note (a note can have a maximum duration of 8 times the speed)
- 2 Bytes (16 Bit) that go into TIMER3 PRESET
- 2 Bytes (16 Bit) that go into TIMER3 PIVOT

The dosound routine just keeps loading these 5 bytes into the correct registers and handles everything.

pxtr
Posts: 4
Joined: May 7th, 2010, 09:00

Re: mini sound programming

Post by pxtr » May 12th, 2010, 18:34

Lupin,

Thanks very much of your reply, I understand now much better, didn't know of the wiki-pages, apparently there have been problems with the site as it have been down quite a lot. Anyway, I still am not able to program it, what I would need (unless it is already possible), a stripped sound.asm from your PokeMusic package, but instead of reading .bin file, the data could be changed/included/ in textual format, my problem is that I'm "ASM-disabled",can read it somehow but not program, I use high(er)-level languages, mostly AWK, Lua, Basic and C. My goal would be a little sequencer where I would be able to add the musical data by other programs I've written by myself. Still, I try to make .bin files, especially now as I can see how the REG values are calculated.

I'm not sure if there any point of making a small/tiny Basic to Pokemon Mini, I've used three with consoles: Batari Basic (Atari 2600), 5200bas (Atari 5200) and BEX (Sega Genesis), they all generate ASM-code, none of them is a 'normal' Basic but I'm sure there are much more game programmers because of the relative easiness of the languages.

btw. I've had problems to listen Pokemusic-pieces with Pokemini 0.3 (doesn't work at all in my machine), minimon plays them but timing is (at least sounds) different than in your tracker.

Thanks Lupin of your help !


-Jukka (pXtR)

Lupin
Team Pokémé
Posts: 94
Joined: January 10th, 2005, 13:06

Re: mini sound programming

Post by Lupin » May 14th, 2010, 12:31

Hi pxtr,

i would appreciate a basic compiler too. But it's quite a lot of work to make one and the Pokemon Mini development has come to quite a hiatus.

I don't think i could strip down the sound.asm any more than it is now. Textual format would not be feasible on pokemon mini.

If you have a simple file format that could be played on PM i could of course assist you in making a player.

The current sound.asm should be enough to play back simple melodies, maybe you can try and experiment with it.

The music only sounds right on real hardware. My PokeMusic tracker doesn't sound exactly good either.

pxtr
Posts: 4
Joined: May 7th, 2010, 09:00

Re: mini sound programming

Post by pxtr » May 14th, 2010, 14:29

Hi Lupin,

I think you're right, there's no point to do Basic if there are no users.

I don't think sound.asm should be stripped, the textual format wasn't a good idea, anyway
I've a simple text format which I can explain here, it is possible that sound.asm would work with it, probably one or two changes are needed. I think it would be best to call txt2bin,
for instance, that might be easier. The format: only three values are needed for each note:

pitch, duration, pulse_width

Pitch: in Hz or any values, perhaps 8-bit (0-255), linearly or otherwise calculated
Duration: practically any values, or 8-bit (0-255) or 0.0-1.0 (float)
Pulse_width: 0.0-1.0

The values can be anything as long there are a lower and upper limits, everything else is pre-calculated by me (and/or others if they're interested of using this). Txt2bin would generate a .bin file for (probably slightly altered) sound.asm and I will compile it with PASM as usually. I've tried to do this by myself, but it doesn't work, I'm only a composer, I think music in seconds, trying to adjust the timers (with LSB and MSB calculations) just doesn't seem to work for me. The third parameter, pulse width, is apparently now fixed to 50%, if it could be changed to adjustable between 0.0-1.0 that would make a lot for a timbre of the music with only one channel, it also change the dynamics of the pitches (0 and 1 would be 0% and 100% ie. silence).

Something like this, please let me know what you think, txt2bin can be quick and dirty hack, just a command line program, or anything, or just assist me with the calculations, I can write the program (I tried with FreeBasic, but for instance Lua or simple C, it doesn't matter as long the job is done).

Thanks you very much of your help Lupin !


-Jukka

Post Reply