Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Music Player and Web-Based Controller

rtttl rttl music player web server webpage controller ring tone

  • Please log in to reply
10 replies to this topic

#1 RonZon

RonZon

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationWaukesha, WI

Posted 13 January 2013 - 08:40 PM

I wrote a RTTTL player for my Netduino Plus 2.

I didn't realize there was one (or two) already existing until I was almost done....  but mine is a bit different:

 

Specification followed from: http://en.wikipedia....ansfer_Language

Strings can be used without any modification.

I also wrote in some error catching, to compensate for strings that are "not-quite" standard.

 

The player has methods(controls) to:

- load in a song string (which can also be completed 'during' play).

- Start Play,  Stop Play,  Pause/Resume,  Repeat Option On/Off.

 

In my second included version:

I modified my basic web server app to allow control of the player.

The web-server generates a simple webpage with buttons to allow control.

The webpage should be compatible with any browser ( I tested with Android, Kindle Fire, etc....).

It utilizes PUT commands so that there is little delay,  but also allows the standard GET type commands.

 

ALSO:

You can load songs onto your SD card and play them :-)

Click the List Files button to read the list of files from the SD card.

Each filename is a 'clickable' link that will load in the file to be played next.

NOTE:  This is also a basic web server that works with most standard type files:

(html, txt, gif, jpg, png,  and will transfer large files of other types).

There is an option to generate a log file of activity, which can also be accessed from the "list files" option to read it.

 

Not a very practical project,  but I though it was fun :)

 

You can google for TONS of RTTTL song strings,  or even better, go to:

http://www.picaxe.co...r-Tune-Command/

and download hundreds of songs in a ZIP file.

Extract the files.  Each song is a *.txt string. Rename to *.rtl  (for use with my program), or

***  Easy way (in Windows): hold shift and right-click in the folder, choose "Open Command Window Here"

***  type: ren *.txt *.rtl

*** Copy the files over to the micro SD card and you're all set !!!

 

Enjoy

-Ron

 

EDIT: The only ERROR I found, is that if there are too many files on the card,  the recurse folders method used to List Files seems to error out....

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 January 2013 - 09:07 PM

Oh wow, nice zonfoto! Do you have a video showcasing this? Thanks for sharing this, Chris

#3 RonZon

RonZon

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationWaukesha, WI

Posted 13 January 2013 - 11:34 PM

Thank you very much, Chris ! :)

 

I do not have a demo of it, at the moment... just finished it....

But,  I may be able to, soon.



#4 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 14 January 2013 - 07:34 AM

Not very practical you say... Well, you could use it for a doorbell playing music whenever somebody's at the door. Other possible applications would be whenever you need audible notification. For instance when receiving a mail, sms or similar - you could have the

 

The Netduino could be sitting on the wall in your hallway and you could issue HTTP PUT requests to it from whatever networked device you have.

 

I've got a GSM-board that I'm thinking of using (some day...) and your code might come in handy.

Well done!



#5 RonZon

RonZon

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationWaukesha, WI

Posted 15 January 2013 - 01:36 AM

I have another version here that I've been experimenting with...

Running multiple instances of songs on separate threads.

In this case, I am running the same song strings, but shifting the octaves.

This gives it a bit of depth !!

 

Considering that the Netduino doesn't have true multitasking, it actually works OK.  (better than I thought it would)...

 

I have tried up to 4 threads at once,  just for fun.

Main "melody" at the base octave.  Then shifted down -1, -2, and -3 octaves.

 

I also wrote in a function to shift by "semi-tones", or individual notes.

This allows you to create CHORDS --

Example:  Major Chord: ROOT,   +4 semitones, +7 semitones.

Then you can even add in a "BASS" line at -2 octaves :-)

Unfortunately,  it seems to loose the timing more with this method....  OR maybe its just more noticeable....

 

I changed the start/stop variables to be static, so that all threads can be started with ONE COMMAND.

PLUS --  I added the songs into a hashtable, so that it loops between all of the songs.

 

OH,  and,  I just updated to the 4.2.2 firmware....  Posted a few days ago.

I saw a mention of a fix for PWM frequency,  and I think it does seem to sound more accurate.

 

 

Have fun !!!

-Ron

 

