Difference between revisions of "Tutorials/VEX Speaker module"

From ROBOTC API Guide
Jump to: navigation, search
 
(3 intermediate revisions by one user not shown)
Line 3: Line 3:
 
<br />
 
<br />
  
{| width="740px"
+
{|  
|-
+
|VEX Robotics just announced (and released) their new Speaker accessory for the VEX Cortex Microcontroller. This cool new speaker will allow you to play tones, sounds and wave (.wav) sound files from your VEX Cortex. The new speaker plugs into the “SP” port on the Cortex – check near the bottom of the sensor bank of ports. The speaker even has a built in volume control:
|[[Image:Tut-vex-speaker.jpg|left|thumb|VEX Speaker]]
+
|style="vertical-align: top;"|Got a new VEX Speaker?
+
 
+
 
+
VEX Robotics just announced (and released) their new Speaker accessory for the VEX Cortex Microcontroller. This cool new speaker will allow you to play tones, sounds and wave (.wav) sound files from your VEX Cortex. The new speaker plugs into the “SP” port on the Cortex – check near the bottom of the sensor bank of ports. The speaker even has a built in volume control:
+
  
  
Line 19: Line 14:
 
Wiki Link: [[VEX2_Functions_Sound]]
 
Wiki Link: [[VEX2_Functions_Sound]]
  
To help you get started, here are two sample programs to try out your new VEX speaker attachment.
+
To help you get started, here are two sample programs to try out your new VEX speaker attachment.  
 +
 
 +
|[[Image:Tut-vex-speaker.jpg|left|thumb|VEX Speaker]]
 
|}
 
|}
 
<br />
 
<br />
Line 33: Line 30:
  
 
== Uploading Sound Files to the Cortex ==
 
== Uploading Sound Files to the Cortex ==
 +
Before you can start using the VEX Speaker with ROBOTC, you must first move the sound files you wish to use onto the Cortex. The sound files must be formatted for 8-bit, 8.000 kHz, Mono output and saved as a .wav (waveform audio file format) file. You can use a free, open source program called Audacity to perform this conversion.
 +
 +
'''1)''' Download and install Audacity from their download site, http://audacity.sourceforge.net/ <br /><br />
 +
 +
'''2)''' Open Audacity and open the file you wish to convert (File -> Open).<br /><br />
 +
 +
'''3)''' Play the opened sound file to ensure Audacity was able to read it properly by pressing the green 'Play' button.<br /><br />
 +
 +
[[File:PlayButton.jpg]]<br /><br />
 +
 +
'''4)''' In the bottom left corner of the screen, change the 'Project Rate (Hz)' setting to 8000 Hz.<br /><br />
 +
 +
[[File:Project_Rate.jpg]]<br /><br />
 +
 +
'''5)''' Navigate to the File menu and select 'Export'. A window will pop up asking you how and where you would like to save the file. Choose an appropriate file location and change the 'Save as type:' drop menu to 'Other uncompressed files', then click the 'Options' button.<br /><br />
 +
 +
[[File:Export_Type.png]]<br /><br />
 +
 +
'''6)''' Another window will pop up labelled 'Specify Uncompressed Options'. Select 'WAV (Microsoft)' for the Header option and 'Unsigned 8 bit PCM' for the Encoding, then click OK.<br /><br />
 +
 +
[[File:Specify_Uncompressed.png]]<br /><br />
 +
 +
'''7)''' On the Export File page click 'Save' to save the file to your computer. A window will pop up labelled 'Edit Metadata'. You must click select all of the information provided (including any blank cells) and click the 'Remove' button. There will still be some Tag titles remaining; this is normal. Once the information is removed, click the 'OK' button to save the file.<br /><br />
 +
 +
[[File:Edit_Metadata.png]]<br /><br />
 +
 +
'''8)''' With the Cortex connect to the computer and turned on, open ROBOTC and navigate to the 'Robot -> Advanced Tools -> File Management' window.<br /><br />
 +
 +
[[File:File_Management.png]]<br /><br />
 +
 +
