Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: Vogtinator on February 28, 2013, 02:26:08 pm

Title: Nspire Audio player!
Post by: Vogtinator on February 28, 2013, 02:26:08 pm
WARNING: Two people destroyed their touchpads by accidentially shorting some pins, so be VERY careful!
Read the thread here (http://ourl.ca/18458)


Some days ago I found out (with diags) there are some GPIOs connected to the dock connector.
We also have one relatively fast timer we could use for pwm and one for loading new data from the buffer, so here ya go:



Dock connector (connected to pins 5 + 6):

(http://i.imgur.com/Hz5Uf8Cl.jpg)

There are still a few bugs/improvements that need to be done:
-Only 10 kHz sampling rate, more is possible
-Crashes on exit
-Loads file twice
-Max file size 2000000 Bytes (2MB)
-Only works on CX
-Only loads "/documents/ndless/monsta.raw.tns" for now
-Haven't got a name, any suggestions?

I'll publish the source code after it works completely.

Possible features:
-WAV loading
-Volume control
-Stereo :-)

BTW: Don't plug your speaker in before "Playing!" or you'll short 3,6 V (While playing, you only short ~1,8V)! Unplug them before exiting, the GPIO becomes high on reset! Don't use your amplifier, you may blow it!

Edit: Updated video

Newest version: here (http://ourl.ca/18438/340399)
Title: Re: Nspire Audio player!
Post by: ElementCoder on February 28, 2013, 02:28:39 pm
WOW this is freaking amazing! O_O Even at 10kHz that sound sounded... soundtastic. I do wonder, why no rickroll :P
Title: Re: Nspire Audio player!
Post by: Adriweb on February 28, 2013, 03:10:24 pm
Very nice hack :D
Title: Re: Nspire Audio player!
Post by: christop on February 28, 2013, 03:23:08 pm
BTW: Don't plug your speaker in before "Playing!" or you'll short 3,6 V (While playing, you only short ~1,8V)! Unplug them before exiting, the GPIO becomes high on reset! Don't use your amplifier, you may blow it!
Do you know how the GPIO port is driven? If it uses a pull-up resistor (this is what all the TI-8x and TI-9x calculators use in their link port hardware), shorting the port to ground will not harm the calculator (the pull-up resistor is between the 3.6V source and the GPIO pin).
Title: Re: Nspire Audio player!
Post by: Vogtinator on February 28, 2013, 03:26:59 pm
Nope, I don't. I haven't got the right screwdriver, but if it really uses a pull-up, it'd be great!

BTW: I'll make a new video tomorrow, this one isn't the greatest.
Title: Re: Nspire Audio player!
Post by: critor on February 28, 2013, 04:08:22 pm
Very glad to see there is finally an audio solution for Ndless programs and some progress on the TI-Nspire Dock Connector! :)

And very glad to see that somebody has allready updated Hackspire:
http://hackspire.unsads.com/wiki/index.php/Hardware#Connector_J01_-_Dock_connector


Let's go on: we still have a little more than 20 pins to identify! ;)
Title: Re: Nspire Audio player!
Post by: Vogtinator on February 28, 2013, 04:18:25 pm
Quote
And very glad to see that somebody has allready updated Hackspire:
That somebody was me, some days ago :D

Quote
Let's go on: we still have a little more than 20 pins to identify!
The long pins are GND, now we only have 19 more D: (3 of them SPI, 8(?, don't remember exactly) GPIOs)
They shouldn't be a problem with diags and SLED tests
Title: Re: Nspire Audio player!
Post by: excale on February 28, 2013, 04:22:34 pm
Awesome! Make it for clickpads too :D.

PS: Can you please update hackspire ( http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#90000000_-_General_Purpose_I.2FO_.28GPIO.29 ) ? (not now, but when you think you've found enough and have some time :) ).
Title: Re: Nspire Audio player!
Post by: christop on February 28, 2013, 09:02:53 pm
Nope, I don't. I haven't got the right screwdriver, but if it really uses a pull-up, it'd be great!
Sorry, I didn't mean to imply that there would be a visible, discrete resistor on the board. More likely than not the pull-up resistor (if there is one) is inside an ASIC that controls the GPIO hardware, so you wouldn't be able to see it without an electron microscope or something. :)
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on February 28, 2013, 09:42:12 pm
Awesome
Though I had problems when I just tried it
First. I did not solder, I just used scotch tape, and I may not have done it correctly (I did red wire 6 from the left, and the black wire of my speakers 5 from the left), nor do I know if I took apart my speakers very well. And one of the wires was thin
Also, I took a random song, changed it to 10 seconds long, used a converter to change it to .raw (where do you find those?) then saved as the monsta file
Anyway, I ran it and got a bunch of fuzz and high pitch sounds, instead of classical accordion
So I got something, which is good

(Also, was that Peter Fox? He is one of the few german singers I have listened to, so idk)
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on February 28, 2013, 10:39:50 pm
Okay update on the problem. I got a rough form of the audio to play, but it still has way to much squeaky sound to be good. I used this (http://www.nch.com.au/switch/index.html) to convert it, and converted an mp3 to a mono 8000 raw file
It still is fuzzy and squeaky though, so I don’t know if it is my file or my speaker.
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 01, 2013, 01:17:04 am
I used audacity, change project rate to 10000 (after import), convert it to mono
and export it as raw data (unsigned 8-bit pcm).
Title: Re: Nspire Audio player!
Post by: ElementCoder on March 01, 2013, 04:06:03 am
/me wonders if this could be used in games
/me thinks VVVVVV
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 01, 2013, 04:49:33 am
PWM only uses 60 cpu cycles every pwm cycle (128 kHz) so you can still use 124 MHz.
Title: Re: Nspire Audio player!
Post by: Keoni29 on March 01, 2013, 06:57:38 am
Needs more amp.
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 01, 2013, 07:28:45 am
I used audacity, change project rate to 10000 (after import), convert it to mono
and export it as raw data (unsigned 8-bit pcm).
I did that and it is much better, though it is really slow for some reason, even with nover
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 01, 2013, 08:58:43 am
Quote
even with nover
With nover you can only decrease the pwm speed. I don't know how (and whether) you can change the speed of the second timer (~31 kHz) which is used for setting the pwm output value.
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 01, 2013, 09:09:15 am
Though mine is very slow, like 50%-80%, and vocals sound ridiculous, while your's seem just fine
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 01, 2013, 09:14:01 am
Is the length reported correct? It should be the exact (rounded) duration in seconds
Title: Re: Nspire Audio player!
Post by: critor on March 01, 2013, 04:33:53 pm
We have to add sound support in gbcnspire, gpSP and nDoom ! ;)
Except that I'll probably won't have any time to work on nDoom in the next few months.
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 01, 2013, 04:55:37 pm
We have to add sound support in gbcnspire, gpSP and nDoom ! ;)
Except that I'll probably won't have any time to work on nDoom in the next few months.
And nspire movie player most of all!
Is the length reported correct? It should be the exact (rounded) duration in seconds
It is 181s for 2000000 bytes, like yours was, because I accidentally went over
It is slow, and I think the scratchy noise just might be my bad speakers.
But I send the mp3 files to audacity change it to 8000, export it as Other compressed files with Raw (header-less) and unsigned 8 bit PCM selected in the options

Maybe you could post one of your files for me to see?
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 01, 2013, 05:52:01 pm
Quote
But I send the mp3 files to audacity change it to 8000,
8000, that should be too fast  ???. 10000 is correct (you can type in any value you want)

Quote
Maybe you could post one of your files for me to see?
If it doesn't work with this version, I'll post some free stuff here.

We have to add sound support in gbcnspire, gpSP and nDoom ! ;)
Except that I'll probably won't have any time to work on nDoom in the next few months.
And nspire movie player most of all!
All of them :) But I think it might get a bit complicated with tone generation :-\

