Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
Home Register Downloads FAQ Members List Calendar Arcade Mark Forums Read

WON'T YOU JOIN US?
You are not a registered member and
are viewing this site as a guest.
Registration is simple and FREE.
Join this CrowdGather community today.
Registration offers the following perks:

» Less advertising throughout
» Post and participate in discussions
» Network with other forum members
» Free private messaging

join

Reply
 
Thread Tools Display Modes
Old November 16th, 2011, 08:59   #41
Prads
Registered User
 
Prads's Avatar
 
Join Date: Sep 2011
Location: Australia
Posts: 89
Quote:
Originally Posted by paul_nicholls View Post
Thanks for the info Prads
No problem...

Quote:
Originally Posted by paul_nicholls View Post
Oh, and your website looks interesting...some cool projects there
Thank you!

I should look into Chip16 after I finish sound emulation in my GBC emu (which is almost done).
__________________
My Programming Projects: www.pradsprojects.com
Prads is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old November 16th, 2011, 19:16   #42
Bill_gates
Linux's worst nightmare..
 
Bill_gates's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 1,505
I liked your 3d racing game! Wish it was open sauce...
On topic: we could really use some more cool games/demos
__________________
OS: WinXP Professional Service Pack 3
CPU: Intel pentium 4 3.0GHz
Video: Nvidia Geforce 8400GS
Sound: ASUS Xonar DS 7.1 Channels 24-bit 192KHz PCI Interface Audio Card
Memory: 512 MB
HD: [C:] 140.36/449.09 GB
Connection: Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller
Bill_gates is offline   Reply With Quote
Old November 17th, 2011, 02:14   #43
Prads
Registered User
 
Prads's Avatar
 
Join Date: Sep 2011
Location: Australia
Posts: 89
Quote:
Originally Posted by Bill_gates View Post
I liked your 3d racing game! Wish it was open sauce...
Glad you like it. All textures were taken from cgtextures.com and their license terms says no open source projects allowed or something like that... that was why I didn't make it open source. But I think I should email them and ask if it's ok or not, they are really friendly (not a sarcasm).

Quote:
Originally Posted by Bill_gates View Post
On topic: we could really use some more cool games/demos
Maybe now is the time to start making a compiler for chip16? Hmmm... maybe I should try and build one, I always wanted to know more about compilers and how they work and this seems like a perfect opportunity...
__________________
My Programming Projects: www.pradsprojects.com
Prads is offline   Reply With Quote
Old November 17th, 2011, 02:50   #44
paul_nicholls
Registered User
 
Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
Quote:
Originally Posted by Prads View Post
Maybe now is the time to start making a compiler for chip16? Hmmm... maybe I should try and build one, I always wanted to know more about compilers and how they work and this seems like a perfect opportunity...
One of the other users here is making a Pascal compiler for the Chip16

If you want to make one as well, then I highly recommend this resource:
http://compilers.iecc.com/crenshaw/

I have used it to make simple scripting languages/compilers in the past that use similar recursive-descent parsers

It is fun, and an educational experience to make a compiler

cheers,
Paul
paul_nicholls is offline   Reply With Quote
Old November 17th, 2011, 02:59   #45
Prads
Registered User
 
Prads's Avatar
 
Join Date: Sep 2011
Location: Australia
Posts: 89
Quote:
Originally Posted by paul_nicholls View Post
One of the other users here is making a Pascal compiler for the Chip16

If you want to make one as well, then I highly recommend this resource:
http://compilers.iecc.com/crenshaw/

I have used it to make simple scripting languages/compilers in the past that use similar recursive-descent parsers
Thanks for the resource, I should read those. I have also been reading 'Advanced Compiler Design and Implementation' by Steven S. Muchnick.

