|
|||||||
| Technical Discussion Open Technical Discussion of the VEX Robotics System. |
![]() |
|
|
Thread Tools |
|
#1
|
||||
|
||||
|
EasyC 4 sound library for cortex
So I'm posting a project for everyone to BETA TEST as it's not really production code.
This project is a demo for a sound library I hacked together today that allows tones to be played both synchronously and asynchronously from EasyC on the cortex. The demo is tested using EasyC V 4.1.0.3 and plays mission impossible (thanks ROBOTC) while driver control is running. User functions are as follows. Code:
void PlayFrequency( int freq, int amplitude, int timems ); void PlayFrequencyWait( int freq, int amplitude, int timems ); void ClearSounds( void ); PlayFrequencyWait is the same but blocks until the sound is done. ClearSounds just stop the currently playing sound. There are also alternative functions to play tones in the background. Probably best not to mix these with the above, use one or the other. Code:
void InitChipToneMusic( int len ); void SetNextTone( int freq, int amplitude, int timems ); void StartChipTone( int repeat ); See the included example on how to use but it goes basically like this. Code:
// play mission impossible asynchronously
void
MissionImpossible()
{
InitChipToneMusic( 66 );
//
SetNextTone( 880, 128, 70); // Note(D, Duration(32th))
SetNextTone( 933, 128, 70); // Note(D#, Duration(32th))
SetNextTone( 880, 128, 70); // Note(D, Duration(32th))
// skipped code
SetNextTone( 932, 128, 140); // Note(A#5, Duration(16th))
SetNextTone( 784, 128, 140); // Note(C, Duration(16th))
SetNextTone( 0, 128, 500); //
StartChipTone(1); // 1 means repeat
return;
}
Hopefully Intelitek will have some official code soon. Enjoy Last edited by jpearman; 04-29-2012 at 07:04 PM. |
|
#3
|
||||
|
||||
|
Re: EasyC 4 sound library for cortex
Actually, here is an update, now you can play ring tones directly in RTTTL format such as.
Code:
char tune4[] = "Beethoven:d=4,o=6,b=125:8e,8d,8e,8d,8e,8b5,8d,8c,a5,8p,8c5,8e5,8a5,b5,8p,8e5,8g5,8b5,c,8p,8e5,8e,8d,8e,8d,8e,8b5,8d,8c,a5,8p,8c5,8e5,8a5,b5,8p,8e5,8c,8b5,a5"; Code:
PlayRtttl( tune5, 128, 1 ); The demo has 5 tunes included, change using joystick button 8R and 8L. There are dozens of RTTTL tunes on the internet, anything you want. Enjoy Last edited by jpearman; 04-29-2012 at 07:04 PM. |
|
#4
|
|||
|
|||
|
Re: EasyC 4 sound library for cortex
Do I just download the code straight into my cortex and have the speaker in the speaker port?
Edit: is there any way I can use a speaker on a microcontroller? I am working on a project currently and im using an old brain that we have and I would like to use my new speaker. Last edited by devinc; 04-26-2012 at 07:43 PM. |
|
#5
|
||||
|
||||
|
Re: EasyC 4 sound library for cortex
Quote:
If you want to add this to a new project the following files should be moved into the project directory. vsl.h vsl.c vslrtttl.c the vsl_include folder with everything in it. vsl.c and vslrtttl.c need to be added as user source files and the following added to the UserInclude.h file along with any functions you use to call them. Code:
void PlayFrequency( int freq, int amplitude, int timems ); void ClearSounds( void ); void InitChipToneMusic( int len ); void SetNextTone( int freq, int amplitude, int timems ); void StartChipTone( int repeat ); char *PlayRtttl( char *song , int amplitude, int repeat ); Quote:
|
|
#7
|
||||
|
||||
|
Re: EasyC 4 sound library for cortex
|
|
#8
|
||||
|
||||
|
Re: EasyC 4 sound library for cortex
Quote:
If you can chain into an interrupt handler under EasyC, then you could get it to work with one of the I/O ports. Instead of PIC support, I can offer a utility function for ROBOTC+Cortex that lets you pass in a music string and play it as a series of notes/rests. Here is the wiki page. Cheers, - Dean |
|
#9
|
||||
|
||||
|
Re: EasyC 4 sound library for cortex
Quote:
|
|
#10
|
|||
|
|||
|
Re: EasyC 4 sound library for cortex
I tried your code out today. it worked perfectly. it was really weird hearing super mario and pac man coming out of my robot. I really hope that the speaker is not legal in competition because it got annoying just after a few seconds.
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|