I made a newer version, resolved some bugs and copied nTxt/hoffa's file browser:
-24000 samples per seconds (second timer is only 24 kHz  >:( )
-Doesn't crash anymore
-Loads file only once (Limit is now at 5 MB)
-Works with ndless.cfg.tns
-Source code (Not very well commented - yet  :-[ )

16 bit pwm is not possible, 500 Hz is a bit too slow  >:(
A higher samplerate would only be possible with a lower pwm frequency as I would have to abuse the fiq handler for pwm, but I think we don't need 64000 samples per second  ::)

I also made a few tests with nover, it plays fine (even at the right speed) with 162/81/40 MHz.. Does the second timer have a seperate clock source?
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 01, 2013, 07:25:59 pm
Thank you
This is much faster, but for some reason this still isn’t fast enough for vocals.
I also like that I don’t have to keep changing the name of the file to monsta.raw.tns :)
Title: Re: Nspire Audio player!
Post by: Sorunome on March 01, 2013, 11:41:35 pm
Wow, that is looking pretty awesome!
And *yay* german :D/me isn't alone anymore

I just like how much stuff is made for the nspire, that makes me wish I had one >.<
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 02, 2013, 05:51:48 am
Quote
This is much faster, but for some reason this still isn’t fast enough for vocals.
Whoops, now I see.. :banghead: It's really just 16000, I swapped the files.. sorry  :-[
16000 is indeed a bit low, I'll search for a better way to load it (Fast timer No.2 maybe?)

Quote
And *yay* german
* Sorunome isn't alone anymore
Ich bin hier doch schon 'ne ganze Weile xD

Quote
I just like how much stuff is made for the nspire, that makes me wish I had one >.<
Wishing alone doesn't work (except for christmas), you may have to buy one  :P

Edit:
Newer version:
-WAV support (mono, 8-bit pcm)
-samplerate up to 33 MHz xD
-fixed small bug with GPIOs
-Max file size = free ram
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 02, 2013, 11:20:03 am
Okay, I went to audacity selected stereo to mono, changed it to 10000 saved it as other compressed file, unsigned 8 bit wav, and sent it to my calculator.
The player just stays at zero seconds now, and doesn't play the song.
Quote
And *yay* german
* Sorunome isn't alone anymore
Ich bin hier doch schon 'ne ganze Weile xD
Und ich spreche kleine Deutsch :)
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 02, 2013, 11:25:37 am
Quote
Okay, I went to audacity selected stereo to mono, changed it to 10000 saved it as other compressed file, unsigned 8 bit wav, and sent it to my calculator.
The player just stays at zero seconds now.
Hmm, theres a bug: You have to start it twice after rebooting..
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 02, 2013, 11:29:03 am
When I do that it still stays at 0 seconds, but I get a constant buzz sound.
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 02, 2013, 11:30:38 am
Strange, does escape still work?
I made a reset on my calc, opened a wav in pwmtest, pressed escape, opened it again an it plays as it should.
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 02, 2013, 11:33:53 am
Escape works, but what you said doesn’t work.
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 02, 2013, 11:45:05 am
Ok, it seems to not work with 10000, could you try it with 32000? I'll try to find the bug :D

Edit: Found: Try to delete the author, title, track information.. My wav decoder tries to interpret it as the file length
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 02, 2013, 11:50:13 am
How would I delete those things?
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 02, 2013, 11:51:30 am
Audacity should ask you after the file save dialog. There's a delete (or remove or similiar) button on the bottom right

Edit: Bug resolved
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 02, 2013, 12:00:19 pm
Whooo!
Thank you!
It is the correct speed!
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 02, 2013, 12:01:35 pm
Great! BTW: Try it with 32000 nevertheless, it sounds SO MUCH better ;)
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 02, 2013, 12:10:39 pm
What does that new file do? Does it just bypass the titles and such? I haven't yet tried it.
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 02, 2013, 12:11:43 pm
yes, it jumps over every chunk until it finds "data".
Title: Re: Nspire Audio player!
Post by: Rhombicuboctahedron on March 02, 2013, 03:54:40 pm
Though just wondering, would it be possible to change the volume coming out? Because I connected a headphone jack and my headphones, and it is way to loud
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 02, 2013, 03:58:52 pm
Quote
Though just wonderinjg, would it be possible to change the volume coming out? Because I connected a headphone jack and my headphones, and it is way to loud
Yes, by making the pwm off period longer. I'll try it and upload when ready :)

