Input data from Line-in is output to Line-out.

Dependencies:   R_BSP TLV320_RBSP mbed-rtos mbed

Input data from Line-in is output to Line-out.

Please refer to following link about Audio/Camera Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

Committer:
Osamu Nakamura
Date:
Tue Mar 14 17:54:42 2017 +0900
Revision:
3:d3782a74823f
Parent:
2:ab3033c3bb17
Replaced mbed os classic with mbed os 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:480b6b28ead4 1 #include "mbed.h"
dkato 0:480b6b28ead4 2 #include "TLV320_RBSP.h"
dkato 0:480b6b28ead4 3
dkato 0:480b6b28ead4 4 #define WRITE_BUFF_NUM (16)
dkato 0:480b6b28ead4 5 #define READ_BUFF_SIZE (4096)
dkato 0:480b6b28ead4 6 #define READ_BUFF_NUM (16)
dkato 0:480b6b28ead4 7 #define MAIL_QUEUE_SIZE (WRITE_BUFF_NUM + READ_BUFF_NUM + 1)
dkato 0:480b6b28ead4 8 #define INFO_TYPE_WRITE_END (0)
dkato 0:480b6b28ead4 9 #define INFO_TYPE_READ_END (1)
dkato 0:480b6b28ead4 10
dkato 1:8790a736df31 11 TLV320_RBSP audio(P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7, P4_6, 0x80, WRITE_BUFF_NUM, READ_BUFF_NUM); // I2S Codec
dkato 0:480b6b28ead4 12
dkato 0:480b6b28ead4 13 typedef struct {
dkato 0:480b6b28ead4 14 uint32_t info_type;
dkato 0:480b6b28ead4 15 void * p_data;
dkato 0:480b6b28ead4 16 int32_t result;
dkato 0:480b6b28ead4 17 } mail_t;
dkato 0:480b6b28ead4 18 Mail<mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:480b6b28ead4 19
dkato 2:ab3033c3bb17 20 #if defined(__ICCARM__)
dkato 2:ab3033c3bb17 21 #pragma data_alignment=4
dkato 2:ab3033c3bb17 22 static uint8_t audio_read_buff[READ_BUFF_NUM][READ_BUFF_SIZE]@ ".mirrorram"; //4 bytes aligned! No cache memory
dkato 2:ab3033c3bb17 23 #else
dkato 0:480b6b28ead4 24 static uint8_t audio_read_buff[READ_BUFF_NUM][READ_BUFF_SIZE] __attribute((section("NC_BSS"),aligned(4))); //4 bytes aligned! No cache memory
dkato 2:ab3033c3bb17 25 #endif
dkato 0:480b6b28ead4 26
dkato 0:480b6b28ead4 27 static void callback_audio_tans_end(void * p_data, int32_t result, void * p_app_data) {
dkato 0:480b6b28ead4 28 mail_t *mail = mail_box.alloc();
dkato 0:480b6b28ead4 29
dkato 0:480b6b28ead4 30 if (result < 0) {
dkato 0:480b6b28ead4 31 printf("error %d\n", result);
dkato 0:480b6b28ead4 32 }
dkato 0:480b6b28ead4 33 if (mail == NULL) {
dkato 0:480b6b28ead4 34 printf("error mail alloc\n");
dkato 0:480b6b28ead4 35 } else {
dkato 0:480b6b28ead4 36 mail->info_type = (uint32_t)p_app_data;
dkato 0:480b6b28ead4 37 mail->p_data = p_data;
dkato 0:480b6b28ead4 38 mail->result = result;
dkato 0:480b6b28ead4 39 mail_box.put(mail);
dkato 0:480b6b28ead4 40 }
dkato 0:480b6b28ead4 41 }
dkato 0:480b6b28ead4 42
dkato 0:480b6b28ead4 43 void audio_read_task(void const*) {
dkato 0:480b6b28ead4 44 uint32_t cnt;
dkato 0:480b6b28ead4 45 rbsp_data_conf_t audio_write_data = {&callback_audio_tans_end, (void *)INFO_TYPE_WRITE_END};
dkato 0:480b6b28ead4 46 rbsp_data_conf_t audio_read_data = {&callback_audio_tans_end, (void *)INFO_TYPE_READ_END};
dkato 0:480b6b28ead4 47
dkato 0:480b6b28ead4 48 // Read buffer setting
dkato 0:480b6b28ead4 49 for (cnt = 0; cnt < READ_BUFF_NUM; cnt++) {
dkato 0:480b6b28ead4 50 if (audio.read(audio_read_buff[cnt], READ_BUFF_SIZE, &audio_read_data) < 0) {
dkato 0:480b6b28ead4 51 printf("read error\n");
dkato 0:480b6b28ead4 52 }
dkato 0:480b6b28ead4 53 }
dkato 0:480b6b28ead4 54
dkato 0:480b6b28ead4 55 while (1) {
dkato 0:480b6b28ead4 56 osEvent evt = mail_box.get();
dkato 0:480b6b28ead4 57 if (evt.status == osEventMail) {
dkato 0:480b6b28ead4 58 mail_t *mail = (mail_t *)evt.value.p;
dkato 0:480b6b28ead4 59
dkato 0:480b6b28ead4 60 if ((mail->info_type == INFO_TYPE_READ_END) && (mail->result > 0)) {
dkato 0:480b6b28ead4 61 audio.write(mail->p_data, mail->result, &audio_write_data);
dkato 0:480b6b28ead4 62 } else {
dkato 0:480b6b28ead4 63 audio.read(mail->p_data, READ_BUFF_SIZE, &audio_read_data); // Resetting read buffer
dkato 0:480b6b28ead4 64 }
dkato 0:480b6b28ead4 65 mail_box.free(mail);
dkato 0:480b6b28ead4 66 }
dkato 0:480b6b28ead4 67 }
dkato 0:480b6b28ead4 68 }
dkato 0:480b6b28ead4 69
dkato 0:480b6b28ead4 70 int main() {
dkato 0:480b6b28ead4 71 #if(0)
dkato 0:480b6b28ead4 72 // Microphone
dkato 0:480b6b28ead4 73 audio.mic(true); // Input select for ADC is microphone.
dkato 0:480b6b28ead4 74 audio.power(0x00); // mic on
dkato 0:480b6b28ead4 75 #else
dkato 0:480b6b28ead4 76 // Line in
dkato 0:480b6b28ead4 77 audio.power(0x02); // mic off
dkato 0:480b6b28ead4 78 #endif
dkato 0:480b6b28ead4 79 audio.inputVolume(0.7, 0.7);
dkato 0:480b6b28ead4 80
dkato 0:480b6b28ead4 81 Thread audioReadTask(audio_read_task, NULL, osPriorityNormal, 1024 * 8);
dkato 0:480b6b28ead4 82
dkato 0:480b6b28ead4 83 while(1) {
dkato 0:480b6b28ead4 84 Thread::wait(500);
dkato 0:480b6b28ead4 85 }
dkato 0:480b6b28ead4 86 }