Skip to content

Commit

Permalink
Merge pull request #3 from RAKWireless/1.0.3
Browse files Browse the repository at this point in the history
1.0.3 version
  • Loading branch information
nerodu committed Sep 23, 2022
2 parents 714c688 + 99fc999 commit 84b7496
Show file tree
Hide file tree
Showing 54 changed files with 183,425 additions and 14,619 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,27 @@ The examples can be separated 4 parts. The test code is just for test and can be

![play3](assets/play3.png)

#### How to general header from
#### How to general header from WAV

#### WAV
First you need put your WAV file with the WAVconvert.py in the same folder.

Please use the python in tool, and put your WAV at the same place, run **python .\WAVconvert.py**
![](assets/convert1.png)

![](assets/python.jpg)
Second, run the CMD console program.

![](assets/convert2.png)

Third, enter the "**python ./WAVconvert.py**" command and run .If your computer not installed the Python environment you can download the python by this link:https://www.python.org/downloads/.

![](assets/convert3.png)

After convert done, the converted .h file name is the same as your WAV name.

![](assets/convert4.png)

Then, open the .h file and copy the sound buffer to replace the example's sound buffer.

![](assets/convert5.png)



Expand Down
Binary file added assets/convert1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/convert2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/convert3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/convert4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/convert5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7,057 changes: 2,923 additions & 4,134 deletions examples/RAK11200/DSPG_PlayBack/sound.h

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file PlayBack.ino
* @file PlayBack22K.ino
* @author rakwireless.com
* @brief This example use RAK18060 Play mono audio file data with sampling rate of 22.05KHz
* and sampling depth of 16 bits.
Expand Down Expand Up @@ -46,13 +46,16 @@ void setup() {
{
Serial.printf("TAS2560 left init failed\r\n");
}


AMP_Left.set_volume(1);
AMP_Left.set_pcm_channel(LeftMode);

if(!AMP_Right.begin(AMP_RIGTT_ADDRESS))
{
Serial.printf("TAS2560 rigth init failed\r\n");
}

AMP_Left.set_pcm_channel(LeftMode);
AMP_Right.set_volume(1);
AMP_Right.set_pcm_channel(RightMode);

I2S.setSampleBit(16);
Expand Down
File renamed without changes.
78 changes: 78 additions & 0 deletions examples/RAK11200/PlayBack48KHz/PlayBack48KHz.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @file PlayBack48K.ino
* @author rakwireless.com
* @brief This example use RAK18060 Play mono audio file data with sampling rate of 48KHz
* and sampling depth of 16 bits mono.
* @How to convert WAV file to HEX format .h file can use the WAVconvert.py in the 'tool' folder.
* @note This example need use the battery power for the WisBase.
* @version 0.1
* @date 2022-06-20
* @copyright Copyright (c) 2022
*/
#include "audio.h"
#include "sound.h"

TAS2560 AMP_Left;
TAS2560 AMP_Right;

#define AMP_LEFT_ADDRESS 0x4c //amplifier i2c address
#define AMP_RIGTT_ADDRESS 0x4f //amplifier i2c address

int channels = 1; //mono
static const int frequency = 48000; //samplerate 48KHz

void setup() {
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
delay(500);
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 2000)
{
delay(100);
}
else
{
break;
}
}

Serial.println("=====================================");
if(!AMP_Left.begin(AMP_LEFT_ADDRESS))
{
Serial.printf("TAS2560 left init failed\r\n");
}

AMP_Left.set_volume(1);
AMP_Left.set_pcm_channel(LeftMode);
if(!AMP_Right.begin(AMP_RIGTT_ADDRESS))
{
Serial.printf("TAS2560 rigth init failed\r\n");
}

AMP_Right.set_volume(1);
AMP_Right.set_pcm_channel(RightMode);

I2S.setSampleBit(16);
I2S.begin(channels, frequency);
Serial.println("start play");
Serial.println("=====================================");
pinMode(LED_GREEN, OUTPUT);
digitalWrite(LED_GREEN, HIGH);
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_BLUE, HIGH);
}

void loop()
{
int writeByte = I2S.write((void *)sound_buff,sizeof(sound_buff));
if(writeByte>0)
{
delay(150); //Waiting for DMA to transfer remaining data
Serial.println("paly accomplish");
I2S.stop();
}
}
29,457 changes: 29,457 additions & 0 deletions examples/RAK11200/PlayBack48KHz/sound.h

