Fireduino/Fireduino Audio play net Music

来自Firefly wiki
跳转至: 导航搜索

Fireduino Audio

Fireduino internal integration of the HIFI level high quality of audio decoder,professional hardware accelerators to decode MP3,low loss decoded audio hardware accelerators and rich peripherals,support wi-fi protocol,support 24bits 192k Hz sampling rate,low loss,low power consumption of audio decoding.
Fireduino support to play audio files on the SD card and network, support the format APE/FLAC/WAV/MP3/WMA/AAC/OGG;

Fireduino Audio library

Fireduino is very good in audio decoding,using the API of Audio library allows users to more easy to use audio development.Fireduino provides audio interface is as follows:

Earphone jack.jpg

FireDuino audio.jpg

Fireduino Audio play the TF music

This case demonstrates how the Fireduino play the music files via TF cache on the network,at regular intervals to judge whether the play stop and continue play next one or loop.

Hardware requirement

1.Fireduino board
2.TF Card
3.Network music file

Code

Before start

Before using Audio,wifi and TF Card,first of all have to include Audio,wifi and TF library header files

#include "TF.h"
#include "Audio.h"
#include <WiFi.h>

build http server

Here is building the http server via HFS,as shown below:

FireDuino hfs.jpg

setup()

1.Initialize the serial port,to convenient print debugging information for later.
2.Initialize TF card,and need the network cache file of TF for later.
3.Initialize WiFi,and need to connected to the Internet to download the audio file for decoding.
4.Through a serial port to print network connection information.
5.Initialize Audio,and use the way of AUDIO_NET.
6.If initialize Audio successfully,play the MP3 file specified network address.

void setup() {
	Serial.begin(115200);
	Serial.print("\r\narduino setup ...\r\n");
	if(!SD.begin())
	{
		Serial.println("sd init err\r\n");
		while(1);
	}
	// check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    // delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
  Audio.begin(AUDIO_NET);
  Audio.playNetFile("http://192.168.199.240/%E6%89%93%E8%80%81%E8%99%8E.MP3");
}

loop()

1.Get the status of Audio state machine.
2.Judge if the status of decoding is stop status.
3.If it's to stop status,continue to decode the specified file.

void loop() {
	Serial.println("loop");
	delay(2000);
	if(Audio.getStatus() == AudioStop)
	{
		Audio.playNetFile("http://192.168.199.240/%E6%89%93%E8%80%81%E8%99%8E.MP3");
	}
}

Example program -- play online music

Code

#include <Arduino.h>
#include "TF.h"
#include "Audio.h"
#include <WiFi.h>
char ssid[] = "Fireduino";     //  your network SSID (name)
char pass[] = "12345678";  // your network password
int status = WL_IDLE_STATUS;
void printWifiStatus();
void setup() {
	Serial.begin(115200);
	Serial.print("\r\narduino setup ...\r\n");
	if(!SD.begin())
	{
		Serial.println("sd init err\r\n");
		while(1);
	}
	// check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    // delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
	Audio.begin(AUDIO_NET);
	Audio.playNetFile("http://192.168.199.240/%E6%89%93%E8%80%81%E8%99%8E.MP3");
}
void loop() {
	Serial.println("loop");
	delay(2000);
	if(Audio.getStatus() == AudioStop)
	{
		Audio.playNetFile("http://192.168.199.240/%E6%89%93%E8%80%81%E8%99%8E.MP3");
	}
}
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Serial printing information

As shown below:

FireDuino net audio debug.jpg