EDIT:

I forgot to mention, that ----

So that you don't have to have 3 or 4 separate speakers,

I used a "quick and dirty" mixing method to mix the PWM outputs.

YES,  I know this isn't the best way to create an AUDIO-MIXER:

 ----   But,  run a 120ohm resistor off each PWM output to a junction, going to the positive lead of the speaker.

----  I also have a pot. connected as a voltage divider, for MAIN VOLUME CONTROL.

Attached Files



#6 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 15 January 2013 - 12:21 PM

Cool, very creative!

 

You could also try something like they did on the SID chip of the old C64. I think they switched between different octaves rather quickly during each note to create kind of a vibrating note instead of a regular continuous note. This produced very characteristic sounding chords that became somewhat of a C64 trademark.

 

I once saw some code to play 8 channel polyphonic sound using a single PWM output. They used a mixer, a lot like yours I guess, that probably switched between different PWM frequencies during overlapping notes.



#7 RonZon

RonZon

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationWaukesha, WI

Posted 16 January 2013 - 02:02 AM

Awesome idea ! but.. I haven't been able to find any info on that method...  :(

I did find some incredible work by Roman Black at http://www.romanblack.com/picsound.htm

where he creates audio from ONE or TWO digital PIC outputs.

Its actually a ONE-BIT output from a standard 8-bit audio file....

I downloaded the encoding program, and it sounds "ok"....

but,   the key to that requires a stable clock frequency to recreate the sound-stream.

I don't think the Netduino can sustain a 16khz or 44khz data stream with any accuracy to be able to make those sounds.

 

Originally,  with the multiple threads,  I was hoping that the timing would be good enough,

to be able to create some sort of a MIDI equivalent.

But,  I don't think that is possible, unfortunately,  without one of the add-on shields.

SO..ooooooo  ....  instead:

I did make a different version that generates three notes at the same time

(root,  one octave down, and two octave down)

all in  the same thread.   This maintains the timing needed.

Much, much better results than the multi-threading method.

 

NOTE: This is still using PWM outputs 11, 10, and 9, so you need to use a 120ohm resistor (or so) from each input, joined together to go to the speaker....

 

I also added some more example songs, so that there is now 50 to cycle through :-)

 

-Ron

 



#8 RonZon

RonZon

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationWaukesha, WI

Posted 27 January 2013 - 06:51 PM

yayyyyyy !!! It's MIDI time :)

I am almost complete with a new version here.

I have completely re-written the program as a standard format MIDI file player (*.mid files).

There can be up to 6 notes (polyphonic) at a time!!!

No longer limited to the single note ring tone format.

....  and all of this WITHOUT needing to buy an add-on board.

Of course,  these are still just TONES,  no actual instrument voices,  BUT it sounds pretty darn good.

 

I have attached a copy of the current project, along with a video.

I will be completing the project and then re-posting as a new showcase, when done ( and with a better quality video ).

This week I am going to work on an actual MIXER circuit using a LM358 IC, and a few more tweaks.

But, as-is,  it works VERY WELL.

 

Please check out the video, and let me know what you think so far....

 

Video on YouTube:

 

Also, to note ---

MIDI files should be TYPE 0, which is all instuments in one track.
Use a Midi type converter, such as:

http://web.archive.o...gs/software.htm

 

And ---  similar to my RTTTL player,  I am using all 6 of the PWM channels.

An easy way of mixing them is to use a 110ohm resistor from each channel tied together, and then going to the + speaker lead. I also have a potentiometer connected as a main volume control.

(in this video, I only am using 4 channels. You can select the Maximum to use in the program)

 

The MIDI file should be loaded onto the SD card.

You can also use a HEX convertor, such as HxD Hex Editor, and embed the BYTES into the program:

http://mh-nexus.de/en/programs.php

In this program,  open your Format 0 midi file, and export to C#. That creates a *.CS file you can open in Visual Studio.

 

Attached Files



#9 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 28 January 2013 - 06:06 AM

Wow, that is just so cool and very impressive!

 

So you implemented a MIDI file parser on the Netuino then?

 

I should really try and get this running on the mini, however I need to connect an SD card reader for the MIDI files and suddenly it would require more time than I can afford.

 

