Fez domino + mp3shield read from sd and no audio out problem


static void playFile()
        {
            FEZ_Shields.MP3.Initialize();
            FEZ_Shields.MP3.SetVolume(200, 200);
            int blockSize = 1024;
            int offset = 0;
            byte[] data = new byte[blockSize];
            FileStream fs = new FileStream("\\SD\\sample.mp3", FileMode.Open, FileAccess.Read);
            fs.Seek(offset, SeekOrigin.Begin);


            int size = (int)fs.Length - (int)fs.Length % blockSize;
            while (offset < fs.Length)
            {
                fs.Seek(offset, SeekOrigin.Current);
                fs.Read(data, 0, blockSize);
                FEZ_Shields.MP3.SendData(data);
                Debug.Print(data[0].ToString());
                offset += blockSize ;
            }
            fs.Close();
            fs.Dispose();
            fs = null;

        }

i am using fez domino and mp3-shield … i am getting list of files without any problem.
filestream opens the file and shows correct size…
i cant get any audio out…
when i start debugging… at the offset 7075 , the data readed from filestream becomes 0…
also i tried lower blocksize like 32, 64, 128, 256 etc…
where is the problem?

[quote]FEZ_Shields.MP3.SetVolume(200, 200);
[/quote]

I think the highest volume is (0,0)

joe can you give a simple example that reads from sd card and plays on mp3 shield?
still i cant get any success…
i need your help…
there is no document about reading and sending to mp3 shield…

the sample provided in code library gives memory exception error…
so i need a working simple example…

It should be simple. You only need to read chuncks of the file and feed it to the MP3 decoder.

Did you test using this example first?
[url]http://code.tinyclr.com/project/54/mp3-shield/[/url]
here is the mp3 file:
[url]http://www.ghielectronics.com/downloads/FEZ/Extension/FEZ_Monkey.mp3[/url]

Finally i get it working! :slight_smile:

_DREQ = new InputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false, Port.ResistorMode.PullUp);

this did not worked on many time…

then i used

_DREQ = new InputPort((Cpu.Pin)FEZ_Pin.Digital.An1, false, Port.ResistorMode.PullUp);

suddenly it get strange/distorted sound! :slight_smile: then i returned to

_DREQ = new InputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false, Port.ResistorMode.PullUp);

i started to get correct sound…
but the thread.sleep(1) made stops on output audio randomly…
i removed it from shield driver…

here is the code i used to get sound from file :


        static void playFile()
        {
            int blockSize = 32 ;
            int offset = 0;
            byte[] data = new byte[blockSize];
            FileStream fs = new FileStream("\\SD\\test.mp3", FileMode.Open, FileAccess.Read);
            fs.Seek(offset, SeekOrigin.Begin);

            int bytesRead = 0;
            while((bytesRead = fs.Read(data, 0, blockSize)) != 0)
            {
              
                FEZ_Shields.MP3.SendData(data);
            }
            fs.Close();
            fs.Dispose();
            fs = null;

        }


but now i have 4 new problem :))
1- how can i get audio duration
2- how can i get current position
3- how can i detect silence
4- how can i get volume level of output

why i need those:

  • i want to play next file before last 5 seconds of the current playing file (is it possible to mix files?)
  • if i get silence 1-2 seconds, i want to play next file
  • i want to get max output volume level, so i will normalize or decrease/increase current volume…

do you have any idea?

In general:

  1. Get info from file (refer to file format spec)
  2. Keep track of samples played to total number of samples (refer to file format spec)
  3. Check individual samples
  4. Keep track of what it was set to.

Check the audio processor IC datasheet. Most likely some of the above are implemented on chip and you just need to add it to your managed driver.

For all those, you need to analyse the complete file. For the lenght you don’t need to decode the audio data but you can just read the header of each frame in the mp3. This is doable, I remember I once wrote this in C++.

For the normalizing you need to decode the audio data, stay away from this :slight_smile:

You could write a desktop application that determines the avg level of each file.

Why not normalize the files before you put them on the device?

i have 400.000 files on my servers, i have a legal music distribution company for public areas.
i got my own music repositories. i will download the playlist for device,then it will download each file regarding to playlist… it will play files according to dates, times, days etc based on playlist…
by the way, i have desktop applications running and downloading files to pcs. so they have the file sizes etc… my players runs on 1.000 different location… i cant change any file’s normalization etc…
each day new files are coming to our servers… i can’t do it…
so it is impossible to normalize the files before putting them to device :))

i need to get current volume level from current stream… will i check the current array or can mp3-shield give volume level from any pin?

I would let the servers scan each new file for avg level, length and silence position. Then the players can request this information from the online service.

Or write your own mp3 decoder, but then you’ll need a faster processor I guess.

i think i got the solution…
for the duration , bitrate etc… i wrote my id3v1 and id3v2 tag and full mp3 header reading class …

the vs1053 has Replay Gain feature for volume normalization… i have to find how to use it…

for the silence detection, i will check each 128 byte average data while playing…
if the silence average is under threshold in 1000 ms , then i will understand that there is a silence…

currently i am using connect-shield, mp3-shield, fez domino (also i have fez panda II) , 3 leds…

yesterday i noted a interesting thing on connect shield… i put a led on Di3 SCI port of connect shield…
while music is playing, the led starts blinking according to audio…
so there must be a way to get the volume level or if sound is present from mp3-shield…

Dont ask me how it works, but there is a patch for the vs1053 in VLSI’s site that you can load into the vs1053 to add functionality. The main thing that this patch adds that will help you is a stereo VU meter. :slight_smile:

:))) errol thank you bro…
you are telling me what i want but not telling how it works… :slight_smile:
did you used it before? and how? :))))

Never used it before. I think I ordered a chip from Sparkfun long time ago, but never placed it on a board… :frowning:

http://www.vlsi.fi/en/support/software/vs10xxpatches.html

Look at the PDF for the patch. Apparently they give you a block of code that you must download into the vs1053. They tell you how at the bottom of the PDF.

After that there is an extra register that you can read to get the VU…

[quote]VU Meter
SCI STATUS bit 9 enables VU meter, which calculates the peak sample value from both
channels and returns the values in 3 dB resolution through SCI AICTRL3. The high 8
bits represent the left channel, the low 8 bits the right channel.
Values from 0 to 31 are valid for both channels.
The VU meter takes about 0.2MHz of processing power with 48 kHz samplerate.[/quote]

patch document says like this…
how to enable sci status bit 9?
and how to get data from sci aictrl3? :slight_smile:
does anyone has any suggestion?

Look at the Reset() method of the shield driver. It sets/enables SM_RESET (3) bit of the SCI_MODE register.
You have to do something similar for the register where SCI STATUS bit 9 is located.