Results 1 to 8 of 8

Thread: C Programming with Audio IP Cores

  1. #1
    Join Date
    Mar 2008
    Posts
    6
    Rep Power
    1

    Question C Programming with Audio IP Cores

    I am trying to take an inputted Audio file and trying to save it to the SDRAM (ie recording a word said into a microphone to the memory).

    My system uses a DE2 board with a Nios II Processor and Quartus 7.2 software.
    The Nios II system uses the University program's audio codec IP cores.

    I have created a C program using the functions provided by the audio core (found on the Altera website), but am having trouble saving an audio stream to the memory and then playing it back.

    Below is my code and any help you could provide would be greatly appreciated.

    Thanks,
    Mel



    #include <Z:\try3\app_software\include\alt_up_audio.h>
    #define Switch (volatile char *) 0x01001020

    #define MAX_DATA 4096

    int main()
    {
    unsigned len[2000];
    alt_u32 audiobuf[128]; //audio buffer
    alt_u32 audiostream[MAX_DATA]; //for audio storage
    unsigned index= 0;
    int ii,jj,NUM=0;


    // Switch 0 should be off for playback

    alt_up_audio_reset_audio_core(); //initiating the Audio Core

    while(1){

    if ((*Switch) & 0x01){ // if Switch 0 is on, read data in through
    microphone

    len[NUM] = alt_up_audio_read_left_channel(audiobuf,128); //array of
    lengths stored for playback

    if((index + len[NUM]) < MAX_DATA){ // check for data overflow
    for(ii = 0; ii < len[NUM]; ii++){
    audiostream[ii+index] = audiobuf[ii]; //saving all the data to an
    array for playback
    }

    index = index+len[NUM++];
    }
    }

    else if((*Switch) & 0x02){ // if Switch 2 is on, playback data to
    line-out

    index = 0;
    for (jj = 0; jj < NUM; jj++){
    alt_up_audio_write_left_channel(audiostream+index, len[jj]);
    alt_up_audio_write_right_channel(audiostream+index ,len[jj]);
    index=index+len[jj];
    }
    NUM = 0;
    }
    }
    }

  2. #2
    Join Date
    Dec 2006
    Posts
    48
    Rep Power
    1

    Default Re: C Programming with Audio IP Cores

    What kind of trouble are you in, recording or playback?

    One thing, if you are using NiosII/f with data cache, you can not get correct value of Switch because of data caching, I think. To bypass data cache, you have to define
    #define Switch ((volatile char *) (0x01001020 | 0x80000000))
    or read through IORD macro
    IORD(Switch,0) instead of (*Switch)

  3. #3
    Join Date
    Mar 2008
    Posts
    6
    Rep Power
    1

    Default Re: C Programming with Audio IP Cores

    Thanks, I figured it out though.
    It was because I was incrementing the value NUM within a statement:

    index = index+len[NUM++];

    So it was taking the next value, when instead I wanted the present value and the incrementation to happen after. I also changed the max values and the unsigned integers to regular integers.

    Seems to work now. This is what I have:

    #include <Z:\try3\app_software\include\alt_up_audio.h>
    #define Switch (volatile char *) 0x01001020
    #define MAX_DATA 480000

    int main()
    {
    int len[480000];
    alt_u32 audiobuf[128];
    alt_u32 audiostream[MAX_DATA];
    int index= 0;
    int ii,jj,NUM=0;


    // Switch 0 should be off for playback

    alt_up_audio_reset_audio_core();
    while(1)
    {
    if ((*Switch) & 0x01)
    {
    len[NUM] = alt_up_audio_read_left_channel(audiobuf,128);
    if((index + len[NUM]) < MAX_DATA) // chek for data overflow
    {
    for(ii = 0; ii < len[NUM]; ii++){
    audiostream[ii+index] = audiobuf[ii];
    }
    index = index+len[NUM];
    NUM=NUM+1;
    }
    }

    else if((*Switch) & 0x02)
    {
    index = 0;
    for (jj = 0; jj < NUM; jj++){

    alt_up_audio_write_left_channel(audiostream+index, len[jj]);
    alt_up_audio_write_right_channel(audiostream+index ,len[jj]);
    index=index+len[jj];
    }
    NUM = 0;
    index = 0;
    }
    }
    }

  4. #4
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    1

    Default Re: C Programming with Audio IP Cores

    Hi, I'm trying to do a similar program with Audio IP core but I am using the the latest University IP audio core ==> "altera_up_avalon_audio.h".

    The problem I am having is that before I execute my code on Nios, I connect my 3.55 mm audio cable from my PC to the MIC or LineIn port and I am able to listen from earphones what the PC's audio out is from the audio out of the board without executing the code on Nios. This occurs right after I compile and run the board. Does anyone have ideas?

    Also, I was wondering foleyme, what component you used to develop with just the normal "alt_up_audio.h".


    Thanks,

    Charlton

  5. #5
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    1

    Default Re: C Programming with Audio IP Cores

    Also, when plugging in a MP3 player and playing music into the MIC port, I am able to hear music from the LINE-OUT port.

    The main problem is that even after adding the audio components from the Audio IP cores to the Quartus hardware generated (Audio and Video Config Core, Audio Core and DE Board External Interface) and setting in the Audio Config to "Power Down Audio Chip", I am still able to hear music from the MP3 player.

    Is this supposed to be occuring or is there a mistake I am making in regard to the adding of my hardware components?

  6. #6
    Join Date
    Aug 2008
    Posts
    3
    Rep Power
    1

    Default Re: C Programming with Audio IP Cores

    I'm having the same problem as well, even when i configure it to avoid the bypass mode. Also, I can't enable the fifospace. When i try to write to the audio, the fifospace is always emptly.

    If anyone can help it would be great.

  7. #7
    Join Date
    Jul 2008
    Posts
    3
    Rep Power
    1

    Default Re: C Programming with Audio IP Cores

    Well I found out what the problem was and it was basically my stupidity. When building the hardware, not all the pins were connected so you may want to check to see if the PIN map is correct.

  8. #8
    Join Date
    Dec 2009
    Location
    Surat
    Posts
    9
    Rep Power
    1

    Default Re: C Programming with Audio IP Cores

    hi!
    i m working on talking mic input and store it in sdram...
    i m using Quartus 8.
    i m using the following components
    1.NIOS2 cpu
    2. SDRAM
    3. Audio Core
    4. Audio and Video Config Core...

    but on simply running the " hello world" software on this, it wudnt build...
    also if i use the sopc builder file given in the examples itself, it wud build in NIOS IDE, but on adding the audio core and audio and video and video config in SOPC builder and then trying to builder the "hello world" on it, it gives error...
    plz help!

Similar Threads

  1. Altera's new UP cores for 9.0 available
    By jrierab in forum University Program
    Replies: 0
    Last Post: June 12th, 2009, 05:35 AM
  2. C Programming with Audio IP Cores
    By foleyme in forum IP Discussion
    Replies: 1
    Last Post: April 18th, 2008, 01:39 AM
  3. PIO cores
    By mendonca in forum General Discussion Forum
    Replies: 8
    Last Post: February 1st, 2007, 01:46 AM
  4. Univeristy IP cores
    By wenninra in forum General Discussion Forum
    Replies: 5
    Last Post: January 18th, 2007, 02:36 PM
  5. opencores.org usb cores
    By smcnutt in forum General Discussion Forum
    Replies: 3
    Last Post: March 9th, 2005, 05:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •