What I want to do is send music over the I/O port that my headphones understand and play. Instead of playing an audio file, I would like to generate music using a sort of sequencer. I would also love to somehow implement ByteBeat on my Ti-84+. How do I get the data to my headphones?
The closest thing I could think of is this post on instructables.
Are you asking about the hardware or the software? For the hardware, you just need a 2.5mm to 3.5mm stereo adapter that you can plug headphones into. On the software side, the most practical solution is writing an assembly program that rapidly toggles Port 0 from the z80 CPU, one for the left ear, the other for the right ear. Many existing projects use cycle-counted assembly loops to generate specific frequencies, or offload the waveform generation to an interrupt and move more complex computation into a main program. This requires a nontrivial amount of assembly knowledge, so isn't an ideal place to start if you haven't written z80 assembly before.

This also assumes you're talking about a TI-84 Plus monochrome-screen calculator with a 2.5mm link port.
I think axe parser contains commands allowing you to send sound frequencies through the I/O port.
Quote:
rapidly toggles Port 0


Two Questions:
1. Can I only send one bit to the port at a time?
2. Is

Code:
ld(0), a
how I send a value to the port?
Beakbonk wrote:
Quote:
rapidly toggles Port 0


Two Questions:
1. Can I only send one bit to the port at a time?
2. Is

Code:
ld(0), a
how I send a value to the port?
'
Did you read the example on the page that was linked above?
MateoConLechuga wrote:
Beakbonk wrote:
Quote:
rapidly toggles Port 0


Two Questions:
1. Can I only send one bit to the port at a time?
2. Is

Code:
ld(0), a
how I send a value to the port?
'
Did you read the example on the page that was linked above?
Specifically the Port 0 documentation that I linked. You can also take a look at the source for benryves' QuadPlayer for inspiration.
Quote:
Specifically the Port 0 documentation that I linked


Thanks, sorry for not reading that more carefully before asking questions. I was successfully able to make my calculator send a small pop to my headphones! I'm going to try Bytebeat next, as that should be a fairly simple way to get musical sounds.
Okayyy so. The port can indeed only output a high voltage or a low voltage. That's one bit of data at a time. This corresponds to roughly 3V and 0V according to my own experiments. I hear on some older models it's closer to 5V. This voltage is directly fed into the electromagnet that controls the diaphragm of your headphones or speaker or whatever. Most devices can output 16 bits of data (so, 65536 different voltages) over their analog audio jacks, but we're doing this on a calculator where the port is intended as a serial port, so we only get 1 bit. You can't send encoded binary data that the headphones will decode into a pretty-sounding song, you are directly controlling the diaphragm of your headphones.

So, you probably know how sound consists of waves. You need to make those waves yourself, by outputting 000000001111111100000000111111110000000011111111... The amount of time you wait between switching from 0 to 1 or vice-versa is how you control the frequency and thus the pitch. This requires very precisely written code where you hand-count individual clock cycles.

Now, let's say you want to output an A4 at 440 Hz on a calculator running at 6 MHz: that means you want roughly 13636 clock cycles per wave, which means you want to toggle between 1 and 0 twice as often as that. Every 6818 clock cycles, say. Let's implement that in code: (this should build in spasm, fasmg will work if you replace the first two lines with the standard fasmg-z80 header)

Code:
.db $bb,$6d
.org $9d95
  di          ; TI-OS's interrupt routine would mess with timing (and also with the linkport value)
  xor a       ; value of the linkport
  ld de,3776  ; counter to stop after four seconds
  ld hl,$8000 ; make sure the inc (hl) below is harmless

loop:
  inc (hl)    ; 11/0 (delay to compensate for when the dec d \ jr nz below is not executed)
loop_lessdelay:
  ld b,183    ; 7
delay:
  jr $+2      ; 12*183
  jr $+2      ; 12*183
  djnz delay  ; 13*183-5

; output
  out (0),a   ; 11
  xor 3       ; 7

; loop
  dec e       ; 4
  jr nz,loop  ; 12/7
  dec d       ; 0/4
  jr nz,loop_lessdelay ; 0/12

  xor a       ; reset linkport: very important if you don't want the OS to freeze up (quadplayer doesn't do this FSR)
  out (0),a   ; FWIW it doesn't matter in this case because we're guaranteed to toggle it an even number of times but i wanted to make this point
  ei
  ret
Notice the comments containing clock cycles of individual instructions. I carefully added padding instructions to make sure the loop is exactly 6818cc long. Of course it won't be in tune unless your calc is clocked at exactly 6 MHz (which it isn't). And it doesn't need to be that exact, slight timing inconsistencies will affect sound quality, but the song should still be recognisable.

The DE value 3776 is to have a counter so we can stop after 4 seconds of playing. (the way this loop works, the number of repeats is actually 3776-256=3520)

Now, if you're interested in playing multiple notes at the same time... I'll infodump about that later if you're interested. Or you can look into "1-bit music" on your own. There's 3 broad techniques to do this and each has their pros and cons.
Thank you so much. I was starting to go crazy trying to figure out what I was doing wrong. Having only 1 bit to work with should be an interesting challenge. Smile
fghsgh wrote:
This corresponds to roughly 3V and 0V according to my own experiments. I hear on some older models it's closer to 5V.

The TI-83 Plus originally used 5 V TTL logic levels in all its electronics. But any device manufactured in like the last 20 years will use 3.3 V CMOS logic levels. The I/O port simply operates at whatever the calculator's main logic voltage is. The I/O port has driving transistors which coincidentally protect the digital logic from the aggressive voltage spikes headphones would send back.

The I/O port should be able to reach hundreds of kilohertz---and possibly into the megahertz---but I don't feel like writing a bandwidth testing program. But hey, if you want to write one, I can run it on a TI-83 Plus SE and show oscilloscope results.
In a recent discussion on IRC/Discord, using a clever SMC trick that calc84maniac suggested, we could get 1.25 million state changes per second (or a 625KHz signal) out of the link port at the 15MHz CPU speed.
Slightly off topic to this discussion, would it be possible for the newer models to use the USB port to make music? Maybe something like this:
TI-84+CE -> Mini to normal USB adapter -> Silver link -> headphones
That would be interesting even if can only be really a proof of concept
Potatoman1234 wrote:
Slightly off topic to this discussion, would it be possible for the newer models to use the USB port to make music? Maybe something like this:
TI-84+CE -> Mini to normal USB adapter -> Silver link -> headphones
That would be interesting even if can only be really a proof of concept

I'm not too familiar with how the silverlink works, but I imagine that it can't do the type of bit-banging that you can with the I/O port directly. Even if it could, the delay involved with USB is going to be much longer and much less predictable, making generating music through it difficult. You could probably just plug in a USB sound card, though.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement