Fireduino/audio

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

Fireduino Audio

Fireduino internal integration of HIFI level of high-quality audio decoder, specialized hardware accelerators to decode MP3, low-loss audio decoding hardware accelerators and rich peripheral support WI-FI protocol, support 24bits 192k Hz sampling rate, low loss, low power consumption audio decoding.

Fireduino support playback on SD cards and network audio file decoding format support APE / FLAC / WAV / MP3 / WMA / AAC / OGG;

Fireduino Audio API providing the operating of play, pause, stop, and set and get the volume。

Fireduino Audio Struct

// playing status
typedef enum
{
	AudioFailed = 0,
	AudioPlay ,
	AudioPause ,
	AudioStop ,
}AudioStatus;
typedef enum
{
	AUDIO_SD,         // SD
	AUDIO_NET    	  // NET
}Storage;

Fireduino Audio API

begin(...)

   Description 
       Initialization Audio.
Syntax Audio.begin(AUDIO_NET); Audio.begin(AUDIO_SD);
Parameter Storage:AUDIO_SD、AUDIO_NET
Returns None

playFile(...)

   Description
       Play the specified file.
Syntax Audio.playFile("\\4.MP3");
Parameter char * :File path
Returns None

playNetFile(...)

   Description 
       Address broadcasting network resources (support only http protocol).
Syntax Audio.playNetFile("http://192.168.199.240/%E6%89%93%E8%80%81%E8%99%8E.MP3");
Parameter char* : network address resources.
Returns None

setVolume(...)

   Description 
       Setting the sound volume
Syntax Audio. setVolume(16);
Parameter int :Sound volume(0~31)
Returns None

getVolume(...)

   Description 
       Get sound size.
Syntax Audio. getVolume();
Parameter None
Returns Volume value

pause()

   Description 
       Pause playback.
Syntax Audio. pause();
Parameter None
Returns None

resume()

   Description 
       Resume playback.
Syntax Audio. resume();
Parameter None
Returns None

stop()

   Description 
       Stop play.
Syntax Audio. stop();
Parameter None
Returns None

getStatus()

   Description 
       Get playback.
Syntax Audio. getStatus();
Parameter None
Returns return status

end()

   Description 
       End use Audio, and begin the opposite.
Syntax Audio. end();
Parameter None
Returns None

Fireduino Audio Example

#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;
 
//#define PLAY_SD
 
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);
	}
#ifndef PLAY_SD
  // 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();	
#endif
 
#ifdef PLAY_SD
	Audio.begin(AUDIO_SD);
	if(Audio)
	{
		Audio.playFile("\\4.MP3");
	}
#else
	Audio.begin(AUDIO_NET);
	Audio.playNetFile("http://192.168.199.240/%E6%89%93%E8%80%81%E8%99%8E.MP3");
#endif
}
 
void loop() {
	Serial.println("loop");
#ifdef PLAY_SD
	if(Audio.getStatus() == AudioStop)
	{
		Audio.playFile("\\3.MP3");
	}
#else
	if(Audio.getStatus() == AudioStop)
	{
		Audio.playNetFile("http://192.168.199.240/%E6%89%93%E8%80%81%E8%99%8E.MP3");
	}
#endif
}
 
#ifndef PLAY_SD
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");
}
#endif