[SOLVED]Audio codec shield with Arduino Due

Re: Audio codec shield with Arduino Due

Postby youthreewire » Thu Jun 11, 2015 7:16 am

So,What is left_in,left_out, right_in and right_out in this code? How do I manipulate these to just echo and playback with little delay like in the example fixed_delay etc. I could not understand when you wrote this
Code: Select all
left = (temp_spi[0] << 8) | temp_spi[1];
right = (temp_spi[2] << 8) | temp_spi[3];
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Thu Jun 11, 2015 11:21 am

Code: Select all
left_in = (temp_spi[0] << 8) | temp_spi[1];
right_in = (temp_spi[2] << 8) | temp_spi[3];


Code: Select all
temp = left_out;
temp1 = right_out;
temp_spi[0] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
temp_spi[1] = SPI.transfer(10,lowByte(temp),SPI_CONTINUE);
temp_spi[2] = SPI.transfer(10,highByte(temp1),SPI_CONTINUE);
temp_spi[3] = SPI.transfer(10,lowByte(temp1),SPI_LAST);
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sat Jun 13, 2015 7:27 am

So what could be connection diagram for Due? I2C I know.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Sat Jun 13, 2015 11:58 am

i dont know much about the DUE, i dont own one and have never used one. if you find an I2S library for it, that will probably also have a connection diagram.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Jun 14, 2015 5:06 am

You mentioned this code left_in and right_in
Code: Select all
left_in = (temp_spi[0] << 8) | temp_spi[1];
        right_in = (temp_spi[2] << 8) | temp_spi[3];

But where are we mapping left_out and right_out in the device? You just declared them as temp variables. Like in your library the audio_codec_init function takes all these four parameters but here how do we map it?
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Jun 14, 2015 6:00 am

I want to convert this function.I understand the following code attempts to do what AudioCodecMega_data( does.

AudioCodecMega_data( function definition from official library:
Code: Select all
static inline void AudioCodecMega_data(int* _lin, int* _rin, int _lout, int _rout) {
  int _out_temp = _lout;
  PORTB |= (1<<PORTB0);  // toggle ss pina
  asm volatile ("out %0, %B1" : : "I" (_SFR_IO_ADDR(SPDR)), "r" (_out_temp) );
  PORTB &= ~(1<<PORTB0); // toggle ss pin
  while(!(SPSR & (1<<SPIF))){ // wait for data transfer to complete
  }
  asm volatile ("out %0, %A1" : : "I" (_SFR_IO_ADDR(SPDR)), "r" (_out_temp) );
  asm volatile ("in r3, %0" : : "I" (_SFR_IO_ADDR(SPDR)) );
  _out_temp = _rout;
  while(!(SPSR & (1<<SPIF))){ // wait for data transfer to complete
  }
  asm volatile ("out %0, %B1" : : "I" (_SFR_IO_ADDR(SPDR)), "r" (_out_temp) );
  asm volatile ("in r2, %0" : : "I" (_SFR_IO_ADDR(SPDR)) );
  asm volatile ("movw %0, r2" : "=r" (*_lin) : );
  while(!(SPSR & (1<<SPIF))){ // wait for data transfer to complete
  }
  asm volatile ("out %0, %A1" : : "I" (_SFR_IO_ADDR(SPDR)), "r" (_out_temp) );
  asm volatile ("in r3, %0" : : "I" (_SFR_IO_ADDR(SPDR)) );
  while(!(SPSR & (1<<SPIF))){ // wait for data transfer to complete
  }
  asm volatile ("in r2, %0" : : "I" (_SFR_IO_ADDR(SPDR)) );
  asm volatile ("movw %0, r2" : "=r" (*_rin) : );
}


The code for Due which attempts to as the above code but no knowledge of _rout/right_ out and _lout/left_out
Code: Select all
void TC3_Handler()
{
        TC_GetStatus(TC1, 0);

        temp = random(65535);
        temp1 = left_out;
        temp2 = right_out;
       
        temp_spi[0] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
        temp_spi[1] = SPI.transfer(10,lowByte(temp),SPI_CONTINUE);
        temp_spi[2] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
        temp_spi[3] = SPI.transfer(10,lowByte(temp),SPI_LAST);
        left_in = (temp_spi[0] << 8) | temp_spi[1];
        right_in = (temp_spi[2] << 8) | temp_spi[3];
       
}
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Sun Jun 14, 2015 12:32 pm

_rout is only needed because the code is in the library, otherwise just declaring your variable right_out is enough.

the very first hit on google for "arduino due i2s library" gave me this:
https://github.com/delsauce/ArduinoDueHiFi (which is linked from the arduino website itself as the reccomended i2s library, so it probably works)

if you are going to spend a bunch of time getting a library to work with the codec shield, you might as well have a good starting point.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Jun 14, 2015 9:18 pm

I have seen the I2S library and I wanted to mention the same but you already did. I think your code is straightforward. I have most of them ported but just the AudioCodecMega_data function has to be ported.I do not understand what you are trying to do in the assembly here.I found one more thread but incomplete here:
http://forum.arduino.cc/index.php?topic=267937.0
So left_out and right_out are used in the functions so how do I replicate it through here
Code: Select all
void TC3_Handler()
{
        TC_GetStatus(TC1, 0);

        temp = random(65535);
        temp1 = left_out;
        temp2 = right_out;
       
        temp_spi[0] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
        temp_spi[1] = SPI.transfer(10,lowByte(temp),SPI_CONTINUE);
        temp_spi[2] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
        temp_spi[3] = SPI.transfer(10,lowByte(temp),SPI_LAST);
        left_in = (temp_spi[0] << 8) | temp_spi[1];
        right_in = (temp_spi[2] << 8) | temp_spi[3];
       
}


How will the codec know how to pipe out right_out and left_out?If we just declare them as variables it wont be sufficient. They are to be written to some registers of the WM8731.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Jun 14, 2015 10:53 pm

Also you are using Timer1 in the library and connected one pin SS to T1 in atmega328. In the mega library people changed it to Timer 5 and connected it to T5. Now as the per the new code for Due. TC1 and TC3 Handler are being used so which pin will correspond in functionality to T1 or T5.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Jun 14, 2015 11:38 pm

guest wrote:
Code: Select all
left_in = (temp_spi[0] << 8) | temp_spi[1];
right_in = (temp_spi[2] << 8) | temp_spi[3];


Code: Select all
temp = left_out;
temp1 = right_out;
temp_spi[0] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
temp_spi[1] = SPI.transfer(10,lowByte(temp),SPI_CONTINUE);
temp_spi[2] = SPI.transfer(10,highByte(temp1),SPI_CONTINUE);
temp_spi[3] = SPI.transfer(10,lowByte(temp1),SPI_LAST);

Could you tell me more clearly as to how the left_in is being mapped to left_out. Because WM8731 should also know how to set its output. Dont you think we have to use SPI to write the output out as well.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

PreviousNext

Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron