Sound For Afx
#1
Posted 11 January 2005 - 05:53 PM
You need no special hardware or controllers for it, what you need is nothing more than a 3.5mm to 2.5mm stereo jack adapter and a headphone. Plug the Phone into the adapter and the adapter into the calc - the COM signal is strong enough that you can hear it.
By writing defined data to the port then you can create every audio frequency you want
Try THIS, it's a simple demo program (screenshot below) that allows you to play all twelve notes of the scale over five octaves. It also supports a two channel mode, but this mode's quality isn't that good.
(Note: if it has a too low volume, take a headphone with a smaller resistor, or plug an amplifier between. I used an earphone, and it was loud enough. Btw I hope this won't demage the COM port? Naturally it shouldn't I think...)
#2
Posted 11 January 2005 - 06:23 PM
#3
Posted 11 January 2005 - 06:39 PM
#4
Posted 11 January 2005 - 07:25 PM
#5
Posted 11 January 2005 - 07:51 PM
#6
Posted 11 January 2005 - 08:25 PM
- background music for low performance games (you can innterrupt sound output by int 1C for example and use it for tasks necessarry for the game; if the int takes not a too long time, it doesn't disturb sound output much). For example, I could imagine a tetris version with background music (think I'll try one)
- if it's a high performance game, you can use sound for intros or menus, and for sound effects (for example, halting the game for about 0.1s and playing a sound when shooting on the enemy or sth. like this)
Don't know about the circuit. Bits are putted out as square, I think, so an edge occurs when one bit is 1 and the next 0, or one 0 and the next 1. Additionally, a stop-bit seems always to cause an edge, no matter what the other bits are.how do you generate the square over tx? do you use break-bit uart function (if there is one on afx) or do you just send null-bits when the edge should appear? what about stop-bits? which circuit is actually controling COM on afx
Another way we could use background music also for high performance games was, when we could prepare a buffer that is to be send through the port, not single bytes only. We could play (send) it then without having a care for it. But I think the port doesn't provide such a functionality?
#7
Posted 11 January 2005 - 09:52 PM
http://www.casiopowe...oundsystem3.gif
@Marco: It sounds really good
btw. Could you give the source of the sound system library? Because then we could add simple sounds to MLC
#8
Posted 11 January 2005 - 09:53 PM
#9
Posted 11 January 2005 - 10:06 PM
@Marco:
http://www.ticalc.or.../338/33890.html
this program would look cool on an AFX, wouldn't it?
#10
Posted 12 January 2005 - 05:52 AM
does this speaker work? because I have the same fabric but I think it is not loud enough
#11
Posted 12 January 2005 - 09:27 AM
The problem is, that for high performance games a delay of even 0.1s is quite too long. And there is no known method to send such packs through the port while the game is still "running"...- if it's a high performance game, you can use sound for intros or menus, and for sound effects (for example, halting the game for about 0.1s and playing a sound when shooting on the enemy or sth. like this)
(...)
Another way we could use background music also for high performance games was, when we could prepare a buffer that is to be send through the port, not single bytes only. We could play (send) it then without having a care for it. But I think the port doesn't provide such a functionality?
What we could do is use the 0x1C or 0x53 interrupt, but not to interrupt the music:
We could run the game normally, and at each call of those int send a byte through the communication port to play a sound... so we could create music at a constant range of 50 Hz
Btw, i'm interested about the kind of data's that must be send to make such sounds
#12
Posted 12 January 2005 - 10:01 AM
#13
Posted 12 January 2005 - 12:48 PM
@4ni8:
does this speaker work? because I have the same fabric but I think it is not loud enough
I think you only need to connect it to an amplified speaker set, like your Hi-Fi or PC Speaker system, and you'll have loud enough system, beside not draining the calculator's battery.
#14
Posted 12 January 2005 - 01:46 PM
what about piezo connected to COM, inbuilt in calculator (eg behind backup battery) with simple amplifier with one transistor supplied from main batteries (you can listen even common data transfers)but surely there is not much point, it is somthing you have to carry round with you, and that defeates the point of portable....
#15
Posted 12 January 2005 - 02:00 PM
EDIT:
Hehe, it works, it works really good. Sound scale is much better than i expected in fact. |
#16
Posted 12 January 2005 - 07:09 PM
I'll put it to the file sharing as soon as possible (Pascal version is ready yet, currently I'm porting it to C as no one likes Pascal). Soundlib btw also has a function now for playing a kind of midi sequences.@Marco:
It sounds really good
btw. Could you give the source of the sound system library? Because then we could add simple sounds to MLC
O yeah, it would! ==> midi tracker in progress yet (didn't know that there was a beat box for TI already- but what I read from the text I think it can play drum sounds only?)@Marco:
http://www.ticalc.or.../338/33890.html
this program would look cool on an AFX, wouldn't it?
I'm a bit surprised by the speaker, too - I'd not expect that you'd hear it even in a speaker loud enough, that's cool .does this speaker work? because I have the same fabric but I think it is not loud enough
The thing with the piezo I also think is a good idea!
@huhn:
If your speaker is too quit, try one of these small earphones you get delivered with a discman, this should be loud enough then.
Yeah, this was also the first I thought about before doing vice versa. But I guess we can't create a scale upon that (although a range from 25 to 50Hz was theoretically enough to do it) cause of the constant timer intervalls of 1/50s.What we could do is use the 0x1C or 0x53 interrupt, but not to interrupt the music:
We could run the game normally, and at each call of those int send a byte through the communication port to play a sound... so we could create music at a constant range of 50 Hz
However, we could use it for 50, 25 and may be 37.5 Hz sounds, so it still will be applicable for some sound effects
#17
Posted 12 January 2005 - 07:22 PM
#18
Posted 14 January 2005 - 10:52 AM
#19
Posted 15 January 2005 - 08:47 AM
Note, that writing the doc took as long the lib itself did (I really hate writing docs...)
Btw, C version hasn't been tested yet, altough the compiler gives no errors for it. Especially for the MIDI track routines for C I don't know if they'll work, so just try out (and tell me if or ifn't so)
#20
Posted 15 January 2005 - 01:02 PM
And made Sweet Sound v 0.1 (it's mostly port from snddemo.pas by you). I works almost fine. It generates sound very well. But I found no way to terminate the program (without using P button). It's really weird I guess it can be a bug in soundclose() (or in soundopen() or soundplay() ).
Sweet Sound v 0.1 (with source):
http://max.iem.pw.ed.../sweets_010.rar
btw. afxsound.c doesn't work with Digital Mars compiler
However, way to go Marco
#21
Posted 15 January 2005 - 03:02 PM
Ah and about the termination problem - it's a mistake I made in snddemo.pas: to leave soundplay() you should prefer setting soundstop variable to 1 instead of calling closesound(), else the port will be closed while soundplay() is running and soundplay() might hang thus (I haven't thought of this when writing the demo ).
So it should work when calling soundclose() only when soundplay() has returned already after setting soundstop.
Thx for testing it btw (would have been much efforts for me to do so as I never yet wrote a C prog running on AFX)
#22
Posted 15 January 2005 - 03:43 PM
Here is the Sweet Sound 0.2 + source:
http://max.iem.pw.ed.../sweets_020.rar
btw. Marco, you can add Sweet Sound to your lib package as a C example if you want .
#23
Posted 15 January 2005 - 03:46 PM
---------- DM ---------- mov word [offset channels],0xFFFF ^ E:\CALCS\CASIO\PROG\sound\moje\afxsound.c(161) : Error: Expected assembler directive PTR to follow assembler cast mov word [offset channels+5],0xFFFF ^ E:\CALCS\CASIO\PROG\sound\moje\afxsound.c(162) : Error: Expected assembler directive PTR to follow assembler cast mov word [offset channels+2],1 ^ E:\CALCS\CASIO\PROG\sound\moje\afxsound.c(163) : Error: Expected assembler directive PTR to follow assembler cast mov word [offset channels+7],1 ^ E:\CALCS\CASIO\PROG\sound\moje\afxsound.c(164) : Error: Expected assembler directive PTR to follow assembler cast mov [offset channels+2],dx ^ E:\CALCS\CASIO\PROG\sound\moje\afxsound.c(188) : Error: Illegal type/size of operands for the mov instruction Fatal error: too many errors --- errorlevel 1 Output completed (0 sec consumed) - Normal Termination
#24
Posted 15 January 2005 - 06:07 PM
That's fine, I'll add itbtw. Marco, you can add Sweet Sound to your lib package as a C example if you want
^^ Got a DM compiler meanwhile, hope I'll fix it soon...
#25
Posted 15 January 2005 - 07:49 PM
try mov word ptr ds:[&channels+xxx], yyyDigital Mars Compiler gives:
[code=auto:0]---------- DM ----------
mov word [offset channels],0xFFFF
^
E:\CALCS\CASIO\PROG\sound\moje\afxsound.c(161) : Error: Expected assembler directive PTR to follow assembler cast
ptr is here a keyword to accent pointer; word is necessary to determinate the length of second operand yyy which is immediate (sometimes required even if yyy isn't immediate, as in case of dx), xxx is shift from base adress; perhaps, offset of channels has not to be declared with offset keyword in DMC's assembler, try &
#26
Posted 15 January 2005 - 08:04 PM
mov word ptr ds:[offset channels], 0xFFFFDM error:
---------- DM ---------- mov word ptr ds:[offset channels], 0xFFFF ^ E:\CALCS\CASIO\PROG\sound\moje\afxsound.c(161) : Error: Illegal type/size of operands for the mov instruction mov word [offset channels],0xFFFF
#27
Posted 15 January 2005 - 09:15 PM
dw myvar mov ax,[myvar]You have to do a type casting similar to C however:
mov (word) [(void) channels],0xFFFFThat works so far, but it's a really strange syntax for an assembler nevertheless (and it's also incompatible with borland inline assembler, so I'll make a third version afxsound_dm.c). They could have documented it anywhere at least
#28
Posted 15 January 2005 - 09:58 PM
most of programmers are used to intel asm syntax (tasm, masm, a86, nasm...) have you ever tried AT&T asm syntax, whichGCC gnu-compiler uses? my first mov was enough (you must declare all used variables, and operands are swapped and so on...)...but it's a really strange syntax for an assembler nevertheless (and it's also incompatible with borland inline assembler...
now seriously: have you noticed (in DMC) any difference between
mov dx, myvar
mov dx, &myvar
mov dx, [myvar]
mov dx, [&myvar]
it seems that it work all the same (but logically, when brackets are used as dereference; & have to be used as reference and vice versa)
#29
Posted 15 January 2005 - 10:39 PM
Please do not make another file, just add someThat works so far, but it's a really strange syntax for an assembler nevertheless (and it's also incompatible with borland inline assembler, so I'll make a third version afxsound_dm.c). They could have documented it anywhere at least
#ifdef __DMC__ ... // DM special code #else ... // other compilers #endifstuff in your code
But in this case, I see you don't use SI or DI... you could use it for that (of course there will be one instruction more, but its not big deal )
If you have
void soundplay() { mloop: asm { mov ax,[offset channels+2] mov bx,[offset channels] cmp ax,bx jna m1then write
void soundplay() { asm lea di, channels; mloop: asm { mov ax,[di+2] mov bx,[di] cmp ax,bx jna m1etc
#30
Posted 17 January 2005 - 05:46 PM
- works also with Digital Mars compilers now
- contains 4nics C demo
- the closesound bug in the other two demos has been fixed
#31 Guest_Newbie_*
Posted 18 February 2007 - 08:24 PM
#32
Posted 18 February 2007 - 11:39 PM
#33 Guest_bengx_*
Posted 28 February 2007 - 04:47 PM
#34
Posted 01 March 2007 - 01:04 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users