Another idea would be to also implement a real time MIDI player using the UART @ 31250 8N1 connected to a PC and later to the MIDI out of a MIDI enabled keyboard or even a digital piano. This would omit the need of an SD card reader plus I guess parsing MIDI-packets over serials is simpler that parsing MIDI files.

 

There are cheap separate piano-looking MIDI keypads like this one from Akai:

http://www.ebay.com/...=item35c3543779

 

A bit pointless perhaps but it would be so cool for me to sit on my wife's digital piano and play through a beeper. Love to hear what it would sound like.

 

Do you implement the effects of notes being played according to how hard the "key was pressed" too and what about not bending and such?

 

I trust there are no drums, that would be asking too much of course.

 

From the images, I see you snuck a potentiometer directly into the N+ header, I suppose this is for volume?

 

Do you use some kind of amplifier to drive that (8 ohm?) loudspeaker or are you actually driving it directly from the PWM pis via the "resistor mixer" - I didn't think that was possible due to the currents and inductiveness of the speaker?

 

There are these cheap 2 x 3W miniature D-class amplifiers:

http://www.ebay.com/...=item1c2f901497

 

The h/w mixer seem to have just 4 channels, are the other two implemented i software?

 

Got schematics to share?

 

That was a lot of questions, I'm just curious  :)



#10 RonZon

RonZon

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationWaukesha, WI

Posted 29 January 2013 - 01:59 AM

Thank you.

 

Yes, the code is a complete MIDI file parser.  All valid events are decoded.  Only SOME of them are used though....

Mainly:  TEMPO,  Ticks-Per-Quarter-Note, Channel #,   NOTE-NUMBER,  and  ticks-delay between events.

Basically the first two set up the timing and resolution of the song.

Then each channel is monitored for either a note-ON or note-OFF command.

VOLUME is really not possible with standard PWM outputs.

 

In-between each "event", there is whats called the "ticks-delay". Basically it is a count to wait until the next event.

If this is 0 (zero) than the events are considered simultaneous.

 

I have 6 PWM channels set up and able to play.

So, basically, this means up to SIX tones can be played at the same time.  POLYPHONIC !!!!  :-)

Each time a new note is requested,  it looks for an available channel to play on.

If there aren't any channels left,  the event is just ignored.

For a lot of songs, this works just fine.   SOME songs are extremely busy with a lot of instruments going on, and don't work as well.

I did build in the ability to limit the number of channels to monitor, though, which helps this issue.

 

Please note,  like I mentioned above:  I only had 4 resistors connected in the posted video. 

You do need a resistor connected to each channel if you want to use it.

You can also set the maximum number of PWM's to play at the same time. 

 

I am currently working on a simple Op-Amp summing circuit to do a better job of mixing the output.

I will post when I am complete with it.

I will also post a better description of everything going on, schematics, etc..... if anyone would like.

I do have lots of comments and regions marked in my code...  trying to make it as readable as possible.

 

I am not bothering with an audio amp (yet, at least), I will just be using a 1/8" headphone jack which

can easily attach to a number of available audio amps if I ever wanted to CRANK UP the cheesy MIDI craziness !!  :-)

With the simple resistor mixer,  the volume is QUITE SUFFICIENT with any old PC speaker.

In fact, I added the potentiometer to tame it down... I was driving the girlfriend crazy with the wonderful sounds. haha :)

 

OH, and again....   you should be able to adapt this code to any of the netduinos.

You DON'T NEED AN SD-CARD.

You can embed the bytes of the MIDI song into the code. Use HxD hex editor (or similar) and export the file as a *.CS.

It should work fine with your MINI.   Just be careful of the size of the code.  Stick with smaller songs.

 

-Ron



#11 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 29 January 2013 - 05:47 AM

Ok, but even as MIDI files are very compact (especially when comared to digitally sampled music), can you really fit whole songs onto flash?

 

I've been fiddeling with MIDI a bit myself but mostly on the hardware side of things, which (as you know) is basically only 32150 baud 8N1 serial communication.

 

I still can't help wondering what real time MIDI would sound like when playing it on a digital piano.







Also tagged with one or more of these keywords: rtttl, rttl, music, player, web, server, webpage, controller, ring, tone

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.