Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12409 Discussions

Changing the play back rate of a buffer in C?

Honored Contributor II



I am using an Altera DE2 FPGA board and running Quartus II, Nios II (V10.1). I loaded the Terasic V1.6 demo "DE2_SD_Card_Audio." 

Currently, I can play a .wav file from the SD card to the Line Out. Ignoring all the other details, the C code (hello_led.c) from the demo that outputs to Line Out is: 


UINT16 Tmp1=0; 


Tmp1=(Buffer[i+1]<<8)|Buffer[i]; //loads the data from the SD card to Tmp1  

//change the buffer rate? 

IOWR(AUDIO_BASE, 0, Tmp1); //sends Tmp1 data to Line Out 


If I were to print Tmp1, it's basically the points on a sine wave. What I want to do now is fiddle with how the sound plays by changing the play back rate (ideally I want to play the sound up or down an octave, which is just double or half the frequency). Can anyone provide some suggestions on how I can do this in the section: 


//change the buffer rate? 


Is it possible in C to write a few lines of code in that section to obtain what I'm looking for? ie. change how fast I'm reading from the Tmp1 buffer to the AUDIO_BASE. 


Thanks in advance! 

0 Kudos
1 Reply
Honored Contributor II

Here are some options 

-simple software delay loop 

-timer interrupt with a variable interrupt frequency based upon how fast you want to set the DAC 

-Software writes samples to a FIFO and statemachine, which writes data out to a DAC at a particular output rate specified by the software