'''9)''' On the right hand side of the window, click the 'Download' button and select the formatted audio file. Once the file is uploaded it will appear in the Cortex's file list and the window can be closed.<br /><br />
 +
 +
[[File:File_Download.jpg]]<br /><br />
 +
 +
'''10)''' Now that the file is on the Cortex, you can access it via code by using the 'PlaySoundFile("filename.wav");' command.<br /><br />
  
 
== Example Code ==
 
== Example Code ==

Latest revision as of 21:29, 19 November 2012

Tutorials → VEX Speaker module


VEX Robotics just announced (and released) their new Speaker accessory for the VEX Cortex Microcontroller. This cool new speaker will allow you to play tones, sounds and wave (.wav) sound files from your VEX Cortex. The new speaker plugs into the “SP” port on the Cortex – check near the bottom of the sensor bank of ports. The speaker even has a built in volume control:


Check out our cool unboxing photos below, exclusive from the VEX World Championships!


The awesome thing with this new speaker accessory is that ROBOTC already has support for this new speaker built into version 3.08! For more information on how to use the speaker, check the ROBOTC help documentation built into ROBOTC, or look at our new (under construction) ROBOTC code wiki!

Wiki Link: VEX2_Functions_Sound

To help you get started, here are two sample programs to try out your new VEX speaker attachment.

VEX Speaker


Unboxing


Uploading Sound Files to the Cortex

Before you can start using the VEX Speaker with ROBOTC, you must first move the sound files you wish to use onto the Cortex. The sound files must be formatted for 8-bit, 8.000 kHz, Mono output and saved as a .wav (waveform audio file format) file. You can use a free, open source program called Audacity to perform this conversion.

1) Download and install Audacity from their download site, http://audacity.sourceforge.net/

2) Open Audacity and open the file you wish to convert (File -> Open).

3) Play the opened sound file to ensure Audacity was able to read it properly by pressing the green 'Play' button.

PlayButton.jpg

4) In the bottom left corner of the screen, change the 'Project Rate (Hz)' setting to 8000 Hz.

Project Rate.jpg

5) Navigate to the File menu and select 'Export'. A window will pop up asking you how and where you would like to save the file. Choose an appropriate file location and change the 'Save as type:' drop menu to 'Other uncompressed files', then click the 'Options' button.

Export Type.png

6) Another window will pop up labelled 'Specify Uncompressed Options'. Select 'WAV (Microsoft)' for the Header option and 'Unsigned 8 bit PCM' for the Encoding, then click OK.

Specify Uncompressed.png

7) On the Export File page click 'Save' to save the file to your computer. A window will pop up labelled 'Edit Metadata'. You must click select all of the information provided (including any blank cells) and click the 'Remove' button. There will still be some Tag titles remaining; this is normal. Once the information is removed, click the 'OK' button to save the file.

Edit Metadata.png

8) With the Cortex connect to the computer and turned on, open ROBOTC and navigate to the 'Robot -> Advanced Tools -> File Management' window.

File Management.png

9) On the right hand side of the window, click the 'Download' button and select the formatted audio file. Once the file is uploaded it will appear in the Cortex's file list and the window can be closed.

File Download.jpg

10) Now that the file is on the Cortex, you can access it via code by using the 'PlaySoundFile("filename.wav");' command.

Example Code

Sound Test:

task main()
{
  //Basic "Play Sound" commands
  PlaySound(soundBeepBeep);
  wait1Msec(200);
 
  //Intelligent "Play Sound" command
  //Delay until sound is done playing
  PlaySound(soundFastUpwardTones);
  while(bSoundActive)
  wait1Msec(1);
 
  //Play a tone:
  //First Parameter: Frequence in Hz
  //Second Parameter: Length to play in 1/100th of a seconds (50 = .5 seconds)
  PlayTone(440, 50);
  wait1Msec(500);
 
  //Play a Sound File (need to use the File Management to Upload First)
  PlaySoundFile("1.wav");
  wait1Msec(1000);
}


Sample Program Downloads


PowerPoint explaining VEX Speaker


Sound Files