Large diffs are not rendered by default.

48 changes: 38 additions & 10 deletions examples/RAK11200/PlayBackFromSD/PlayBackFromSD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ TPT29555 Expander2(0x25);
TAS2560 AMP_Left;
TAS2560 AMP_Right;

uint8_t m_vol = 64; // volume
int8_t m_balance = 0; // -16 (mute left) ... +16 (mute right)

File audiofile;
static uint32_t f_startPos = 44; //audio data start position
static uint32_t f_readPos = 0; //read audio data position
static uint32_t f_endPos = 0; //audio data end position

typedef enum { LEFTCHANNEL = 0, RIGHTCHANNEL = 1 } SampleIndex;
const uint8_t volumetable[22] = { 0, 1, 2, 3, 4 , 6 , 8, 10, 12, 14, 17,
20, 23, 27, 30 , 34, 38, 43 , 48, 52, 58, 64
}; //22 elements
uint8_t play_flag = 0;

#define WAV_HEAD_LEN 320
Expand Down Expand Up @@ -64,7 +70,7 @@ void listDir( const char * dirname, uint8_t levels);
bool connectFS(fs::FS &fs, const char* path);
void play_wav(const char* file);
void play_task(void);

void setVolume(uint8_t vol);
void setup()
{
pinMode(WB_IO2, OUTPUT);
Expand All @@ -83,7 +89,8 @@ void setup()
{
break;
}
}
}
setVolume(8);
pinMode(LED_GREEN, OUTPUT);
digitalWrite(LED_GREEN, HIGH);
pinMode(LED_BLUE, OUTPUT);
Expand All @@ -100,28 +107,50 @@ void loop()
play_wav("test.wav"); //play test.wav
while (1); //If you need to repeat playback, you can comment out this line.
}
void setVolume(uint8_t vol) { // vol 22 steps, 0...21
if (vol > 21) vol = 21;
m_vol = volumetable[vol];
}
int32_t Gain(int16_t s[2]) {
int32_t v[2];
float step = (float)m_vol / 64;
uint8_t l = 0, r = 0;

if (m_balance < 0) {
step = step * (float)(abs(m_balance) * 4);
l = (uint8_t)(step);
}
if (m_balance > 0) {
step = step * m_balance * 4;
r = (uint8_t)(step);
}

v[LEFTCHANNEL] = (s[LEFTCHANNEL] * (m_vol - l)) >> 6;
v[RIGHTCHANNEL] = (s[RIGHTCHANNEL] * (m_vol - r)) >> 6;

return (v[LEFTCHANNEL] << 16) | (v[RIGHTCHANNEL] & 0xffff);
}
void play_task(void)
{
uint8_t sound_buff[4] = {0};
int16_t sample[2] = {0};
uint32_t data = 0;
SD_CS_low(); //enable the SPI
delay(10);
audiofile.seek(f_startPos);
f_readPos = f_startPos;
memset(sound_buff, 0, sizeof(sound_buff));
Serial.println("start play");
while (f_readPos < f_endPos)
{
int bytes_read = audiofile.read(sound_buff, sizeof(sound_buff));
I2S.write((void *)sound_buff, sizeof(sound_buff));
int bytes_read = audiofile.read((uint8_t*)&sample, sizeof(sample));
uint32_t s32 = Gain(sample); // vosample2lume;
I2S.write((void *) &s32, sizeof(uint32_t));
f_readPos = f_readPos + bytes_read;
}
delay(200);
SD_CS_high(); //disable the SPI CS
I2S.end();
audiofile.close();
Serial.println("stop play");
// while (1);
}
void AMP_init(void)
{
Expand All @@ -130,14 +159,13 @@ void AMP_init(void)
Serial.printf("TAS2560 left init failed\r\n");
delay(500);
}
AMP_Left.set_pcm_channel(LeftMode);

if (!AMP_Right.begin(AMP_RIGTT_ADDRESS))
{
Serial.printf("TAS2560 rigth init failed\r\n");
delay(500);
}

AMP_Left.set_pcm_channel(LeftMode);
AMP_Right.set_pcm_channel(RightMode);
}
void SD_init(void)
Expand Down
Binary file modified examples/RAK11200/PlayBackFromSD/test.wav
Binary file not shown.
Loading

0 comments on commit 84b7496

Please sign in to comment.