- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I created a simple project with Nios II. In this project, I wrote a text file into an SD card successfully. Now, I must read data of a wav file (amplitude of a sound source) to process. I also search in the internet but I can't find out the way to read a wav file to an array. Please help me to read a wav file in an SD card in a Nios system. Thank you in advance!Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Mods,
I'm sorry when I posted this thread here. Would you please move this thread to "General Software Forum". I think there will be more suitable than here. Thank you!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
That may sound opportunistic, but can you please upload your simple project code ? I'm currently struggling to write / read a file from the SD card. As for your wav file, maybe you can convert it into a .dat file to read it easily ?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The sd card audio player Demo project available with most of the Altera DE boards has all the functions that you need to read a wav file from SD card.
If you don't have it, then maybe you can download the CD from Terasic website http://www.terasic.com.tw/cgi-bin/page/archive.pl?language=english&categoryno=139&no=502&partno=4- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hmm.. can u send your full write/read program on SD Card. Because now, im stuck in build the read instruction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- hmm.. can u send your full write/read program on SD Card. Because now, im stuck in build the read instruction --- Quote End --- we too has the same problem.. how to read the .wav file in sd card in the de2 115 board .. pls help or complete code :(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess we all have the same problem xD! if someone can do it with DE2-115 (read/write data with SD card or RS232 or even displayin using VGA )) pleaaase help xD! very urgent :s, let me a message at ch_natasha@hotmail.fr thanx !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is my program:
# include <stdio.h>#include <math.h># include <altera_up_sd_card_avalon_interface.h># include "functions.h"
//#include <time.h>
# define Pushbuttons ((volatile long *) 0x1011410)
short int sd_fileh;
int main()
{
// clock_t tic, toc;
// float run_time;
printf("Running...press the button to begin\n");
int N_samples = 256, NumChannels = 0, sampleRate = 0;
int i,j;
while(1)
{
long PBval;
*Pushbuttons = 0; //clear out any changes so far
PBval = *Pushbuttons;
// printf("not be pushed %ld\n",PBval);
while (1)
{
PBval = *Pushbuttons;
if (PBval == 0)
break;
}
// printf("pushed %ld\n",PBval);
// short int temp;
// signed int *temp2;
float data;
// double number;
int count;
// int n;
// These variables are used
// when wanting to display the header of the wav file
long int long_total;
short int byte1, byte2, byte3, byte4;
signed int total;
printf("Accessing SD Card ...\n");
alt_up_sd_card_dev *sd_card_dev = alt_up_sd_card_open_dev(SDCARD_NAME);
if(sd_card_dev != 0)
{
if(alt_up_sd_card_is_Present())
{
if(alt_up_sd_card_is_FAT16())
printf("Card is FAT16\n");
else
printf("Card is not FAT16\n");
// sd_fileh = alt_up_sd_card_fopen("testfile.txt", true);
sd_fileh = alt_up_sd_card_fopen("TESTSIG4.WAV", false);
if (sd_fileh < 0)
printf("Problem reading file. Error %i", sd_fileh);
else // open the file
{
printf("Reading file...\n");
// // Jump over the header of the wav file
// count = 0;
// while (count < 44) // 44-byte header
// {
// alt_up_sd_card_read(sd_fileh);
// count++;
// }
// Get information of number of channels
count = 0;
while (count < 22) // 44-byte header
{
alt_up_sd_card_read(sd_fileh);
count++;
}
// printf("NumChannels ");
byte1 = 0;byte2 = 0;total = 0;
byte1 = alt_up_sd_card_read(sd_fileh);
byte2 = alt_up_sd_card_read(sd_fileh);
total = (byte1 & 0x00ff) | (byte2 << 8);
NumChannels = total;
// printf("%d\n",total);
// printf("SampleRate ");
byte1 = 0;byte2 = 0;byte3 = 0;byte4 = 0;long_total = 0;
byte1 = alt_up_sd_card_read(sd_fileh);
byte2 = alt_up_sd_card_read(sd_fileh);
byte3 = alt_up_sd_card_read(sd_fileh);
byte4 = alt_up_sd_card_read(sd_fileh);
long_total = (byte4 << 24) | (byte3 << 16) | (byte2 << 8) | ( byte1 & 0x000000ff);
sampleRate = long_total;
// printf("%ld\n",long_total);
count = 0;
while (count < 16) // 44-byte header
{
alt_up_sd_card_read(sd_fileh);
count++;
}....
You should know the structure of a wav file. You read the header of wav file first and then you have to continue reading its data two bytes by two bytes. Hope this will be able to help you.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page