Quote:
Originally Posted by paul_nicholls View Post
It is fun, and an educational experience to make a compiler
That is exactly why I want to do it.
__________________
My Programming Projects: www.pradsprojects.com
Prads is offline   Reply With Quote
Old November 17th, 2011, 03:08   #46
paul_nicholls
Registered User
 
Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
Hey all,
I have gotten somewhere with sound generation using some of my proposed sound stuff I posted earlier

I can output triangle, sawtooth, pulse wave (limited to square ATM), and noise just like in the C64 SID chip at a frequency (0..65535 Hz)!

I am using the waveform data to produce a WAV file formatted output stream using the user's frequency and duration, which I am saving as a test so I can examine and play it externally for now (will be played internally by an emulator of course!).

I am generating a 44100Hz sample rate WAV file using mono 8-Bit format (unsigned)...

I just have to get the output to be modulated by the ADSR settings too

Here is a screenshot of the waveforms in the free Audacity audio editor:


cheers,
Paul
paul_nicholls is offline   Reply With Quote
Old November 17th, 2011, 10:20   #47
tykel
Sober coder
 
tykel's Avatar
 
Join Date: Aug 2010
Location: London, UK
Posts: 433
That looks great! What sound is that at the bottom (pulse wave)?

Also, you speak of a 44100 Hz sample rate. This is just for the WAV files right, I seem to remember variable sample rates being mentioned? Because 44KB for 1 second of sound is not feasible!

One of your previous posts mentioned a 4-bit ADSR envelope, is that encoded in the PCM, or will it be encoded in the instruction?
__________________
tchip16 (chip16 assembler) Js16 (browser chip16 emulator)
mash16 (chip16 emulator) img16 (chip16 sprite converter)
______________________________________

Desktop: i5 750 @ 3.6 Ghz, 4GB ram, GTX 570 OC | Windows 7 Pro 64
Laptop: (Thinkpad) i5 430M, 4GB ram, Intel IGP | Arch Linux, Windows 7 Pro 64
tykel is offline   Reply With Quote
Old November 17th, 2011, 10:43   #48
paul_nicholls
Registered User
 
Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
Quote:
Originally Posted by tykel View Post
That looks great! What sound is that at the bottom (pulse wave)?
The bottom sound is the pseudo-random noise waveform, just like in the C64

Quote:
Originally Posted by tykel View Post
Also, you speak of a 44100 Hz sample rate. This is just for the WAV files right, I seem to remember variable sample rates being mentioned? Because 44KB for 1 second of sound is not feasible!
yeah, 44100 is the number of samples per second for the WAV file encoding only

So, for a 1 second sound encoded with my current scheme requires:

44100 x 1 (bytes per sample) x 1 (number of channels), or around 4.4KB.

We could reduce this by using 22050 sampling rate instead...it is entirely up to us (or the creator of the emulator) as to what sound quality we use

Quote:
Originally Posted by tykel View Post
One of your previous posts mentioned a 4-bit ADSR envelope, is that encoded in the PCM, or will it be encoded in the instruction?
The 4-bit A, D, S, R parts are going to modulate, or alter the amplitude, of the output waves in the screenshot above so that they sound much more like proper sounds...currently those are not modulated at all.

eg. a typical ADSR envelope which could modulate a waveform's output amplitude might look like this:

Code:
volume
        1      /\
        |     /  \_______
        |    /           \
        |   /             \
        0    A  D    S    R
I hope this makes sense?

cheers,
Paul
paul_nicholls is offline   Reply With Quote
Old November 17th, 2011, 14:57   #49
tykel
Sober coder
 
tykel's Avatar
 
Join Date: Aug 2010
Location: London, UK
Posts: 433
Quote:
Originally Posted by paul_nicholls View Post
eg. a typical ADSR envelope which could modulate a waveform's output amplitude might look like this:

Code:
volume
        1      /\
        |     /  \_______
        |    /           \
        |   /             \
        0    A  D    S    R
I hope this makes sense?
Got that thanks

Quote:
Originally Posted by paul_nicholls View Post
So, for a 1 second sound encoded with my current scheme requires:

44100 x 1 (bytes per sample) x 1 (number of channels), or around 4.4KB.
That's 43 KB no?

Quote:
Originally Posted by paul_nicholls View Post
We could reduce this by using 22050 sampling rate instead...it is entirely up to us (or the creator of the emulator) as to what sound quality we use
Wait, the sample frequency depends on the game and how it chooses to store its samples, not the emulator, right?
__________________
tchip16 (chip16 assembler) Js16 (browser chip16 emulator)
mash16 (chip16 emulator) img16 (chip16 sprite converter)
______________________________________

Desktop: i5 750 @ 3.6 Ghz, 4GB ram, GTX 570 OC | Windows 7 Pro 64
Laptop: (Thinkpad) i5 430M, 4GB ram, Intel IGP | Arch Linux, Windows 7 Pro 64
tykel is offline   Reply With Quote
Old November 17th, 2011, 17:33   #50
refraction
PCSX2 Coder
 
refraction's Avatar
 
Join Date: Jan 2004
Location: Plymouth, UK
Posts: 10,037
For downloads of RefChip16 please follow this link http://code.google.com/p/refchip16/downloads/list
__________________

http://www.pcsx2.net
Intel i7 920 @ 3.4Ghz, POV GTX 570 1.3Gb, 1.8Tb HD space, 6Gb OCZ Reaper PC3-14400 Triple Channel
Dont PM me for help, use the forums, thats what its for!


My Chip16 Emulator RefChip16 http://code.google.com/p/refchip16/

Last edited by refraction; March 9th, 2012 at 16:10..
refraction is offline   Reply With Quote
Old November 17th, 2011, 19:50   #51
paul_nicholls
Registered User
 
Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
@tykel: Ok, it is closer to around 43KB in size, I was lazy and didn't calculate it like I should have LOL

As to the sound quality, I thought this was up to the emulator since the Chip16 sound instructions only define frequency and duration, not sound sampling rates, etc.?

@refraction: Neat! thanks for sharing your emulator + code

cheers,
Paul
paul_nicholls is offline   Reply With Quote
Old November 18th, 2011, 12:17   #52
refraction
PCSX2 Coder
 
refraction's Avatar
 
Join Date: Jan 2004
Location: Plymouth, UK
Posts: 10,037
Nps you might wanna get the updated version, it fixes a few memory leaks which Prads kindly pointed out to me!
__________________

http://www.pcsx2.net
Intel i7 920 @ 3.4Ghz, POV GTX 570 1.3Gb, 1.8Tb HD space, 6Gb OCZ Reaper PC3-14400 Triple Channel
Dont PM me for help, use the forums, thats what its for!


My Chip16 Emulator RefChip16 http://code.google.com/p/refchip16/
refraction is offline   Reply With Quote
Old November 25th, 2011, 03:08   #53
paul_nicholls
Registered User
 
Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
Well, I have gotten ADSR modulation into my sound creation class now

I have attached a simple retro-sounding explosion generated by my sound class using these parameters:

Duration: 310mS
Frequency: 100Hz
Attack: 2mS
Decay: 6mS
Sustain: 15 (volume level)
Release: 300mS

PS. I was thinking that a delay, wait, or sleep command might be useful for timing events in a Chip16 program, like in sound generation, or just a general pause...how about it?

Something like this maybe?
Code:
D0 00 LL HH	WAIT HHLL		Wait HHLL miliseconds before continuing
cheers,
Paul
Attached Files
File Type: 7z SID_3.7z (812 Bytes, 6 views)
paul_nicholls is offline   Reply With Quote
Old November 25th, 2011, 09:32   #54
tykel
Sober coder
 
tykel's Avatar
 
Join Date: Aug 2010
Location: London, UK
Posts: 433
Nice example, suitably retro sounding!
Also, sorry for insisting on this, but would this sound take up 100Hz * 0.310s * 1B = 31B? Or am I not getting this?
Another thing, wouldn't it be better to use sound instructions rather than ports for modulation, for better orthogonality?