Edit: Nope, pwm gets too slow if too quiet.. You can hear it as a high-pitch squarewave then (annoying as hell)
Title: Re: Nspire Audio player!
Post by: DJ Omnimaga on March 03, 2013, 11:21:10 pm
This seems very cool. :) What would be great in the future is an USB mode (for those who got USB speakers with a mini-USB adapter) since it would be easier to do the connections and might prevent some calculator horror stories (http://ourl.ca/18458).
Title: Re: Nspire Audio player!
Post by: ElementCoder on March 05, 2013, 02:01:22 am
How did you discover this? (How do things like this even get discovered in the first place.) I've alwasy wanted to mess around with my nspire to do stuff like this, but never had (and still have) no clue how or where to start.
Title: Re: Nspire Audio player!
Post by: Lionel Debroux on March 05, 2013, 02:03:25 am
Quote
How did you discover this?

From the first post:
Quote
Some days ago I found out (with diags) there are some GPIOs connected to the dock connector.
Running, and then disassembling, diags software :)
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 05, 2013, 09:11:27 am
Quote
Running, and then disassembling, diags software :)
Only running :)
I curiously explored the menus and tried to touch the ports on the back and noticed it recognized my fingers. There is MOSI, MISO, too (SPI).
Somewhere there's even SD-Cart support (D0, D1, D2, GND?)
Title: Re: Nspire Audio player!
Post by: christop on March 06, 2013, 09:16:50 pm
How do you generate the PWM signal? Do you just set the output high or low at each clock interrupt, and what is the clock rate of that interrupt?