Also, for timing, you can currently use VBLNK if you don't mind waiting for multiples of 16ms
If anyone else is interested in a WAIT instruction, please make your voice heard!
__________________
tchip16 (chip16 assembler) Js16 (browser chip16 emulator)
mash16 (chip16 emulator) img16 (chip16 sprite converter)
______________________________________

Desktop: i5 750 @ 3.6 Ghz, 4GB ram, GTX 570 OC | Windows 7 Pro 64
Laptop: (Thinkpad) i5 430M, 4GB ram, Intel IGP | Arch Linux, Windows 7 Pro 64
tykel is offline   Reply With Quote
Old November 25th, 2011, 09:58   #55
refraction
PCSX2 Coder
 
refraction's Avatar
 
Join Date: Jan 2004
Location: Plymouth, UK
Posts: 10,037
As I think I've said previously, if you need custom wait times you can write a number to a register and do a sub then compare zero cond, hell you could even do other stuff then like

Compare test reg
Inst
Inst
Inst
Sub 5 from test reg
Compare test reg

It's handy knowing each Inst is 1 cycle
__________________

http://www.pcsx2.net
Intel i7 920 @ 3.4Ghz, POV GTX 570 1.3Gb, 1.8Tb HD space, 6Gb OCZ Reaper PC3-14400 Triple Channel
Dont PM me for help, use the forums, thats what its for!


My Chip16 Emulator RefChip16 http://code.google.com/p/refchip16/
refraction is offline   Reply With Quote
Old November 25th, 2011, 12:02   #56
paul_nicholls
Registered User
 
Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
Quote:
Originally Posted by tykel View Post
Nice example, suitably retro sounding!
Also, sorry for insisting on this, but would this sound take up 100Hz * 0.310s * 1B = 31B? Or am I not getting this?
After thinking about it, I got the formula wrong before...sorry!

Ok, to find out how much a sound takes up in memory (ignoring any headers and other stuff, just raw sound data), you can use this formula (I am pretty sure I didn't stuff up this time ):

Code:
  SoundSize = Round(BytesPerSample * NumberOfChannels * Duration_mSec * SampleRate / 1000)
so I am using 44100Hz as the sampling rate, 8-Bits per sound sample (or 1 byte), and mono sound output (1 channel...stereo would be 2 channels...)

So I get this:

Code:
  SoundSize = Round(BytesPerSample * NumberOfChannels * Duration_mSec * SampleRate / 1000)
  SoundSize = Round(1              * 1                * 310           * 44100      / 1000)
  SoundSize = 13671
  SoundSize = 13.3505859375 KB
Quote:
Originally Posted by tykel View Post
Another thing, wouldn't it be better to use sound instructions rather than ports for modulation, for better orthogonality?
I was only going on the suggestion that someone else did, to use memory mapped sound ports
None of this is set in stone yet...we can use sound instructions for playing sounds AND changing the sound's waveform + ADSR parts too...

Ok, so how about this then:

Code:
...
09 00 00 00	SND0			Stop playing sounds.
0A 00 LL HH	SND1 HHLL		Play 500Hz tone for HHLL miliseconds (uses current sound generator settings; ADSR, etc.).
0B 00 LL HH	SND2 HHLL		Play 1000Hz tone for HHLL miliseconds (uses current sound generator settings; ADSR, etc.).
0C 00 LL HH	SND3 HHLL		Play 1500Hz tone for HHLL milliseconds (uses current sound generator settings; ADSR, etc.).

0D 0X LL HH     SNP                     Play Sound for HHLL miliseconds at the tone specified in address pointed to by Register X (uses current sound generator settings; ADSR, etc.).

0E AD SR VT     SNG                     Sound generator (applies to all sound tones which follow).
                                        A = attack  (0..15)
                                        D = decay   (0..15)
                                        S = sustain (0..15, volume)
                                        R = release (0..15)
                                        V = volume  (0..15)
                                        T = type of sound:
                                          00 = triangle wave
                                          01 = sawtooth wave
                                          02 = pulse wave (is just square for now)
                                          03 = noise
                                          non-valid values default to 0 output

// Jumps
10 00 LL HH	JMP HHLL		Jump to the specified address.
...
Quote:
Originally Posted by tykel View Post
Also, for timing, you can currently use VBLNK if you don't mind waiting for multiples of 16ms
If anyone else is interested in a WAIT instruction, please make your voice heard!
Interesting idea, but I would really prefer a WAIT instruction...more accurate

cheers,
Paul

Last edited by paul_nicholls; November 25th, 2011 at 19:58..
paul_nicholls is offline   Reply With Quote
Old November 25th, 2011, 12:13   #57
paul_nicholls
Registered User
 
Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
Quote:
Originally Posted by refraction View Post
As I think I've said previously, if you need custom wait times you can write a number to a register and do a sub then compare zero cond, hell you could even do other stuff then like

Compare test reg
Inst
Inst
Inst
Sub 5 from test reg
Compare test reg

It's handy knowing each Inst is 1 cycle
That's very cool and all, but I was thinking that a WAIT instruction would make the resulting game/app code much simpler and should be very easy to write in an emulator

cheers,
Paul
paul_nicholls is offline   Reply With Quote
Old November 25th, 2011, 12:42   #58
refraction
PCSX2 Coder
 
refraction's Avatar
 
Join Date: Jan 2004
Location: Plymouth, UK
Posts: 10,037
Very true but if you are doing background music or sound, the game will have to pause while the sound plays, which could be a little annoying if its a long sound tho I guess you don't have to use it
__________________

http://www.pcsx2.net
Intel i7 920 @ 3.4Ghz, POV GTX 570 1.3Gb, 1.8Tb HD space, 6Gb OCZ Reaper PC3-14400 Triple Channel
Dont PM me for help, use the forums, thats what its for!


My Chip16 Emulator RefChip16 http://code.google.com/p/refchip16/
refraction is offline   Reply With Quote
Old November 25th, 2011, 20:21   #59
paul_nicholls
Registered User
 
Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
Quote:
Originally Posted by refraction View Post
Very true but if you are doing background music or sound, the game will have to pause while the sound plays, which could be a little annoying if its a long sound tho I guess you don't have to use it
haha..ok, that is true

Well, thinking about it most sound libraries allow sounds to play and the user doesn't have to wait for them to finish before continuing...so I don't think we need the wait instruction for sound playing anymore (maybe for other tasks though...don't know).

Ok everyone, what do you think of the proposed sound instructions then?

If you all like the idea of the ADSR and waveform generation being put into the Chip16, I will share my code...it is in Delphi (Object Pascal) code but should be easily converted over to other languages like C++ or similar

cheers,
Paul
paul_nicholls is offline   Reply With Quote
Old November 25th, 2011, 22:41   #60
tykel
Sober coder
 
tykel's Avatar
 
Join Date: Aug 2010
Location: London, UK
Posts: 433
I think it looks good. Once there is a consensus I will be able to add it to the next revision of the spec, along with PAL.
Just clarify one thing for me, what is the frequency for? How does it differ from the sample rate?
__________________
tchip16 (chip16 assembler) Js16 (browser chip16 emulator)
mash16 (chip16 emulator) img16 (chip16 sprite converter)
______________________________________

Desktop: i5 750 @ 3.6 Ghz, 4GB ram, GTX 570 OC | Windows 7 Pro 64
Laptop: (Thinkpad) i5 430M, 4GB ram, Intel IGP | Arch Linux, Windows 7 Pro 64
tykel is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 07:11.

© 2006 - 2012 Emu Forums | About Emu Forums | Advertisers | Investors | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.