I'm just wondering if you could alternate the output signal (pulses) more frequently, as in multiple times per WAV sample, in order to push the pulses into the inaudible frequency range, or at least into a range that can be filtered out with a low-pass filter. I would think that this can be done fairly easily with delta-sigma modulation (http://en.wikipedia.org/wiki/Pulse-density_modulation#Algorithm).
Title: Re: Re: Nspire Audio player!
Post by: TheNlightenedOne on March 07, 2013, 12:09:28 am
Wait, to what extent is the SD support useful?
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 07, 2013, 01:25:06 am
Everytime the (fast)timer fires an fiq, I toggle gpio 4 and set the timer value.
For instance, if pwm=40, I set the timer to 40, after toggling I set the timer to (256-40).
So I get a pwm freq of about 33000000/256 Hz, but for whatever reason I have to shift the timef value one left. If pwm is updated while the gpio is on, the off period is already computed with the new value, so it should atleast feel faster :)

SD card support might be good for nspire-linux, the usb port is slow as hell.
Title: Re: Nspire Audio player!
Post by: Tremled on March 18, 2013, 12:31:47 pm
Just wondered... wouldn't it be possible to have a stereo-signal coming out? As far as I know there are other pins at the dock-connector that could be used for something like that.
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 18, 2013, 12:41:10 pm
Yes it would be possible, but we only have two 33 MHz timers (for pwm), we would have to use the 33 kHz timer as sample update.
That would mean wav loading is impossible (if they're not 33kHz) or it'd sound weird. Mono is noisy enough (8 bit).
But one thing is interesting, with some resistors and two GPIOs it's possible to do 16 bit pwm, but that would destroy the simplicity :-/
Title: Re: Nspire Audio player!
Post by: Tremled on March 18, 2013, 12:54:08 pm
Isn't it possible to set the pwm-values for both the left and the right channel using the same timer, thereby enabling wav-loading even though it's stereo (by using the faster timer)?
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 18, 2013, 12:55:57 pm
How would you do that? You're only able to execute 132/33=4 cpu cycles each timer interrupt (and the JMP already needs 5)
Title: Re: Nspire Audio player!
Post by: Tremled on March 18, 2013, 01:13:32 pm
Too bad; using the same timer for both channels apparently isn't a solution.  :(
Title: Re: Nspire Audio player!
Post by: Vogtinator on March 18, 2013, 01:16:53 pm
Exactly, the calc is too slow..
But it would work on the older (non-cx) models, they actually have 6 33MHz timers Second timer (http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#900D0000_-_Second_timer), but I don't have one :-(
Title: Re: Nspire Audio player!
Post by: l6979630 on June 27, 2014, 11:32:06 pm
I have a Ti-nspire CAS non-CX.I try to modify your code to make it work on my Ti-nspire.But It always resets when it registers FIQ handler.
Title: Re: Nspire Audio player!
Post by: Streetwalrus on June 28, 2014, 03:29:08 am
If you posted the changes you made it would probably help. Also which OS are you running ?
Title: Re: Nspire Audio player!
Post by: l6979630 on June 28, 2014, 05:50:49 am
I just deleted the part to check OS.It doesn't works on 3.1 or 3.6.
Title: Re: Nspire Audio player!
Post by: Vogtinator on June 28, 2014, 09:00:00 pm
The non-cx hardware is entirely different, so you'd need to rewrite the asm code and the timer setup code in audio.c almost completely.
It shouldn't be too hard, though, as only the bit positions, register layout and clock speeds changed.
Title: Re: Nspire Audio player!
Post by: l6979630 on June 28, 2014, 10:30:10 pm
It's too hard to me to rewrite the asm code.I even don't know its meaning.Could you help me?
Title: Re: Nspire Audio player!
Post by: l6979630 on June 28, 2014, 10:58:04 pm
When i delete asm code in interrupt.c it has some problem,but it doesn't reset again.
Title: Re: Nspire Audio player!
Post by: Vogtinator on June 29, 2014, 06:50:33 am
Don't double post, the "edit" button has a meaning ;)

Quote
It's too hard to me to rewrite the asm code.I even don't know its meaning.Could you help me?
I literally commented every instruction.. Except for some basic blocks. BTW: You can replace the "unaligned read at r9" by a simple "ldrb r9, [r9]".
But you definitely need to understand it well enough to make such a rewrite.

Quote
When i delete asm code in interrupt.c it has some problem,but it doesn't reset again.
Which asm code in interrupt.c?
Title: Re: Nspire Audio player!
Post by: l6979630 on July 03, 2014, 09:49:26 am
I try to modify memory-mapped in interrupt.c.Then there is not error in log window.But it still resets. :banghead:
Title: Re: Nspire Audio player!
Post by: Vogtinator on July 03, 2014, 11:30:07 am
Without your changes nobody can help you..
Title: Re: Nspire Audio player!
Post by: l6979630 on November 06, 2014, 07:46:47 am
How to set the timer to 32bit?
http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#900D0000_-_Second_timer
It says Set to 32 by the OS.but how?
Title: Re: Nspire Audio player!
Post by: Vogtinator on November 06, 2014, 08:09:26 am
It doesn't mean 32bit, it means that the timer load value is "32".
You can simply write it to the port (32 bit write)
Title: Re: Nspire Audio player!
Post by: InventorX on January 23, 2016, 10:22:48 pm
Vogtinator,

I am fairly new to programming , and the only languages that I've had experience with are Java and the Arduino's language. I managed to make a capacitive-sensor piano with the Arduino, but it is rather clunky. I realized that the Ti-inspire calculator already has a built-in keypad and that I might be able to play tones with the nspire. I was wondering if you have any directions, tips, or references that would help me with this project. Also, should I be using Assembly or Lua? I would also like to mention that in the future, I would like to add a synthesizer as well, where I might be able to use waveform equations to creates the timbre and/or the ability to draw the wave. Any information that you could give me would be helpful!

Sincerely,
InvX
Title: Re: Nspire Audio player!
Post by: Vogtinator on January 24, 2016, 05:44:13 am
Hi InvX,

"pwmtest" is written in ARM assembler and C ("the Arduino's language"), so you have to learn them to fully understand and work with pwmtest.
You have to setup your calc as usual (solder to a dock pin or connect to it in a different way) before you can try pwmtest.
There is a fairly high-level API exposed by audio.c you can use to play your synthesized tones.
Title: Re: Nspire Audio player!
Post by: InventorX on January 24, 2016, 12:52:00 pm
Thanks, this helps me out a lot!  ;D

One more thing; would it be possible to remove the static from the audio? Maybe with some kind of low-pass filter?
Title: Re: Nspire Audio player!
Post by: Vogtinator on January 24, 2016, 03:21:09 pm
Quote
One more thing; would it be possible to remove the static from the audio? Maybe with some kind of low-pass filter?
Some part of it, yes. It only has 8 bit resolution (I tried 9 and even 10 bit, didn't work out well) so you won't get rid of the resulting inaccuracies.
Title: Re: Nspire Audio player!
Post by: InventorX on January 30, 2016, 09:55:32 pm
Where do your common.h and os.h libraries come from?
Title: Re: Nspire Audio player!
Post by: Legimet on January 31, 2016, 11:10:40 pm
common.h and os.h used to be in the SDK. After the Newlib transition, they are no longer used, although there is an os.h for compatibility. You'll have to figure out what to replace them with, I personally haven't looked at this code.
Title: Re: Nspire Audio player!
Post by: MichaelaJoy on April 02, 2016, 01:05:53 pm
Awesome!

A suggestion. You might want to use a capacitor to couple the audio from the pin. Then, a low impedance load won't adversely affect the calculators' operation.
Try a 0.1 uf ceramic capacitor. 50 volt rating is fine. You can use a poly cap too.

The signal might be low, but a small amp (LM386) would bring the level up and allow you to drive a speaker.

I hope this helps.